PresetCtrl.cs 9.8 KB

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