Added NetworkManager
This commit is contained in:
@@ -1,26 +1,56 @@
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
using Assets.Scripts;
|
||||
using System;
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.Udon.Serialization.OdinSerializer;
|
||||
|
||||
public abstract class GridMover : UdonSharpBehaviour
|
||||
public abstract class GridMover : SyncedObject
|
||||
{
|
||||
protected Vector2 direction;
|
||||
|
||||
public virtual Vector2 GetPosition()
|
||||
{
|
||||
Debug.LogError($"{gameObject} does not implement GetPosition");
|
||||
return Vector2.zero;
|
||||
return (Vector2)transform.localPosition;
|
||||
}
|
||||
|
||||
public virtual void SetPosition(Vector2 position)
|
||||
{
|
||||
Debug.LogError($"{gameObject} does not implement SetPosition");
|
||||
transform.localPosition = new Vector3(position.x, position.y, transform.localPosition.z);
|
||||
}
|
||||
|
||||
public virtual Vector2 GetDirection()
|
||||
{
|
||||
Debug.LogError($"{gameObject} does not implement GetDirection");
|
||||
return Vector2.zero;
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void SetDirection(Vector2 direction)
|
||||
{
|
||||
this.direction = direction;
|
||||
UpdateAnimator();
|
||||
}
|
||||
|
||||
protected abstract void UpdateAnimator();
|
||||
|
||||
public override void AppendSyncedData(byte[][] data, ref int offset)
|
||||
{
|
||||
var position = GetPosition();
|
||||
data[offset++] = BitConverter.GetBytes(position.x);
|
||||
data[offset++] = BitConverter.GetBytes(position.y);
|
||||
|
||||
var direction = GetDirection();
|
||||
data[offset++] = BitConverter.GetBytes(direction.x);
|
||||
data[offset++] = BitConverter.GetBytes(direction.y);
|
||||
}
|
||||
|
||||
public override bool SetSyncedData(byte[] data, ref int offset)
|
||||
{
|
||||
SetPosition(new Vector2(BitConverter.ToSingle(data, offset), BitConverter.ToSingle(data, offset + 2)));
|
||||
SetDirection(new Vector2(BitConverter.ToSingle(data, offset + 4), BitConverter.ToSingle(data, offset + 6)));
|
||||
offset += 8;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user