SceneEventCollectLogic.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityGameFramework.Runtime;
  6. public class SceneEventCollectLogic : MonoBehaviour
  7. {
  8. public enum CollectDropType
  9. {
  10. /// <summary>
  11. /// 掉落 拾取获得
  12. /// </summary>
  13. Drop,
  14. /// <summary>
  15. /// 更改 修改数据
  16. /// </summary>
  17. Alter,
  18. }
  19. GameObject interactiveObj;
  20. Button btnInteractive;
  21. Scrollbar collectBar;
  22. Text collectDescText;
  23. float nowCollectTime = 0;
  24. bool isCollect = false;
  25. private bool isLive = true;
  26. /// <summary>
  27. /// 采集类型 功能 名称
  28. /// </summary>
  29. /// [Header("机关组件")]
  30. public string collectName = "";
  31. /// <summary>
  32. /// 采集类型 功能 描述
  33. /// </summary>
  34. public string collectDesc = "";
  35. /// <summary>
  36. /// 采集完成时 tips 描述
  37. /// </summary>
  38. public string completeTips = "";
  39. /// <summary>
  40. /// 机关自身 播放动画名称
  41. /// </summary>
  42. public string collectAnim = "";
  43. /// <summary>
  44. /// 机关动画是否循环
  45. /// </summary>
  46. public bool isCollectLoop = false;
  47. [Header("掉落类型")]
  48. public CollectDropType dropType = CollectDropType.Alter;
  49. /// <summary>
  50. /// 道具ID
  51. /// </summary>
  52. public int itemDropId;
  53. /// <summary>
  54. /// 最小数量
  55. /// </summary>
  56. [Tooltip("DropType为Drop时生效")]
  57. public int mindNumber;
  58. /// <summary>
  59. /// 最大数量
  60. /// </summary>
  61. [Tooltip("DropType为Drop时生效")]
  62. public int maxNumber;
  63. /// <summary>
  64. /// 给予概率
  65. /// </summary>
  66. [Tooltip("DropType为Drop时生效")]
  67. public float probability = 1;
  68. public float collectTime = 1.0f;
  69. public int dialogIndex = 0;
  70. // 完成后是否销毁
  71. bool isDestroy = false;
  72. /// <summary>
  73. /// 角色播放动画
  74. /// </summary>
  75. [Header("角色控制")]
  76. string palyAnim = "";
  77. /// <summary>
  78. /// 是否循环
  79. /// </summary>
  80. bool isLoop = false;
  81. /// <summary>
  82. /// 是否可以移动
  83. /// </summary>
  84. bool isMove = false;
  85. /// <summary>
  86. /// 是否可以用技能
  87. /// </summary>
  88. bool isSkill = false;
  89. private void Awake()
  90. {
  91. }
  92. // Start is called before the first frame update
  93. void Start()
  94. {
  95. SceneEventCollect info = this.gameObject.GetComponent<SceneEventCollect>();
  96. this.collectName = info.collectName;
  97. this.collectDesc = info.collectDesc;
  98. this.completeTips = info.completeTips;
  99. this.collectAnim = info.collectAnim;
  100. this.isCollectLoop = info.isCollectLoop;
  101. this.dropType = (CollectDropType)info.dropType;
  102. this.itemDropId = info.itemDropId;
  103. this.mindNumber = info.mindNumber;
  104. this.maxNumber = info.maxNumber;
  105. this.probability = info.probability;
  106. this.collectTime = info.collectTime;
  107. this.dialogIndex = info.dialogIndex;
  108. }
  109. // Update is called once per frame
  110. void Update()
  111. {
  112. if(isCollect)
  113. {
  114. nowCollectTime += Time.deltaTime;
  115. collectBar.size = nowCollectTime / collectTime;
  116. if (collectBar.size >= 1)
  117. {
  118. collectBar.size = 1;
  119. Collecting();
  120. }
  121. }
  122. }
  123. public void OnCollisionEnter(Collision collision)
  124. {
  125. }
  126. public void OnCollisionExit(Collision collision)
  127. {
  128. }
  129. public void OnCollisionStay(Collision collision)
  130. {
  131. }
  132. public void OnTriggerEnter(Collider collider)
  133. {
  134. if(!isLive)
  135. {
  136. return;
  137. }
  138. Role role = collider.GetComponent<Role>();
  139. BattleCanvas battlePanel = UI_BaseMainWindow.Instance().battleCanvas;
  140. interactiveObj = battlePanel.transform.Find("Main/Interactive").gameObject;
  141. interactiveObj.SetActive(true);
  142. collectBar = battlePanel.transform.Find("Main/Interactive/collectBar").gameObject.GetComponent<Scrollbar>();
  143. collectDescText = collectBar.transform.Find("desc").GetComponent<Text>();
  144. collectDescText.text = collectDesc;
  145. UI_BaseMainWindow.Instance().ShowInteractiveIcon(UI_BaseMainWindow.InteractiveType.NpcDialog, (_btn) =>
  146. {
  147. OnClickInteractive();
  148. });
  149. collectBar.gameObject.SetActive(false);
  150. collectBar.size = 0;
  151. isCollect = false;
  152. nowCollectTime = 0;
  153. }
  154. public void OnTriggerExit(Collider collider)
  155. {
  156. UI_BaseMainWindow.Instance().HideInteractive();
  157. }
  158. public void OnClickInteractive()
  159. {
  160. collectBar.gameObject.SetActive(true);
  161. isCollect = true;
  162. }
  163. public void Collecting()
  164. {
  165. isCollect = false;
  166. isLive = false;
  167. nowCollectTime = 0;
  168. collectBar.size = 0;
  169. collectBar.gameObject.SetActive(false);
  170. switch(dropType)
  171. {
  172. case CollectDropType.Alter:
  173. if (itemDropId != 0 && Random.Range(probability, 1) >= 1.0f)
  174. {
  175. ItemProxy.Instance.AddItem(itemDropId, Random.Range(mindNumber, maxNumber));
  176. }
  177. break;
  178. case CollectDropType.Drop:
  179. DropManager.Instance.DropItems(itemDropId, this.transform.position);
  180. break;
  181. }
  182. btnInteractive.onClick.RemoveAllListeners();
  183. btnInteractive.gameObject.SetActive(false);
  184. interactiveObj.gameObject.SetActive(false);
  185. UI_TipsWindow.InitStaticDialog(this.collectName, this.completeTips, null);
  186. if (isDestroy)
  187. {
  188. Destroy(this.gameObject);
  189. }
  190. }
  191. }