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; /// /// 是否追踪 小地图箭头引导 /// 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(); 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(); anim.Play("curse", 0, 0); } if (isTrack) { SceneCmptManager.Instance.AddTrackBox(this.gameObject); } // 通过网络数据刷新关卡数据 if(MapTcpProxy.Instance.Peer.MapData.cmptMgr != null) { Dictionary 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(); 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(); anim.Play("relieve"); isDamnation = false; } } } public void OnEnable() { if (isDamnation && !isOpen) { Animator anim = this.GetComponent(); anim.Play("curse", 0, 0); } if (isOpen) { Animator anim = this.GetComponent(); 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(); if (anim) { anim.Play("open"); } EventComponent e = GameEntry.GetComponent(); 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(); if (bubble) { bubble.Hide(); bubble.enabled = false; } // 地图怪物同步 MapTcpProxy.Instance.Peer.MapData.cmptMgr.ResetData(); MapTcpProxy.Instance.Peer.ReportDataChange(MapTcpProxy.Instance.Peer.MapData.cmptMgr); } } /// /// 掉落 掉率计算 /// bool DropItemCompute(float val) { int pVal = (int)(val * 100); //System.Random return false; } }