123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityGameFramework.Runtime;
- /// <summary>
- /// 场景 可破坏的
- /// </summary>
- public class SceneEventDamagedLogic : MonoBehaviour
- {
- /// <summary>
- /// 掉落ID
- /// </summary>
- public int dropID;
- /// <summary>
- /// 破坏次数
- /// </summary>
- public int number = 1;
- public int index = 0;
- Button btnInteractive;
- Collider player;
- private void Awake()
- {
-
- }
- // Start is called before the first frame update
- void Start()
- {
- SceneEventDamaged info = this.gameObject.GetComponent<SceneEventDamaged>();
- this.dropID = info.dropID;
- this.number = info.number;
- SceneCmptManager.Instance.AddDamageCmpt(this.gameObject);
- }
- public void OnTriggerEnter(Collider collider)
- {
- if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
- {
- return;
- }
- if (collider.name == "WeaponCollider")
- {
- return;
- }
- player = collider;
- BattleCanvas battlePanel = UI_BaseMainWindow.Instance().battleCanvas;
- GameObject interactive = battlePanel.transform.Find("Main/Buttons/0").gameObject;
- interactive.SetActive(true);
- btnInteractive = interactive.GetComponent<Button>();
- btnInteractive.onClick.AddListener(OnClickInteractive);
- //EventTriggerListener.Get(btnInteractive.gameObject).onClick = ((_btn) =>
- //{
- // ();
- //});
- // 按键同样能打车
- battlePanel.JKeyEvent(OnClickInteractive);
- }
- public void OnTriggerExit(Collider collider)
- {
- if(player == null)
- {
- return;
- }
- if (player.gameObject.layer != LayerMask.NameToLayer("Player"))
- {
- return;
- }
- if (player.name == "WeaponCollider")
- {
- return;
- }
- player = null;
- btnInteractive.onClick.RemoveListener(OnClickInteractive);
- }
- public void EnableCollider()
- {
- }
- public void OnClickInteractive()
- {
- if(this == null)
- {
- btnInteractive.onClick.RemoveListener(OnClickInteractive);
- return;
- }
- if(player == null)
- {
- return;
- }
- if (player.name == "WeaponCollider")
- {
- return;
- }
- if (player)
- {
- player.transform.LookAt(transform);
- }
- Animator anim = gameObject.GetComponent<Animator>();
- if(anim)
- {
- switch (number)
- {
- case 3:
- anim.Play("hit", 0, 0);
- break;
- case 2:
- anim.Play("hit", 0, 0);
- break;
- case 1:
- anim.Play("destroy", 0, 0);
- break;
- case 0:
- anim.Play("destroy");
- btnInteractive.onClick.RemoveListener(OnClickInteractive);
- EventComponent e = GameEntry.GetComponent<EventComponent>();
- e.FireNow(this, new BattleEventOpenBoxEvt(dropID));
- break;
- }
- }
- anim.StartRecording(1);
- number -= 1;
- if(number <= 0)
- {
- DropManager.Instance.DropItems(dropID, this.transform.position);
- SceneCmptManager.Instance.RemoveDamageCmpt(this.gameObject);
- StartCoroutine("AnimationComplete", 2.0f);
- Collider col = this.GetComponent<Collider>();
- if(col != null)
- {
- col.enabled = false;
- }
- }
- }
- public void AnimationComplete()
- {
-
- Destroy(this.gameObject, 2);
- }
- }
|