123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityGameFramework.Runtime;
- public class SceneEventCmptLogic : MonoBehaviour
- {
- public enum SceneCmptDropType
- {
- /// <summary>
- /// 空的
- /// </summary>
- Empty,
- /// <summary>
- /// 掉落 拾取获得
- /// </summary>
- Drop,
- /// <summary>
- /// 更改 修改数据
- /// </summary>
- Alter,
- }
- GameObject interactiveObj;
- Button btnInteractive;
- Scrollbar loadingBar;
- float nowCollectTime = 0;
- /// <summary>
- /// 使用该组件 交互
- /// </summary>
- bool isUse = false;
- private bool isLive = true;
- /// <summary>
- /// 功能 名称
- /// </summary>
- /// [Header("机关组件")]
- public string sceneCmptName = "";
- /// <summary>
- /// 功能 描述
- /// </summary>
- public string sceneCmptDesc = "";
- /// <summary>
- /// 机关自身 播放动画名称
- /// </summary>
- public string sceneCmptAnim = "";
- /// <summary>
- /// 机关动画是否循环
- /// </summary>
- public bool isCmptAnimLoop = false;
- [Header("掉落类型")]
- public SceneCmptDropType dropType = SceneCmptDropType.Alter;
- /// <summary>
- /// 道具ID
- /// </summary>
- public int itemDropId;
- /// <summary>
- /// 最小数量
- /// </summary>
- [Tooltip("DropType为Drop时生效")]
- public int mindNumber;
- /// <summary>
- /// 最大数量
- /// </summary>
- [Tooltip("DropType为Drop时生效")]
- public int maxNumber;
- /// <summary>
- /// 给予概率
- /// </summary>
- [Tooltip("DropType为Drop时生效")]
- public float probability = 1;
- public float liveTime = 3.5f;
- public int dialogIndex = 0;
- // 完成后是否销毁
- public bool isDestroy = false;
- /// <summary>
- /// 角色播放动画
- /// </summary>
- [Header("角色控制")]
- public string palyAnim = "";
- /// <summary>
- /// 是否循环
- /// </summary>
- public bool isLoop = false;
- /// <summary>
- /// 是否可以移动
- /// </summary>
- public bool isMove = false;
- /// <summary>
- /// 是否可以用技能
- /// </summary>
- public bool isSkill = false;
-
- private void Awake()
- {
- }
- // Start is called before the first frame update
- void Start()
- {
- SceneEventCmpt info = this.gameObject.GetComponent<SceneEventCmpt>();
- this.sceneCmptAnim = info.sceneCmptAnim;
- this.sceneCmptDesc = info.sceneCmptDesc;
- this.sceneCmptName = info.sceneCmptName;
- this.dropType = (SceneEventCmptLogic.SceneCmptDropType)info.dropType;
- this.isCmptAnimLoop = info.isCmptAnimLoop;
- this.itemDropId = info.itemDropId;
- this.mindNumber = info.mindNumber;
- this.maxNumber = info.maxNumber;
- this.probability = info.probability;
- this.liveTime = info.liveTime;
- this.dialogIndex = info.dialogIndex;
- this.isDestroy = info.isDestroy;
- this.palyAnim = info.palyAnim;
- this.isLoop = info.isLoop;
- this.isMove = info.isMove;
- this.isSkill = info.isSkill;
- }
- // Update is called once per frame
- void Update()
- {
- if(isUse)
- {
- nowCollectTime += Time.deltaTime;
- loadingBar.size = nowCollectTime / liveTime;
- if (loadingBar.size >= 1)
- {
- loadingBar.size = 1;
- CmptTrigger();
- }
- }
- }
- public void OnCollisionEnter(Collision collision)
- {
- }
- public void OnCollisionExit(Collision collision)
- {
- }
- public void OnCollisionStay(Collision collision)
- {
- }
- public void OnTriggerEnter(Collider collider)
- {
- if(!isLive)
- {
- return;
- }
- Role role = collider.GetComponent<Role>();
- BattleCanvas battlePanel = UI_BaseMainWindow.Instance().battleCanvas;
- interactiveObj = battlePanel.transform.Find("Main/Interactive").gameObject;
- interactiveObj.SetActive(true);
- GameObject interactiveBtnObj = battlePanel.transform.Find("Main/Interactive/collect").gameObject;
- loadingBar = battlePanel.transform.Find("Main/Interactive/collectBar").gameObject.GetComponent<Scrollbar>();
- loadingBar.gameObject.SetActive(false);
- loadingBar.size = 0;
- isUse = false;
- nowCollectTime = 0;
- UI_BaseMainWindow.Instance().ShowInteractiveIcon(UI_BaseMainWindow.InteractiveType.NpcDialog, (_btn) =>
- {
- OnClickInteractive();
- });
- }
- public void OnTriggerExit(Collider collider)
- {
- UI_BaseMainWindow.Instance().HideInteractive();
- }
- public void OnClickInteractive()
- {
- loadingBar.gameObject.SetActive(true);
- isUse = true;
- }
- public void CmptTrigger()
- {
- isUse = false;
- isLive = false;
- loadingBar.gameObject.SetActive(false);
- switch(dropType)
- {
- case SceneCmptDropType.Empty:
- return;
- case SceneCmptDropType.Alter:
- if (itemDropId != 0 && Random.Range(probability, 1) >= 1.0f)
- {
- ItemProxy.Instance.AddItem(itemDropId, Random.Range(mindNumber, maxNumber));
- }
- break;
- case SceneCmptDropType.Drop:
- DropManager.Instance.DropItems(itemDropId, this.transform.position);
- break;
- }
-
- btnInteractive.onClick.RemoveAllListeners();
- btnInteractive.gameObject.SetActive(false);
- interactiveObj.gameObject.SetActive(false);
- PanelHelper.Instance.ShowPanel("UI_TipsWindow",(panel)=> {
- UI_TipsWindow.InitStaticDialog(this.sceneCmptName, this.sceneCmptDesc, null);
- });
-
- if (isDestroy)
- {
- Destroy(this.gameObject);
- }
- }
- }
|