123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEditor;
- using James.Util;
- namespace JamesGame {
- public class TargetCtrl : MonoBehaviour {
- public enum ObstacleType
- {
- None,
- Woman,
- Bee,
- OilDrum,
- }
- public enum TargetPromptType
- {
- None,
- CanAttack, //可攻击
- ForbidAttack //禁止攻击
- }
- public bool autoDestoryOnAnimEnd = false;
- public System.Action OnAutoDestory;
- private float _destoryCD = float.MaxValue;
- private System.Action _customCallback;
- public bool destoryTimerEnable = false;
- [Tooltip("女战士马蜂窝属于障碍物,其他目标不属于none")]
- public ObstacleType TcType = ObstacleType.None;
- [Tooltip("打中障碍物的target不进行相机跟踪特效")]
- public bool CameraFollow = true;
- [Tooltip("打中障碍物后间隔多久进行结算ui的显示")]
- public float DelayMatchedTime = 3f;
- [Tooltip("靶子首次出现需要进行提示 None为默认不提示")]
- public TargetPromptType promptType = TargetPromptType.None;
- public List<TargetScoreCollider> colliders = new List<TargetScoreCollider>();
- [SerializeField]
- private bool _isCrownTarget = false;
- public bool IsCrownTarget
- {
- get { return _isCrownTarget; }
- }
- private void FixedUpdate()
- {
- if (destoryTimerEnable)
- {
- _destoryCD -= Time.deltaTime;
- if (_destoryCD < 0f)
- {
- _customCallback?.Invoke();
- OnAutoDestory?.Invoke();
- _destoryCD = float.MaxValue;
- _customCallback = null;
- destoryTimerEnable = false;
- }
- }
- }
- public int GetScore(Collider col) {
- var idx = colliders.FindIndex((entity) => entity.collider == col);
- return idx == -1 ? 0 : colliders[idx].score;
- }
- public void DestoryDelay(float sec, System.Action callback) {
- _destoryCD = sec;
- _customCallback = callback;
- destoryTimerEnable = true;
- //callback?.Invoke();
- //OnAutoDestory?.Invoke();
- }
- public void OnSpeedChanged(float animSpeedRatio,float preTime,float delayTime)
- {
- if (preTime - delayTime >= _destoryCD)
- {
- _destoryCD /= animSpeedRatio;
- }
- else
- {
- float temp = preTime - delayTime;
- float delya_Time = _destoryCD - temp;
- _destoryCD = delya_Time + (temp/animSpeedRatio);
- }
- }
- public void ActiveCollider(bool activeFlag)
- {
- for (int i = 0; i < colliders.Count; ++i)
- {
- colliders[i].collider.enabled = activeFlag;
- }
- }
- }
- [System.Serializable]
- public struct TargetScoreCollider {
- public Collider collider;
- public int score;
- }
- #if UNITY_EDITOR
- [CustomEditor(typeof(TargetCtrl))]
- public class TargetControllerInspector : Editor {
- private TargetCtrl _target;
- private void OnEnable() {
- _target = target as TargetCtrl;
- }
- public override void OnInspectorGUI() {
- base.OnInspectorGUI();
- //
- GUILayout.BeginHorizontal();
- if(GUILayout.Button("Auto Fill")) {
- _target.colliders.Clear();
- var colliders = _target.transform.GetComponentsInChildren<Collider>();
- foreach(var col in colliders) {
- int score;
- if(! int.TryParse(col.name, out score)) {
- score = 0;
- }
- _target.colliders.Add(new TargetScoreCollider {
- collider = col,
- score = score,
- });
- }
- }
- if(GUILayout.Button("Remove Empty")) {
- var tmpList = new List<TargetScoreCollider>();
- _target.colliders.ForEach((entity) => {
- if (entity.collider != null) tmpList.Add(entity);
- });
- _target.colliders = tmpList;
- }
- if(GUILayout.Button("Remove All")) {
- _target.colliders.Clear();
- }
- //
- GUILayout.EndHorizontal();
- }
- }
- #endif
- }
|