InventoryHolder_inspector.cs 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace SoftKitty.InventoryEngine
  6. {
  7. [CustomEditor(typeof(InventoryHolder))]
  8. public class InventoryHolder_inspector : Editor
  9. {
  10. bool _itemExpand = false;
  11. bool _hiddenExpand = false;
  12. bool _currencyExpand = false;
  13. bool _callbackExpand = false;
  14. bool _merchantExpand = false;
  15. bool _statsExpand = false;
  16. bool _tradeListExpand = false;
  17. bool _tradeCategoryListExpand = false;
  18. int _tradeItemId = 0;
  19. int _tradeType = 0;
  20. int _tradeCategoryType = 0;
  21. int _attIndex = 0;
  22. float _attValue = 0F;
  23. string _attStringValue = "";
  24. Color _activeColor = new Color(0.1F, 0.3F, 0.5F);
  25. Color _disableColor = new Color(0F, 0.1F, 0.3F);
  26. Color _actionColor = new Color(0F, 1F, 0.4F);
  27. Color _titleColor = new Color(0.3F, 0.5F, 1F);
  28. Color _buttonColor = new Color(0F, 0.8F, 0.3F);
  29. GUIStyle _titleButtonStyle;
  30. ItemManager Manager;
  31. string _search = "Search item by name";
  32. public override void OnInspectorGUI()
  33. {
  34. GUI.changed = false;
  35. bool _valueChanged = false;
  36. _titleButtonStyle = new GUIStyle(GUI.skin.button);
  37. _titleButtonStyle.alignment = TextAnchor.MiddleLeft;
  38. Color _backgroundColor = GUI.backgroundColor;
  39. var script = MonoScript.FromScriptableObject(this);
  40. InventoryHolder myTarget = (InventoryHolder)target;
  41. string _thePath = AssetDatabase.GetAssetPath(script);
  42. _thePath = _thePath.Replace("InventoryHolder_inspector.cs", "");
  43. Texture logoIcon = (Texture)AssetDatabase.LoadAssetAtPath(_thePath + "Logo.png", typeof(Texture));
  44. Texture warningIcon = (Texture)AssetDatabase.LoadAssetAtPath(_thePath + "warning.png", typeof(Texture));
  45. GUILayout.BeginHorizontal();
  46. GUILayout.Box(logoIcon);
  47. GUILayout.EndHorizontal();
  48. GUILayout.BeginHorizontal();
  49. EditorGUILayout.HelpBox("Each <InventoryHolder> is a unique container of items. The player should have two <InventoryHolder> components: Inventory & Equipment. " +
  50. "Other units that carry items should also have their own <InventoryHolder>, such as Merchant, Crates, or Monsters. " +
  51. "There is no performance cost to having this component on many units; it only functions as a database.", MessageType.Info, true);
  52. GUILayout.EndHorizontal();
  53. GUILayout.BeginHorizontal();
  54. GUILayout.Space(30);
  55. GUI.backgroundColor = new Color(1F, 0.8F, 0.1F, 1F);
  56. if (GUILayout.Button(new GUIContent("Help", "Open the [UserGuide] pdf."), GUILayout.Width(120)))
  57. {
  58. string _path = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + _thePath.Replace("Editor", "Documentation") + "UserGuide.pdf";
  59. Application.OpenURL(_path);
  60. }
  61. GUI.backgroundColor = _backgroundColor;
  62. GUILayout.EndHorizontal();
  63. if (Manager == null)
  64. {
  65. Manager = FindObjectOfType<ItemManager>();
  66. }
  67. if (Manager == null)
  68. {
  69. GameObject _managerObj = AssetDatabase.LoadAssetAtPath<GameObject>(_thePath.Replace("Editor/", "Prefabs/System/InventoryEngine.prefab"));
  70. if (_managerObj != null)
  71. {
  72. Manager = _managerObj.GetComponent<ItemManager>();
  73. }
  74. else
  75. {
  76. GUILayout.BeginHorizontal();
  77. GUILayout.Space(20);
  78. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  79. GUI.color = Color.red;
  80. GUILayout.Label("You must have ItemManager prefab in the scene to modify this script.");
  81. GUI.color = Color.white;
  82. GUILayout.EndHorizontal();
  83. return;
  84. }
  85. }
  86. GUILayout.BeginHorizontal();
  87. GUILayout.Label(new GUIContent("Type:", "Make sure set matched type, this will change behavior of this component."), GUILayout.Width(150));
  88. myTarget.Type = (InventoryHolder.HolderType)EditorGUILayout.EnumPopup(myTarget.Type, GUILayout.Width(200));
  89. GUILayout.EndHorizontal();
  90. GUILayout.BeginHorizontal();
  91. GUILayout.Label(new GUIContent("Display Name:", "This will be the name shows as the title of the window."), GUILayout.Width(150));
  92. myTarget.Name = GUILayout.TextField(myTarget.Name);
  93. GUILayout.EndHorizontal();
  94. GUILayout.BeginHorizontal();
  95. GUILayout.Label(new GUIContent("Auto Save:", "When any data changes, check this will auto save data to the [Save Data Path]."), GUILayout.Width(150));
  96. myTarget.AutoSave = GUILayout.Toggle(myTarget.AutoSave, "");
  97. GUILayout.EndHorizontal();
  98. GUILayout.BeginHorizontal();
  99. GUILayout.Label(new GUIContent("Save Data Path:", "When auto-saving or you manually calling <InventoryHolder>().Save(), data will be saved into this path. (file name and extension required.)"), GUILayout.Width(150));
  100. myTarget.SavePath = GUILayout.TextField(myTarget.SavePath);
  101. GUILayout.EndHorizontal();
  102. GUILayout.BeginHorizontal();
  103. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  104. GUILayout.Label("Click this if you have changed the item settings in DataBase:", GUILayout.Width(400));
  105. GUILayout.EndHorizontal();
  106. GUILayout.BeginHorizontal();
  107. GUI.backgroundColor = _buttonColor;
  108. GUILayout.Space(25);
  109. if (GUILayout.Button(new GUIContent("Copy data base settings to all items", "If you have changed the item settings in DataBase, click this to sync the changes."), GUILayout.Width(300)))
  110. {
  111. for (int i = 0; i < myTarget.Stacks.Count; i++)
  112. {
  113. if (!myTarget.Stacks[i].Empty && myTarget.Stacks[i].Item != null)
  114. {
  115. int _level = myTarget.Stacks[i].Item.upgradeLevel;
  116. myTarget.Stacks[i].Item = Manager.items[myTarget.Stacks[i].GetItemId()].Copy();
  117. myTarget.Stacks[i].Item.upgradeLevel = _level;
  118. }
  119. }
  120. for (int i = 0; i < myTarget.HiddenStacks.Count; i++)
  121. {
  122. if (!myTarget.HiddenStacks[i].Empty && myTarget.HiddenStacks[i].Item != null)
  123. {
  124. int _level = myTarget.HiddenStacks[i].Item.upgradeLevel;
  125. myTarget.HiddenStacks[i].Item = Manager.items[myTarget.HiddenStacks[i].GetItemId()].Copy();
  126. myTarget.HiddenStacks[i].Item.upgradeLevel = _level;
  127. }
  128. }
  129. }
  130. GUI.backgroundColor = _backgroundColor;
  131. GUILayout.EndHorizontal();
  132. if (myTarget.Type == InventoryHolder.HolderType.PlayerEquipment || myTarget.Type == InventoryHolder.HolderType.NpcEquipment)
  133. {
  134. for (int i = 0; i < myTarget.BaseStats.Count; i++)
  135. {
  136. Attribute _att = Manager.GetAtttibute(myTarget.BaseStats[i].key);
  137. if (_att == null)
  138. {
  139. myTarget.BaseStats.RemoveAt(i);
  140. }
  141. else if (_att.name != myTarget.BaseStats[i].name || _att.upgradeIncrement != myTarget.BaseStats[i].upgradeIncrement || _att.visible != myTarget.BaseStats[i].visible
  142. || _att.displayFormat != myTarget.BaseStats[i].displayFormat || _att.suffixes != myTarget.BaseStats[i].suffixes || _att.coreStats != myTarget.BaseStats[i].coreStats
  143. || _att.compareInfo != myTarget.BaseStats[i].compareInfo || _att.visibleInStatsPanel != myTarget.BaseStats[i].visibleInStatsPanel || _att.stringValue != myTarget.BaseStats[i].stringValue)
  144. {
  145. myTarget.BaseStats[i].name = _att.name;
  146. myTarget.BaseStats[i].upgradeIncrement = _att.upgradeIncrement;
  147. myTarget.BaseStats[i].locked = false;
  148. myTarget.BaseStats[i].visible = _att.visible;
  149. myTarget.BaseStats[i].displayFormat = _att.displayFormat;
  150. myTarget.BaseStats[i].suffixes = _att.suffixes;
  151. myTarget.BaseStats[i].coreStats = _att.coreStats;
  152. myTarget.BaseStats[i].compareInfo = _att.compareInfo;
  153. myTarget.BaseStats[i].visibleInStatsPanel = _att.visibleInStatsPanel;
  154. myTarget.BaseStats[i].stringValue = _att.stringValue;
  155. }
  156. }
  157. GUILayout.BeginHorizontal();
  158. GUI.backgroundColor = _statsExpand ? _activeColor : _disableColor;
  159. _titleButtonStyle.normal.textColor = _statsExpand ? Color.white : new Color(0.65F, 0.65F, 0.65F);
  160. GUILayout.Label(_statsExpand ? "[-]" : "[+]", GUILayout.Width(20));
  161. if (GUILayout.Button(new GUIContent(" Base Stats", "The base stats of this character without any equipment."), _titleButtonStyle))
  162. {
  163. _statsExpand = !_statsExpand;
  164. EditorGUI.FocusTextInControl(null);
  165. }
  166. GUI.color = Color.white;
  167. GUI.backgroundColor = _backgroundColor;
  168. GUILayout.EndHorizontal();
  169. if (_statsExpand)
  170. {
  171. if (Manager.itemAttributes.Count <= 0)
  172. {
  173. GUILayout.BeginHorizontal();
  174. GUILayout.Space(50);
  175. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  176. GUI.color = Color.red;
  177. GUILayout.Label("You must have at least one attribute setup in ItemManager prefab.");
  178. GUI.color = Color.white;
  179. GUILayout.EndHorizontal();
  180. }
  181. else
  182. {
  183. GUILayout.BeginHorizontal();
  184. EditorGUILayout.HelpBox("Use <InventoryHolder>().GetBaseStatsValue(string _key) to get the base stats value.\n" +
  185. "Use <InventoryHolder>().SetBaseStatsValue(string _key, float _value) to update the base stats value.\n" +
  186. "For example:\n" +
  187. "ItemManager.PlayerEquipmentHolder.SetBaseStatsValue('lvl',20);", MessageType.Info, true);
  188. GUILayout.EndHorizontal();
  189. string[] _attributeOptions = new string[Manager.itemAttributes.Count];
  190. for (int i = 0; i < _attributeOptions.Length; i++) _attributeOptions[i] = Manager.itemAttributes[i].name;
  191. GUILayout.BeginHorizontal();
  192. GUILayout.Space(40);
  193. GUILayout.Label("New:", GUILayout.Width(50));
  194. _attIndex = Mathf.Clamp(_attIndex, 0, Manager.itemAttributes.Count - 1);
  195. GUI.backgroundColor = _titleColor;
  196. _attIndex = EditorGUILayout.Popup("", _attIndex, _attributeOptions, GUILayout.Width(150));
  197. GUI.backgroundColor = Color.white;
  198. if (Manager.itemAttributes[_attIndex].stringValue)
  199. {
  200. _attStringValue = EditorGUILayout.TextField(_attStringValue, GUILayout.Width(100));
  201. GUILayout.EndHorizontal();
  202. GUILayout.BeginHorizontal();
  203. GUILayout.Space(100);
  204. GUI.color = _buttonColor;
  205. GUILayout.Label("String Value", GUILayout.Width(145));
  206. GUI.color = Color.white;
  207. GUI.backgroundColor = _buttonColor;
  208. if (GUILayout.Button("Add", GUILayout.Width(100)))
  209. {
  210. Attribute _newAtt = Manager.itemAttributes[_attIndex].Copy();
  211. _newAtt.locked = false;
  212. bool _found = false;
  213. foreach (var obj in myTarget.BaseStats)
  214. {
  215. if (obj.key == _newAtt.key)
  216. {
  217. obj.UpdateValue(_attStringValue);
  218. _found = true;
  219. }
  220. }
  221. if (!_found)
  222. {
  223. _newAtt.UpdateValue(_attStringValue);
  224. myTarget.BaseStats.Add(_newAtt);
  225. }
  226. _valueChanged = true;
  227. }
  228. GUI.backgroundColor = Color.white;
  229. GUILayout.EndHorizontal();
  230. }
  231. else
  232. {
  233. _attValue = EditorGUILayout.FloatField(_attValue, GUILayout.Width(50));
  234. GUI.backgroundColor = _buttonColor;
  235. if (GUILayout.Button("Add", GUILayout.Width(70)))
  236. {
  237. Attribute _newAtt = Manager.itemAttributes[_attIndex].Copy();
  238. _newAtt.locked = false;
  239. bool _found = false;
  240. foreach (var obj in myTarget.BaseStats)
  241. {
  242. if (obj.key == _newAtt.key)
  243. {
  244. obj.UpdateValue(_attValue);
  245. _found = true;
  246. }
  247. }
  248. if (!_found)
  249. {
  250. _newAtt.UpdateValue(_attValue);
  251. myTarget.BaseStats.Add(_newAtt);
  252. }
  253. _valueChanged = true;
  254. }
  255. GUI.backgroundColor = Color.white;
  256. GUILayout.EndHorizontal();
  257. }
  258. EditorGUILayout.Separator();
  259. for (int i = 0; i < myTarget.BaseStats.Count; i++)
  260. {
  261. GUILayout.BeginHorizontal();
  262. GUILayout.Space(40);
  263. GUI.backgroundColor = _titleColor;
  264. GUILayout.Button(myTarget.BaseStats[i].name, _titleButtonStyle, GUILayout.Width(120));
  265. GUI.backgroundColor = Color.white;
  266. if (myTarget.BaseStats[i].stringValue)
  267. {
  268. myTarget.BaseStats[i].value = EditorGUILayout.TextField(myTarget.BaseStats[i].value, GUILayout.Width(100));
  269. }
  270. else
  271. {
  272. myTarget.BaseStats[i].value = EditorGUILayout.FloatField(float.Parse(myTarget.BaseStats[i].value), GUILayout.Width(100)).ToString();
  273. }
  274. GUI.color = _buttonColor;
  275. GUILayout.Label("(Key: " + myTarget.BaseStats[i].key + ")", GUILayout.Width(100));
  276. GUI.color = Color.white;
  277. GUI.backgroundColor = Color.red;
  278. if (GUILayout.Button("X", GUILayout.Width(30)))
  279. {
  280. myTarget.BaseStats.RemoveAt(i);
  281. _valueChanged = true;
  282. }
  283. GUI.backgroundColor = Color.white;
  284. GUILayout.EndHorizontal();
  285. }
  286. }
  287. }
  288. }
  289. if (myTarget.Type == InventoryHolder.HolderType.Merchant)
  290. {
  291. GUILayout.BeginHorizontal();
  292. GUI.backgroundColor = _merchantExpand ? _activeColor : _disableColor;
  293. _titleButtonStyle.normal.textColor = _merchantExpand ? Color.white : new Color(0.65F, 0.65F, 0.65F);
  294. GUILayout.Label(_merchantExpand ? "[-]" : "[+]", GUILayout.Width(20));
  295. if (GUILayout.Button(new GUIContent(" Merchant Settings", "The settings of merchant."), _titleButtonStyle))
  296. {
  297. _merchantExpand = !_merchantExpand;
  298. EditorGUI.FocusTextInControl(null);
  299. }
  300. GUI.color = Color.white;
  301. GUI.backgroundColor = _backgroundColor;
  302. GUILayout.EndHorizontal();
  303. if (_merchantExpand)
  304. {
  305. GUILayout.BeginHorizontal();
  306. GUILayout.Space(30);
  307. GUILayout.Label(new GUIContent("Sell Price Multiplier:", "This multiplier is applied when selling items. For example, a merchant NPC with a SellPriceMultiplier of 1.2 will sell an item priced at 1000 for 1200"), GUILayout.Width(150));
  308. myTarget.SellPriceMultiplier = EditorGUILayout.Slider(myTarget.SellPriceMultiplier, 0F, 2F);
  309. GUILayout.Label("x", GUILayout.Width(15));
  310. GUILayout.EndHorizontal();
  311. GUILayout.BeginHorizontal();
  312. GUILayout.Space(30);
  313. GUILayout.Label(new GUIContent("Buy Price Multiplier:", "This multiplier is applied when buying items. For example, a merchant NPC with a BuyPriceMultiplier of 0.8 will buy an item priced at 1000 for 800"), GUILayout.Width(150));
  314. myTarget.BuyPriceMultiplier = EditorGUILayout.Slider(myTarget.BuyPriceMultiplier, 0F, 2F);
  315. GUILayout.Label("x", GUILayout.Width(15));
  316. GUILayout.EndHorizontal();
  317. GUILayout.BeginHorizontal();
  318. GUILayout.Space(30);
  319. myTarget.TradeAllItems = GUILayout.Toggle(myTarget.TradeAllItems, new GUIContent("Accept all tradeable items.", "When unchecked, this merchant will only accept tradeable items within a list."), GUILayout.Width(200));
  320. GUILayout.EndHorizontal();
  321. if (!myTarget.TradeAllItems)
  322. {
  323. string[] _typeOption = new string[Manager.itemTypes.Count];
  324. for (int i = 0; i < _typeOption.Length; i++) _typeOption[i] = Manager.itemTypes[i].name;
  325. GUILayout.BeginHorizontal();
  326. GUILayout.Space(30);
  327. GUI.color = _buttonColor;
  328. _tradeCategoryListExpand = EditorGUILayout.Foldout(_tradeCategoryListExpand, "Accept items of these categories:");
  329. GUI.color = Color.white;
  330. GUILayout.EndHorizontal();
  331. if (_tradeCategoryListExpand)
  332. {
  333. GUILayout.BeginHorizontal();
  334. GUILayout.Space(40);
  335. GUILayout.Label("Category:", GUILayout.Width(60));
  336. _tradeCategoryType = Mathf.Clamp(_tradeCategoryType, 0, Manager.itemTypes.Count - 1);
  337. GUI.backgroundColor = Manager.itemTypes[_tradeCategoryType].color;
  338. _tradeCategoryType = EditorGUILayout.Popup("", _tradeCategoryType, _typeOption, GUILayout.Width(150));
  339. GUI.backgroundColor = _buttonColor;
  340. if (GUILayout.Button("Add", GUILayout.Width(70)))
  341. {
  342. myTarget.TradeCategoryList.Add(_tradeCategoryType);
  343. _valueChanged = true;
  344. }
  345. GUI.backgroundColor = Color.white;
  346. GUILayout.EndHorizontal();
  347. for (int i = 0; i < myTarget.TradeCategoryList.Count; i++)
  348. {
  349. if (myTarget.TradeCategoryList[i] >= 0 && myTarget.TradeCategoryList[i] < Manager.itemTypes.Count)
  350. {
  351. GUILayout.BeginHorizontal();
  352. GUILayout.Space(50);
  353. GUI.backgroundColor = Manager.itemTypes[myTarget.TradeCategoryList[i]].color; ;
  354. GUILayout.Button(Manager.itemTypes[myTarget.TradeCategoryList[i]].name, _titleButtonStyle, GUILayout.Width(150));
  355. GUI.backgroundColor = Color.red;
  356. if (GUILayout.Button("X", GUILayout.Width(30)))
  357. {
  358. myTarget.TradeCategoryList.RemoveAt(i);
  359. _valueChanged = true;
  360. }
  361. GUI.backgroundColor = Color.white;
  362. GUILayout.EndHorizontal();
  363. }
  364. else
  365. {
  366. myTarget.TradeCategoryList.RemoveAt(i);
  367. }
  368. }
  369. }
  370. GUILayout.BeginHorizontal();
  371. GUILayout.Space(30);
  372. GUI.color = _buttonColor;
  373. _tradeListExpand = EditorGUILayout.Foldout(_tradeListExpand, "Accept items within this list:");
  374. GUI.color = Color.white;
  375. GUILayout.EndHorizontal();
  376. if (_tradeListExpand)
  377. {
  378. if (Manager.items.Count <= 0)
  379. {
  380. GUILayout.BeginHorizontal();
  381. GUILayout.Space(50);
  382. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  383. GUI.color = Color.red;
  384. GUILayout.Label("You must have at least one item setup in ItemManager prefab.");
  385. GUI.color = Color.white;
  386. GUILayout.EndHorizontal();
  387. }
  388. else
  389. {
  390. string[] _itemOption = new string[Manager.items.Count];
  391. for (int i = 0; i < _itemOption.Length; i++) _itemOption[i] = Manager.items[i].name;
  392. GUILayout.BeginHorizontal();
  393. GUILayout.Space(40);
  394. Color _color = Manager.itemTypes[Manager.items[_tradeItemId].type].color;
  395. GUILayout.Box(Manager.items[_tradeItemId].icon, GUILayout.Width(20), GUILayout.Height(20));
  396. GUI.backgroundColor = _color;
  397. _tradeItemId = EditorGUILayout.Popup("", _tradeItemId, _itemOption, GUILayout.Width(190));
  398. GUI.backgroundColor = _buttonColor;
  399. if (GUILayout.Button("Add", GUILayout.Width(70)))
  400. {
  401. if (!myTarget.TradeList.Contains(_tradeItemId)) myTarget.TradeList.Add(_tradeItemId);
  402. _valueChanged = true;
  403. }
  404. GUI.backgroundColor = Color.white;
  405. GUILayout.EndHorizontal();
  406. GUILayout.BeginHorizontal();
  407. GUILayout.Space(40);
  408. GUILayout.Label("Category:", GUILayout.Width(60));
  409. _tradeType = Mathf.Clamp(_tradeType, 0, Manager.itemTypes.Count - 1);
  410. GUI.backgroundColor = Manager.itemTypes[_tradeType].color;
  411. _tradeType = EditorGUILayout.Popup("", _tradeType, _typeOption, GUILayout.Width(150));
  412. GUI.backgroundColor = _buttonColor;
  413. if (GUILayout.Button("Add All", GUILayout.Width(70)))
  414. {
  415. for (int i = 0; i < Manager.items.Count; i++)
  416. {
  417. if (Manager.items[i].type == _tradeType && !myTarget.TradeList.Contains(i)) myTarget.TradeList.Add(i);
  418. }
  419. _valueChanged = true;
  420. }
  421. GUI.backgroundColor = Color.red;
  422. if (GUILayout.Button("Remove All", GUILayout.Width(85)))
  423. {
  424. for (int i = myTarget.TradeList.Count - 1; i >= 0; i--)
  425. {
  426. if (Manager.items[myTarget.TradeList[i]].type == _tradeType) myTarget.TradeList.RemoveAt(i);
  427. }
  428. _valueChanged = true;
  429. }
  430. GUI.backgroundColor = Color.white;
  431. GUILayout.EndHorizontal();
  432. for (int i = 0; i < myTarget.TradeList.Count; i++)
  433. {
  434. if (myTarget.TradeList[i] >= 0 && myTarget.TradeList[i] < Manager.items.Count)
  435. {
  436. GUILayout.BeginHorizontal();
  437. GUILayout.Space(50);
  438. Color _itemColor = Manager.itemTypes[Manager.items[myTarget.TradeList[i]].type].color;
  439. GUILayout.Box(Manager.items[myTarget.TradeList[i]].icon, GUILayout.Width(20), GUILayout.Height(20));
  440. GUI.backgroundColor = _itemColor;
  441. GUILayout.Button(Manager.items[myTarget.TradeList[i]].name, _titleButtonStyle, GUILayout.Width(190));
  442. if (!Manager.items[myTarget.TradeList[i]].tradeable)
  443. {
  444. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  445. GUI.color = Color.red;
  446. GUILayout.Label("NOT tradeable", GUILayout.Width(100));
  447. GUI.color = Color.white;
  448. }
  449. GUI.backgroundColor = Color.red;
  450. if (GUILayout.Button("X", GUILayout.Width(30)))
  451. {
  452. myTarget.TradeList.RemoveAt(i);
  453. _valueChanged = true;
  454. }
  455. GUI.backgroundColor = Color.white;
  456. GUILayout.EndHorizontal();
  457. }
  458. else
  459. {
  460. myTarget.TradeList.RemoveAt(i);
  461. }
  462. }
  463. }
  464. }
  465. }
  466. }
  467. }
  468. GUILayout.BeginHorizontal();
  469. GUI.backgroundColor = _currencyExpand ? _activeColor : _disableColor;
  470. _titleButtonStyle.normal.textColor = _currencyExpand ? Color.white : new Color(0.65F, 0.65F, 0.65F);
  471. GUI.color = myTarget.Currency.Count <= 0 ? Color.red : Color.white;
  472. GUILayout.Label(_currencyExpand ? "[-]" : "[+]", GUILayout.Width(20));
  473. if (GUILayout.Button(new GUIContent(" Currency", "The currencies this unit carries."), _titleButtonStyle))
  474. {
  475. _currencyExpand = !_currencyExpand;
  476. EditorGUI.FocusTextInControl(null);
  477. }
  478. GUI.color = Color.white;
  479. GUI.backgroundColor = _backgroundColor;
  480. if (Manager.currencies.Count <= 0)
  481. {
  482. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  483. }
  484. else
  485. {
  486. if (myTarget.Currency.Count < Manager.currencies.Count)
  487. {
  488. myTarget.Currency.Add(0);
  489. }
  490. }
  491. GUILayout.EndHorizontal();
  492. if (_currencyExpand)
  493. {
  494. if (Manager.currencies.Count <= 0)
  495. {
  496. GUILayout.BeginHorizontal();
  497. GUILayout.Space(20);
  498. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  499. GUI.color = Color.red;
  500. GUILayout.Label("You must have at least one currency setup in ItemManager prefab.");
  501. GUI.color = Color.white;
  502. GUILayout.EndHorizontal();
  503. }
  504. //===Currency List
  505. for (int i = 0; i < Manager.currencies.Count; i++)
  506. {
  507. if (myTarget.Currency.Count <= i) myTarget.Currency.Add(0);
  508. GUILayout.BeginHorizontal();
  509. GUILayout.Space(30);
  510. GUILayout.Label("(ID:" + i.ToString() + ")", GUILayout.Width(40), GUILayout.Height(20));
  511. if (Manager.currencies[i].icon != null) GUILayout.Box(Manager.currencies[i].icon.texture, GUILayout.Width(20), GUILayout.Height(20));
  512. GUI.color = Manager.currencies[i].color;
  513. GUILayout.Label(Manager.currencies[i].name + " :", GUILayout.Width(100), GUILayout.Height(20));
  514. GUI.color = Color.white;
  515. GUI.backgroundColor = Manager.currencies[i].color;
  516. myTarget.Currency.Currency[i] = EditorGUILayout.IntField(myTarget.Currency.Currency[i], GUILayout.Width(100), GUILayout.Height(20));
  517. GUI.backgroundColor = _backgroundColor;
  518. GUILayout.EndHorizontal();
  519. }
  520. //===Currency List
  521. }
  522. GUILayout.BeginHorizontal();
  523. GUI.backgroundColor = _itemExpand ? _activeColor : _disableColor;
  524. _titleButtonStyle.normal.textColor = _itemExpand ? Color.white : new Color(0.65F, 0.65F, 0.65F);
  525. GUI.color = Manager.items.Count <= 0 ? Color.red : Color.white;
  526. GUILayout.Label(_itemExpand ? "[-]" : "[+]", GUILayout.Width(20));
  527. if (GUILayout.Button(new GUIContent(" Inventory Items", "The items this unit carries."), _titleButtonStyle))
  528. {
  529. _itemExpand = !_itemExpand;
  530. _search = "Search item by name";
  531. EditorGUI.FocusTextInControl(null);
  532. }
  533. GUI.backgroundColor = Color.white;
  534. GUI.color = Color.white;
  535. if (Manager.items.Count <= 0)
  536. {
  537. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  538. }
  539. GUILayout.EndHorizontal();
  540. if (_itemExpand)
  541. {
  542. if (Manager.items.Count <= 0)
  543. {
  544. GUILayout.BeginHorizontal();
  545. GUILayout.Space(20);
  546. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  547. GUI.color = Color.red;
  548. GUILayout.Label("You must have at least one item setup in ItemManager prefab.");
  549. GUI.color = Color.white;
  550. GUILayout.EndHorizontal();
  551. }
  552. else
  553. {
  554. string[] _itemOption = new string[Manager.items.Count + 1];
  555. if (_itemExpand || _hiddenExpand)
  556. {
  557. _itemOption[0] = "Empty";
  558. for (int i = 1; i < _itemOption.Length; i++) _itemOption[i] = Manager.items[i - 1].name;
  559. }
  560. string[] _enchantOptions = new string[Manager.itemEnchantments.Count];
  561. for (int i = 0; i < Manager.itemEnchantments.Count; i++) _enchantOptions[i] = Manager.itemEnchantments[i].name;
  562. float _weight = 0F;
  563. for (int i = 0; i < myTarget.Stacks.Count; i++) _weight += myTarget.Stacks[i].GetWeight();
  564. GUILayout.BeginHorizontal();
  565. GUILayout.Space(30);
  566. GUILayout.Label(new GUIContent("Maxmium CarryWeight:", "The maxmium carry weight of this unit."), GUILayout.Width(130));
  567. GUI.backgroundColor = _actionColor;
  568. myTarget.MaxiumCarryWeight = EditorGUILayout.FloatField(myTarget.MaxiumCarryWeight, GUILayout.Width(70));
  569. GUI.color = _weight <= myTarget.MaxiumCarryWeight ? Color.green : Color.red;
  570. GUILayout.Label(" (" + _weight.ToString("0.0") + "/" + myTarget.MaxiumCarryWeight.ToString("0.0") + ")", GUILayout.Width(100));
  571. GUI.color = Color.white;
  572. GUILayout.EndHorizontal();
  573. GUILayout.BeginHorizontal();
  574. GUILayout.Space(30);
  575. GUILayout.Label(new GUIContent("Inventory Size:", "This will be the total count of the slots in the bag."), GUILayout.Width(130));
  576. myTarget.InventorySize = EditorGUILayout.IntSlider(myTarget.InventorySize, 1, 200, GUILayout.Width(300));
  577. GUILayout.EndHorizontal();
  578. GUI.backgroundColor = _backgroundColor;
  579. GUILayout.BeginHorizontal();
  580. GUILayout.Space(30);
  581. GUI.backgroundColor = _titleColor;
  582. if (GUILayout.Button("Expand All", GUILayout.Width(100)))
  583. {
  584. for (int i = 0; i < myTarget.Stacks.Count; i++) myTarget.Stacks[i].Fold = false;
  585. }
  586. if (GUILayout.Button("Shrink All", GUILayout.Width(100)))
  587. {
  588. for (int i = 0; i < myTarget.Stacks.Count; i++) myTarget.Stacks[i].Fold = true;
  589. }
  590. GUILayout.EndHorizontal();
  591. GUI.backgroundColor = _backgroundColor;
  592. //===Item List
  593. if (myTarget.Stacks.Count > myTarget.InventorySize)
  594. {
  595. for (int i = myTarget.InventorySize; i < myTarget.Stacks.Count; i++) myTarget.Stacks.RemoveAt(i);
  596. }
  597. else if (myTarget.Stacks.Count < myTarget.InventorySize)
  598. {
  599. for (int i = myTarget.Stacks.Count; i < myTarget.InventorySize; i++) myTarget.Stacks.Add(new InventoryStack());
  600. }
  601. for (int i = 0; i < myTarget.Stacks.Count; i++)
  602. {
  603. GUILayout.BeginHorizontal();
  604. GUILayout.Space(30);
  605. int _item = 0;
  606. Color _color = Color.white;
  607. if (GUILayout.Button(myTarget.Stacks[i].Fold ? "+" : "-", GUILayout.Width(20)))
  608. {
  609. myTarget.Stacks[i].Fold = !myTarget.Stacks[i].Fold;
  610. _search = "Search item by name";
  611. }
  612. if (myTarget.Stacks[i].Item != null && !myTarget.Stacks[i].Empty)
  613. {
  614. if (myTarget.Stacks[i].Item.uid >= Manager.items.Count)
  615. {
  616. myTarget.Stacks[i].Delete();
  617. }
  618. else
  619. {
  620. myTarget.Stacks[i].Item.type = Mathf.Clamp(myTarget.Stacks[i].Item.type, 0, Manager.itemTypes.Count - 1);
  621. _item = myTarget.Stacks[i].Item.uid + 1;
  622. _color = Manager.itemTypes[myTarget.Stacks[i].Item.type].color;
  623. GUILayout.Box(myTarget.Stacks[i].Item.icon, GUILayout.Width(20), GUILayout.Height(20));
  624. }
  625. }
  626. else
  627. {
  628. GUILayout.Box("-", GUILayout.Width(20), GUILayout.Height(20));
  629. }
  630. EditorGUI.BeginChangeCheck();
  631. GUI.backgroundColor = _color;
  632. _item = EditorGUILayout.Popup("", _item, _itemOption, GUILayout.Width(180));
  633. if (EditorGUI.EndChangeCheck())
  634. {
  635. if (_item == 0)
  636. {
  637. myTarget.Stacks[i].Empty = true;
  638. myTarget.Stacks[i].Item = null;
  639. myTarget.Stacks[i].Number = 0;
  640. }
  641. else
  642. {
  643. myTarget.Stacks[i] = new InventoryStack(Manager.items[_item - 1], Mathf.Max(1, myTarget.Stacks[i].Number));
  644. }
  645. }
  646. GUILayout.Label(" x", GUILayout.Width(20));
  647. int _maxStack = 0;
  648. if (myTarget.Stacks[i].Item != null && !myTarget.Stacks[i].Empty)
  649. {
  650. _maxStack = myTarget.Stacks[i].Item.maxiumStack;
  651. }
  652. GUI.backgroundColor = _titleColor;
  653. myTarget.Stacks[i].Number = Mathf.FloorToInt(GUILayout.HorizontalSlider(myTarget.Stacks[i].Number, 0, _maxStack, GUILayout.Width(120)));
  654. if (_item == 0) myTarget.Stacks[i].Number = 0;
  655. GUILayout.Label(myTarget.Stacks[i].Number.ToString(), GUILayout.Width(30));
  656. GUI.backgroundColor = _backgroundColor;
  657. GUI.color = _actionColor;
  658. if (myTarget.Stacks[i].Item != null && myTarget.Stacks[i].Item.upgradeLevel > 0)
  659. {
  660. GUILayout.Label("Lv." + myTarget.Stacks[i].Item.upgradeLevel.ToString(), GUILayout.Width(40));
  661. }
  662. else
  663. {
  664. GUILayout.Space(40);
  665. }
  666. GUI.color = Color.white;
  667. GUI.backgroundColor = Color.red;
  668. if (GUILayout.Button("X", GUILayout.Width(30)))
  669. {
  670. myTarget.Stacks[i].Empty = true;
  671. myTarget.Stacks[i].Item = null;
  672. myTarget.Stacks[i].Number = 0;
  673. _valueChanged = true;
  674. }
  675. GUI.backgroundColor = _backgroundColor;
  676. GUILayout.EndHorizontal();
  677. if (!myTarget.Stacks[i].Fold)
  678. {
  679. GUILayout.BeginHorizontal();
  680. GUILayout.Space(80);
  681. GUI.color = Color.gray;
  682. _search = GUILayout.TextField(_search, GUILayout.Width(180));
  683. GUILayout.EndHorizontal();
  684. if (_search != "")
  685. {
  686. for (int u = 0; u < Manager.items.Count; u++)
  687. {
  688. if (Manager.items[u].name.ToLower().Contains(_search.ToLower()))
  689. {
  690. GUILayout.BeginHorizontal();
  691. GUILayout.Space(100);
  692. if (GUILayout.Button(Manager.items[u].name, GUILayout.Width(160)))
  693. {
  694. myTarget.Stacks[i] = new InventoryStack(Manager.items[u], Mathf.Max(1, myTarget.Stacks[i].Number));
  695. myTarget.Stacks[i].Fold = true;
  696. EditorGUI.FocusTextInControl(null);
  697. }
  698. GUILayout.EndHorizontal();
  699. }
  700. }
  701. }
  702. GUI.color = Color.white;
  703. if (Manager.EnableEnhancing && myTarget.Stacks[i].Item.type == Manager.EnhancingCategoryID)
  704. {
  705. GUILayout.BeginHorizontal();
  706. GUILayout.Space(80);
  707. GUILayout.Label("Enhancing Level: ", GUILayout.Width(120));
  708. myTarget.Stacks[i].Item.upgradeLevel = EditorGUILayout.IntSlider(myTarget.Stacks[i].Item.upgradeLevel, 0, Manager.MaxiumEnhancingLevel, GUILayout.Width(230));
  709. GUILayout.EndHorizontal();
  710. }
  711. if (Manager.EnableEnchanting && Manager.itemEnchantments.Count > 0 && myTarget.Stacks[i].Item.type == Manager.EnchantingCategoryID)
  712. {
  713. GUILayout.BeginHorizontal();
  714. GUILayout.Space(80);
  715. GUILayout.Label("Enchantments (" + myTarget.Stacks[i].Item.enchantments.Count + "): ", GUILayout.Width(120));
  716. GUI.backgroundColor = _buttonColor;
  717. if (GUILayout.Button("+", GUILayout.Width(30)))
  718. {
  719. myTarget.Stacks[i].Item.enchantments.Add(0);
  720. }
  721. GUI.backgroundColor = _backgroundColor;
  722. GUILayout.EndHorizontal();
  723. for (int u = myTarget.Stacks[i].Item.enchantments.Count - 1; u >= 0; u--)
  724. {
  725. GUILayout.BeginHorizontal();
  726. GUILayout.Space(90);
  727. int _ent = myTarget.Stacks[i].Item.enchantments[u];
  728. EditorGUI.BeginChangeCheck();
  729. _ent = EditorGUILayout.Popup("", _ent, _enchantOptions, GUILayout.Width(120));
  730. if (EditorGUI.EndChangeCheck())
  731. {
  732. myTarget.Stacks[i].Item.enchantments[u] = _ent;
  733. }
  734. GUILayout.Label(Manager.itemEnchantments[myTarget.Stacks[i].Item.enchantments[u]].GetDescription(), GUILayout.Width(190));
  735. GUI.backgroundColor = Color.red;
  736. if (GUILayout.Button("X", GUILayout.Width(25)))
  737. {
  738. myTarget.Stacks[i].Item.enchantments.RemoveAt(u);
  739. }
  740. GUI.backgroundColor = _backgroundColor;
  741. GUILayout.EndHorizontal();
  742. }
  743. }
  744. if (Manager.EnableSocketing && myTarget.Stacks[i].Item.type == Manager.SocketedCategoryFilter)
  745. {
  746. GUILayout.BeginHorizontal();
  747. GUILayout.Space(80);
  748. GUILayout.Label("Socketing Slots (" + myTarget.Stacks[i].Item.socketingSlots.ToString() + "):", GUILayout.Width(120));
  749. GUI.backgroundColor = myTarget.Stacks[i].Item.socketedItems.Count < Manager.MaxmiumSocketingSlotsNumber ? _buttonColor : Color.gray;
  750. if (GUILayout.Button("+", GUILayout.Width(30)))
  751. {
  752. if (myTarget.Stacks[i].Item.socketedItems.Count < Manager.MaxmiumSocketingSlotsNumber)
  753. {
  754. myTarget.Stacks[i].Item.socketedItems.Add(Manager.LockSocketingSlotsByDefault ? -2 : -1);
  755. myTarget.Stacks[i].Item.socketingSlots = myTarget.Stacks[i].Item.socketedItems.Count;
  756. }
  757. }
  758. GUI.backgroundColor = myTarget.Stacks[i].Item.socketedItems.Count > 0 ? Color.red : Color.gray;
  759. if (GUILayout.Button("-", GUILayout.Width(30)))
  760. {
  761. if (myTarget.Stacks[i].Item.socketedItems.Count > 0)
  762. {
  763. myTarget.Stacks[i].Item.socketedItems.RemoveAt(myTarget.Stacks[i].Item.socketedItems.Count - 1);
  764. myTarget.Stacks[i].Item.socketingSlots = myTarget.Stacks[i].Item.socketedItems.Count;
  765. }
  766. }
  767. GUI.backgroundColor = _backgroundColor;
  768. GUILayout.EndHorizontal();
  769. GUILayout.BeginHorizontal();
  770. GUILayout.Space(100);
  771. for (int u = 0; u < myTarget.Stacks[i].Item.socketedItems.Count; u++)
  772. {
  773. GUI.backgroundColor = myTarget.Stacks[i].Item.socketedItems[u] == -2 ? Color.gray : _buttonColor;
  774. if (GUILayout.Button(new GUIContent(myTarget.Stacks[i].Item.socketedItems[u] == -2 ? "X" : "O", myTarget.Stacks[i].Item.socketedItems[u] == -2 ? "Locked" : "Available"), GUILayout.Width(30)))
  775. {
  776. if (myTarget.Stacks[i].Item.socketedItems[u] == -2)
  777. {
  778. myTarget.Stacks[i].Item.socketedItems[u] = -1;
  779. }
  780. else
  781. {
  782. myTarget.Stacks[i].Item.socketedItems[u] = -2;
  783. }
  784. }
  785. }
  786. GUI.backgroundColor = _backgroundColor;
  787. GUILayout.EndHorizontal();
  788. }
  789. }
  790. }
  791. //===Item List
  792. }
  793. }
  794. GUILayout.BeginHorizontal();
  795. GUI.backgroundColor = _hiddenExpand ? _activeColor : _disableColor;
  796. _titleButtonStyle.normal.textColor = _hiddenExpand ? Color.white : new Color(0.65F, 0.65F, 0.65F);
  797. GUI.color = Manager.items.Count <= 0 ? Color.red : Color.white;
  798. GUILayout.Label(_hiddenExpand ? "[-]" : "[+]", GUILayout.Width(20));
  799. if (GUILayout.Button(new GUIContent(" Hidden Items", "Hidden items will not show in the normal inventory window, but shows in the interfaces using scripts that inherit from HiddenContainer.cs"), _titleButtonStyle))
  800. {
  801. _hiddenExpand = !_hiddenExpand;
  802. _search = "Search item by name";
  803. EditorGUI.FocusTextInControl(null);
  804. }
  805. GUI.backgroundColor = Color.white;
  806. GUI.color = Color.white;
  807. if (Manager.items.Count <= 0)
  808. {
  809. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  810. }
  811. GUILayout.EndHorizontal();
  812. if (_hiddenExpand)
  813. {
  814. if (Manager.items.Count <= 0)
  815. {
  816. GUILayout.BeginHorizontal();
  817. GUILayout.Space(20);
  818. GUILayout.Box(warningIcon, GUIStyle.none, GUILayout.Width(20));
  819. GUI.color = Color.red;
  820. GUILayout.Label("You must have at least one item setup in ItemManager prefab.");
  821. GUI.color = Color.white;
  822. GUILayout.EndHorizontal();
  823. }
  824. else
  825. {
  826. string[] _itemOption = new string[Manager.items.Count + 1];
  827. if (_itemExpand || _hiddenExpand)
  828. {
  829. _itemOption[0] = "Empty";
  830. for (int i = 1; i < _itemOption.Length; i++) _itemOption[i] = Manager.items[i - 1].name;
  831. }
  832. GUI.backgroundColor = _buttonColor;
  833. GUILayout.BeginHorizontal();
  834. GUILayout.Space(30);
  835. if (GUILayout.Button("Add Item", GUILayout.Width(200)))
  836. {
  837. myTarget.HiddenStacks.Add(new InventoryStack());
  838. _valueChanged = true;
  839. }
  840. GUI.backgroundColor = _titleColor;
  841. if (GUILayout.Button("Expand All", GUILayout.Width(100)))
  842. {
  843. for (int i = 0; i < myTarget.HiddenStacks.Count; i++) myTarget.HiddenStacks[i].Fold = false;
  844. }
  845. if (GUILayout.Button("Shrink All", GUILayout.Width(100)))
  846. {
  847. for (int i = 0; i < myTarget.HiddenStacks.Count; i++) myTarget.HiddenStacks[i].Fold = true;
  848. }
  849. GUILayout.EndHorizontal();
  850. GUI.backgroundColor = _backgroundColor;
  851. //===Hidden List
  852. for (int i = 0; i < myTarget.HiddenStacks.Count; i++)
  853. {
  854. GUILayout.BeginHorizontal();
  855. GUILayout.Space(30);
  856. if (GUILayout.Button(myTarget.HiddenStacks[i].Fold ? "+" : "-", GUILayout.Width(20)))
  857. {
  858. myTarget.HiddenStacks[i].Fold = !myTarget.HiddenStacks[i].Fold;
  859. _search = "Search item by name";
  860. }
  861. int _item = 0;
  862. Color _color = Color.white;
  863. if (myTarget.HiddenStacks[i].Item != null && !myTarget.HiddenStacks[i].Empty)
  864. {
  865. if (myTarget.HiddenStacks[i].Item.uid >= Manager.items.Count)
  866. {
  867. myTarget.HiddenStacks[i].Delete();
  868. }
  869. else
  870. {
  871. myTarget.HiddenStacks[i].Item.type = Mathf.Clamp(myTarget.HiddenStacks[i].Item.type, 0, Manager.itemTypes.Count - 1);
  872. _item = myTarget.HiddenStacks[i].Item.uid + 1;
  873. _color = Manager.itemTypes[myTarget.HiddenStacks[i].Item.type].color;
  874. GUILayout.Box(myTarget.HiddenStacks[i].Item.icon, GUILayout.Width(20), GUILayout.Height(20));
  875. }
  876. }
  877. else
  878. {
  879. GUILayout.Box("-", GUILayout.Width(20), GUILayout.Height(20));
  880. }
  881. EditorGUI.BeginChangeCheck();
  882. GUI.backgroundColor = _color;
  883. _item = EditorGUILayout.Popup("", _item, _itemOption, GUILayout.Width(180));
  884. if (EditorGUI.EndChangeCheck())
  885. {
  886. if (_item == 0)
  887. {
  888. myTarget.HiddenStacks[i].Empty = true;
  889. myTarget.HiddenStacks[i].Item = null;
  890. myTarget.HiddenStacks[i].Number = 0;
  891. }
  892. else
  893. {
  894. myTarget.HiddenStacks[i] = new InventoryStack(Manager.items[_item - 1], Mathf.Max(1, myTarget.HiddenStacks[i].Number));
  895. }
  896. }
  897. GUILayout.Label(" x", GUILayout.Width(20));
  898. int _maxStack = 0;
  899. if (myTarget.HiddenStacks[i].Item != null && !myTarget.HiddenStacks[i].Empty)
  900. {
  901. _maxStack = myTarget.HiddenStacks[i].Item.maxiumStack;
  902. }
  903. GUI.backgroundColor = _titleColor;
  904. myTarget.HiddenStacks[i].Number = Mathf.FloorToInt(GUILayout.HorizontalSlider(myTarget.HiddenStacks[i].Number, 0, _maxStack, GUILayout.Width(120)));
  905. if (_item == 0) myTarget.HiddenStacks[i].Number = 0;
  906. GUILayout.Label(myTarget.HiddenStacks[i].Number.ToString(), GUILayout.Width(30));
  907. GUI.backgroundColor = _backgroundColor;
  908. GUI.color = _actionColor;
  909. if (myTarget.HiddenStacks[i].Item != null && myTarget.HiddenStacks[i].Item.upgradeLevel > 0)
  910. {
  911. GUILayout.Label("Lv." + myTarget.HiddenStacks[i].Item.upgradeLevel.ToString(), GUILayout.Width(40));
  912. }
  913. else
  914. {
  915. GUILayout.Space(40);
  916. }
  917. GUI.color = Color.white;
  918. GUI.backgroundColor = Color.red;
  919. if (GUILayout.Button("X", GUILayout.Width(30)))
  920. {
  921. myTarget.HiddenStacks.RemoveAt(i);
  922. _valueChanged = true;
  923. }
  924. GUI.backgroundColor = _backgroundColor;
  925. GUILayout.EndHorizontal();
  926. if (!myTarget.HiddenStacks[i].Fold)
  927. {
  928. GUILayout.BeginHorizontal();
  929. GUILayout.Space(80);
  930. GUI.color = Color.gray;
  931. _search = GUILayout.TextField(_search, GUILayout.Width(180));
  932. GUILayout.EndHorizontal();
  933. if (_search != "")
  934. {
  935. for (int u = 0; u < Manager.items.Count; u++)
  936. {
  937. if (Manager.items[u].name.ToLower().Contains(_search.ToLower()))
  938. {
  939. GUILayout.BeginHorizontal();
  940. GUILayout.Space(100);
  941. if (GUILayout.Button(Manager.items[u].name, GUILayout.Width(160)))
  942. {
  943. myTarget.HiddenStacks[i] = new InventoryStack(Manager.items[u], Mathf.Max(1, myTarget.HiddenStacks[i].Number));
  944. myTarget.HiddenStacks[i].Fold = true;
  945. EditorGUI.FocusTextInControl(null);
  946. }
  947. GUILayout.EndHorizontal();
  948. }
  949. }
  950. }
  951. GUI.color = Color.white;
  952. }
  953. }
  954. //===Hidden List
  955. }
  956. }
  957. GUILayout.BeginHorizontal();
  958. GUI.backgroundColor = _callbackExpand ? _activeColor : _disableColor;
  959. _titleButtonStyle.normal.textColor = _callbackExpand ? Color.white : new Color(0.65F, 0.65F, 0.65F);
  960. GUI.color = myTarget.Currency.Count <= 0 ? Color.red : Color.white;
  961. GUILayout.Label(_callbackExpand ? "[-]" : "[+]", GUILayout.Width(20));
  962. if (GUILayout.Button(new GUIContent(" Code Example", "Code example for this inventory holder."), _titleButtonStyle))
  963. {
  964. _callbackExpand = !_callbackExpand;
  965. EditorGUI.FocusTextInControl(null);
  966. }
  967. GUI.color = Color.white;
  968. GUI.backgroundColor = _backgroundColor;
  969. GUILayout.EndHorizontal();
  970. if (_callbackExpand)
  971. {
  972. if (myTarget.Type == InventoryHolder.HolderType.NpcInventory || myTarget.Type == InventoryHolder.HolderType.PlayerInventory || myTarget.Type == InventoryHolder.HolderType.Crate || myTarget.Type == InventoryHolder.HolderType.Merchant)
  973. {
  974. GUILayout.BeginHorizontal();
  975. GUILayout.Space(30);
  976. GUI.color = Color.yellow;
  977. GUILayout.Label("Add an item:");
  978. GUI.color = Color.white;
  979. GUILayout.EndHorizontal();
  980. GUI.color = _buttonColor;
  981. GUILayout.BeginHorizontal();
  982. GUILayout.Space(50);
  983. GUILayout.Label("ThisInventoryHolder.AddItem(new Item(int _uid),int _number);");
  984. GUILayout.EndHorizontal();
  985. GUI.color = Color.white;
  986. GUILayout.BeginHorizontal();
  987. GUILayout.Space(50);
  988. GUILayout.Label("//_uid: The unique ID of the item to add, \"_number\" is the number of item you want to add.");
  989. GUILayout.EndHorizontal();
  990. GUILayout.BeginHorizontal();
  991. GUILayout.Space(50);
  992. GUILayout.Label("//_number: The quantity of item to add.");
  993. GUILayout.EndHorizontal();
  994. EditorGUILayout.Separator();
  995. GUILayout.BeginHorizontal();
  996. GUILayout.Space(30);
  997. GUI.color = Color.yellow;
  998. GUILayout.Label("Remove an item:");
  999. GUI.color = Color.white;
  1000. GUILayout.EndHorizontal();
  1001. GUI.color = _buttonColor;
  1002. GUILayout.BeginHorizontal();
  1003. GUILayout.Space(50);
  1004. GUILayout.Label("ThisInventoryHolder.RemoveItem(int _uid, int _number, int _index=-1);");
  1005. GUILayout.EndHorizontal();
  1006. GUI.color = Color.white;
  1007. GUILayout.BeginHorizontal();
  1008. GUILayout.Space(50);
  1009. GUILayout.Label("//_uid: The unique ID of the item to remove.");
  1010. GUILayout.EndHorizontal();
  1011. GUILayout.BeginHorizontal();
  1012. GUILayout.Space(50);
  1013. GUILayout.Label("//_number: The quantity of the item to remove. If the number exceeds the quantity available, it will be capped at the actual number.");
  1014. GUILayout.EndHorizontal();
  1015. GUILayout.BeginHorizontal();
  1016. GUILayout.Space(50);
  1017. GUILayout.Label("//_index: (Optional) If specified, removes the item from the slot at this index in the inventory interface. Use -1 to ignore the index.");
  1018. GUILayout.EndHorizontal();
  1019. EditorGUILayout.Separator();
  1020. GUILayout.BeginHorizontal();
  1021. GUILayout.Space(30);
  1022. GUI.color = Color.yellow;
  1023. GUILayout.Label("Use an item:");
  1024. GUI.color = Color.white;
  1025. GUILayout.EndHorizontal();
  1026. GUI.color = _buttonColor;
  1027. GUILayout.BeginHorizontal();
  1028. GUILayout.Space(50);
  1029. GUILayout.Label("ThisInventoryHolder.UseItem(int _uid, int _number, int _index = -1);");
  1030. GUILayout.EndHorizontal();
  1031. GUI.color = Color.white;
  1032. GUILayout.BeginHorizontal();
  1033. GUILayout.Space(50);
  1034. GUILayout.Label("//_uid: The unique ID of the item to use.");
  1035. GUILayout.EndHorizontal();
  1036. GUILayout.BeginHorizontal();
  1037. GUILayout.Space(50);
  1038. GUILayout.Label("//_number: The quantity of the item to use.If the number exceeds the available quantity, it will be capped at the actual number.");
  1039. GUILayout.EndHorizontal();
  1040. GUILayout.BeginHorizontal();
  1041. GUILayout.Space(50);
  1042. GUILayout.Label("//_index: (Optional) If specified, use the item from the slot at this index in the inventory interface. Use -1 to ignore the index.");
  1043. GUILayout.EndHorizontal();
  1044. GUILayout.BeginHorizontal();
  1045. GUILayout.Space(50);
  1046. GUILayout.Label("//After using an item, the ItemUseCallback will be triggered. Refer to the Callbacks section for more details.");
  1047. GUILayout.EndHorizontal();
  1048. EditorGUILayout.Separator();
  1049. }
  1050. GUILayout.BeginHorizontal();
  1051. GUILayout.Space(30);
  1052. GUI.color = Color.yellow;
  1053. if (myTarget.Type == InventoryHolder.HolderType.PlayerEquipment || myTarget.Type == InventoryHolder.HolderType.NpcEquipment)
  1054. {
  1055. GUILayout.Label("Callback for equip or unequip an item:");
  1056. }
  1057. else if (myTarget.Type == InventoryHolder.HolderType.NpcInventory || myTarget.Type == InventoryHolder.HolderType.PlayerInventory || myTarget.Type == InventoryHolder.HolderType.Crate || myTarget.Type == InventoryHolder.HolderType.Merchant)
  1058. {
  1059. GUILayout.Label("Callback for get or remove an item:");
  1060. }
  1061. GUI.color = Color.white;
  1062. GUILayout.EndHorizontal();
  1063. GUI.color = _buttonColor;
  1064. if (myTarget.Type == InventoryHolder.HolderType.PlayerEquipment || myTarget.Type == InventoryHolder.HolderType.NpcEquipment)
  1065. {
  1066. GUILayout.BeginHorizontal();
  1067. GUILayout.Space(50);
  1068. GUILayout.Label("ThisInventoryHolder.RegisterItemChangeCallback(OnItemEquip);");
  1069. GUILayout.EndHorizontal();
  1070. EditorGUILayout.Separator();
  1071. GUILayout.BeginHorizontal();
  1072. GUILayout.Space(50);
  1073. GUILayout.Label("public void OnItemEquip(Dictionary<Item, int> _changedItems){");
  1074. GUILayout.EndHorizontal();
  1075. GUILayout.BeginHorizontal();
  1076. GUILayout.Space(50);
  1077. GUILayout.Label(" foreach (var _item in _changedItems.Keys) {");
  1078. GUILayout.EndHorizontal();
  1079. GUI.color = Color.white;
  1080. GUILayout.BeginHorizontal();
  1081. GUILayout.Space(50);
  1082. GUILayout.Label(" //when _changedItems[_item]>0 means equip _item");
  1083. GUILayout.EndHorizontal();
  1084. GUILayout.BeginHorizontal();
  1085. GUILayout.Space(50);
  1086. GUILayout.Label(" //when _changedItems[_item]<0 means unequip _item");
  1087. GUILayout.EndHorizontal();
  1088. #if MASTER_CHARACTER_CREATOR
  1089. EditorGUILayout.Separator();
  1090. GUILayout.BeginHorizontal();
  1091. GUILayout.Space(50);
  1092. GUILayout.Label(" //when work with Master Character Creator:");
  1093. GUILayout.EndHorizontal();
  1094. GUI.color = _buttonColor;
  1095. GUILayout.BeginHorizontal();
  1096. GUILayout.Space(50);
  1097. GUILayout.Label(" if (_changedItems[_item] > 0){");
  1098. GUILayout.EndHorizontal();
  1099. GUILayout.BeginHorizontal();
  1100. GUILayout.Space(50);
  1101. GUILayout.Label(" Player.Equip(_item.equipAppearance); //Equip");
  1102. GUILayout.EndHorizontal();
  1103. GUILayout.BeginHorizontal();
  1104. GUILayout.Space(50);
  1105. GUILayout.Label(" }else{");
  1106. GUILayout.EndHorizontal();
  1107. GUILayout.BeginHorizontal();
  1108. GUILayout.Space(50);
  1109. GUILayout.Label(" Player.Unequip(_item.equipAppearance.Type); //Unequip");
  1110. GUILayout.EndHorizontal();
  1111. GUILayout.BeginHorizontal();
  1112. GUILayout.Space(50);
  1113. GUILayout.Label(" }");
  1114. GUILayout.EndHorizontal();
  1115. #endif
  1116. GUI.color = _buttonColor;
  1117. GUILayout.BeginHorizontal();
  1118. GUILayout.Space(50);
  1119. GUILayout.Label(" }");
  1120. GUILayout.EndHorizontal();
  1121. GUILayout.BeginHorizontal();
  1122. GUILayout.Space(50);
  1123. GUILayout.Label("}");
  1124. GUILayout.EndHorizontal();
  1125. }
  1126. else if (myTarget.Type == InventoryHolder.HolderType.NpcInventory || myTarget.Type == InventoryHolder.HolderType.PlayerInventory || myTarget.Type == InventoryHolder.HolderType.Crate || myTarget.Type == InventoryHolder.HolderType.Merchant)
  1127. {
  1128. GUILayout.BeginHorizontal();
  1129. GUILayout.Space(50);
  1130. GUILayout.Label("ThisInventoryHolder.RegisterItemChangeCallback(OnItemChange);");
  1131. GUILayout.EndHorizontal();
  1132. EditorGUILayout.Separator();
  1133. GUILayout.BeginHorizontal();
  1134. GUILayout.Space(50);
  1135. GUILayout.Label("public void OnItemChange(Dictionary<Item, int> _changedItems){");
  1136. GUILayout.EndHorizontal();
  1137. GUILayout.BeginHorizontal();
  1138. GUILayout.Space(50);
  1139. GUILayout.Label(" foreach (var _item in _changedItems.Keys) {");
  1140. GUILayout.EndHorizontal();
  1141. GUI.color = Color.white;
  1142. GUILayout.BeginHorizontal();
  1143. GUILayout.Space(50);
  1144. GUILayout.Label(" //when _changedItems[_item]>0 means get new _item");
  1145. GUILayout.EndHorizontal();
  1146. GUILayout.BeginHorizontal();
  1147. GUILayout.Space(50);
  1148. GUILayout.Label(" //when _changedItems[_item]<0 means _item been removed");
  1149. GUILayout.EndHorizontal();
  1150. GUI.color = _buttonColor;
  1151. GUILayout.BeginHorizontal();
  1152. GUILayout.Space(50);
  1153. GUILayout.Label(" }");
  1154. GUILayout.EndHorizontal();
  1155. GUILayout.BeginHorizontal();
  1156. GUILayout.Space(50);
  1157. GUILayout.Label("}");
  1158. GUILayout.EndHorizontal();
  1159. }
  1160. if (myTarget.Type == InventoryHolder.HolderType.NpcInventory || myTarget.Type == InventoryHolder.HolderType.PlayerInventory || myTarget.Type == InventoryHolder.HolderType.Crate || myTarget.Type == InventoryHolder.HolderType.Merchant)
  1161. {
  1162. EditorGUILayout.Separator();
  1163. EditorGUILayout.Separator();
  1164. GUILayout.BeginHorizontal();
  1165. GUILayout.Space(30);
  1166. GUI.color = Color.yellow;
  1167. GUILayout.Label("Callback for use an item:");
  1168. GUILayout.EndHorizontal();
  1169. GUI.color = _buttonColor;
  1170. GUILayout.BeginHorizontal();
  1171. GUILayout.Space(50);
  1172. GUILayout.Label("ThisInventoryHolder.RegisterItemUseCallback(OnItemUse);");
  1173. GUILayout.EndHorizontal();
  1174. EditorGUILayout.Separator();
  1175. GUILayout.BeginHorizontal();
  1176. GUILayout.Space(50);
  1177. GUILayout.Label("public void OnItemUse(string _action, int _id, int _index){");
  1178. GUILayout.EndHorizontal();
  1179. GUI.color = Color.white;
  1180. GUILayout.BeginHorizontal();
  1181. GUILayout.Space(50);
  1182. GUILayout.Label(" //_action is the action string you set in the ItemManager, _id is the item UID");
  1183. GUILayout.EndHorizontal();
  1184. GUILayout.BeginHorizontal();
  1185. GUILayout.Space(50);
  1186. GUILayout.Label(" //_id is the item UID");
  1187. GUILayout.EndHorizontal();
  1188. GUILayout.BeginHorizontal();
  1189. GUILayout.Space(50);
  1190. GUILayout.Label(" //_index is the slot index of inventory");
  1191. GUILayout.EndHorizontal();
  1192. GUI.color = _buttonColor;
  1193. GUILayout.BeginHorizontal();
  1194. GUILayout.Space(50);
  1195. GUILayout.Label("}");
  1196. GUILayout.EndHorizontal();
  1197. }
  1198. GUI.color = Color.white;
  1199. }
  1200. if ((_valueChanged || GUI.changed) && !Application.isPlaying) myTarget.UpdatePrefab();
  1201. }
  1202. }
  1203. }