123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityGameFramework.Runtime;
- public class SceneEventCollectLogic : MonoBehaviour
- {
- public enum CollectDropType
- {
- /// <summary>
- /// 掉落 拾取获得
- /// </summary>
- Drop,
- /// <summary>
- /// 更改 修改数据
- /// </summary>
- Alter,
- }
- GameObject interactiveObj;
- Button btnInteractive;
- Scrollbar collectBar;
- Text collectDescText;
- float nowCollectTime = 0;
- bool isCollect = false;
- private bool isLive = true;
- /// <summary>
- /// 采集类型 功能 名称
- /// </summary>
- /// [Header("机关组件")]
- public string collectName = "";
- /// <summary>
- /// 采集类型 功能 描述
- /// </summary>
- public string collectDesc = "";
- /// <summary>
- /// 采集完成时 tips 描述
- /// </summary>
- public string completeTips = "";
- /// <summary>
- /// 机关自身 播放动画名称
- /// </summary>
- public string collectAnim = "";
- /// <summary>
- /// 机关动画是否循环
- /// </summary>
- public bool isCollectLoop = false;
- [Header("掉落类型")]
- public CollectDropType dropType = CollectDropType.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 collectTime = 1.0f;
- public int dialogIndex = 0;
- // 完成后是否销毁
- bool isDestroy = false;
- /// <summary>
- /// 角色播放动画
- /// </summary>
- [Header("角色控制")]
- string palyAnim = "";
- /// <summary>
- /// 是否循环
- /// </summary>
- bool isLoop = false;
- /// <summary>
- /// 是否可以移动
- /// </summary>
- bool isMove = false;
- /// <summary>
- /// 是否可以用技能
- /// </summary>
- bool isSkill = false;
-
- private void Awake()
- {
- }
- // Start is called before the first frame update
- void Start()
- {
- SceneEventCollect info = this.gameObject.GetComponent<SceneEventCollect>();
- this.collectName = info.collectName;
- this.collectDesc = info.collectDesc;
- this.completeTips = info.completeTips;
- this.collectAnim = info.collectAnim;
- this.isCollectLoop = info.isCollectLoop;
- this.dropType = (CollectDropType)info.dropType;
- this.itemDropId = info.itemDropId;
- this.mindNumber = info.mindNumber;
- this.maxNumber = info.maxNumber;
- this.probability = info.probability;
- this.collectTime = info.collectTime;
- this.dialogIndex = info.dialogIndex;
- }
- // Update is called once per frame
- void Update()
- {
- if(isCollect)
- {
- nowCollectTime += Time.deltaTime;
- collectBar.size = nowCollectTime / collectTime;
- if (collectBar.size >= 1)
- {
- collectBar.size = 1;
- Collecting();
- }
- }
- }
- 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);
- collectBar = battlePanel.transform.Find("Main/Interactive/collectBar").gameObject.GetComponent<Scrollbar>();
- collectDescText = collectBar.transform.Find("desc").GetComponent<Text>();
- collectDescText.text = collectDesc;
- UI_BaseMainWindow.Instance().ShowInteractiveIcon(UI_BaseMainWindow.InteractiveType.NpcDialog, (_btn) =>
- {
- OnClickInteractive();
- });
- collectBar.gameObject.SetActive(false);
- collectBar.size = 0;
- isCollect = false;
- nowCollectTime = 0;
- }
- public void OnTriggerExit(Collider collider)
- {
- UI_BaseMainWindow.Instance().HideInteractive();
- }
- public void OnClickInteractive()
- {
- collectBar.gameObject.SetActive(true);
- isCollect = true;
- }
- public void Collecting()
- {
- isCollect = false;
- isLive = false;
- nowCollectTime = 0;
- collectBar.size = 0;
- collectBar.gameObject.SetActive(false);
- switch(dropType)
- {
- case CollectDropType.Alter:
- if (itemDropId != 0 && Random.Range(probability, 1) >= 1.0f)
- {
- ItemProxy.Instance.AddItem(itemDropId, Random.Range(mindNumber, maxNumber));
- }
- break;
- case CollectDropType.Drop:
- DropManager.Instance.DropItems(itemDropId, this.transform.position);
- break;
- }
-
- btnInteractive.onClick.RemoveAllListeners();
- btnInteractive.gameObject.SetActive(false);
- interactiveObj.gameObject.SetActive(false);
- UI_TipsWindow.InitStaticDialog(this.collectName, this.completeTips, null);
- if (isDestroy)
- {
- Destroy(this.gameObject);
- }
- }
- }
|