added generic spawned object loader for images
parent
885b27bfe1
commit
1f9bb4f97f
|
|
@ -0,0 +1,70 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using VelNet;
|
||||
|
||||
namespace VELConnect
|
||||
{
|
||||
public class GenericSpawnedObject : SyncState
|
||||
{
|
||||
private string url;
|
||||
|
||||
private string Url
|
||||
{
|
||||
get => url;
|
||||
set
|
||||
{
|
||||
if (url == value) return;
|
||||
|
||||
url = value;
|
||||
|
||||
if (url.EndsWith(".png") || url.EndsWith(".jpg"))
|
||||
{
|
||||
StartCoroutine(DownloadImage(url));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Invalid image url: " + url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RawImage rawImage;
|
||||
|
||||
public void Init(string dataUrl)
|
||||
{
|
||||
Url = dataUrl;
|
||||
}
|
||||
|
||||
protected override void SendState(BinaryWriter binaryWriter)
|
||||
{
|
||||
binaryWriter.Write(Url);
|
||||
}
|
||||
|
||||
protected override void ReceiveState(BinaryReader binaryReader)
|
||||
{
|
||||
Url = binaryReader.ReadString();
|
||||
}
|
||||
|
||||
private IEnumerator DownloadImage(string downloadUrl)
|
||||
{
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(downloadUrl);
|
||||
yield return request.SendWebRequest();
|
||||
if (request.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Debug.Log(request.error);
|
||||
yield break;
|
||||
}
|
||||
|
||||
rawImage.texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
|
||||
float aspect = (float)rawImage.texture.width / rawImage.texture.height;
|
||||
Transform t = transform;
|
||||
Vector3 s = t.localScale;
|
||||
s = new Vector3(aspect * s.y, s.y, s.z);
|
||||
t.localScale = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 16f283d9b4aeffc429940a70600d2e5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -173,19 +173,15 @@ namespace VELConnect
|
|||
{
|
||||
if (instance != null) Debug.LogError("VELConnectManager instance already exists", this);
|
||||
instance = this;
|
||||
|
||||
// Compute device id
|
||||
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
|
||||
StringBuilder sb = new StringBuilder(SystemInfo.deviceUniqueIdentifier);
|
||||
sb.Append(Application.productName);
|
||||
#if UNITY_EDITOR
|
||||
// allows running multiple builds on the same computer
|
||||
// return SystemInfo.deviceUniqueIdentifier + Hash128.Compute(Application.dataPath);
|
||||
sb.Append(Application.dataPath);
|
||||
sb.Append("EDITOR");
|
||||
#endif
|
||||
string id = Convert.ToBase64String(md5.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString())));
|
||||
deviceId = CreateDeviceId();
|
||||
VelNetManager.OnLocalNetworkObjectSpawned += networkObject =>
|
||||
{
|
||||
if (!networkObject.ownershipLocked)
|
||||
{
|
||||
// TODO
|
||||
// SetRoomData("spawned_" + networkObject.networkId, networkObject.prefabName);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Computes 15-char device id compatibly with pocketbase
|
||||
|
|
|
|||
|
|
@ -45,6 +45,16 @@ namespace VELConnect
|
|||
{
|
||||
loading = true;
|
||||
if (debugLogs) Debug.Log($"[VelNetPersist] Loading {Id}");
|
||||
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;
|
||||
}
|
||||
VELConnectManager.GetDataBlock(Id, data =>
|
||||
{
|
||||
if (!data.data.TryGetValue("state", out string d))
|
||||
|
|
@ -71,6 +81,16 @@ namespace VELConnect
|
|||
private void Save()
|
||||
{
|
||||
if (debugLogs) Debug.Log($"[VelNetPersist] Saving {Id}");
|
||||
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;
|
||||
}
|
||||
VELConnectManager.SetDataBlock(Id, new VELConnectManager.State.DataBlock()
|
||||
{
|
||||
category = "object_persist",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "edu.uga.engr.vel.vel-connect",
|
||||
"displayName": "VEL-Connect",
|
||||
"version": "4.0.1",
|
||||
"version": "4.0.2",
|
||||
"unity": "2019.1",
|
||||
"description": "Web-based configuration for VR applications",
|
||||
"keywords": [],
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ export type AuthSystemFields<T = never> = {
|
|||
|
||||
// Record types for each collection
|
||||
|
||||
export type DataBlockRecord<Tdata = unknown> = {
|
||||
export type DataBlockRecord<Tdata = { [key: string]: any }> = {
|
||||
block_id?: string
|
||||
category?: string
|
||||
data?: null | Tdata
|
||||
|
|
@ -74,10 +74,10 @@ export type UsersRecord = {
|
|||
}
|
||||
|
||||
// Response types include system fields and match responses from the PocketBase API
|
||||
export type DataBlockResponse<Tdata = unknown, Texpand = unknown> = Required<DataBlockRecord<Tdata>> & BaseSystemFields<Texpand>
|
||||
export type DataBlockResponse<Tdata = { [key: string]: any }, Texpand = unknown> = Required<DataBlockRecord<Tdata>> & BaseSystemFields<Texpand>
|
||||
export type DeviceResponse<Texpand = unknown> = Required<DeviceRecord> & BaseSystemFields<Texpand>
|
||||
export type UserCountResponse<Texpand = unknown> = Required<UserCountRecord> & BaseSystemFields<Texpand>
|
||||
export type UsersResponse<Texpand = unknown> = Required<UsersRecord> & AuthSystemFields<Texpand>
|
||||
export type UsersResponse<Texpand = { devices: DeviceResponse[]; profiles: DataBlockResponse[] }> = Required<UsersRecord> & AuthSystemFields<Texpand>
|
||||
|
||||
// Types containing all Records and Responses, useful for creating typing helper functions
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue