SceneEventCmptLogic.cs 5.8 KB

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