PresetSaveWindow.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. namespace SceneEditWindow
  6. {
  7. [AddComponentMenu("SceneEditWindow/PresetSaveWindow")]
  8. public class PresetSaveWindow : BasePhotoWindow
  9. {
  10. public override string windowName
  11. {
  12. get
  13. {
  14. return "PresetSaveIconWindow";
  15. }
  16. }
  17. public override void Awake()
  18. {
  19. base.Awake();
  20. for (int i = 0; i < PresetSaveWindow.IconTexFileNames.Length; i++)
  21. {
  22. UIWFTabButton uiwftabButton = this.CreateItemObject(this.itemGrit.gameObject, PresetSaveWindow.IconTexFileNames[i]);
  23. uiwftabButton.name = i.ToString();
  24. EventDelegate.Add(uiwftabButton.onClick, delegate
  25. {
  26. this.OnClickItem((PresetSaveWindow.SaveType)int.Parse(UIButton.current.name));
  27. });
  28. }
  29. this.UpdateChildren();
  30. }
  31. protected virtual void OnDestroy()
  32. {
  33. foreach (KeyValuePair<string, Texture> keyValuePair in this.texDic)
  34. {
  35. UnityEngine.Object.DestroyImmediate(keyValuePair.Value);
  36. }
  37. this.texDic.Clear();
  38. }
  39. protected void OnClickItem(PresetSaveWindow.SaveType type)
  40. {
  41. if (this.onClickPresetSaveEvent != null)
  42. {
  43. this.onClickPresetSaveEvent(type);
  44. }
  45. }
  46. protected UIWFTabButton CreateItemObject(GameObject parent, string textFileName)
  47. {
  48. GameObject gameObject = Utility.CreatePrefab(parent, "SceneEdit/WindowParts/PoseIconItem", true);
  49. if (!this.texDic.ContainsKey(textFileName))
  50. {
  51. this.texDic.Add(textFileName, ImportCM.CreateTexture(textFileName));
  52. }
  53. UITexture component = gameObject.GetComponent<UITexture>();
  54. component.mainTexture = this.texDic[textFileName];
  55. return gameObject.GetComponent<UIWFTabButton>();
  56. }
  57. public static readonly string[] IconTexFileNames = new string[]
  58. {
  59. "cm3d2_edit_priset_buttom_clothes_body.tex",
  60. "cm3d2_edit_priset_buttom_clothes.tex",
  61. "cm3d2_edit_preset_buttom_body.tex"
  62. };
  63. [SerializeField]
  64. public SceneEdit sceneEdit;
  65. [SerializeField]
  66. private UIGrid itemGrit;
  67. public Action<PresetSaveWindow.SaveType> onClickPresetSaveEvent;
  68. private Dictionary<string, Texture> texDic = new Dictionary<string, Texture>();
  69. public enum SaveType
  70. {
  71. All,
  72. ClothesOnly,
  73. BodyOnly
  74. }
  75. }
  76. }