YotogiOldSkillIcon.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using UnityEngine;
  3. using Yotogis;
  4. public class YotogiOldSkillIcon : MonoBehaviour
  5. {
  6. public void Awake()
  7. {
  8. this.ui2d_sprite_ = base.GetComponent<UI2DSprite>();
  9. this.box_collider_ = base.GetComponent<BoxCollider>();
  10. NDebug.AssertNull(this.ui2d_sprite_);
  11. }
  12. public void OnDestroy()
  13. {
  14. if (this.ui2d_sprite_.sprite2D != null && this.ui2d_sprite_.sprite2D.texture != null)
  15. {
  16. UnityEngine.Object.DestroyImmediate(this.ui2d_sprite_.sprite2D.texture);
  17. }
  18. }
  19. public void SetSkillData(Skill.Old.Data skill_data)
  20. {
  21. this.skill_data_ = skill_data;
  22. if (this.skill_data_ == null)
  23. {
  24. if (this.ui2d_sprite_.sprite2D != null && this.ui2d_sprite_.sprite2D.texture != null)
  25. {
  26. UnityEngine.Object.DestroyImmediate(this.ui2d_sprite_.sprite2D.texture);
  27. }
  28. this.ui2d_sprite_.sprite2D = null;
  29. }
  30. else
  31. {
  32. this.LoadImage(this.skill_data_.icon_file_name);
  33. }
  34. }
  35. public void LoadImage(string file_name)
  36. {
  37. file_name += ".tex";
  38. if (!GameUty.FileSystemOld.IsExistentFile(file_name))
  39. {
  40. file_name = "icon_none.tex";
  41. }
  42. this.tex_ = ImportCM.CreateTexture(file_name);
  43. Sprite sprite = Sprite.Create(this.tex_, new Rect(0f, 0f, (float)this.tex_.width, (float)this.tex_.height), default(Vector2));
  44. sprite.name = file_name;
  45. if (this.ui2d_sprite_.sprite2D != null && this.ui2d_sprite_.sprite2D.texture != null)
  46. {
  47. UnityEngine.Object.DestroyImmediate(this.ui2d_sprite_.sprite2D.texture);
  48. }
  49. this.ui2d_sprite_.sprite2D = sprite;
  50. this.ui2d_sprite_.SetDimensions(this.IconSize, this.IconSize);
  51. if (this.box_collider_ != null && this.AutoColliderChange)
  52. {
  53. this.box_collider_.size = new Vector3((float)this.IconSize, (float)this.IconSize, 1f);
  54. }
  55. }
  56. public void SetOnClickEvent(YotogiOldSkillIcon.OnClickEvent set_event)
  57. {
  58. UIButton component = base.GetComponent<UIButton>();
  59. if (component == null || set_event == null)
  60. {
  61. return;
  62. }
  63. this.on_click_event_ = set_event;
  64. EventDelegate eventDelegate = new EventDelegate(this, "OnClickButtonCallBack");
  65. EventDelegate.Parameter parameter = eventDelegate.parameters[0];
  66. parameter.obj = base.gameObject;
  67. EventDelegate.Add(component.onClick, eventDelegate);
  68. }
  69. public Skill.Old.Data skill_data
  70. {
  71. get
  72. {
  73. return this.skill_data;
  74. }
  75. }
  76. private void OnClickButtonCallBack(GameObject my)
  77. {
  78. if (this.on_click_event_ != null)
  79. {
  80. this.on_click_event_(my, my.GetComponent<YotogiOldSkillIcon>());
  81. }
  82. }
  83. public int IconSize = 80;
  84. public bool AutoColliderChange = true;
  85. private UI2DSprite ui2d_sprite_;
  86. private BoxCollider box_collider_;
  87. private Texture2D tex_;
  88. private Skill.Old.Data skill_data_;
  89. private YotogiOldSkillIcon.OnClickEvent on_click_event_;
  90. public delegate void OnClickEvent(GameObject my, YotogiOldSkillIcon click_obj);
  91. }