1118OPSSNew/Assets/Zion/Scripts/GameScene/Processes/GroundConnection.cs

73 lines
2.3 KiB
C#

using UnityEngine;
/// <summary>
/// 接地
/// </summary>
public class GroundConnection : Device
{
public FunctionSync_Parent parent;
/// <summary>
/// 接地线物体
/// </summary>
public OneValueSyncObject ConnectObj;
public FunctionSync_PositionRoate groundLine;
/// <summary>
/// 是否接地
/// </summary>
public OneValueSyncObject isConnect;
/// <summary>
/// 接地位置
/// </summary>
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<FunctionSync_Parent>().SetParent(parent, linePos.localPosition, linePos.localEulerAngles);
}
}
private void OnTriggerStay(Collider other)
{
if (string.IsNullOrEmpty(ConnectObj.mystring) && other.tag.Equals("GroundLine"))
{
ConnectObj.mystring = other.GetComponent<FunctionSync_PositionRoate>().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();
}
}
}