Files
Ultimate-Fishing-Simulator-…/Assets/Scripts/Assembly-CSharp/Michsky/UI/MTP/ImageItem.cs
2026-03-04 09:37:33 +08:00

121 lines
2.5 KiB
C#

using UnityEngine;
using UnityEngine.UI;
namespace Michsky.UI.MTP
{
[RequireComponent(typeof(Image))]
public class ImageItem : MonoBehaviour
{
[Header("Resources")]
public string itemID = "Item ID";
public StyleManager styleManager;
public Image imageObject;
public UIGradient gradientComponent;
[Header("Color Settings")]
public bool preferGradient;
public Color imageColor = new Color(255f, 255f, 255f, 255f);
public Gradient imageGradient;
[Header("Thickness Settings")]
public bool enableThickness;
public bool isHorizontal = true;
[Range(1f, 50f)]
public float thickness;
[Header("Twin Settings")]
public bool isIdentical;
public bool updateSubTwins;
public ImageItem twinObject;
private void Start()
{
if (imageObject == null)
{
imageObject = base.gameObject.GetComponent<Image>();
}
if (styleManager != null && styleManager.forceUpdate)
{
UpdateAll();
}
}
public void UpdateAll()
{
UpdateSprite();
UpdateColor();
if (isIdentical && updateSubTwins)
{
twinObject.UpdateAll();
}
}
public void UpdateSprite()
{
if (!enableThickness)
{
return;
}
if (isHorizontal)
{
imageObject.rectTransform.sizeDelta = new Vector2(thickness, imageObject.rectTransform.sizeDelta.y);
if (isIdentical)
{
twinObject.thickness = thickness;
}
}
else
{
imageObject.rectTransform.sizeDelta = new Vector2(imageObject.rectTransform.sizeDelta.x, thickness);
if (isIdentical)
{
twinObject.thickness = thickness;
}
}
}
public void UpdateColor()
{
if (!preferGradient)
{
imageObject.color = imageColor;
if (gradientComponent != null)
{
gradientComponent.enabled = false;
}
if (isIdentical && twinObject != null)
{
twinObject.preferGradient = false;
twinObject.imageColor = imageColor;
if (twinObject.gradientComponent != null)
{
twinObject.gradientComponent.enabled = false;
}
}
}
else if (preferGradient && gradientComponent != null)
{
imageObject.color = new Color(255f, 255f, 255f, 255f);
gradientComponent.enabled = true;
gradientComponent.EffectGradient = imageGradient;
if (isIdentical && twinObject != null)
{
twinObject.preferGradient = true;
twinObject.imageObject.color = new Color(255f, 255f, 255f, 255f);
twinObject.gradientComponent.enabled = true;
twinObject.imageGradient = imageGradient;
}
}
}
}
}