commit
b16de5434d
|
|
@ -0,0 +1,47 @@
|
||||||
|
env:
|
||||||
|
SUBFOLDER: docs_website
|
||||||
|
|
||||||
|
name: Publish Docs to docs.velconnect.ugavel.com (Cloudflare Pages)
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- docs_website/**
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish-docs:
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ${{env.SUBFOLDER}}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
deployments: write
|
||||||
|
name: Publish to Cloudflare Pages
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: 3.x
|
||||||
|
|
||||||
|
- run: echo "CACHE_ID=$(date --utc '+%V')" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
key: mkdocs-material-${{ env.CACHE_ID }}
|
||||||
|
path: .cache
|
||||||
|
restore-keys: |
|
||||||
|
mkdocs-material-
|
||||||
|
|
||||||
|
- run: pip install -r requirements.txt
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: mkdocs build --site-dir public
|
||||||
|
|
||||||
|
- name: Upload
|
||||||
|
env:
|
||||||
|
PROJECT_NAME: velconnect-docs
|
||||||
|
CLOUDFLARE_ACCOUNT_ID: 8077b5b1f8e2ade41874cbaa3f883069
|
||||||
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
run: npx wrangler@3.1.1 pages deploy public --project-name="${{env.PROJECT_NAME}}" --branch="${{env.GITHUB_REF_NAME}}"
|
||||||
|
|
@ -20,6 +20,6 @@ jobs:
|
||||||
registry-url: "https://registry.npmjs.org"
|
registry-url: "https://registry.npmjs.org"
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm publish
|
- run: npm publish --access public
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,6 @@ jobs:
|
||||||
registry-url: "https://registry.npmjs.org"
|
registry-url: "https://registry.npmjs.org"
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm publish
|
- run: npm publish --access public
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
env/
|
||||||
|
public/
|
||||||
|
site/
|
||||||
|
.venv/
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Serve Docs",
|
||||||
|
"type": "node-terminal",
|
||||||
|
"request": "launch",
|
||||||
|
"command": "mkdocs serve"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"python.terminal.activateEnvironment": true,
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "Autogenerate docs from code",
|
||||||
|
"detail": "Runs generate_docs.py",
|
||||||
|
"command": "python generate_docs.py",
|
||||||
|
"type": "shell",
|
||||||
|
"args": [],
|
||||||
|
"problemMatcher": [],
|
||||||
|
"presentation": {
|
||||||
|
"reveal": "always"
|
||||||
|
},
|
||||||
|
"group": "build"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# VEL-Connect Docs
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
1. Create or activate a pip environment
|
||||||
|
- Create:
|
||||||
|
- `python -m venv env`
|
||||||
|
- Activate:
|
||||||
|
- PowerShell: `.\env\Scripts\Activate.ps1`
|
||||||
|
- CMD: `.\env\Scripts\Activate.bat`
|
||||||
|
2. Install requirements:
|
||||||
|
- `pip install -r requirements.txt`
|
||||||
|
3. Run:
|
||||||
|
- `mkdocs serve`
|
||||||
|
- or use `F5` in VSCode
|
||||||
|
4. Build and Deploy
|
||||||
|
- Building and deploying happens automatically using a GitHub Action on push. If you want to build manually, use this command:
|
||||||
|
- `mkdocs build`
|
||||||
|
- For more information, visit these docs pages: https://squidfunk.github.io/mkdocs-material/getting-started/
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 659 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 108 KiB |
|
|
@ -0,0 +1,8 @@
|
||||||
|
# VEL-Connect
|
||||||
|
|
||||||
|
VEL-Connect is a persistent shared storage mechanism for Unity projects. It can be used as a key-value store as a networked replacement for PlayerPrefs, to share a profile of user data across multiple devices, or to easily switch between different user profiles on a single device.
|
||||||
|
|
||||||
|
Important pages:
|
||||||
|
|
||||||
|
- [Installation](/installation)
|
||||||
|
- [Quick Start](/quick-start)
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
|
||||||
|
Install the UPM package in Unity:
|
||||||
|
|
||||||
|
=== "**Option 1:** Add the VEL package registry"
|
||||||
|
|
||||||
|
{ align=right }
|
||||||
|
|
||||||
|
Using the scoped registry allows you to easily install a specific version of the package by using the Version History tab.
|
||||||
|
|
||||||
|
- In Unity, go to `Edit->Project Settings...->Package Manager`
|
||||||
|
- Under "Scoped Registries" click the + icon
|
||||||
|
- Add the following details, then click Apply
|
||||||
|
- Name: `VEL` (or anything you want)
|
||||||
|
- URL: `https://npm.ugavel.com`
|
||||||
|
- Scope(s): `edu.uga.engr.vel`
|
||||||
|
- Install the package:
|
||||||
|
- In the package manager, select `My Registries` from the dropdown
|
||||||
|
- Install the `VEL-Connect` package.
|
||||||
|
|
||||||
|
=== "**Option 2:** Add the package by git url"
|
||||||
|
|
||||||
|
1. Open the Package Manager in Unity with `Window->Package Manager`
|
||||||
|
- Add the local package:
|
||||||
|
- `+`->`Add package from git URL...`
|
||||||
|
- Set the path to `https://github.com/velaboratory/VEL-Connect`
|
||||||
|
|
||||||
|
To update the package, click the `Update` button in the Package Manager, or delete the `packages-lock.json` file.
|
||||||
|
|
||||||
|
=== "**Option 3:** Add the package locally"
|
||||||
|
|
||||||
|
1. Clone the repository on your computer:
|
||||||
|
`git clone git@github.com:velaboratory/VEL-Connect.git`
|
||||||
|
- Open the Package Manager in Unity with `Window->Package Manager`
|
||||||
|
- Add the local package:
|
||||||
|
- `+`->`Add package from disk...`
|
||||||
|
- Set the path to `VEL-Connect/package.json` on your hard drive.
|
||||||
|
|
||||||
|
To update the package, use `git pull` in the VEL-Connect folder.
|
||||||
|
|
||||||
|
Then check out the [quick start guide](quick-start.md).
|
||||||
|
|
@ -0,0 +1,180 @@
|
||||||
|
---
|
||||||
|
title: Quick Start
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
1. [Install the package](/)
|
||||||
|
2. Add the VelConnectManager script to an object in your scene. If you transition between scenes in your application, mark the object as `DontDestroyOnLoad`
|
||||||
|
3. Set the `Vel Connect Url` field on the component to a valid velconnect server. `https://velconnect-v4.ugavel.com` is useful for VEL projects.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Setting data
|
||||||
|
|
||||||
|
To set user data in VEL-Connect use the static function `SetUserData`.
|
||||||
|
|
||||||
|
You can add a single key and value:
|
||||||
|
```cs
|
||||||
|
VELConnectManager.SetUserData("key1", "val1");
|
||||||
|
```
|
||||||
|
|
||||||
|
Or set multiple keys with the dictionary syntax:
|
||||||
|
```cs
|
||||||
|
VELConnectManager.SetUserData(new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "key2", "val2" },
|
||||||
|
{ "key3", "val3" }
|
||||||
|
});
|
||||||
|
```
|
||||||
|
Data will be set instantly locally, then pushed to the server. You don't have to wait for VEL-Connect to initialize at the beginning of your game to set data.
|
||||||
|
|
||||||
|
### Getting data
|
||||||
|
|
||||||
|
Fetching data from a remote server can be more tricky because it won't be available immediately when the game starts. Data can also be set from other applications (such as a dashboard or other users in the case of room data), so change listeners are useful.
|
||||||
|
|
||||||
|
To fetch a single value from a key:
|
||||||
|
```cs
|
||||||
|
string value1 = VELConnectManager.GetUserData("key1");
|
||||||
|
```
|
||||||
|
The latest local value will be returned. This will always return null in `Start()` because no data has been fetched yet, so you could wrap this call in the `OnInitialState` callback:
|
||||||
|
```cs
|
||||||
|
VELConnectManager.OnInitialState += state =>
|
||||||
|
{
|
||||||
|
VELConnectManager.GetUserData("key1");
|
||||||
|
};
|
||||||
|
```
|
||||||
|
If the data was already on the server before the start of your application, the correct value will be returned.
|
||||||
|
|
||||||
|
|
||||||
|
#### Change listeners
|
||||||
|
|
||||||
|
If you want to subscribe to changes in a key you can set up change listeners:
|
||||||
|
```cs
|
||||||
|
VELConnectManager.AddUserDataListener("key1", this, value =>
|
||||||
|
{
|
||||||
|
Debug.Log($"key1: {value}");
|
||||||
|
}, true);
|
||||||
|
```
|
||||||
|
Passing in `this` binds the lifetime of the listener to the lifetime of the current script. It is often tedious to make sure to unsubscribe to all of your listeners OnDisable or OnDestroy to prevent the event emitter from sending events to objects that no longer exist, but VEL-Connect will remove listeners when their `keepAliveObject` parameter becomes null. The last parameter in this function (`true` in the example) tells VEL-Connect to activate the callback immediately or when the first value is received. You can add the listener on `Start()` and the first invokation of the callback will have the previous value of the server.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Full example:
|
||||||
|
```cs
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using VELConnect;
|
||||||
|
|
||||||
|
public class VELConnectTesting : MonoBehaviour
|
||||||
|
{
|
||||||
|
private IEnumerator Start()
|
||||||
|
{
|
||||||
|
VELConnectManager.OnInitialState += state =>
|
||||||
|
{
|
||||||
|
Debug.Log($"[OnInitialState] key1: {VELConnectManager.GetUserData("key1")}");
|
||||||
|
};
|
||||||
|
|
||||||
|
VELConnectManager.AddUserDataListener("key1", this, value =>
|
||||||
|
{
|
||||||
|
Debug.Log($"[Listener] key1: {value}");
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
VELConnectManager.AddUserDataListener("key2", this, value =>
|
||||||
|
{
|
||||||
|
Debug.Log($"[Listener] key2: {value}");
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
|
||||||
|
VELConnectManager.SetUserData("key1", "val1");
|
||||||
|
|
||||||
|
VELConnectManager.SetUserData(new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "key1", "val1" },
|
||||||
|
{ "key2", "val2" },
|
||||||
|
});
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
|
||||||
|
VELConnectManager.SetUserData("key1", "val1_later");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
JSON.Net Example that illustrates how to persist a complex object of data using VEL-Connect, initializing at start, and saving on application quit
|
||||||
|
|
||||||
|
```cs
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using VELConnect;
|
||||||
|
public class VelConnectDemo1 : MonoBehaviour
|
||||||
|
{
|
||||||
|
class ExampleJSON
|
||||||
|
{
|
||||||
|
public string a_string="a"; //you can use initializers
|
||||||
|
public int a_int=0;
|
||||||
|
public List<ExampleChildJSON> a_list = new List<ExampleChildJSON>(); // you can use lists of objects
|
||||||
|
}
|
||||||
|
class ExampleChildJSON
|
||||||
|
{
|
||||||
|
public string a_string; //if you don't, that's fine too, but you probably want a constructor then
|
||||||
|
public int a_int;
|
||||||
|
public ExampleChildJSON() { } //you need to make sure you have a blank constructor for deserialization
|
||||||
|
public ExampleChildJSON(string a_string, int a_int)
|
||||||
|
{
|
||||||
|
this.a_string = a_string;
|
||||||
|
this.a_int = a_int;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ExampleJSON dataToPersist = null;
|
||||||
|
|
||||||
|
IEnumerator Start()
|
||||||
|
{
|
||||||
|
VELConnectManager.OnInitialState += (state) =>
|
||||||
|
{
|
||||||
|
var s = VELConnectManager.GetUserData("mydata");
|
||||||
|
Debug.Log("Retrieved: " + s);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
dataToPersist = JsonConvert.DeserializeObject<ExampleJSON>(s);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Log("Error serializing state: " + e.Message);
|
||||||
|
}
|
||||||
|
if(dataToPersist == null)
|
||||||
|
{
|
||||||
|
Debug.Log("Null state, initializing");
|
||||||
|
dataToPersist =new ExampleJSON();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
while (dataToPersist == null) yield return null;
|
||||||
|
|
||||||
|
dataToPersist.a_list.Add(
|
||||||
|
new ExampleChildJSON("" + UnityEngine.Random.Range(0, 10),
|
||||||
|
UnityEngine.Random.Range(0, 10))
|
||||||
|
);
|
||||||
|
Debug.Log(JsonConvert.SerializeObject(dataToPersist));
|
||||||
|
|
||||||
|
}
|
||||||
|
private void OnApplicationQuit()
|
||||||
|
{
|
||||||
|
VELConnectManager.SetUserData("mydata", JsonConvert.SerializeObject(dataToPersist));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
:root {
|
||||||
|
--md-primary-fg-color: #7a2020;
|
||||||
|
--md-primary-fg-color--light: #ffffff;
|
||||||
|
--md-primary-fg-color--dark: #e4002b;
|
||||||
|
--md-primary-bg-color: hsla(0, 0%, 100%, 1);
|
||||||
|
--md-primary-bg-color--light: hsla(0, 0%, 100%, 0.7);
|
||||||
|
|
||||||
|
/* --md-accent-fg-color: #ffffff;
|
||||||
|
--md-accent-fg-color--transparent: #ffffff11;
|
||||||
|
--md-accent-bg-color: hsla(0, 0%, 100%, 1);
|
||||||
|
--md-accent-bg-color--light: hsla(0, 0%, 100%, 0.7); */
|
||||||
|
}
|
||||||
|
[data-md-color-scheme="slate"] {
|
||||||
|
--md-hue: 34;
|
||||||
|
--md-default-bg-color: #191818;
|
||||||
|
--md-code-bg-color: #252525;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
site_name: VEL-Connect Docs
|
||||||
|
site_url: https://docs.velconnect.ugavel.com
|
||||||
|
repo_url: https://github.com/velaboratory/VEL-Connect
|
||||||
|
repo_name: velaboratory/VEL-Connect
|
||||||
|
edit_uri: edit/main/docs_website/docs
|
||||||
|
|
||||||
|
theme:
|
||||||
|
name: material
|
||||||
|
features:
|
||||||
|
- content.action.edit
|
||||||
|
- navigation.instant
|
||||||
|
# - navigation.sections
|
||||||
|
- navigation.expand
|
||||||
|
- navigation.path
|
||||||
|
- navigation.indexes
|
||||||
|
- toc.follow
|
||||||
|
- toc.integrate
|
||||||
|
- content.code.copy
|
||||||
|
|
||||||
|
palette:
|
||||||
|
scheme: slate
|
||||||
|
primary: custom
|
||||||
|
accent: red
|
||||||
|
# background: custom
|
||||||
|
font: false
|
||||||
|
# text: Oswald
|
||||||
|
# text: Merriweather
|
||||||
|
# text: Merriweather Sans
|
||||||
|
logo: assets/vel_logo_3d.png
|
||||||
|
favicon: assets/vel_logo_3d_square.png
|
||||||
|
|
||||||
|
plugins:
|
||||||
|
- search:
|
||||||
|
# - social:
|
||||||
|
# cards_layout_options:
|
||||||
|
# font_family: Oswald
|
||||||
|
- git-revision-date-localized:
|
||||||
|
enable_creation_date: true
|
||||||
|
|
||||||
|
markdown_extensions:
|
||||||
|
- attr_list
|
||||||
|
- md_in_html
|
||||||
|
- pymdownx.emoji:
|
||||||
|
emoji_index: !!python/name:material.extensions.emoji.twemoji
|
||||||
|
emoji_generator: !!python/name:material.extensions.emoji.to_svg
|
||||||
|
- pymdownx.superfences
|
||||||
|
- pymdownx.tabbed:
|
||||||
|
alternate_style: true
|
||||||
|
- admonition
|
||||||
|
- pymdownx.details
|
||||||
|
- pymdownx.highlight:
|
||||||
|
anchor_linenums: true
|
||||||
|
line_spans: __span
|
||||||
|
pygments_lang_class: true
|
||||||
|
- pymdownx.inlinehilite
|
||||||
|
- pymdownx.snippets
|
||||||
|
|
||||||
|
extra_css:
|
||||||
|
- stylesheets/extra.css
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
mkdocs-material
|
||||||
|
mkdocs-git-revision-date-localized-plugin
|
||||||
|
|
@ -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:
|
||||||
|
|
@ -171,21 +171,18 @@ namespace VELConnect
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
velConnectUrl = velConnectUrl.TrimEnd('/');
|
||||||
if (instance != null) Debug.LogError("VELConnectManager instance already exists", this);
|
if (instance != null) Debug.LogError("VELConnectManager instance already exists", this);
|
||||||
instance = 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();
|
deviceId = CreateDeviceId();
|
||||||
|
VelNetManager.OnLocalNetworkObjectSpawned += networkObject =>
|
||||||
|
{
|
||||||
|
if (!networkObject.ownershipLocked)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
// SetRoomData("spawned_" + networkObject.networkId, networkObject.prefabName);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Computes 15-char device id compatibly with pocketbase
|
// Computes 15-char device id compatibly with pocketbase
|
||||||
|
|
@ -264,25 +261,7 @@ namespace VELConnect
|
||||||
state = JsonConvert.DeserializeObject<State>(json);
|
state = JsonConvert.DeserializeObject<State>(json);
|
||||||
if (state == null) return;
|
if (state == null) return;
|
||||||
|
|
||||||
bool isInitialState = false;
|
bool isInitialState = lastState == null;
|
||||||
|
|
||||||
// first load stuff
|
|
||||||
if (lastState == null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
OnInitialState?.Invoke(state);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Debug.LogError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
isInitialState = true;
|
|
||||||
// lastState = state;
|
|
||||||
// return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// if (state.device.modified_by != DeviceId)
|
// if (state.device.modified_by != DeviceId)
|
||||||
{
|
{
|
||||||
|
|
@ -413,7 +392,7 @@ namespace VELConnect
|
||||||
foreach (KeyValuePair<string, string> elem in state.room.data)
|
foreach (KeyValuePair<string, string> elem in state.room.data)
|
||||||
{
|
{
|
||||||
string oldValue = null;
|
string oldValue = null;
|
||||||
lastState?.room.data.TryGetValue(elem.Key, out oldValue);
|
lastState?.room?.data.TryGetValue(elem.Key, out oldValue);
|
||||||
if (elem.Value != oldValue)
|
if (elem.Value != oldValue)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -482,6 +461,18 @@ namespace VELConnect
|
||||||
{
|
{
|
||||||
Debug.LogError("Pairing code nulllll");
|
Debug.LogError("Pairing code nulllll");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isInitialState)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OnInitialState?.Invoke(state);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
@ -689,6 +680,11 @@ namespace VELConnect
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetUserData(string key, string value)
|
||||||
|
{
|
||||||
|
SetUserData(new Dictionary<string, string> { { key, value } });
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the 'data' object of the Device table
|
/// Sets the 'data' object of the Device table
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -755,6 +751,7 @@ namespace VELConnect
|
||||||
State.DataBlock room = new State.DataBlock
|
State.DataBlock room = new State.DataBlock
|
||||||
{
|
{
|
||||||
category = "room",
|
category = "room",
|
||||||
|
modified_by = "Unity",
|
||||||
data = data
|
data = data
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -795,6 +792,9 @@ namespace VELConnect
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unpairs this device from the current user.
|
||||||
|
/// </summary>
|
||||||
public static void Unpair()
|
public static void Unpair()
|
||||||
{
|
{
|
||||||
if (instance.state?.device != null)
|
if (instance.state?.device != null)
|
||||||
|
|
@ -917,7 +917,7 @@ namespace VELConnect
|
||||||
case UnityWebRequest.Result.ConnectionError:
|
case UnityWebRequest.Result.ConnectionError:
|
||||||
case UnityWebRequest.Result.DataProcessingError:
|
case UnityWebRequest.Result.DataProcessingError:
|
||||||
case UnityWebRequest.Result.ProtocolError:
|
case UnityWebRequest.Result.ProtocolError:
|
||||||
Debug.LogError(url + ": Error: " + webRequest.error + "\n" + webRequest.downloadHandler.text + "\n" + Environment.StackTrace);
|
Debug.LogWarning(url + ": Error: " + webRequest.error + "\n" + webRequest.downloadHandler.text + "\n" + Environment.StackTrace);
|
||||||
failureCallback?.Invoke(webRequest.error);
|
failureCallback?.Invoke(webRequest.error);
|
||||||
break;
|
break;
|
||||||
case UnityWebRequest.Result.Success:
|
case UnityWebRequest.Result.Success:
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,16 @@ namespace VELConnect
|
||||||
{
|
{
|
||||||
loading = true;
|
loading = true;
|
||||||
if (debugLogs) Debug.Log($"[VelNetPersist] Loading {Id}");
|
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 =>
|
VELConnectManager.GetDataBlock(Id, data =>
|
||||||
{
|
{
|
||||||
if (!data.data.TryGetValue("state", out string d))
|
if (!data.data.TryGetValue("state", out string d))
|
||||||
|
|
@ -63,7 +73,6 @@ namespace VELConnect
|
||||||
loading = false;
|
loading = false;
|
||||||
}, s =>
|
}, s =>
|
||||||
{
|
{
|
||||||
Debug.LogError(s);
|
|
||||||
loading = false;
|
loading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +80,16 @@ namespace VELConnect
|
||||||
private void Save()
|
private void Save()
|
||||||
{
|
{
|
||||||
if (debugLogs) Debug.Log($"[VelNetPersist] Saving {Id}");
|
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()
|
VELConnectManager.SetDataBlock(Id, new VELConnectManager.State.DataBlock()
|
||||||
{
|
{
|
||||||
category = "object_persist",
|
category = "object_persist",
|
||||||
|
|
|
||||||
|
|
@ -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.1",
|
"version": "4.0.7",
|
||||||
"unity": "2019.1",
|
"unity": "2019.1",
|
||||||
"description": "Web-based configuration for VR applications",
|
"description": "Web-based configuration for VR applications",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
|
|
@ -13,6 +13,6 @@
|
||||||
"samples": [],
|
"samples": [],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.unity.nuget.newtonsoft-json": "3.0.0",
|
"com.unity.nuget.newtonsoft-json": "3.0.0",
|
||||||
"edu.uga.engr.vel.velnet": "1.1.8"
|
"edu.uga.engr.vel.velnet": "1.3.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@velaboratory/velconnect",
|
"name": "@velaboratory/velconnect",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@velaboratory/velconnect",
|
"name": "@velaboratory/velconnect",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pocketbase": "^0.20.3"
|
"pocketbase": "^0.20.3"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@velaboratory/velconnect",
|
"name": "@velaboratory/velconnect",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "Use VEL-Connect with a dashboard",
|
"description": "Use VEL-Connect with a dashboard",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ export type AuthSystemFields<T = never> = {
|
||||||
|
|
||||||
// Record types for each collection
|
// Record types for each collection
|
||||||
|
|
||||||
export type DataBlockRecord<Tdata = unknown> = {
|
export type DataBlockRecord<Tdata = { [key: string]: any }> = {
|
||||||
block_id?: string
|
block_id?: string
|
||||||
category?: string
|
category?: string
|
||||||
data?: null | Tdata
|
data?: null | Tdata
|
||||||
|
|
@ -74,10 +74,10 @@ export type UsersRecord = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response types include system fields and match responses from the PocketBase API
|
// 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 DeviceResponse<Texpand = unknown> = Required<DeviceRecord> & BaseSystemFields<Texpand>
|
||||||
export type UserCountResponse<Texpand = unknown> = Required<UserCountRecord> & 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
|
// Types containing all Records and Responses, useful for creating typing helper functions
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue