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.
233 lines
9.0 KiB
233 lines
9.0 KiB
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class CloneCurtainLine : CloneMultiLine |
|
{ |
|
private string curtainResourcesName; |
|
public GameObject curtainPrefab; //水幕预设 |
|
|
|
public override void Awake() |
|
{ |
|
variableX = 10; |
|
variableY = 18; |
|
variableZ = 10; |
|
Height = 0.2f; |
|
cloneObjType = CloneObjType.CurtainLine; |
|
parentResourcesName = "Prefab/Tool/CurtainLineParent"; |
|
ResourcesName = "Prefab/Tool/CurtainLineItem"; |
|
curtainResourcesName = "Prefab/Tool/WaterCurtain"; |
|
if (parentPrefab == null) |
|
{ |
|
parentPrefab = Resources.Load(parentResourcesName) as GameObject; |
|
} |
|
if (clonePrefab == null) |
|
{ |
|
clonePrefab = Resources.Load(ResourcesName) as GameObject; |
|
} |
|
if (curtainPrefab == null) |
|
{ |
|
curtainPrefab = Resources.Load(curtainResourcesName) as GameObject; |
|
} |
|
} |
|
protected override void Clone() |
|
{ |
|
var hitPoint = data.hitPos; |
|
if (!started) |
|
{ |
|
prePos = hitPoint; |
|
started = true; |
|
//克隆父物体 |
|
var parentObj = EntitiesManager.Instance.CreateObj(parentPrefab, prePos, transform, gameObjID); |
|
parentObj.name = gameObjID.ToString(); |
|
SelectedObjs.gameObjs.Add(parentObj); |
|
|
|
//设置克隆物体所在楼层属性,属性从点击的对象上获取 |
|
var hitObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID); |
|
CloneGameObjInfo objMsg = parentObj.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; |
|
} |
|
parentObj.AddComponent<WaterCurtainAttribute>(); |
|
parentObj.AddComponent<ObjSelectCtrl>(); |
|
parentObj.AddComponent<ObjDelete>(); |
|
nowObj = parentObj; |
|
AddRecordEventCloneParent(parentObj.transform); //记录克隆父物体 |
|
} |
|
else |
|
{ |
|
curPos = hitPoint; |
|
//如果两点不重合 |
|
if (curPos.x != prePos.x && curPos.x != prePos.x) |
|
{ |
|
//克隆子物体 |
|
DrawLine(prePos, curPos, nowObj); |
|
} |
|
prePos = curPos; |
|
} |
|
} |
|
protected override void DrawLine(Vector3 prePos, Vector3 curPos, GameObject nowObj) |
|
{ |
|
midPos = (prePos + curPos) / 2; |
|
Vector3 clonedObjPos = new Vector3(midPos.x, midPos.y + Height, midPos.z); |
|
var clonedObj = Instantiate(clonePrefab, clonedObjPos, Quaternion.identity) as GameObject; |
|
clonedObj.transform.parent = nowObj.transform; |
|
clonedObj.name = nowObj.name; |
|
SetClonedObj(clonedObj); |
|
CreateCurtain(prePos, curPos, nowObj.transform); |
|
|
|
CurtainLineItem objMsg = clonedObj.GetComponent<CurtainLineItem>(); |
|
objMsg.gameObjID = nowObj.GetComponent<CloneGameObjInfo>().gameObjID; |
|
objMsg.gameObjType = cloneObjType; |
|
objMsg.prePos = prePos; |
|
objMsg.curPos = curPos; |
|
//设置克隆物体所在楼层属性,属性从点击的对象上获取 |
|
var hitObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID); |
|
CloneGameObjInfo floorMsg = hitObj.GetComponent<CloneGameObjInfo>(); |
|
objMsg.buildNum = floorMsg.buildNum; |
|
objMsg.floorNum = floorMsg.floorNum; |
|
objMsg.interlayerNum = floorMsg.interlayerNum; |
|
|
|
SelectedObjs.gameObjs.Add(clonedObj); |
|
AddRecordEventCloneChild(clonedObj.transform);//记录克隆子物体 |
|
} |
|
/// <summary> |
|
/// 生成水幕 |
|
/// </summary> |
|
/// <param name="prePos"></param> |
|
/// <param name="curPos"></param> |
|
private void CreateCurtain(Vector3 prePos, Vector3 curPos,Transform parent) |
|
{ |
|
Vector3 vertPos; |
|
var Distance = Vector3.Distance(prePos, curPos); |
|
float pos = Mathf.CeilToInt(Distance); |
|
float count = Mathf.CeilToInt(pos / 2); |
|
int dex = 1; |
|
if (count < 1) |
|
{ |
|
count = 1; |
|
dex = 0; |
|
} |
|
for (int i = 0; i < count + dex; i++) |
|
{ |
|
if (count > 1) |
|
{ |
|
if (i != 0) |
|
{ |
|
vertPos = new Vector3(prePos.x + (i / (float)count) * (curPos.x - prePos.x), prePos.y + (i / (float)count) * (curPos.y - prePos.y) + 0.6f, prePos.z + (i / (float)count) * (curPos.z - prePos.z)); |
|
GameObject curtain = Instantiate(curtainPrefab, vertPos, Quaternion.identity) as GameObject; |
|
curtain.transform.parent = parent; |
|
curtain.transform.forward = -Vector3.up; |
|
curtain.name = "Curtain-" + parent.name; |
|
var curtainCtrl=curtain.AddComponent<WaterCurtainControl>(); |
|
curtainCtrl.gameObjID = long.Parse(nowObj.name); |
|
CloneGameObjInfo floorMsg = parent.GetComponent<CloneGameObjInfo>(); |
|
curtainCtrl.buildNum = floorMsg.buildNum; |
|
curtainCtrl.floorNum = floorMsg.floorNum; |
|
curtainCtrl.interlayerNum = floorMsg.interlayerNum; |
|
} |
|
} |
|
} |
|
} |
|
/// <summary> |
|
/// 添加初始状态记录 |
|
/// </summary> |
|
/// <param name="list"></param> |
|
public override void AddRecordFrame(List<ObjectData> list) |
|
{ |
|
foreach (Transform child in transform) |
|
{ |
|
var data = new RecordCurtainLineParent(); |
|
SetBaseData(data, child); |
|
data.isEvent = false; |
|
for(int i = 0; i < child.childCount; i++) |
|
{ |
|
var item = child.GetChild(i); |
|
if (!item.name.Contains("Curtain")) |
|
{ |
|
CurtainLineItem itemMsg = item.GetComponent<CurtainLineItem>(); |
|
var itemData = new RecordCurtainLineChild(); |
|
SetBaseData(itemData, item.transform); |
|
itemData.prePos = itemMsg.prePos; |
|
itemData.curPos = itemMsg.curPos; |
|
data.list.Add(itemData); |
|
} |
|
} |
|
data.task = child.GetComponent<WaterCurtainAttribute>().task; |
|
string json = JsonUtility.ToJson(data); |
|
var objectJson = new ObjectData(); |
|
objectJson.cloneObjType = cloneObjType; |
|
objectJson.json = json; |
|
list.Add(objectJson); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 克隆记录父物体 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
public override void AddRecordEventCloneParent(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 RecordCurtainLineParent(); |
|
SetBaseData(data, obj); |
|
data.isEvent = true; |
|
data.isChild = false; |
|
string json = JsonUtility.ToJson(data); |
|
eventData.json = json; |
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
} |
|
} |
|
/// <summary> |
|
/// 克隆记录子物体 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
public override void AddRecordEventCloneChild(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 RecordCurtainLineChild(); |
|
SetBaseData(data, obj); |
|
data.isEvent = true; |
|
data.isChild = true; |
|
data.prePos = obj.GetComponent<CurtainLineItem>().prePos; |
|
data.curPos = obj.GetComponent<CurtainLineItem>().curPos; |
|
string json = JsonUtility.ToJson(data); |
|
eventData.json = json; |
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
} |
|
} |
|
} |
|
[Serializable] |
|
public class RecordCurtainLine:RecordObjectBase |
|
{ |
|
public bool isChild; |
|
public bool isEvent; |
|
} |
|
[Serializable] |
|
public class RecordCurtainLineChild: RecordCurtainLine |
|
{ |
|
public Vector3 prePos; |
|
public Vector3 curPos; |
|
} |
|
[Serializable] |
|
public class RecordCurtainLineParent : RecordCurtainLine |
|
{ |
|
public List<RecordCurtainLineChild> list = new List<RecordCurtainLineChild>(); |
|
public string task; |
|
} |