大连中石油电子沙盘
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.
 
 
 
 

119 lines
4.2 KiB

using AX.InputSystem;
using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
///克隆单一物体
/// </summary>
[DisallowMultipleComponent]
public class CloneSingleObj : CloneBase
{
[SerializeField]
[Tooltip("距离地面距离")]
protected float Height = 0;
protected long gameObjID;
protected CloneCmdArgs data;
protected GameObject clonedObj;
public override void Execute(IMessage obj)
{
gameObjID = (long)obj.Sender;
data = ((CloneCmdArgs)obj.Data);
if (data.cloneObjType == cloneObjType)
{
Clone();
}
}
protected virtual void Clone()
{
var hitPoint = data.hitPos;
Vector3 clonedObjPos = new Vector3(hitPoint.x, hitPoint.y + Height, hitPoint.z);
clonedObj = EntitiesManager.Instance.CreateObj(clonePrefab, clonedObjPos, transform, gameObjID);
clonedObj.name = gameObjID.ToString();//名字即ID
//clonedObj.name = CloneObjectTool.Instance().getCloneObjectName(cloneObjType);
////有需要的类型赋值头顶名
//string topname = CloneObjName.Instance.GetCloneNameByType(cloneObjType);
SelectedObjs.gameObjs.Add(clonedObj);
//设置克隆物体所在楼层属性,属性从点击的对象上获取
var hitObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID);
number++;
CloneGameObjInfo objMsg = clonedObj.GetComponent<CloneGameObjInfo>();
objMsg.gameObjType = cloneObjType;
if (hitObj.GetComponent<CloneGameObjInfo>())
{
CloneGameObjInfo floorMsg = hitObj.GetComponent<CloneGameObjInfo>();
objMsg.buildNum = floorMsg.buildNum;
objMsg.floorNum = floorMsg.floorNum;
objMsg.interlayerNum = floorMsg.interlayerNum;
}
SetCloneGameObject(clonedObj);
AddRecordEventClone(clonedObj.transform);//测试
}
public virtual void SetCloneGameObject(GameObject obj)
{
obj.AddComponent<ObjSelectCtrl>();
obj.AddComponent<ObjDrag>();
obj.AddComponent<ObjDelete>();
}
/// <summary>
/// 添加初始状态记录
/// </summary>
/// <param name="list"></param>
public override void AddRecordFrame(List<ObjectData> list)
{
foreach (Transform child in transform)
{
var data = new RecordObjectBase();
SetBaseData(data, child);
string json = JsonUtility.ToJson(data);
var objectJson = new ObjectData();
objectJson.cloneObjType = cloneObjType;
objectJson.json = json;
list.Add(objectJson);
}
}
public void SetBaseData(RecordObjectBase data, Transform obj)
{
var msg = obj.GetComponent<CloneGameObjInfo>();
data.gameObjType = msg.gameObjType;
data.objectName = obj.gameObject.name;
data.buildNum = msg.buildNum;
data.floorNum = msg.floorNum;
data.interlayerNum = msg.interlayerNum;
data.myTransform.setMyPosition(obj.localPosition);
data.myTransform.setMyRotation(obj.localRotation);
data.myTransform.setMyScale(obj.localScale);
data.isActive = obj.gameObject.activeSelf;
if (obj.GetComponent<ObjSelectCtrl>())
{
data.IsSelect= obj.GetComponent<ObjSelectCtrl>().selected;
}
}
/// <summary>
/// 添加记录(克隆)
/// </summary>
public override void AddRecordEventClone(Transform obj)
{
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
{
var eventData = new EventData();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = cloneObjType;
eventData.eventType = RecordEventType.Clone;
var data = new RecordObjectBase();
SetBaseData(data, obj);
string json = JsonUtility.ToJson(data);
eventData.json = json;
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
public override void AddRecordTag(List<ObjectData> list)
{
}
}