123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityGameFramework.Runtime;
- public class SceneEventOpenBoxLogic : MonoBehaviour
- {
- public int index;
- public int[] dropIDs;
- public bool isLock = false;
- public bool isOpen = false;
- public bool isDamnation = false;
- public int enableSpawner = 0;
- /// <summary>
- /// 是否追踪 小地图箭头引导
- /// </summary>
- public bool isTrack = false;
- Button btnInteractive;
- private YLBattle.ZoneSpawnerLogic zoneSpawner = null;
- private void Awake()
- {
-
- }
- // Start is called before the first frame update
- void Start()
- {
- SceneEventOpenBox info = this.gameObject.GetComponent<SceneEventOpenBox>();
- this.index = info.index;
- this.dropIDs = info.dropID;
- this.isLock = info.isLock;
- this.isOpen = info.isOpen;
- this.isDamnation = info.isDamnation;
- this.isTrack = info.isTrack;
- this.enableSpawner = info.enableSpawner;
- SceneCmptManager.Instance.AddTreasureBox(this.gameObject);
- if (isDamnation)
- {
- Animator anim = this.GetComponent<Animator>();
- anim.Play("curse", 0, 0);
- }
- if (isTrack)
- {
- SceneCmptManager.Instance.AddTrackBox(this.gameObject);
- }
- // 通过网络数据刷新关卡数据
- if(MapTcpProxy.Instance.Peer.MapData.cmptMgr != null)
- {
- Dictionary<int, NetData.Info_Map_Cmpt_TreasureBox> tbList = MapTcpProxy.Instance.Peer.MapData.cmptMgr._allTreasureBox;
- if(tbList.ContainsKey(this.index))
- {
- this.dropIDs = tbList[this.index].dropID;
- this.isLock = tbList[this.index].isLock;
- this.isOpen = tbList[this.index].isOpen;
- this.isDamnation = tbList[this.index].isDamnation;
- this.isTrack = tbList[this.index].isTrack;
- this.enableSpawner = tbList[this.index].enableSpawner;
- }
- }
-
-
- if (isOpen)
- {
- Animator anim = this.GetComponent<Animator>();
- if (anim)
- {
- anim.Play("open");
- }
- isTrack = false;
- }
- }
- public void Update()
- {
- if (isDamnation)
- {
- if(!zoneSpawner)
- {
- zoneSpawner = YLBattle.SpawnerSystem.Instance.GetSpawnerByIndex(enableSpawner);
- return;
- }
- if (zoneSpawner.IsCleanComplete())
- {
- Animator anim = this.GetComponent<Animator>();
- anim.Play("relieve");
- isDamnation = false;
- }
- }
- }
- public void OnEnable()
- {
- if (isDamnation && !isOpen)
- {
- Animator anim = this.GetComponent<Animator>();
- anim.Play("curse", 0, 0);
- }
- if (isOpen)
- {
- Animator anim = this.GetComponent<Animator>();
- if (anim)
- {
- anim.Play("open");
- }
- isTrack = false;
- }
- }
- public void OnTriggerEnter(Collider collider)
- {
- if(isOpen)
- {
- return;
- }
- if(collider.gameObject.layer != LayerMask.NameToLayer("Player"))
- {
- return;
- }
- UI_BaseMainWindow.Instance().ShowInteractiveIcon(UI_BaseMainWindow.InteractiveType.Storage, (_btn) =>
- {
- OnClickInteractive();
- });
- }
- public void OnTriggerExit(Collider collider)
- {
- if (isOpen)
- {
- return;
- }
- if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
- {
- return;
- }
- UI_BaseMainWindow.Instance().HideInteractive();
- }
- public void EnableCollider()
- {
- }
- public void OnClickInteractive()
- {
- if (!isLock && !isOpen)
- {
- if(!isDamnation)
- {
- Animator anim = this.GetComponent<Animator>();
- if (anim)
- {
- anim.Play("open");
- }
- EventComponent e = GameEntry.GetComponent<EventComponent>();
- foreach (var dropID in dropIDs)
- {
- e.FireNow(this, new BattleEventOpenBoxEvt(dropID));
- DropManager.Instance.DropItems(dropID, this.transform.position);
- }
- btnInteractive.gameObject.SetActive(false);
- btnInteractive.onClick.RemoveAllListeners();
- isOpen = true;
- isTrack = false;
- SceneCmptManager.Instance.OpenTreasureBox(this.gameObject);
- BattleCanvas.Instance.mapCmpt.RemoveArrow(this.gameObject);
- }
- // 激活孵化器
- if(isDamnation)
- {
- if(enableSpawner != 0)
- {
- YLBattle.SpawnerSystem.Instance.EnableSpawnerByIndex(enableSpawner);
- zoneSpawner = YLBattle.SpawnerSystem.Instance.GetSpawnerByIndex(enableSpawner);
- }
- }
- // 去除对话泡泡框
- SceneBubbleWindow bubble = this.gameObject.GetComponent<SceneBubbleWindow>();
- if (bubble)
- {
- bubble.Hide();
- bubble.enabled = false;
- }
- // 地图怪物同步
- MapTcpProxy.Instance.Peer.MapData.cmptMgr.ResetData();
- MapTcpProxy.Instance.Peer.ReportDataChange(MapTcpProxy.Instance.Peer.MapData.cmptMgr);
- }
- }
-
- /// <summary>
- /// 掉落 掉率计算
- /// </summary>
- bool DropItemCompute(float val)
- {
- int pVal = (int)(val * 100);
- //System.Random
- return false;
- }
- }
|