62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Good : MonoBehaviour
|
|
{
|
|
bool isJiaohu;
|
|
public bool IsJiaohu { get => isJiaohu; set => isJiaohu = value; }
|
|
public bool isExistServer;
|
|
|
|
public string sn;//设备SN
|
|
public Text user;//体验者昵称
|
|
public uint group;//分组名
|
|
public int x, y, z, q, w, e, r;//位置和旋转
|
|
|
|
float times;
|
|
|
|
float sendInterval = 0.1f; // 发送间隔(秒)
|
|
float nextSendTime; // 下次发送时间
|
|
|
|
void Start()
|
|
{
|
|
times = Config.times;
|
|
// 向管理类注册自己
|
|
VR2.Instance.RegisterGood(this);
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
// 从管理类注销
|
|
VR2.Instance.UnregisterGood(this);
|
|
}
|
|
private void Update()
|
|
{
|
|
if (IsJiaohu)
|
|
{
|
|
// 发送模式:固定间隔发送位置
|
|
if (Time.time >= nextSendTime)
|
|
{
|
|
nextSendTime = Time.time + sendInterval;
|
|
sendGoodPos();
|
|
}
|
|
}
|
|
else if (isExistServer)
|
|
{
|
|
UpdateGoodPos();
|
|
}
|
|
}
|
|
|
|
|
|
void UpdateGoodPos()
|
|
{
|
|
Vector3 tarpos = new Vector3(x / times, y / times, z / times);
|
|
Quaternion tarqua = new Quaternion(q / times, w / times, e / times, r / times);
|
|
transform.position = Vector3.Lerp(transform.position, tarpos, 0.1f);
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, tarqua, 0.1f);
|
|
|
|
}
|
|
public void sendGoodPos()
|
|
{
|
|
VR2.Instance.sendGoodPos(transform.name, transform.position, transform.rotation);
|
|
}
|
|
}
|