备份CatanBuilding瘦身独立工程
This commit is contained in:
241
Assets/Scripts/EventWashing/Tools/OperatingToolsBase.cs
Normal file
241
Assets/Scripts/EventWashing/Tools/OperatingToolsBase.cs
Normal file
@@ -0,0 +1,241 @@
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace game
|
||||
{
|
||||
public class OperatingToolsBase : MonoBehaviour
|
||||
{
|
||||
[Tooltip("工具ID")]
|
||||
public int m_ID = 0;
|
||||
|
||||
[Tooltip("工具操作前的准备时间,常用于移到指定位置等。")]
|
||||
public float m_PreparationTime = 0.1f;
|
||||
|
||||
//[Tooltip("初始Transform")]
|
||||
[HideInInspector] public Transform InitTransfom;
|
||||
|
||||
#region Transform变换相关
|
||||
|
||||
/// <summary>
|
||||
/// 跳转到展示区(即:初始Transform : m_InitTransfom)
|
||||
/// </summary>
|
||||
public void JumpToExhibition()
|
||||
{
|
||||
if (InitTransfom is null) return;
|
||||
|
||||
this.transform.parent = InitTransfom.parent;
|
||||
this.transform.SetParent(InitTransfom.parent, false);
|
||||
|
||||
this.transform.localScale = InitTransfom.localScale;
|
||||
this.transform.rotation = InitTransfom.rotation;
|
||||
this.transform.position = InitTransfom.position;
|
||||
}
|
||||
/// <summary>
|
||||
/// 移动到指定 Transform
|
||||
/// </summary>
|
||||
/// <param name="transform"></param>
|
||||
public void MoveToTransform(Transform transform)
|
||||
{
|
||||
if (transform is null) return;
|
||||
this.transform.DOKill();
|
||||
this.transform.DOMove(transform.position, m_PreparationTime).SetEase(Ease.OutQuad);
|
||||
this.transform.DOScale(transform.localScale, m_PreparationTime).SetEase(Ease.Linear);
|
||||
this.transform.DORotateQuaternion(transform.rotation, m_PreparationTime).SetEase(Ease.Linear);
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回到展示区(即:初始Transform : m_InitTransfom)
|
||||
/// </summary>
|
||||
public virtual void MoveToExhibition()
|
||||
{
|
||||
// 停止播放操作动画
|
||||
StopPlayOperationAnimation();
|
||||
// 停止播放准备动画
|
||||
StopPlayPrepareAnimation();
|
||||
|
||||
if (InitTransfom == null) return;
|
||||
MoveToTransform(InitTransfom);
|
||||
|
||||
m_Status = EventWashingActionStatus.Invalid;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 动画相关
|
||||
protected bool m_IsAuthorizedAnimation = true;
|
||||
public bool IsAuthorizedAnimation { get => m_IsAuthorizedAnimation; }
|
||||
public void AuthorizedAnimation()
|
||||
{
|
||||
m_IsAuthorizedAnimation = true;
|
||||
}
|
||||
public void NotAuthorizedAnimation()
|
||||
{
|
||||
m_IsAuthorizedAnimation = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// 播放工具操作动画
|
||||
/// </summary>
|
||||
protected virtual void PlayOperationAnimation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止播放工具操作动画
|
||||
/// </summary>
|
||||
protected virtual void StopPlayOperationAnimation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 播放准备动画
|
||||
/// </summary>
|
||||
protected virtual void PlayPrepareAnimation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止播放准备动画
|
||||
/// </summary>
|
||||
protected virtual void StopPlayPrepareAnimation()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 行为相关
|
||||
/// <summary>
|
||||
/// 开始工具操作行为
|
||||
/// </summary>
|
||||
/// <param name="overAction"></param>
|
||||
public virtual void StartExecuting()
|
||||
{
|
||||
m_Status = EventWashingActionStatus.Executing;
|
||||
m_PrepareCumulativeTime = 0f;
|
||||
|
||||
// 播放操作动画
|
||||
if (m_IsAuthorizedAnimation) PlayOperationAnimation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 操作前的准备行为,如:移动等
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
public void PrepareAction(Transform transform, UnityAction<OperatingToolsBase> readyAction, params object[] args)
|
||||
{
|
||||
m_Status = EventWashingActionStatus.Preparing;
|
||||
m_PrepareCumulativeTime = 0f;
|
||||
|
||||
m_ReadyAction = readyAction;
|
||||
|
||||
MoveToTransform(transform);
|
||||
if (m_IsAuthorizedAnimation) PlayPrepareAnimation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止操作行为
|
||||
/// </summary>
|
||||
public virtual void StopExecuting()
|
||||
{
|
||||
if (m_Status == EventWashingActionStatus.Executing)
|
||||
{
|
||||
MoveToExhibition();
|
||||
StopPlayOperationAnimation();
|
||||
}
|
||||
m_Status = EventWashingActionStatus.Stopping;
|
||||
}
|
||||
|
||||
public virtual void Enter1stStage()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void Exit1stStage()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void Enter2ndStage()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void Exit2ndStage()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 事件
|
||||
/// <summary>
|
||||
/// 准备结束事件
|
||||
/// </summary>
|
||||
UnityAction<OperatingToolsBase> m_ReadyAction = null;
|
||||
#endregion
|
||||
|
||||
#region 状态&数据等
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
protected EventWashingActionStatus m_Status = EventWashingActionStatus.Invalid;
|
||||
|
||||
public EventWashingActionStatus Status
|
||||
{
|
||||
get { return m_Status; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 准备操作累计时间,用以本地计时
|
||||
/// </summary>
|
||||
protected float m_PrepareCumulativeTime = 0f;
|
||||
|
||||
protected EventWashingTool m_Type = EventWashingTool.None; // 工具类型
|
||||
|
||||
public EventWashingTool ToolType { get { return m_Type; } }
|
||||
|
||||
public int ToolID { get { return m_ID; } }
|
||||
#endregion
|
||||
|
||||
#region 生命周期
|
||||
/// <summary>
|
||||
/// 初始化工具
|
||||
/// </summary>
|
||||
public virtual void InitTool()
|
||||
{
|
||||
m_Type = EventWashingTool.None;
|
||||
m_PrepareCumulativeTime = 0f;
|
||||
m_Status = EventWashingActionStatus.Invalid;
|
||||
|
||||
JumpToExhibition();
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
protected virtual void Start()
|
||||
{
|
||||
m_PrepareCumulativeTime = 0f;
|
||||
m_Status = EventWashingActionStatus.Invalid;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (m_Status == EventWashingActionStatus.Preparing)
|
||||
{
|
||||
m_PrepareCumulativeTime += Time.deltaTime;
|
||||
if (m_PrepareCumulativeTime >= m_PreparationTime)
|
||||
{
|
||||
if (m_ReadyAction != null)
|
||||
{
|
||||
m_ReadyAction.Invoke(this);
|
||||
}
|
||||
m_PrepareCumulativeTime = 0f;
|
||||
m_Status = EventWashingActionStatus.Executing;
|
||||
StopPlayPrepareAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user