using UnityEngine; /// /// 接地 /// public class GroundConnection : Device { public FunctionSync_Parent parent; /// /// 接地线物体 /// public OneValueSyncObject ConnectObj; public FunctionSync_PositionRoate groundLine; /// /// 是否接地 /// public OneValueSyncObject isConnect; /// /// 接地位置 /// public Transform linePos; public override void Start() { ConnectObj.InitDynamic("sync_" + name, Callback, ValueType.String); } // Update is called once per frame void Update() { if (groundLine != null) { groundLine.transform.localPosition = linePos.localPosition; groundLine.transform.localEulerAngles = linePos.localEulerAngles; groundLine.SetPos(true, groundLine.transform.localPosition.x, groundLine.transform.localPosition.y, groundLine.transform.localPosition.z); groundLine.SetRot(true, groundLine.transform.localEulerAngles.x, groundLine.transform.localEulerAngles.y, groundLine.transform.localEulerAngles.z); } } private void Callback(string id, bool isEnterRoom) { if (string.IsNullOrEmpty(id)) { groundLine = null; } else { groundLine = FunctionSync_PositionRoate.positionRoateSyncObejctList[id]; groundLine.GetComponent().SetParent(parent, linePos.localPosition, linePos.localEulerAngles); } } private void OnTriggerStay(Collider other) { if (string.IsNullOrEmpty(ConnectObj.mystring) && other.tag.Equals("GroundLine")) { ConnectObj.mystring = other.GetComponent().Id; Callback(ConnectObj.mystring, false); isConnect.mybool = true; isConnect.SendSync(); if (isConnect.action_apprisedetail != null) isConnect.action_apprisedetail.Invoke(); } } private void OnTriggerExit(Collider other) { if (other.tag.Equals("GroundLine")) { ConnectObj.mystring = ""; isConnect.mybool = false; isConnect.SendSync(); if (isConnect.action_apprisedetail != null) isConnect.action_apprisedetail.Invoke(); } } }