using AX.InputSystem; using AX.MessageSystem; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /// /// Author:zzj /// 画线基类 /// 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 MorePointList = new List();//用于存储多点 protected float MorePointDistance;//多点的长度 public LineType lintType = LineType.None; protected GameObject LineParent; protected float variableX; protected float variableY; protected float variableZ; protected List RangList = new List(); 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(); } } /// /// 管线连接检查 /// public virtual void CheckWater() { } public virtual void CreateLine(Vector3 placementPos, Vector3 placementPos2) { } public virtual bool CheckPersonLine(bool flag) { return false; } /// /// 查看线的父物体 /// public void CheckParent() { if (LineParent == null) { LineParent = Instantiate(Resources.Load("Prefab/Lines/LineParent")) as GameObject; LineParent.transform.SetParent(SetParent()); LineParent.name = SetParentName(); if (CheckLineType()) { RangList.Add(LineParent); } else { LineParent.GetComponent().SetGameObjID(GameID); LineParent.GetComponent().gameObjType = InputManager.cloneObjType; EntitiesManager.Instance.AddEntity(GameID, LineParent); NeedLineParentData(); } } } public virtual void NeedLineParentData() { } /// /// 给线赋值楼层信息 /// public void MutatorMethod(GameObject obj, long ID) { //设置克隆物体所在楼层属性,属性从点击的对象上获取 var hitObj = EntitiesManager.Instance.GetEntityByID(ID); CloneGameObjInfo floorMsg = hitObj.GetComponent(); CloneGameObjInfo objMsg = obj.GetComponent(); objMsg.buildNum = floorMsg.buildNum; objMsg.floorNum = floorMsg.floorNum; objMsg.interlayerNum = floorMsg.interlayerNum; } /// /// 给画出来的子物体赋值 /// /// public virtual void ChildMutatorMethod(GameObject Child) { Child.AddComponent(); Child.GetComponent().SetGameObjID(LineParent.GetComponent().GameObjID); Child.GetComponent().gameObjType = LineParent.GetComponent().gameObjType; SelectedObjs.gameObjs.Add(Child); MutatorMethod(Child, HitGameID); } /// /// 查看类型是否为测距,添加到RangList数组,控制测距线不能多生成 /// public bool CheckLineType() { if (InputManager.cloneObjType == CloneObjType.SpacePointsRanging || InputManager.cloneObjType == CloneObjType.MorePointsRanging || InputManager.cloneObjType == CloneObjType.TwoPointsRanging) { return true; } return false; } /// /// 用于子类重写对应线段的方法 /// 每次点击都会调用 /// /// false是第一次点击 public virtual void HandleOther(bool flag) { } /// /// 处理吸附功能 /// public virtual void Adsorb(bool flag) { } public Transform SetParent() { return transform; } public string SetParentName() { Number++; return InputManager.cloneObjType.ToString() + Number.ToString(); } }