using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; //车载物体录屏控制类 public class OnBoardEquipCtrl : MonoBehaviour,IAnimation,IPicked { UnityAction playOverEvent; public UnityAction setOnFloor;//自身控制时 主动放置在地面上 public GameObject EquipGO;//实际装备模型 public void SetInitName(string goName) { this.gameObject.name = goName; if (GroupLearnHelper.isGroup)//分组训练时 添加同步发送和处理类 只有科目二触发当前逻辑 { this.gameObject.AddComponent(); this.gameObject.AddComponent(); } } // Start is called before the first frame update void Start() { //Play(1); } public void AddPlayOverEvent(UnityAction action) { playOverEvent += action; } //被鼠标放下 时自动播放动画 public void PickDown() { setOnFloor?.Invoke(this.transform.position);//放置在地面上执行事件 PlayOpenAnimation(); } //同步他人放置事件 public void SyncSetFloor(Vector3 pos) { this.gameObject.SetActive(true); this.transform.position = pos; PlayOpenAnimation(); } //播放展开动画 private void PlayOpenAnimation() { this.GetComponent().enabled = false;//放置后隐藏定位框 EquipGO.gameObject.SetActive(true);//放置后显示实际物体 开始播放动画 Play(1); } //创建时默认被捡起 public void PickUp() { EquipGO.gameObject.SetActive(false);//创建时先定位 不显示实际的物体 只显示定位框 this.GetComponent().enabled = true;//放置后隐藏定位框 } //播放动画 public void Play(float speed) { Speed = speed; if (speed > 0) { Debug.Log("开始播放展开动画"); } else { Debug.Log("开始播放收起动画"); } } //动画播放完毕 void AnimatorPlayOver() { Debug.Log("车载设备动画播放完成"); playOverEvent?.Invoke(); playOverEvent = null; } //模拟动画逻辑 待实际动画替换 float Speed; private void Update() { if (Speed > 0) { if (EquipGO.transform.localScale.z < 130) { EquipGO.transform.localScale += new Vector3(0, 0, 1); } else { Speed = 0; AnimatorPlayOver(); } } if (Speed < 0) { if (EquipGO.transform.localScale.z > 1) { EquipGO.transform.localScale -= new Vector3(0, 0, 1); } else { Speed = 0; AnimatorPlayOver(); } } } //该物体放置后不能被再次拾起 public bool CanPickUpByRay() { return false; } //任何方位都能放下 public bool CanPickDown() { return true; } //中途无法放弃无需实现 public void StopPick() { } //该物体必须成功放置 不能中间停止 public bool CanStopPick() { return false; } public GameObject GetGameObject() { return this.gameObject; } }