55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Passer.Control;
|
|
|
|
public class Thing : MonoBehaviour {
|
|
public Client client;
|
|
public byte networkId;
|
|
public byte thingId;
|
|
public byte objectType;
|
|
public string modelUrl;
|
|
//protected Sensor sensor;
|
|
|
|
public static List<Thing> allThings = new();
|
|
|
|
public static Thing GetThing(byte networkId, byte thingId) {
|
|
Thing thing = allThings.Find(aThing => aThing.networkId == networkId && aThing.thingId == thingId);
|
|
return thing;
|
|
}
|
|
|
|
protected virtual void Init() {
|
|
//if (this.objectType == 2) {
|
|
// sensor = this.gameObject.AddComponent<DistanceSensor>();
|
|
// sensor.thing = this;
|
|
//}
|
|
}
|
|
|
|
public static Thing Create(GameObject obj, Client client, byte networkId, byte objId, byte objType) {
|
|
Thing thing = obj.AddComponent<Thing>();
|
|
thing.client = client;
|
|
thing.thingId = objId;
|
|
thing.objectType = objType;
|
|
thing.networkId = networkId;
|
|
thing.Init();
|
|
allThings.Add(thing);
|
|
|
|
return thing;
|
|
}
|
|
|
|
public virtual Thing CopyTo(GameObject obj) {
|
|
//Debug.Log($"copy {obj}");
|
|
Thing foundThing = Thing.Create(obj, this.client, this.networkId, this.thingId, this.objectType);
|
|
Destroy(this.gameObject);
|
|
return foundThing;
|
|
}
|
|
|
|
public void ProcessBytes(byte[] bytes) {
|
|
//if (sensor != null)
|
|
// sensor.ProcessBytes(bytes);
|
|
}
|
|
//public void Update() {
|
|
// if (objectId == 0)
|
|
// Debug.Log(this.transform.eulerAngles);
|
|
//}
|
|
}
|