93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
namespace AdamSync
|
|
{
|
|
public class SyncPlayerTransform : AsyncObjectBase
|
|
{
|
|
private string latestData = "";
|
|
|
|
private void OnInit()
|
|
{
|
|
SyncCreateRoom.playerInfoRequset += ReceivePlayInfo;
|
|
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
selfCamera = GetComponent<Camera>();
|
|
rect = GameObject.Find("MainCanvas").GetComponent<RectTransform>();
|
|
}
|
|
void Update()
|
|
{
|
|
if (selfCamera != null)
|
|
{
|
|
if (selfCamera.transform.position.y > 500)
|
|
{
|
|
if (Input.GetMouseButton(2))
|
|
{
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(rect, Input.mousePosition))
|
|
{
|
|
float mouseX = Input.GetAxis("Mouse X") * 10f * Time.deltaTime;
|
|
float mouseY = Input.GetAxis("Mouse Y") * 10f * Time.deltaTime;
|
|
selfCamera.transform.Translate(Vector3.down * mouseY * 60f);
|
|
selfCamera.transform.Translate(Vector3.left * mouseX * 60f);
|
|
}
|
|
}
|
|
Debug.Log("½øÀ´ÁË");
|
|
float scrollInput = Input.GetAxis("Mouse ScrollWheel");
|
|
if (scrollInput != 0)
|
|
{
|
|
float newOrthoSize = selfCamera.orthographicSize - scrollInput * 50;
|
|
selfCamera.orthographicSize = newOrthoSize;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private IEnumerator SendMsg()
|
|
{
|
|
while (true)
|
|
{
|
|
yield return new WaitForSeconds(0.01f);
|
|
|
|
var nowData = GetSyncData();
|
|
if (!nowData.Equals(latestData))
|
|
{
|
|
latestData = nowData;
|
|
|
|
_ = SyncCreateRoom.SendMessageAsync(string.Format("player {0}", nowData));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ReceivePlayInfo(ulong id, string pos, string angle)
|
|
{
|
|
if (id.Equals(userID))
|
|
{
|
|
transform.position = Trans(pos);
|
|
transform.eulerAngles = Trans(angle);
|
|
}
|
|
}
|
|
|
|
private Vector3 Trans(string msg)
|
|
{
|
|
string[] data = msg.Split(',');
|
|
Vector3 temp = new Vector3(float.Parse(data[0]), float.Parse(data[1]), float.Parse(data[2]));
|
|
return temp;
|
|
}
|
|
//private void OnDisable()
|
|
//{
|
|
// Debug.Log("OnDisable");
|
|
// StopAllCoroutines();
|
|
// SyncCreateRoom.playerInfoRequset -= ReceivePlayInfo;
|
|
//}
|
|
}
|
|
}
|