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.
217 lines
6.7 KiB
217 lines
6.7 KiB
using AX.InputSystem; |
|
using AX.MessageSystem; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
/// <summary> |
|
/// Author:zzj |
|
/// 画线基类 |
|
/// </summary> |
|
public enum LineType : int |
|
{ |
|
None = 0, |
|
AttackLine = 1, |
|
BlockLine = 2, |
|
BrokenLine = 3, |
|
EjectSmokeLine = 4, |
|
OrdinaryHose = 5, |
|
RetreatLine = 6, |
|
ScintillationHose = 7, |
|
WarningLine = 8 |
|
} |
|
|
|
public class DrawLineBase : MonoBehaviour |
|
{ |
|
protected bool Control = false; //开关 |
|
protected Vector3 placementPos;//第一碰撞点 |
|
protected Vector3 placementPos2;//第二碰撞点 |
|
protected bool MorePoint = false;//判断是否多点 |
|
protected List<Vector3> MorePointList = new List<Vector3>();//用于存储多点 |
|
protected float MorePointDistance;//多点的长度 |
|
public LineType lintType = LineType.None; |
|
protected GameObject LineParent; |
|
protected float variableX; |
|
protected float variableY; |
|
protected float variableZ; |
|
protected List<GameObject> RangList = new List<GameObject>(); |
|
protected int Number = 0; |
|
protected long GameID = 0; |
|
protected long HitGameID = 0; |
|
//protected RaycastHit Hit; |
|
|
|
public static bool CheckCloneObjTypeLine() |
|
{ |
|
|
|
if (InputManager.cloneObjType == CloneObjType.AttackLine || |
|
InputManager.cloneObjType == CloneObjType.BlockLine || |
|
InputManager.cloneObjType == CloneObjType.BrokenLine || |
|
InputManager.cloneObjType == CloneObjType.EjectSmokeLine || |
|
InputManager.cloneObjType == CloneObjType.MorePointsRanging || |
|
InputManager.cloneObjType == CloneObjType.SpacePointsRanging || |
|
InputManager.cloneObjType == CloneObjType.TwoPointsRanging || |
|
InputManager.cloneObjType == CloneObjType.None) |
|
{ |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
void Awake() |
|
{ |
|
MessageDispatcher.AddListener("CANCEL_CLONEBTN_SELECTED_COMMAND", ResetData); |
|
} |
|
void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("CANCEL_CLONEBTN_SELECTED_COMMAND", ResetData); |
|
} |
|
private void ResetData(IMessage Img) |
|
{ |
|
ResetData(); |
|
} |
|
|
|
//重置数据 |
|
public void ResetData() |
|
{ |
|
MorePoint = false; |
|
MorePointList.Clear(); |
|
MorePointDistance = 0; |
|
placementPos = new Vector3(0, 0, 0); |
|
placementPos2 = new Vector3(0, 0, 0); |
|
RangList.ForEach(x => Destroy(x)); |
|
RangList.Clear(); |
|
SendMessage(); |
|
LineParent = null; |
|
} |
|
//处理可连接管线类型发送消息 |
|
public virtual void SendMessage() |
|
{ |
|
|
|
} |
|
|
|
//绘制方法 |
|
public void DrawLineOperation(Vector3 vector, long HitID, long gameID) |
|
{ |
|
HitGameID = HitID; |
|
GameID = gameID; |
|
if ((placementPos.x == 0 && placementPos.y == 0 && placementPos.z == 0)) |
|
{ |
|
if (CheckPersonLine(false)) |
|
{ |
|
return; |
|
} |
|
placementPos = vector; |
|
Adsorb(false); |
|
HandleOther(false); |
|
return; |
|
} |
|
placementPos2 = vector; |
|
//判断第二次点击是否和第一次重合,同时避免因为每帧调用的误处理。 |
|
if ((placementPos.x != placementPos2.x)) |
|
{ |
|
if (CheckPersonLine(true)) |
|
{ |
|
return; |
|
} |
|
Adsorb(true);//吸附操作 |
|
CreateLine(placementPos, placementPos2);//创建线 |
|
HandleOther(true); //第二次点击的特殊处理 |
|
CheckWater(); |
|
} |
|
} |
|
/// <summary> |
|
/// 管线连接检查 |
|
/// </summary> |
|
public virtual void CheckWater() { } |
|
|
|
public virtual void CreateLine(Vector3 placementPos, Vector3 placementPos2) { } |
|
|
|
public virtual bool CheckPersonLine(bool flag) { return false; } |
|
/// <summary> |
|
/// 查看线的父物体 |
|
/// </summary> |
|
public void CheckParent() |
|
{ |
|
if (LineParent == null) |
|
{ |
|
LineParent = Instantiate(Resources.Load<GameObject>("Prefab/Lines/LineParent")) as GameObject; |
|
LineParent.transform.SetParent(SetParent()); |
|
LineParent.name = SetParentName(); |
|
|
|
if (CheckLineType()) |
|
{ |
|
RangList.Add(LineParent); |
|
} |
|
else |
|
{ |
|
LineParent.GetComponent<CloneGameObjInfo>().SetGameObjID(GameID); |
|
LineParent.GetComponent<CloneGameObjInfo>().gameObjType = InputManager.cloneObjType; |
|
EntitiesManager.Instance.AddEntity(GameID, LineParent); |
|
NeedLineParentData(); |
|
} |
|
|
|
} |
|
} |
|
public virtual void NeedLineParentData() { } |
|
|
|
/// <summary> |
|
/// 给线赋值楼层信息 |
|
/// </summary> |
|
public void MutatorMethod(GameObject obj, long ID) |
|
{ |
|
//设置克隆物体所在楼层属性,属性从点击的对象上获取 |
|
var hitObj = EntitiesManager.Instance.GetEntityByID(ID); |
|
CloneGameObjInfo floorMsg = hitObj.GetComponent<CloneGameObjInfo>(); |
|
CloneGameObjInfo objMsg = obj.GetComponent<CloneGameObjInfo>(); |
|
objMsg.buildNum = floorMsg.buildNum; |
|
objMsg.floorNum = floorMsg.floorNum; |
|
objMsg.interlayerNum = floorMsg.interlayerNum; |
|
} |
|
/// <summary> |
|
/// 给画出来的子物体赋值 |
|
/// </summary> |
|
/// <param name="Child"></param> |
|
public virtual void ChildMutatorMethod(GameObject Child) |
|
{ |
|
Child.AddComponent<BoxCollider>(); |
|
Child.GetComponent<CloneGameObjInfo>().SetGameObjID(LineParent.GetComponent<CloneGameObjInfo>().GameObjID); |
|
Child.GetComponent<CloneGameObjInfo>().gameObjType = LineParent.GetComponent<CloneGameObjInfo>().gameObjType; |
|
SelectedObjs.gameObjs.Add(Child); |
|
MutatorMethod(Child, HitGameID); |
|
} |
|
|
|
/// <summary> |
|
/// 查看类型是否为测距,添加到RangList数组,控制测距线不能多生成 |
|
/// </summary> |
|
public bool CheckLineType() |
|
{ |
|
if (InputManager.cloneObjType == CloneObjType.SpacePointsRanging |
|
|| InputManager.cloneObjType == CloneObjType.MorePointsRanging |
|
|| InputManager.cloneObjType == CloneObjType.TwoPointsRanging) |
|
{ |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
/// <summary> |
|
/// 用于子类重写对应线段的方法 |
|
/// 每次点击都会调用 |
|
/// </summary> |
|
/// <param name="flag">false是第一次点击</param> |
|
public virtual void HandleOther(bool flag) { } |
|
/// <summary> |
|
/// 处理吸附功能 |
|
/// </summary> |
|
public virtual void Adsorb(bool flag) { } |
|
public Transform SetParent() |
|
{ |
|
return transform; |
|
} |
|
|
|
public string SetParentName() |
|
{ |
|
Number++; |
|
return InputManager.cloneObjType.ToString() + Number.ToString(); |
|
} |
|
}
|
|
|