PresetCtrl.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class PresetCtrl : MonoBehaviour
  6. {
  7. public void Init(GameObject goPresetPanel, Maid maid)
  8. {
  9. this.m_goPresetPanel = goPresetPanel;
  10. this.m_maid = maid;
  11. this.m_goPresetParent = UTY.GetChildObject(this.m_goPresetPanel, "PresetViewer/Contents/PresetUnitParent", false);
  12. GameObject childObject = UTY.GetChildObject(this.m_goPresetPanel, "PresetViewer", false);
  13. this.m_presetScrollView = UTY.GetChildObject(childObject, "Contents", false).GetComponent<UIScrollView>();
  14. this.m_presetScrollBar = UTY.GetChildObject(childObject, "Scroll Bar", false).GetComponent<UIScrollBar>();
  15. this.m_listBtnState = new Dictionary<PresetMgr.Filter, PresetCtrl.FilterButton>();
  16. bool flag = false;
  17. IEnumerator enumerator = Enum.GetValues(typeof(PresetMgr.Filter)).GetEnumerator();
  18. try
  19. {
  20. while (enumerator.MoveNext())
  21. {
  22. object obj = enumerator.Current;
  23. PresetMgr.Filter filter = (PresetMgr.Filter)obj;
  24. if (filter != PresetMgr.Filter.None)
  25. {
  26. UIButton component = UTY.GetChildObject(this.m_goPresetPanel, "FilterButtons/" + filter, false).GetComponent<UIButton>();
  27. if (!flag)
  28. {
  29. this.activeColor = new Color(component.defaultColor.r, component.defaultColor.g, component.defaultColor.b, 1f);
  30. this.inActiveColor = component.defaultColor;
  31. flag = true;
  32. }
  33. GameObject childObject2 = UTY.GetChildObject(this.m_goPresetPanel, "FilterButtons/" + filter + "/SelectCursor", false);
  34. childObject2.SetActive(false);
  35. PresetCtrl.FilterButton filterButton = new PresetCtrl.FilterButton();
  36. filterButton.m_name = filter;
  37. filterButton.m_btnButton = component;
  38. filterButton.m_goSelectCursor = childObject2;
  39. this.m_listBtnState.Add(filterButton.m_name, filterButton);
  40. }
  41. }
  42. }
  43. finally
  44. {
  45. IDisposable disposable;
  46. if ((disposable = (enumerator as IDisposable)) != null)
  47. {
  48. disposable.Dispose();
  49. }
  50. }
  51. }
  52. public void CreatePresetList(List<CharacterMgr.Preset> listPreset)
  53. {
  54. if (listPreset == null)
  55. {
  56. return;
  57. }
  58. if (this.m_presetPrefab == null)
  59. {
  60. this.m_presetPrefab = Resources.Load("SceneEdit/Preset/Prefabs/PresetUnit");
  61. if (this.m_presetPrefab == null)
  62. {
  63. Debug.LogError(string.Format("ロードされるプレハブが見つかりませんでした。パス={0}", "SceneEdit/Preset/Prefabs/PresetUnit"));
  64. return;
  65. }
  66. }
  67. this.ClearExistPreset(this.m_goPresetParent);
  68. this.m_dicPresetButton = new Dictionary<string, PresetCtrl.PresetButton>();
  69. foreach (CharacterMgr.Preset preset in listPreset)
  70. {
  71. GameObject gameObject = UnityEngine.Object.Instantiate(this.m_presetPrefab) as GameObject;
  72. gameObject.transform.parent = this.m_goPresetParent.transform;
  73. gameObject.transform.localScale = Vector3.one;
  74. gameObject.transform.localPosition = Vector3.zero;
  75. gameObject.transform.rotation = Quaternion.identity;
  76. UITexture component = gameObject.GetComponent<UITexture>();
  77. component.mainTexture = preset.texThum;
  78. GameObject childObject = UTY.GetChildObject(gameObject, "TypeIcon", false);
  79. UISprite component2 = childObject.GetComponent<UISprite>();
  80. CharacterMgr.PresetType ePreType = preset.ePreType;
  81. if (ePreType != CharacterMgr.PresetType.All)
  82. {
  83. if (ePreType != CharacterMgr.PresetType.Wear)
  84. {
  85. if (ePreType == CharacterMgr.PresetType.Body)
  86. {
  87. component2.spriteName = "cm3d2_edit_priset_kindicon_body";
  88. }
  89. }
  90. else
  91. {
  92. component2.spriteName = "cm3d2_edit_priset_kindicon_clothes";
  93. }
  94. }
  95. else
  96. {
  97. component2.spriteName = "cm3d2_edit_priset_kindicon_clothes_body";
  98. }
  99. gameObject.name = preset.strFileName;
  100. UIButton component3 = gameObject.GetComponent<UIButton>();
  101. EventDelegate.Add(component3.onClick, new EventDelegate.Callback(BaseMgr<PresetMgr>.Instance.ClickPreset));
  102. PresetCtrl.PresetButton presetButton = new PresetCtrl.PresetButton();
  103. presetButton.id = gameObject.name;
  104. presetButton.presetButton = gameObject;
  105. presetButton.preset = preset;
  106. presetButton.typeIcon = childObject;
  107. this.m_dicPresetButton.Add(presetButton.id, presetButton);
  108. }
  109. this.AdjustTargetPosition(this.m_goPresetParent, this.m_presetScrollView);
  110. }
  111. private void AdjustTargetPosition(GameObject go, UIScrollView scrollView)
  112. {
  113. go.GetComponent<UITable>().Reposition();
  114. scrollView.ResetPosition();
  115. }
  116. private void ClearExistPreset(GameObject parent)
  117. {
  118. IEnumerator enumerator = parent.transform.GetEnumerator();
  119. try
  120. {
  121. while (enumerator.MoveNext())
  122. {
  123. object obj = enumerator.Current;
  124. Transform transform = (Transform)obj;
  125. UnityEngine.Object.Destroy(transform.gameObject);
  126. }
  127. }
  128. finally
  129. {
  130. IDisposable disposable;
  131. if ((disposable = (enumerator as IDisposable)) != null)
  132. {
  133. disposable.Dispose();
  134. }
  135. }
  136. parent.transform.DetachChildren();
  137. }
  138. public void FilterPreset(PresetMgr.Filter clickBtnName, PresetMgr.Filter currentActiveFilterBtnName)
  139. {
  140. this.FilterPreset(clickBtnName, currentActiveFilterBtnName, true);
  141. }
  142. public void FilterPreset(PresetMgr.Filter clickBtnName, PresetMgr.Filter currentActiveFilterBtnName, bool setBtnActive)
  143. {
  144. if (setBtnActive)
  145. {
  146. this.SetFilterButtonActive(clickBtnName, currentActiveFilterBtnName);
  147. }
  148. foreach (KeyValuePair<string, PresetCtrl.PresetButton> keyValuePair in this.m_dicPresetButton)
  149. {
  150. CharacterMgr.Preset preset = keyValuePair.Value.preset;
  151. if (clickBtnName == PresetMgr.Filter.NotFilter)
  152. {
  153. keyValuePair.Value.presetButton.SetActive(true);
  154. keyValuePair.Value.typeIcon.SetActive(true);
  155. }
  156. else if (preset.ePreType.ToString() == clickBtnName.ToString())
  157. {
  158. keyValuePair.Value.presetButton.SetActive(true);
  159. keyValuePair.Value.typeIcon.SetActive(false);
  160. }
  161. else
  162. {
  163. keyValuePair.Value.presetButton.SetActive(false);
  164. }
  165. }
  166. this.AdjustTargetPosition(this.m_goPresetParent, this.m_presetScrollView);
  167. }
  168. public float GetScrollBarValue()
  169. {
  170. return this.m_presetScrollBar.value;
  171. }
  172. public void SetScrollBar(float scrollBarValue)
  173. {
  174. this.m_presetScrollBar.value = scrollBarValue;
  175. }
  176. public void InitFilterButtonActive(PresetMgr.Filter btnName)
  177. {
  178. if (btnName == PresetMgr.Filter.NotFilter)
  179. {
  180. btnName = PresetMgr.Filter.None;
  181. }
  182. this.SetFilterButtonActive(PresetMgr.Filter.NotFilter, btnName);
  183. }
  184. private void SetFilterButtonActive(PresetMgr.Filter clickBtnName, PresetMgr.Filter prevClickBtnName)
  185. {
  186. if (this.m_listBtnState.ContainsKey(clickBtnName))
  187. {
  188. PresetCtrl.FilterButton filterButton = this.m_listBtnState[clickBtnName];
  189. filterButton.m_btnButton.defaultColor = this.activeColor;
  190. filterButton.m_goSelectCursor.SetActive(true);
  191. }
  192. if (prevClickBtnName != PresetMgr.Filter.None)
  193. {
  194. PresetCtrl.FilterButton filterButton2 = this.m_listBtnState[prevClickBtnName];
  195. filterButton2.m_btnButton.defaultColor = this.inActiveColor;
  196. filterButton2.m_goSelectCursor.SetActive(false);
  197. }
  198. }
  199. public void PresetSet()
  200. {
  201. if (this.m_maid.IsBusy)
  202. {
  203. return;
  204. }
  205. string name = UIButton.current.name;
  206. PresetCtrl.PresetButton presetButton;
  207. if (this.m_dicPresetButton.TryGetValue(name, out presetButton))
  208. {
  209. CharacterMgr.Preset preset = presetButton.preset;
  210. GameMain.Instance.CharacterMgr.PresetSet(this.m_maid, preset);
  211. }
  212. else
  213. {
  214. Debug.LogError(string.Format("不適切なプリセットが選択されました。プリセット名={0}", name));
  215. }
  216. }
  217. public void DeletePreset(string clickBtnName)
  218. {
  219. this.m_presetName = clickBtnName;
  220. GameMain.Instance.SysDlg.Show("プリセットを削除して宜しいですか。", SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.DeletePreset), null);
  221. }
  222. private void DeletePreset()
  223. {
  224. GameMain.Instance.SysDlg.Close();
  225. PresetCtrl.PresetButton presetButton;
  226. if (this.m_dicPresetButton.TryGetValue(this.m_presetName, out presetButton))
  227. {
  228. float scrollBarValue = BaseMgr<PresetMgr>.Instance.GetScrollBarValue();
  229. CharacterMgr.Preset preset = presetButton.preset;
  230. GameMain.Instance.CharacterMgr.PresetDelete(preset);
  231. BaseMgr<PresetMgr>.Instance.UpdatePresetList();
  232. if (PresetMgr.m_currentActiveFilterBtnName != PresetMgr.Filter.None)
  233. {
  234. BaseMgr<PresetMgr>.Instance.UpdateFilterPreset(PresetMgr.m_currentActiveFilterBtnName);
  235. this.SetScrollBar(scrollBarValue);
  236. }
  237. Debug.Log(string.Format("プリセット「{0}」を削除しました。", this.m_presetName));
  238. }
  239. }
  240. private Maid m_maid;
  241. private GameObject m_goPresetPanel;
  242. private GameObject m_goPresetParent;
  243. private UIScrollView m_presetScrollView;
  244. private UIScrollBar m_presetScrollBar;
  245. private Dictionary<string, PresetCtrl.PresetButton> m_dicPresetButton;
  246. private Dictionary<PresetMgr.Filter, PresetCtrl.FilterButton> m_listBtnState;
  247. private UnityEngine.Object m_presetPrefab;
  248. private Color activeColor;
  249. private Color inActiveColor;
  250. private string m_presetName;
  251. private const string PRESET_UNIT_PARENT_PATH = "PresetViewer/Contents/PresetUnitParent";
  252. private const string PRESET_UNIT_PREFAB_PATH = "SceneEdit/Preset/Prefabs/PresetUnit";
  253. private const string TYPE_ICON_ALL = "cm3d2_edit_priset_kindicon_clothes_body";
  254. private const string TYPE_ICON_WEAR = "cm3d2_edit_priset_kindicon_clothes";
  255. private const string TYPE_ICON_BODY = "cm3d2_edit_priset_kindicon_body";
  256. private const string DIALOG_MSG_DELETE = "プリセットを削除して宜しいですか。";
  257. public class FilterButton
  258. {
  259. public PresetMgr.Filter m_name { get; set; }
  260. public UIButton m_btnButton { get; set; }
  261. public GameObject m_goSelectCursor { get; set; }
  262. }
  263. public class PresetButton
  264. {
  265. public string id { get; set; }
  266. public GameObject presetButton { get; set; }
  267. public CharacterMgr.Preset preset { get; set; }
  268. public GameObject typeIcon { get; set; }
  269. }
  270. }