OnaholeNodeIconButton.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using UnityEngine;
  3. public class OnaholeNodeIconButton : MonoBehaviour, IOnaholeNodeButton
  4. {
  5. public string uniqueName { get; set; }
  6. public OnaholeNodeButton.SelectType selectType
  7. {
  8. get
  9. {
  10. return this.selectType_;
  11. }
  12. set
  13. {
  14. this.selectType_ = value;
  15. if (value == OnaholeNodeButton.SelectType.None)
  16. {
  17. this.bg.alpha = this.defaultBGAlpha;
  18. }
  19. else if (value == OnaholeNodeButton.SelectType.Focus)
  20. {
  21. this.bg.alpha = 1f;
  22. }
  23. else if (value == OnaholeNodeButton.SelectType.Select)
  24. {
  25. this.bg.alpha = 1f;
  26. }
  27. else if (value == OnaholeNodeButton.SelectType.Disable)
  28. {
  29. this.bg.alpha = 0.2f;
  30. }
  31. }
  32. }
  33. private void Awake()
  34. {
  35. this.defaultBGAlpha = this.bg.alpha;
  36. this.selectType = OnaholeNodeButton.SelectType.None;
  37. this.SetCopyTargetSprite(this.copyTargetSprite);
  38. }
  39. public void SetCopyTargetSprite(UISprite sprite)
  40. {
  41. if (sprite == null || this.iconSprite == null)
  42. {
  43. return;
  44. }
  45. this.copyTargetSprite = sprite;
  46. this.iconSprite.atlas = this.copyTargetSprite.atlas;
  47. this.iconSprite.spriteName = this.copyTargetSprite.spriteName;
  48. this.iconSprite.SetDimensions(this.copyTargetSprite.width, this.copyTargetSprite.height);
  49. this.iconSprite.SetDirty();
  50. this.Update();
  51. }
  52. private void Update()
  53. {
  54. if (this.iconSprite != null && this.copyTargetSprite != null)
  55. {
  56. this.iconSprite.color = this.copyTargetSprite.color;
  57. }
  58. }
  59. GameObject IOnaholeNodeButton.get_gameObject()
  60. {
  61. return base.gameObject;
  62. }
  63. [SerializeField]
  64. private UIWidget bg;
  65. [SerializeField]
  66. private UISprite iconSprite;
  67. [SerializeField]
  68. private UISprite copyTargetSprite;
  69. private float defaultBGAlpha;
  70. private OnaholeNodeButton.SelectType selectType_;
  71. }