MainMenu.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SoftKitty.InventoryEngine
  5. {
  6. /// <summary>
  7. /// This script is an example to show how to use InventoryEngine.
  8. /// </summary>
  9. public class MainMenu : MonoBehaviour
  10. {
  11. #region References
  12. public GameObject LootPackPrefab;
  13. public InventoryHolder MerchantNpc;
  14. public InventoryHolder StorageContainer;
  15. public InventoryHolder NpcEquipment;
  16. public InventoryHolder NpcWorker;
  17. public ListItem DebugItem;
  18. private float SkyBoxRot = 21F;
  19. #endregion
  20. #region Visual Effects
  21. private void Update()
  22. {
  23. //Make the background looks more alive.
  24. RenderSettings.skybox.SetFloat("_Exposure", 1.15F + Mathf.Sin(Time.time * 0.7F) * 0.15F);
  25. RenderSettings.skybox.SetFloat("_Rotation", SkyBoxRot);
  26. SkyBoxRot = Mathf.Lerp(SkyBoxRot, 21F + (Screen.width * 0.5F - InputProxy.mousePosition.x) * 0.003F, Time.deltaTime);
  27. }
  28. #endregion
  29. void Start()
  30. {
  31. ItemManager.PlayerInventoryHolder.RegisterItemUseCallback(OnItemUse);//Register callback to trigger when player's item being use.
  32. ActionBarUi.instance.SetProgressHint("Level. 1"); // Set the text on the bottom progress bar of the ActionBar UI.
  33. ActionBarUi.instance.SetProgress(1230, 2000); // Set the bottom progress bar of the ActionBar UI.
  34. ActionBarUi.instance.SavePath= Application.dataPath + "/../SaveData/ActionBar.sav";//Set the save data path for the ActionBar.
  35. MerchantNpc.SavePath = Application.dataPath + "/../SaveData/" + MerchantNpc.Name.Replace(" ", "") + ".sav";//Set the save data path for the merchant.
  36. ItemManager.PlayerInventoryHolder.SavePath= Application.dataPath + "/../SaveData/PlayerInventory.sav";//Set the save data path for the player's inventory.
  37. ItemManager.PlayerEquipmentHolder.SavePath = Application.dataPath + "/../SaveData/PlayerEquipment.sav";//Set the save data path for the player's equipment.
  38. ItemManager.PlayerEquipmentHolder.RegisterItemChangeCallback(OnEuqipmentItemChange);//Register callback for player's equipment
  39. ItemManager.PlayerInventoryHolder.RegisterItemDropCallback(OnItemDrop);//Register callback for player drop item
  40. ItemManager.PlayerEquipmentHolder.RegisterItemDropCallback(OnItemDrop);//Register callback for player drop item
  41. }
  42. public void OnItemDrop(Item _droppedItem, int _number)
  43. {
  44. DynamicMsg.PopMsg("Player dropped" + " [" + _droppedItem.nameWithAffixing + "] x "+_number.ToString());
  45. }
  46. #if MASTER_CHARACTER_CREATOR
  47. public MasterCharacterCreator.CharacterEntity Player; //If you have Master Character Creator installed, drag the player entity to this slot.
  48. #endif
  49. public void OnEuqipmentItemChange(Dictionary<Item, int> _changedItems)
  50. {
  51. foreach (var _item in _changedItems.Keys) {
  52. #if MASTER_CHARACTER_CREATOR
  53. if (Player != null)
  54. {
  55. if (_changedItems[_item] > 0)
  56. {
  57. Player.Equip(_item.equipAppearance); // Master Character Creator Equip
  58. }
  59. else
  60. {
  61. Player.Unequip(_item.equipAppearance.Type); // Master Character Creator Unequip
  62. }
  63. }
  64. #endif
  65. DynamicMsg.PopMsg("Player "+ (_changedItems[_item]>0?"equipped":"unequipped")+" ["+ _item.nameWithAffixing + "]");
  66. }
  67. }
  68. public void OnItemUse(string _action, int _id, int _index) //When player using an item, this callback will be called.
  69. {
  70. if (_action == "equip" && WindowsManager.getOpenedWindow(ItemManager.PlayerEquipmentHolder)==null)
  71. {
  72. InventoryHolder.EquipItem(ItemManager.PlayerInventoryHolder, ItemManager.PlayerEquipmentHolder, _id, _index);//Equip item when click though action bar.
  73. return;
  74. }
  75. if (_action.Contains("Add")|| _action.Contains("buff") || _action.Contains("permanent"))
  76. {
  77. SoundManager.Play2D("UseItem");
  78. }
  79. else if (_action.Contains("attck")|| _action.Contains("Skill"))
  80. {
  81. SoundManager.Play2D("Attack");
  82. }
  83. //Create item icon in the center of the screen to show how the callback works.
  84. DebugItem.transform.parent.SetAsLastSibling();
  85. GameObject _newItem = Instantiate(DebugItem.gameObject, DebugItem.transform.parent);
  86. _newItem.GetComponent<ListItem>().mImages[0].color = ItemManager.itemDic[_id].GetTypeColor();
  87. _newItem.GetComponent<ListItem>().mRawimages[0].texture = ItemManager.itemDic[_id].icon;
  88. _newItem.GetComponent<ListItem>().mTexts[0].text = _action;
  89. _newItem.gameObject.SetActive(true);
  90. }
  91. private void OnDestroy() // If you ever called RegisterItemUseCallback(), don't forget to call UnRegisterItemUseCallback() when the gameobject going to be destroyed.
  92. {
  93. ItemManager.PlayerInventoryHolder.UnRegisterItemUseCallback(OnItemUse);
  94. ItemManager.PlayerEquipmentHolder.UnRegisterItemChangeCallback(OnEuqipmentItemChange);
  95. }
  96. public void OpenPlayerInventory()
  97. {
  98. if (ItemManager.instance != null && ItemManager.PlayerInventoryHolder != null) ItemManager.PlayerInventoryHolder.OpenWindow();
  99. }
  100. public void OpenNpcWorker()
  101. {
  102. NpcWorker.OpenForgeWindow(true,false,false,false,2F);
  103. }
  104. public void OpenPlayerEquipment()
  105. {
  106. ItemManager.PlayerEquipmentHolder.OpenWindow();
  107. }
  108. public void OpenNpcTeamEquipment()
  109. {
  110. NpcEquipment.OpenWindow();
  111. }
  112. public void OpenCraft()
  113. {
  114. ItemManager.PlayerInventoryHolder.OpenForgeWindow(true, true, true, true, 1F,"Forge"); //Open crafting window
  115. }
  116. public void KillMonster()
  117. {
  118. SoundManager.Play2D("Kill");
  119. Instantiate(LootPackPrefab).GetComponent<LootPack>().OpenPack(); //Create a loot pack and open it
  120. }
  121. public void OpenSkills()
  122. {
  123. ItemManager.PlayerInventoryHolder.OpenWindowByName("Skills","Skills"); //An example to use "Hidden Items" to achive "Skills" management.
  124. }
  125. public void TalkToMerchant()
  126. {
  127. MerchantNpc.OpenWindow();
  128. SoundManager.Play2D("Merchant");
  129. }
  130. public void OpenStorage()
  131. {
  132. StorageContainer.OpenWindow();
  133. }
  134. }
  135. }