feat: adds scriptableobject example

This commit is contained in:
Matteo Cominetti
2021-01-12 18:45:43 +00:00
parent 43c6643d1a
commit a4e0f06013
8 changed files with 131 additions and 8 deletions
+1
View File
@@ -11,6 +11,7 @@
<e p="Selectable.cs" t="Include" />
<e p="SelectionManager.cs" t="Include" />
</e>
<e p="ScriptableObjectExample.cs" t="Include" />
<e p="Speckle Connector" t="Include">
<e p="ConverterUnity.cs" t="Include" />
<e p="ConverterUnity.Geometry.cs" t="Include" />
+15
View File
@@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5578b344ae57415c912729d411df2a5c, type: 3}
m_Name: DataReceiver
m_EditorClassIdentifier:
StreamId: 50e2e61394
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dd0ca65e78b26414a8b4196e921fdcb9
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
+47 -3
View File
@@ -1696,6 +1696,50 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1560746816}
m_CullTransparentMesh: 1
--- !u!1 &1677020035
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1677020036}
- component: {fileID: 1677020037}
m_Layer: 0
m_Name: ScriptableObjectExample
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1677020036
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1677020035}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 25.700481, y: -28.98249, z: 44.967052}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1677020037
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1677020035}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e96d566d63ea69b48805295c46718ab0, type: 3}
m_Name:
m_EditorClassIdentifier:
receiver: {fileID: 11400000, guid: dd0ca65e78b26414a8b4196e921fdcb9, type: 2}
--- !u!1 &1707872729
GameObject:
m_ObjectHideFlags: 0
@@ -1839,7 +1883,7 @@ GameObject:
m_Component:
- component: {fileID: 1729237656}
m_Layer: 0
m_Name: SampleGeometry
m_Name: Cubes
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -1928,7 +1972,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1939550651
GameObject:
@@ -2449,7 +2493,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2098155187
GameObject:
+28
View File
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using Speckle.ConnectorUnity;
using UnityEngine;
//This class shows how to use the ScriptableObject Receiver to receive data in game time
//From the editor navigate to Assets > Create > ScriptableObjects > Receiver
//Set the StreamId on the new DataReceiver created
//Attach it to this script's 'receiver'
//To be honest, creating the Receiver form code is just simpler...!
public class ScriptableObjectExample : MonoBehaviour
{
public Receiver receiver;
void Start()
{
receiver.Init();
receiver.Receive().ConfigureAwait(false);
//... do more stuff eg set materials, subscribe to changes etc
}
void Update()
{
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e96d566d63ea69b48805295c46718ab0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+20 -5
View File
@@ -18,9 +18,10 @@ namespace Speckle.ConnectorUnity
/// A Speckle Receiver, it's a wrapper around a basic Speckle Client
/// that handles conversions and subscriptions for you
/// </summary>
[CreateAssetMenu(fileName = "DataReceiver", menuName = "ScriptableObjects/Receiver", order = 1)]
public class Receiver : ScriptableObject
{
public string StreamId { get; private set; }
public string StreamId;
public delegate void DataReceivedHandler(GameObject data);
@@ -33,7 +34,12 @@ namespace Speckle.ConnectorUnity
public Receiver()
{
}
/// <summary>
/// Initializes the Receiver manually, with StreamId and Account
/// </summary>
/// <param name="streamId"></param>
/// <param name="account"></param>
public void Init(string streamId, Account account = null)
{
StreamId = streamId;
@@ -43,6 +49,17 @@ namespace Speckle.ConnectorUnity
Client.OnCommitCreated += Client_OnCommitCreated;
}
/// <summary>
/// Initializes the Receiver automatically, with t
/// To be used when the StreamId property is set on the Unity ScriptableObject
/// </summary>
public void Init()
{
Client = new Client(AccountManager.GetDefaultAccount());
Client.SubscribeCommitCreated(StreamId);
Client.OnCommitCreated += Client_OnCommitCreated;
}
/// <summary>
/// Gets and converts the data of the last commit on the Stream
/// </summary>
@@ -66,7 +83,6 @@ namespace Speckle.ConnectorUnity
#region private methods
/// <summary>
/// Fired when a new commit is created on this stream
/// It receives and converts the objects and then executes the user defined _onCommitCreated action.
@@ -79,7 +95,7 @@ namespace Speckle.ConnectorUnity
if (OnNewData == null)
return;
//Run on a dispatcher as GOs can only be created on the main thread
Dispatcher.Instance().EnqueueAsync(async () =>
{
@@ -88,7 +104,6 @@ namespace Speckle.ConnectorUnity
});
}
private async Task<GameObject> GetAndConvertObject(string objectId, string commitId)
{
+1
View File
@@ -47,6 +47,7 @@ namespace Speckle.ConnectorUnity
btn2.onClick.AddListener(SendData);
}
// Shows how to create a new Receiver from code
private async void CreateReceiver()
{
var receiver = ScriptableObject.CreateInstance<Receiver>();