You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.5 KiB
102 lines
3.5 KiB
4 years ago
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.EventSystems;
|
||
|
|
||
|
public abstract class ToolAttribute : MonoBehaviour {
|
||
|
public string typeName; //类型名
|
||
|
public string task; //执行任务
|
||
|
protected DateTime t1, t2;
|
||
|
public string[] Tasklist;
|
||
|
protected CloneObjType gameObjType;
|
||
|
|
||
|
protected virtual void Awake()
|
||
|
{
|
||
|
task = "待命";
|
||
|
MessageDispatcher.AddListener("TaskChange", TaskChange);
|
||
|
MessageDispatcher.AddListener("ReplayEvent", ExecuteEvent);
|
||
|
}
|
||
|
protected virtual void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("TaskChange", TaskChange);
|
||
|
MessageDispatcher.RemoveListener("ReplayEvent", ExecuteEvent);
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 回放
|
||
|
/// </summary>
|
||
|
/// <param name="obj"></param>
|
||
|
protected virtual void ExecuteEvent(IMessage obj)
|
||
|
{
|
||
|
var eventData = (EventData)obj.Data;
|
||
|
if (eventData.eventType == RecordEventType.ToolTask && eventData.cloneObjType == gameObjType)
|
||
|
{
|
||
|
var arg = JsonUtility.FromJson<RecordSprayTool>(eventData.json);
|
||
|
if(arg.objectName == gameObject.name)
|
||
|
{
|
||
|
Execute(arg.task);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected void TaskChange(IMessage Message)
|
||
|
{
|
||
|
string task = (string)Message.Data;
|
||
|
if (SelectedObjs.selectedObj.GetComponent<CloneGameObjInfo>().gameObjID != gameObject.GetComponent<CloneGameObjInfo>().gameObjID)
|
||
|
return;
|
||
|
Execute(task);
|
||
|
AddExecuteEvent(task); //添加事件记录
|
||
|
}
|
||
|
public void ReplayTask(string task)
|
||
|
{
|
||
|
Execute(task);
|
||
|
}
|
||
|
|
||
|
protected abstract void Execute(string task);
|
||
|
|
||
|
protected virtual void OnMouseDown()
|
||
|
{
|
||
|
if (!EventSystem.current.IsPointerOverGameObject())
|
||
|
{
|
||
|
t2 = DateTime.Now;
|
||
|
if (t2 - t1 < new TimeSpan(0, 0, 0, 0, 300))
|
||
|
{
|
||
|
if(SelectedObjs.selectedObj ==gameObject)
|
||
|
ToolAttributePanel.Instance.SetAttribute(this.gameObject,typeName);
|
||
|
}
|
||
|
t1 = t2;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected void AddExecuteEvent(string task)
|
||
|
{
|
||
|
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
|
||
|
{
|
||
|
var eventData = new EventData();
|
||
|
var msg = GetComponent<CloneGameObjInfo>();
|
||
|
eventData.time = RecordManager.Instance.RecordTimer;
|
||
|
eventData.cloneObjType = msg.gameObjType;
|
||
|
eventData.eventType = RecordEventType.ToolTask;
|
||
|
var data = new RecordSprayTool();
|
||
|
SetExecuteData(data, transform, task);
|
||
|
string json = JsonUtility.ToJson(data);
|
||
|
eventData.json = json;
|
||
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
|
||
|
}
|
||
|
}
|
||
|
protected void SetExecuteData(RecordSprayTool data, Transform transform, string task)
|
||
|
{
|
||
|
var msg = transform.GetComponent<CloneGameObjInfo>();
|
||
|
data.gameObjType = msg.gameObjType;
|
||
|
data.objectName = transform.gameObject.name;
|
||
|
data.buildNum = msg.buildNum;
|
||
|
data.floorNum = msg.floorNum;
|
||
|
data.interlayerNum = msg.interlayerNum;
|
||
|
data.myTransform.setMyPosition(transform.localPosition);
|
||
|
data.myTransform.setMyRotation(transform.localRotation);
|
||
|
data.myTransform.setMyScale(transform.localScale);
|
||
|
data.task = task;
|
||
|
}
|
||
|
}
|