using AX.InputSystem; using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public enum RotateAxis { X, Y, Z, } public class FCGSPControl : ObjDoubleClick { public bool IsWartering; public Transform particle; private long id; public GameObject part; public GameObject water; public Transform Hrotate; public Transform Vrotate; public RotateAxis HAxis; public RotateAxis VAxis; public string Hpath; public string Vpath; public float MaxV; public float MinV; private void Awake() { //sp/sp_bi/sp_tou int num = int.Parse(name.Substring(2,name.Length-2)); ////if (gameObject.name.Split('_').Length > 0) //{ id = 1990199019901990 + num;//(long.Parse)(gameObject.name.Split('_')[1]); GetComponent().gameObjID = id; gameObject.name = id.ToString(); //} EntitiesManager.Instance.AddEntity(id, gameObject); if (!SelectedObjs.gameObjs.Contains(gameObject)) SelectedObjs.gameObjs.Add(gameObject); if (!water) { water = GameObject.Instantiate(part, transform); } particle = transform.GetComponentInChildren(true).transform; Hrotate = transform.Find(Hpath); Vrotate = transform.Find(Vpath); if (particle.gameObject.activeInHierarchy) { particle.gameObject.SetActive(false); } } // Start is called before the first frame update void Start() { MessageDispatcher.AddListener("ReplayFrame", ReplayFrameZDSP); MessageDispatcher.AddListener("ReplayEvent", ReplayEventZDSP); MessageDispatcher.AddListener("EQUALS_COMMAND", PressureUp); MessageDispatcher.AddListener("MINUS_COMMAND", PressureDown); MessageDispatcher.AddListener("U_COMMAND", U); MessageDispatcher.AddListener("J_COMMAND", J); MessageDispatcher.AddListener("H_COMMAND", H); MessageDispatcher.AddListener("K_COMMAND", K); } private void OnDestroy() { MessageDispatcher.RemoveListener("ReplayFrame", ReplayFrameZDSP); MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventZDSP); MessageDispatcher.RemoveListener("EQUALS_COMMAND", PressureUp); MessageDispatcher.RemoveListener("MINUS_COMMAND", PressureDown); MessageDispatcher.RemoveListener("U_COMMAND", U); MessageDispatcher.RemoveListener("J_COMMAND", J); MessageDispatcher.RemoveListener("H_COMMAND", H); MessageDispatcher.RemoveListener("K_COMMAND", K); } private void K(IMessage obj) { if (Hrotate==null) { return; } var gameObjID = (long)obj.Sender; if (GetComponent().gameObjID == gameObjID) { var speed = ((WeightCmdArgs)obj.Data).Weight * 2f; switch (HAxis) { case RotateAxis.X: //var x = CheckV(Vrotate.localEulerAngles.x); Hrotate.localEulerAngles += new Vector3(speed, 0, 0); break; case RotateAxis.Y: Hrotate.localEulerAngles += new Vector3(0, speed, 0); break; case RotateAxis.Z: Hrotate.localEulerAngles += new Vector3(0, 0, speed); break; default: break; } RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ZDSP, JsonUtility.ToJson(GetData())); } } private void H(IMessage obj) { if (Hrotate == null) { return; } var gameObjID = (long)obj.Sender; if (GetComponent().gameObjID == gameObjID) { var speed = ((WeightCmdArgs)obj.Data).Weight * 2f; switch (HAxis) { case RotateAxis.X: //var x = CheckV(Vrotate.localEulerAngles.x); Hrotate.localEulerAngles -= new Vector3(speed, 0, 0); break; case RotateAxis.Y: Hrotate.localEulerAngles -= new Vector3(0, speed, 0); break; case RotateAxis.Z: Hrotate.localEulerAngles -= new Vector3(0, 0, speed); break; default: break; } RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ZDSP, JsonUtility.ToJson(GetData())); } } private void J(IMessage obj) { if (Vrotate==null) { return; } var gameObjID = (long)obj.Sender; if (GetComponent().gameObjID == gameObjID) { var speed = ((WeightCmdArgs)obj.Data).Weight * 2f; switch (VAxis) { case RotateAxis.X: var x = CheckV(Vrotate.localEulerAngles.x); if (x < MinV) { Vrotate.localEulerAngles = new Vector3(MinV, Vrotate.localEulerAngles.y, Vrotate.localEulerAngles.z); return; } Vrotate.localEulerAngles -= new Vector3(speed, 0, 0); break; case RotateAxis.Y: var y = CheckV(Vrotate.localEulerAngles.y); if (y < MinV) { Vrotate.localEulerAngles = new Vector3(Vrotate.localEulerAngles.x, y, Vrotate.localEulerAngles.z); return; } Vrotate.localEulerAngles -= new Vector3(0, speed, 0); break; case RotateAxis.Z: var z = CheckV(Vrotate.localEulerAngles.z); if (z < MinV) { Vrotate.localEulerAngles = new Vector3(Vrotate.localEulerAngles.x, Vrotate.localEulerAngles.y, z); return; } Vrotate.localEulerAngles -= new Vector3(0, 0, speed); break; default: break; } RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ZDSP, JsonUtility.ToJson(GetData())); } } private void U(IMessage obj) { if (Vrotate == null) { return; } var gameObjID = (long)obj.Sender; if (GetComponent().gameObjID == gameObjID) { var speed = ((WeightCmdArgs)obj.Data).Weight * 2f; switch (VAxis) { case RotateAxis.X: var x = CheckV(Vrotate.localEulerAngles.x); if (x>MaxV) { Vrotate.localEulerAngles = new Vector3(MaxV, Vrotate.localEulerAngles.y, Vrotate.localEulerAngles.z); return; } Vrotate.localEulerAngles += new Vector3( speed, 0,0); break; case RotateAxis.Y: var y = CheckV(Vrotate.localEulerAngles.y); if (y > MaxV) { Vrotate.localEulerAngles = new Vector3(Vrotate.localEulerAngles.x, y, Vrotate.localEulerAngles.z); return; } Vrotate.localEulerAngles += new Vector3( 0,speed, 0); break; case RotateAxis.Z: var z = CheckV(Vrotate.localEulerAngles.z); if (z > MaxV) { Vrotate.localEulerAngles = new Vector3(Vrotate.localEulerAngles.x, Vrotate.localEulerAngles.y, z); return; } Vrotate.localEulerAngles += new Vector3(0, 0,speed); break; default: break; } ZDSPData data = GetData(); RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ZDSP, JsonUtility.ToJson(data)); } } private void PressureDown(IMessage obj) { var gameObjID = (long)obj.Sender; if (GetComponent().gameObjID == gameObjID) { var speed = ((WeightCmdArgs)obj.Data).Weight*0.1f; float size = particle.GetComponent().GetScaleValue(); particle.GetComponent().SetScaleValue(size - speed); RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ZDSP, JsonUtility.ToJson(GetData())); } } private void PressureUp(IMessage obj) { if (SelectedObjs.selectedObj == gameObject && ReplaySetting.PlayStatus != PlayStatus.isReplay) { var gameObjID = (long)obj.Sender; if (GetComponent().gameObjID == gameObjID) { var speed = ((WeightCmdArgs)obj.Data).Weight*0.1f; float size= particle.GetComponent().GetScaleValue(); particle.GetComponent().SetScaleValue(size+speed); RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ZDSP, JsonUtility.ToJson(GetData())); } } } private void ReplayEventZDSP(IMessage obj) { var eventData = (EventData)obj.Data; if (eventData.eventType == RecordEventType.ZDSP) { ZDSPData data = JsonUtility.FromJson(eventData.json); if (data.name == gameObject.name) SetData(data); } } private void ReplayFrameZDSP(IMessage obj) { var objectData = (ObjectData)obj.Data; if (objectData.cloneObjType == CloneObjType.ZDSP) { ZDSPData data = JsonUtility.FromJson(objectData.json); if (data.name == gameObject.name) SetData(data); } } void SetData(ZDSPData data) { id = data.id; GetComponent().gameObjID = data.id; IsWartering = data.isWatering; particle.GetComponent().SetScaleValue(data.scale); switch (HAxis) { case RotateAxis.X: Hrotate.localEulerAngles = new Vector3(data.HRoate, Hrotate.localEulerAngles.y, Hrotate.localEulerAngles.z); break; case RotateAxis.Y: Hrotate.localEulerAngles = new Vector3( Hrotate.localEulerAngles.x, data.HRoate, Hrotate.localEulerAngles.z); break; case RotateAxis.Z: Hrotate.localEulerAngles = new Vector3(Hrotate.localEulerAngles.x, Hrotate.localEulerAngles.y, data.HRoate); break; default: break; } switch (VAxis) { case RotateAxis.X: Vrotate.localEulerAngles = new Vector3(data.VRoate, Vrotate.localEulerAngles.y, Vrotate.localEulerAngles.z); break; case RotateAxis.Y: Vrotate.localEulerAngles = new Vector3(Vrotate.localEulerAngles.x, data.VRoate, Vrotate.localEulerAngles.z); break; case RotateAxis.Z: Vrotate.localEulerAngles = new Vector3(Vrotate.localEulerAngles.x, Vrotate.localEulerAngles.y, data.VRoate); break; default: break; } //Hrotate.localEulerAngles = new Vector3(Hrotate.localEulerAngles.x, Hrotate.localEulerAngles.y, data.xRoate); // Pao.localEulerAngles = new Vector3(data.yRoate, Pao.localEulerAngles.y, Pao.localEulerAngles.z); if (IsWartering) particle.gameObject.SetActive(true); else particle.gameObject.SetActive(false); } // Update is called once per frame void Update() { } public override void ClickFunc() { base.ClickFunc(); if (!IsWartering) ResourceLoadWindow.Instance.LoadTipWindow("开启喷水?", () => { IsWartering = true; particle.gameObject.SetActive(true); RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ZDSP, JsonUtility.ToJson(GetData())); }, null); else ResourceLoadWindow.Instance.LoadTipWindow("关闭喷水?", () => { IsWartering = false; particle.gameObject.SetActive(false); RecordEvent.AddEventData(CloneObjType.None, RecordEventType.ZDSP, JsonUtility.ToJson(GetData())); }, null); } public ZDSPData GetData() { ZDSPData data = new ZDSPData { name = gameObject.name, id = this.id, isWatering = IsWartering, scale = particle.GetComponent().GetScaleValue(), HAxis = HAxis, VAxis = VAxis, // xRoate = Hrotate.localEulerAngles.z, // yRoate = Vrotate.localEulerAngles.x }; switch (data.VAxis) { case RotateAxis.X: data.VRoate= Vrotate.localEulerAngles.x; break; case RotateAxis.Y: data.VRoate = Vrotate.localEulerAngles.y; break; case RotateAxis.Z: data.VRoate = Vrotate.localEulerAngles.z; break; default: break; } switch (data.HAxis) { case RotateAxis.X: data.HRoate = Hrotate.localEulerAngles.x; break; case RotateAxis.Y: data.HRoate = Hrotate.localEulerAngles.y; break; case RotateAxis.Z: data.HRoate = Hrotate.localEulerAngles.z; break; default: break; } return data; } private float CheckV(float x) { if (x >= 180 && x <= 360) { x = x - 360; } return x; } }