架构大更
This commit is contained in:
@@ -6,12 +6,6 @@ namespace Michsky.MUIP
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class AnimatedIconHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
[Header("Settings")]
|
||||
public PlayType playType;
|
||||
public Animator iconAnimator;
|
||||
|
||||
bool isClicked;
|
||||
|
||||
public enum PlayType
|
||||
{
|
||||
Click,
|
||||
@@ -19,21 +13,18 @@ namespace Michsky.MUIP
|
||||
None
|
||||
}
|
||||
|
||||
void Start()
|
||||
[Header("Settings")] public PlayType playType;
|
||||
|
||||
public Animator iconAnimator;
|
||||
|
||||
private bool isClicked;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (iconAnimator == null)
|
||||
iconAnimator = gameObject.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
public void PlayIn() { iconAnimator.Play("In"); }
|
||||
public void PlayOut() { iconAnimator.Play("Out"); }
|
||||
|
||||
public void ClickEvent()
|
||||
{
|
||||
if (isClicked == true) { PlayOut(); isClicked = false; }
|
||||
else { PlayIn(); isClicked = true; }
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (playType == PlayType.Click)
|
||||
@@ -51,5 +42,29 @@ namespace Michsky.MUIP
|
||||
if (playType == PlayType.Hover)
|
||||
iconAnimator.Play("Out");
|
||||
}
|
||||
|
||||
public void PlayIn()
|
||||
{
|
||||
iconAnimator.Play("In");
|
||||
}
|
||||
|
||||
public void PlayOut()
|
||||
{
|
||||
iconAnimator.Play("Out");
|
||||
}
|
||||
|
||||
public void ClickEvent()
|
||||
{
|
||||
if (isClicked)
|
||||
{
|
||||
PlayOut();
|
||||
isClicked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayIn();
|
||||
isClicked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,81 +16,88 @@ namespace Michsky.MUIP
|
||||
public string selectedIconID;
|
||||
public int selectedIconIndex;
|
||||
[Range(0, 3)] public int spriteSize;
|
||||
|
||||
Image imageObject;
|
||||
[HideInInspector] public string currentSize;
|
||||
[HideInInspector] public bool size32;
|
||||
[HideInInspector] public bool size64;
|
||||
[HideInInspector] public bool size128;
|
||||
[HideInInspector] public bool size256;
|
||||
|
||||
void Awake()
|
||||
private Image imageObject;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (iconLibrary == null) { iconLibrary = Resources.Load<IconLibrary>("Icon Library"); }
|
||||
if (imageObject == null) { imageObject = gameObject.GetComponent<Image>(); }
|
||||
if (iconLibrary == null) iconLibrary = Resources.Load<IconLibrary>("Icon Library");
|
||||
if (imageObject == null) imageObject = gameObject.GetComponent<Image>();
|
||||
|
||||
this.enabled = true;
|
||||
enabled = true;
|
||||
UpdateElement();
|
||||
}
|
||||
|
||||
catch { Debug.LogWarning("<b>Icon Library</b> is missing, but it should be assigned.", this); }
|
||||
catch
|
||||
{
|
||||
Debug.LogWarning("<b>Icon Library</b> is missing, but it should be assigned.", this);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
if (iconLibrary.alwaysUpdate == true) { UpdateElement(); }
|
||||
if (Application.isPlaying == true && iconLibrary.optimizeUpdates == true) { this.enabled = false; }
|
||||
if (iconLibrary.alwaysUpdate) UpdateElement();
|
||||
if (Application.isPlaying && iconLibrary.optimizeUpdates) enabled = false;
|
||||
}
|
||||
|
||||
public void UpdateElement()
|
||||
{
|
||||
if (iconLibrary == null)
|
||||
{
|
||||
this.enabled = false;
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < iconLibrary.icons.Count; i++)
|
||||
{
|
||||
if (selectedIconID == iconLibrary.icons[i].iconTitle && gameObject.activeInHierarchy == true)
|
||||
for (var i = 0; i < iconLibrary.icons.Count; i++)
|
||||
if (selectedIconID == iconLibrary.icons[i].iconTitle && gameObject.activeInHierarchy)
|
||||
{
|
||||
if (spriteSize == 0) { imageObject.sprite = iconLibrary.icons[i].iconSprite32; }
|
||||
else if (spriteSize == 1) { imageObject.sprite = iconLibrary.icons[i].iconSprite64; }
|
||||
else if (spriteSize == 2) { imageObject.sprite = iconLibrary.icons[i].iconSprite128; }
|
||||
else if (spriteSize == 3) { imageObject.sprite = iconLibrary.icons[i].iconSprite256; }
|
||||
if (spriteSize == 0)
|
||||
imageObject.sprite = iconLibrary.icons[i].iconSprite32;
|
||||
else if (spriteSize == 1)
|
||||
imageObject.sprite = iconLibrary.icons[i].iconSprite64;
|
||||
else if (spriteSize == 2)
|
||||
imageObject.sprite = iconLibrary.icons[i].iconSprite128;
|
||||
else if (spriteSize == 3) imageObject.sprite = iconLibrary.icons[i].iconSprite256;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (iconLibrary.alwaysUpdate == false)
|
||||
this.enabled = false;
|
||||
if (!iconLibrary.alwaysUpdate)
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public void UpdateSpriteSize(int spriteIndex, int newSize)
|
||||
{
|
||||
if (newSize == 0) { imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite32; }
|
||||
else if (newSize == 1) { imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite64; }
|
||||
else if (newSize == 2) { imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite128; }
|
||||
else if (newSize == 3) { imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite256; }
|
||||
if (newSize == 0)
|
||||
imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite32;
|
||||
else if (newSize == 1)
|
||||
imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite64;
|
||||
else if (newSize == 2)
|
||||
imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite128;
|
||||
else if (newSize == 3) imageObject.sprite = iconLibrary.icons[spriteIndex].iconSprite256;
|
||||
}
|
||||
|
||||
public void ChangeIcon(string newSprite, int preferredSize)
|
||||
{
|
||||
int selectedSpriteIndex = -1;
|
||||
var selectedSpriteIndex = -1;
|
||||
|
||||
for (int i = 0; i < iconLibrary.icons.Count; i++)
|
||||
{
|
||||
for (var i = 0; i < iconLibrary.icons.Count; i++)
|
||||
if (newSprite == iconLibrary.icons[i].iconTitle)
|
||||
{
|
||||
selectedSpriteIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedSpriteIndex != -1) { UpdateSpriteSize(selectedSpriteIndex, preferredSize); }
|
||||
else { Debug.Log("<b>[Icon Manager]</b> Cannot find an icon named '" + newSprite + "'"); }
|
||||
if (selectedSpriteIndex != -1)
|
||||
UpdateSpriteSize(selectedSpriteIndex, preferredSize);
|
||||
else
|
||||
Debug.Log("<b>[Icon Manager]</b> Cannot find an icon named '" + newSprite + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user