123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- namespace ChivaXR.Op
- {
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- /// <summary>
- /// 操作点类型
- /// </summary>
- public enum OperationDataType
- {
- Play, //播放 -激活后直接执行,结束后关闭激活
- Trigger, //监听触发类型 -监听触发
- Toggle, //选择状态类型 -开关(off/on)等状态
- Value //完成量完成程度 -0-1
- }
- /// <summary>
- /// 操作点状态
- /// </summary>
- public enum OperationDataStatus
- {
- InActive, //未激活
- Listening, //激活监听状态
- Playing, //激活播放状态
- }
- public enum OperationDisActiveMode
- {
- once,
- loop
- }
- public interface IDataState
- {
- //设置当前数据状态值 0=false;1=true
- void SetDataStateValue(float value);
- }
- public struct OperationEventArgs
- {
- public OperationDataBase opData;
- }
- public delegate void OperationDataEventHandle(object sender, OperationEventArgs e);
- /// <summary>
- /// 操作点数据基类
- /// </summary>
- public abstract class OperationDataBase : MonoBehaviour
- {
- private float opValue;
- [ReadOnly]
- [PropertyOrder(-2)]
- public string guid;
- [PropertyOrder(-2)]
- [LabelText("操作名称")]
- public string operationName;
- [PropertyOrder(-2)]
- [LabelText("操作描述")]
- [TextArea]
- public string operationDescription;
- [LabelText("操作模式")]
- public OperationDisActiveMode operationDisActioveMode = OperationDisActiveMode.once;
- public float OpValue
- {
- get
- {
- return opValue;
- }
- set
- {
- if (opValue != value)
- {
- opValue = value;
- OnValueChanged();
- CheckOperationDataDisActive();
- }
- }
- }
- [SerializeField]
- [HideInInspector]
- private OperationDataStatus operationDataStatus;
- public virtual OperationDataType OperationType { get; }
- [LabelText("操作点状态")]
- [ShowInInspector]
- [PropertyOrder(0)]
- public OperationDataStatus OperationStatus
- {
- get { return operationDataStatus; }
- set
- {
- if (operationDataStatus != value)
- {
- operationDataStatus = value;
- OperationDataStatusChanged(operationDataStatus);
- }
- }
- }
- /// <summary>
- /// 操作点激活状态改变
- /// </summary>
- public event OperationDataEventHandle OperationStatusChanged;
- public event OperationDataEventHandle OperationValueChanged;
- public void Update()
- {
- if (OperationStatus == OperationDataStatus.Listening)
- {
- PlayUpdata();
- }
- }
- public virtual void OnValueChanged()
- {
- OperationValueChanged?.Invoke(this, new OperationEventArgs() { opData = this });
- }
- public abstract void SetDataStateValue(float value);
- /// <summary>
- /// 当操作点状态改变时
- /// </summary>
- protected void OperationDataStatusChanged(OperationDataStatus status)
- {
- OperationStatusChanged?.Invoke(this, new OperationEventArgs() { opData = this });
- OnOperationDataStatusChanged(status);
- if (OperationStatus == OperationDataStatus.InActive)
- {
- if (OperationType == OperationDataType.Play || OperationType == OperationDataType.Trigger)
- {
- //关闭激活情况下不调用改变
- opValue = 0;
- return;
- }
- }
- if (OperationStatus != OperationDataStatus.InActive)
- {
- PlayOneShot();
- }
- }
- protected virtual void OnOperationDataStatusChanged(OperationDataStatus status) { }
- /// <summary>
- /// 激活时执行一次
- /// </summary>
- protected virtual void PlayOneShot() { }
- /// <summary>
- /// 激活后每帧执行
- /// </summary>
- protected virtual void PlayUpdata() { }
- protected virtual void CheckOperationDataDisActive()
- {
- switch (operationDisActioveMode)
- {
- case OperationDisActiveMode.once:
- OperationStatus = OperationDataStatus.InActive;
- break;
- case OperationDisActiveMode.loop:
- break;
- }
- }
- [PropertyOrder(1)]
- public bool isRegister = false;
- [HideIf("isRegister")]
- [Button("注册操作信息")]
- public void RegisterData()
- {
- if (string.IsNullOrEmpty(guid)) guid = System.Guid.NewGuid().ToString();
- isRegister = OperationManager.Instance.RegisterOpData(this);
- }
- [ShowIf("isRegister")]
- [Button("移除操作信息")]
- public void RemoveRegisterData()
- {
- isRegister = !OperationManager.Instance.RemoveOpData(this);
- }
- /// <summary>
- /// 关闭提示
- /// </summary>
- public virtual void CloseHint()
- {
- }
- /// <summary>
- /// 打开提示
- /// </summary>
- public virtual void OpenHint()
- {
- }
- /// <summary>
- /// 自动填写对应的信息
- /// </summary>
- [ContextMenu("自动填写名称及描述")]
- public void FillInInfo()
- {
- operationName = transform.name;
- operationDescription = transform.name.Split('_').Length <= 1 ? transform.name : transform.name.Split('_')[1];
- }
- }
- }
|