clean up old code, bump version
parent
ad778a616b
commit
48e55550c3
|
|
@ -1,6 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
@ -12,14 +10,6 @@ namespace VELConnect
|
||||||
{
|
{
|
||||||
public static VelConnectPersistenceManager instance;
|
public static VelConnectPersistenceManager instance;
|
||||||
|
|
||||||
public class SpawnedObjectData
|
|
||||||
{
|
|
||||||
public string prefabName;
|
|
||||||
public string base64ObjectData;
|
|
||||||
public string networkId;
|
|
||||||
public int componentIdx;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
@ -56,6 +46,7 @@ namespace VELConnect
|
||||||
Debug.LogError("Persisted object has no data");
|
Debug.LogError("Persisted object has no data");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkObject spawnedObj = VelNetManager.NetworkInstantiate(persistObject.name, Convert.FromBase64String(persistObject.data));
|
NetworkObject spawnedObj = VelNetManager.NetworkInstantiate(persistObject.name, Convert.FromBase64String(persistObject.data));
|
||||||
VelNetPersist persist = spawnedObj.GetComponent<VelNetPersist>();
|
VelNetPersist persist = spawnedObj.GetComponent<VelNetPersist>();
|
||||||
|
|
||||||
|
|
@ -63,69 +54,10 @@ namespace VELConnect
|
||||||
persist.LoadData(persistObject);
|
persist.LoadData(persistObject);
|
||||||
}
|
}
|
||||||
}, s => { Debug.LogError("Failed to get persisted spawned objects", this); });
|
}, s => { Debug.LogError("Failed to get persisted spawned objects", this); });
|
||||||
|
|
||||||
//
|
|
||||||
// string spawnedObjects = VELConnectManager.GetRoomData("spawned_objects", "[]");
|
|
||||||
// List<string> spawnedObjectList = JsonConvert.DeserializeObject<List<string>>(spawnedObjects);
|
|
||||||
// List<NetworkObject> spawnedNetworkObjects = new List<NetworkObject>();
|
|
||||||
// GetSpawnedObjectData(spawnedObjectList, (list) =>
|
|
||||||
// {
|
|
||||||
// foreach (SpawnedObjectData obj in list)
|
|
||||||
// {
|
|
||||||
// NetworkObject spawnedObj = spawnedNetworkObjects.Find(i => i.networkId == obj.networkId);
|
|
||||||
// if (spawnedObj == null)
|
|
||||||
// {
|
|
||||||
// spawnedObj = VelNetManager.NetworkInstantiate(obj.prefabName);
|
|
||||||
// spawnedNetworkObjects.Add(spawnedObj);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// spawnedObj.syncedComponents[obj.componentIdx].ReceiveBytes(Convert.FromBase64String(obj.base64ObjectData));
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DataBlocksResponse
|
|
||||||
{
|
|
||||||
public List<VELConnectManager.State.DataBlock> items;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void GetSpawnedObjectData(List<string> spawnedObjectList, Action<List<SpawnedObjectData>> callback)
|
|
||||||
{
|
|
||||||
VELConnectManager.GetRequestCallback($"/api/collections/DataBlock/records?filter=({string.Join(" || ", "id=\"" + spawnedObjectList + "\"")})", (response) =>
|
|
||||||
{
|
|
||||||
DataBlocksResponse parsedResponse = JsonConvert.DeserializeObject<DataBlocksResponse>(response);
|
|
||||||
callback(parsedResponse.items.Select(i => new SpawnedObjectData()
|
|
||||||
{
|
|
||||||
networkId = i.block_id.Split("_")[-1],
|
|
||||||
componentIdx = int.Parse(i.block_id.Split("_").Last()),
|
|
||||||
prefabName = i.TryGetData("name"),
|
|
||||||
base64ObjectData = i.TryGetData("state")
|
|
||||||
}).ToList());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't need to register objects, because they will do that automatically when they spawn if they have the VelNetPersist component
|
// We don't need to register objects, because they will do that automatically when they spawn if they have the VelNetPersist component
|
||||||
// public static void RegisterObject(NetworkObject obj)
|
|
||||||
// {
|
|
||||||
// if (instance == null)
|
|
||||||
// {
|
|
||||||
// Debug.LogError("VelConnectPersistenceManager not found in scene");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// VelNetPersist[] persistedComponents = obj.GetComponents<VelNetPersist>();
|
|
||||||
// if (persistedComponents.Length > 1)
|
|
||||||
// {
|
|
||||||
// Debug.LogError("NetworkObject has more than one VelNetPersist component");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// foreach (VelNetPersist velNetPersist in persistedComponents)
|
|
||||||
// {
|
|
||||||
// velNetPersist.Save();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// We need to unregister objects when they are destroyed because destroying could happen because we left the scene
|
// We need to unregister objects when they are destroyed because destroying could happen because we left the scene
|
||||||
public static void UnregisterObject(NetworkObject obj)
|
public static void UnregisterObject(NetworkObject obj)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace VELConnect
|
||||||
private const float interval = 5f;
|
private const float interval = 5f;
|
||||||
private double nextUpdate;
|
private double nextUpdate;
|
||||||
private bool loading;
|
private bool loading;
|
||||||
private const bool debugLogs = true;
|
private const bool debugLogs = false;
|
||||||
public string persistId;
|
public string persistId;
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
|
@ -99,20 +99,6 @@ namespace VELConnect
|
||||||
|
|
||||||
using BinaryReader reader = new BinaryReader(new MemoryStream(Convert.FromBase64String(obj.data)));
|
using BinaryReader reader = new BinaryReader(new MemoryStream(Convert.FromBase64String(obj.data)));
|
||||||
networkObject.UnpackState(reader);
|
networkObject.UnpackState(reader);
|
||||||
//
|
|
||||||
// List<SyncState> syncStateComponents = networkObject.syncedComponents.OfType<SyncState>().ToList();
|
|
||||||
// if (obj.data.Count != syncStateComponents.Count)
|
|
||||||
// {
|
|
||||||
// Debug.LogError($"[VelNetPersist] Different number of components");
|
|
||||||
// loading = false;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < syncStateComponents.Count; i++)
|
|
||||||
// {
|
|
||||||
// Debug.Log($"[VelNetPersist] Unpacking {obj.name} {syncStateComponents[i].GetType().Name}");
|
|
||||||
// syncStateComponents[i].UnpackState(Convert.FromBase64String(obj.data[i].state));
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (debugLogs) Debug.Log($"[VelNetPersist] Loaded {name}");
|
if (debugLogs) Debug.Log($"[VelNetPersist] Loaded {name}");
|
||||||
loading = false;
|
loading = false;
|
||||||
|
|
@ -131,28 +117,6 @@ namespace VELConnect
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List<VELConnectManager.ComponentState> componentData = new List<VELConnectManager.ComponentState>();
|
|
||||||
// foreach (SyncState syncState in syncStateComponents)
|
|
||||||
// {
|
|
||||||
// if (syncState == null)
|
|
||||||
// {
|
|
||||||
// Debug.LogError("SyncState is null for Persist", this);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (syncState.networkObject == null)
|
|
||||||
// {
|
|
||||||
// Debug.LogError("Network Object is null for SyncState", syncState);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// componentData.Add(new VELConnectManager.ComponentState()
|
|
||||||
// {
|
|
||||||
// componentIdx = networkObject.syncedComponents.IndexOf(syncState),
|
|
||||||
// state = Convert.ToBase64String(syncState.PackState())
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
using BinaryWriter writer = new BinaryWriter(new MemoryStream());
|
using BinaryWriter writer = new BinaryWriter(new MemoryStream());
|
||||||
networkObject.PackState(writer);
|
networkObject.PackState(writer);
|
||||||
string data = Convert.ToBase64String(((MemoryStream)writer.BaseStream).ToArray());
|
string data = Convert.ToBase64String(((MemoryStream)writer.BaseStream).ToArray());
|
||||||
|
|
@ -160,7 +124,7 @@ namespace VELConnect
|
||||||
// if we have a persistId, update the record, otherwise create a new one
|
// if we have a persistId, update the record, otherwise create a new one
|
||||||
if (string.IsNullOrEmpty(persistId))
|
if (string.IsNullOrEmpty(persistId))
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"We don't have an existing persistId, so we are creating a new record for {networkObject.prefabName}");
|
Debug.LogWarning($"We don't have an existing persistId, so we are creating a new record for {networkObject.name}");
|
||||||
VELConnectManager.PostRequestCallback(VELConnectManager.VelConnectUrl + "/api/collections/PersistObject/records", JsonConvert.SerializeObject(
|
VELConnectManager.PostRequestCallback(VELConnectManager.VelConnectUrl + "/api/collections/PersistObject/records", JsonConvert.SerializeObject(
|
||||||
new VELConnectManager.PersistObject()
|
new VELConnectManager.PersistObject()
|
||||||
{
|
{
|
||||||
|
|
@ -172,8 +136,6 @@ namespace VELConnect
|
||||||
data = data,
|
data = data,
|
||||||
}), null, s =>
|
}), null, s =>
|
||||||
{
|
{
|
||||||
Debug.Log(s);
|
|
||||||
|
|
||||||
VELConnectManager.PersistObject resp = JsonConvert.DeserializeObject<VELConnectManager.PersistObject>(s);
|
VELConnectManager.PersistObject resp = JsonConvert.DeserializeObject<VELConnectManager.PersistObject>(s);
|
||||||
persistId = resp.id;
|
persistId = resp.id;
|
||||||
successCallback?.Invoke(resp);
|
successCallback?.Invoke(resp);
|
||||||
|
|
@ -192,8 +154,6 @@ namespace VELConnect
|
||||||
data = data,
|
data = data,
|
||||||
}), null, s =>
|
}), null, s =>
|
||||||
{
|
{
|
||||||
Debug.Log(s);
|
|
||||||
|
|
||||||
VELConnectManager.PersistObject resp = JsonConvert.DeserializeObject<VELConnectManager.PersistObject>(s);
|
VELConnectManager.PersistObject resp = JsonConvert.DeserializeObject<VELConnectManager.PersistObject>(s);
|
||||||
successCallback?.Invoke(resp);
|
successCallback?.Invoke(resp);
|
||||||
}, method: "PATCH");
|
}, method: "PATCH");
|
||||||
|
|
@ -211,8 +171,6 @@ namespace VELConnect
|
||||||
VELConnectManager.PostRequestCallback(VELConnectManager.VelConnectUrl + "/api/collections/PersistObject/records/" + persistId, null, null,
|
VELConnectManager.PostRequestCallback(VELConnectManager.VelConnectUrl + "/api/collections/PersistObject/records/" + persistId, null, null,
|
||||||
s =>
|
s =>
|
||||||
{
|
{
|
||||||
Debug.Log(s);
|
|
||||||
|
|
||||||
VELConnectManager.PersistObject resp = JsonConvert.DeserializeObject<VELConnectManager.PersistObject>(s);
|
VELConnectManager.PersistObject resp = JsonConvert.DeserializeObject<VELConnectManager.PersistObject>(s);
|
||||||
successCallback?.Invoke(resp);
|
successCallback?.Invoke(resp);
|
||||||
}, Debug.LogError,
|
}, Debug.LogError,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "edu.uga.engr.vel.vel-connect",
|
"name": "edu.uga.engr.vel.vel-connect",
|
||||||
"displayName": "VEL-Connect",
|
"displayName": "VEL-Connect",
|
||||||
"version": "4.0.8",
|
"version": "4.0.9",
|
||||||
"unity": "2019.1",
|
"unity": "2019.1",
|
||||||
"description": "Web-based configuration for VR applications",
|
"description": "Web-based configuration for VR applications",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue