-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from specklesystems/jrm/unity/speckle-properti…
…es-example Added manual speckle properties example
- Loading branch information
Showing
10 changed files
with
124 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Objects.Converter.Unity; | ||
using Speckle.ConnectorUnity.Utils; | ||
using Speckle.ConnectorUnity.Wrappers; | ||
using Speckle.Core.Api; | ||
using Speckle.Core.Credentials; | ||
using Speckle.Core.Models; | ||
using Speckle.Core.Transports; | ||
using UnityEngine; | ||
|
||
/// <summary> | ||
/// Example script for grabbing speckle properties for a specific object "on-the-fly" | ||
/// </summary> | ||
/// <remarks> | ||
/// see discussion https://speckle.community/t/reloading-assemblies-takes-too-long/6708 | ||
/// </remarks> | ||
[AddComponentMenu("Speckle/Extras/" + nameof(AttachSpecklePropertiesExample))] | ||
public class AttachSpecklePropertiesExample : MonoBehaviour | ||
{ | ||
public string streamId; | ||
public string objectId; | ||
|
||
public virtual void Start() | ||
{ | ||
Client speckleClient = new(AccountManager.GetDefaultAccount()); | ||
|
||
StartCoroutine(AttachSpeckleProperties(speckleClient, streamId, objectId)); | ||
} | ||
|
||
public IEnumerator AttachSpeckleProperties( | ||
Client speckleClient, | ||
string streamId, | ||
string objectId | ||
) | ||
{ | ||
//Fetch the object from Speckle | ||
ServerTransport remoteTransport = new(speckleClient.Account, streamId); | ||
Utils.WaitForTask<Base> operation = | ||
new(async () => await Operations.Receive(objectId, remoteTransport)); | ||
|
||
//yield until task completes | ||
yield return operation; | ||
Base speckleObject = operation.Result; | ||
|
||
//Do something with the properties. e.g. attach SpeckleProperties component | ||
DoSomething(speckleObject); | ||
} | ||
|
||
protected virtual void DoSomething(Base speckleObject) | ||
{ | ||
//GetProperties will filter "useful" properties | ||
Dictionary<string, object> properties = ConverterUnity.GetProperties( | ||
speckleObject, | ||
typeof(SpeckleObject) | ||
); | ||
|
||
var sd = this.gameObject.AddComponent<SpeckleProperties>(); | ||
sd.Data = properties; | ||
sd.SpeckleType = speckleObject.GetType(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,20 @@ | ||
{ | ||
"name": "Speckle.Extra", | ||
"references":[ "GUID:eed1b8b83e2c0074d9e5de2348e3ff72", "GUID:e6adfdc4e436206479f48eafc82f32b5", "GUID:d274441ecc3eb3f43b093eec1503d681", "GUID:50d889142fdf9de4b8501c6eaa4b3225" ] | ||
} | ||
"name": "Speckle.Extra", | ||
"rootNamespace": "", | ||
"references": [ | ||
"GUID:eed1b8b83e2c0074d9e5de2348e3ff72", | ||
"GUID:e6adfdc4e436206479f48eafc82f32b5", | ||
"GUID:d274441ecc3eb3f43b093eec1503d681", | ||
"GUID:50d889142fdf9de4b8501c6eaa4b3225", | ||
"GUID:7383cd71541a2aa48a7baf23f74b4d5f" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters