diff --git a/Assets/Extra/AttachSpecklePropertiesExample.cs b/Assets/Extra/AttachSpecklePropertiesExample.cs new file mode 100644 index 0000000..9c4af9c --- /dev/null +++ b/Assets/Extra/AttachSpecklePropertiesExample.cs @@ -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; + +/// +/// Example script for grabbing speckle properties for a specific object "on-the-fly" +/// +/// +/// see discussion https://speckle.community/t/reloading-assemblies-takes-too-long/6708 +/// +[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 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 properties = ConverterUnity.GetProperties( + speckleObject, + typeof(SpeckleObject) + ); + + var sd = this.gameObject.AddComponent(); + sd.Data = properties; + sd.SpeckleType = speckleObject.GetType(); + } +} diff --git a/Assets/Extra/AttachSpecklePropertiesExample.cs.meta b/Assets/Extra/AttachSpecklePropertiesExample.cs.meta new file mode 100644 index 0000000..7089850 --- /dev/null +++ b/Assets/Extra/AttachSpecklePropertiesExample.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b5627857f30c8994c87469d287b2d115 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Extra/Speckle.Extra.asmdef b/Assets/Extra/Speckle.Extra.asmdef index 0f341a8..c402e79 100644 --- a/Assets/Extra/Speckle.Extra.asmdef +++ b/Assets/Extra/Speckle.Extra.asmdef @@ -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 +} \ No newline at end of file diff --git a/Packages/systems.speckle.speckle-unity/Runtime/Components/Deprecated/Receiver.cs b/Packages/systems.speckle.speckle-unity/Runtime/Components/Deprecated/Receiver.cs index dcdf687..8dbbcbe 100644 --- a/Packages/systems.speckle.speckle-unity/Runtime/Components/Deprecated/Receiver.cs +++ b/Packages/systems.speckle.speckle-unity/Runtime/Components/Deprecated/Receiver.cs @@ -21,7 +21,7 @@ namespace Speckle.ConnectorUnity /// that handles conversions and subscriptions for you /// [RequireComponent(typeof(RecursiveConverter))] - [Obsolete] + [Obsolete("See " + nameof(SpeckleReceiver))] public class Receiver : MonoBehaviour { public string StreamId; diff --git a/Packages/systems.speckle.speckle-unity/Runtime/Components/Deprecated/Sender.cs b/Packages/systems.speckle.speckle-unity/Runtime/Components/Deprecated/Sender.cs index bf22e71..25a6bb9 100644 --- a/Packages/systems.speckle.speckle-unity/Runtime/Components/Deprecated/Sender.cs +++ b/Packages/systems.speckle.speckle-unity/Runtime/Components/Deprecated/Sender.cs @@ -21,7 +21,7 @@ namespace Speckle.ConnectorUnity /// that handles conversions for you /// [RequireComponent(typeof(RecursiveConverter)), ExecuteAlways] - [Obsolete] + [Obsolete("See " + nameof(SpeckleSender))] public class Sender : MonoBehaviour { private ServerTransport transport; diff --git a/Packages/systems.speckle.speckle-unity/Runtime/Components/Speckle.ConnectorUnity.Components.asmdef b/Packages/systems.speckle.speckle-unity/Runtime/Components/Speckle.ConnectorUnity.Components.asmdef index 920e120..0db409a 100644 --- a/Packages/systems.speckle.speckle-unity/Runtime/Components/Speckle.ConnectorUnity.Components.asmdef +++ b/Packages/systems.speckle.speckle-unity/Runtime/Components/Speckle.ConnectorUnity.Components.asmdef @@ -6,7 +6,8 @@ "GUID:eed1b8b83e2c0074d9e5de2348e3ff72", "GUID:13aec21e8e96f864bafd00df49f225fc", "GUID:d274441ecc3eb3f43b093eec1503d681", - "GUID:50d889142fdf9de4b8501c6eaa4b3225" + "GUID:50d889142fdf9de4b8501c6eaa4b3225", + "GUID:7383cd71541a2aa48a7baf23f74b4d5f" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Packages/systems.speckle.speckle-unity/Runtime/Components/SpeckleReceiver.cs b/Packages/systems.speckle.speckle-unity/Runtime/Components/SpeckleReceiver.cs index 03c52f0..8c0b424 100644 --- a/Packages/systems.speckle.speckle-unity/Runtime/Components/SpeckleReceiver.cs +++ b/Packages/systems.speckle.speckle-unity/Runtime/Components/SpeckleReceiver.cs @@ -185,6 +185,13 @@ public async Task ReceiveAsync(CancellationToken cancellationToken) return result; } + /// + /// Gets the current selection + /// + /// The selected Account's Client + /// The selected + /// The selected + /// Selection was not complete or invalid public void ValidateSelection(out Client client, out Stream stream, out Commit commit) { Client? selectedClient = Account.Client; @@ -237,7 +244,7 @@ protected internal void FinishOperation() /// /// /// Throws various types of exceptions to indicate faliure - /// + /// The requested Speckle object public static async Task ReceiveAsync( Client client, string streamId, @@ -301,7 +308,7 @@ public static async Task ReceiveAsync( { "hostPlatform", Application.platform.ToString() }, { "isMultiplayer", - commit != null && commit.authorId != client.Account.userInfo.id + commit?.authorId != null && commit?.authorId != client.Account?.userInfo?.id }, } ); diff --git a/Packages/systems.speckle.speckle-unity/Runtime/Converter/Unity/ConverterUnity.Geometry.cs b/Packages/systems.speckle.speckle-unity/Runtime/Converter/Unity/ConverterUnity.Geometry.cs index 7c6eb31..56e8289 100644 --- a/Packages/systems.speckle.speckle-unity/Runtime/Converter/Unity/ConverterUnity.Geometry.cs +++ b/Packages/systems.speckle.speckle-unity/Runtime/Converter/Unity/ConverterUnity.Geometry.cs @@ -163,9 +163,24 @@ public virtual Point PointToSpeckle(Vector3 p) return go; } - public Dictionary GetProperties(Base o) => GetProperties(o, typeof(Base)); + /// Gets all properties of except ignored ones.
+ /// Ignored properties include properties of + /// And some hardcoded ones that are likely to be converted (such as material, elements, and name) + ///
+ /// The speckle object to grab properties from + /// The properties + /// If you don't want to filter any properties, simply use + public static Dictionary GetProperties(Base o) => + GetProperties(o, typeof(Base)); - public Dictionary GetProperties(Base o, Type excludeType) + /// + /// Gets all properties of except ignored ones.
+ /// Ignored properties include properties of + /// And some hardcoded ones that are likely to be converted (such as material, elements, and name) + ///
+ /// + /// A whose properties should be ignored + public static Dictionary GetProperties(Base o, Type excludeType) { var excludeProps = new HashSet( excludeType diff --git a/Packages/systems.speckle.speckle-unity/Runtime/Converter/Unity/ConverterUnity.cs b/Packages/systems.speckle.speckle-unity/Runtime/Converter/Unity/ConverterUnity.cs index 65ba027..f195435 100644 --- a/Packages/systems.speckle.speckle-unity/Runtime/Converter/Unity/ConverterUnity.cs +++ b/Packages/systems.speckle.speckle-unity/Runtime/Converter/Unity/ConverterUnity.cs @@ -156,7 +156,7 @@ public Base ConvertGameObjectToSpeckle(GameObject go) } } - public IList DisplayValuePropertyAliases { get; set; } = + public static IList DisplayValuePropertyAliases { get; set; } = new[] { "displayValue", "@displayValue", "displayMesh", "@displayMesh" }; public GameObject? DisplayValueToNative(Base @object) diff --git a/Packages/systems.speckle.speckle-unity/package.json b/Packages/systems.speckle.speckle-unity/package.json index cdd027d..99ee6a3 100644 --- a/Packages/systems.speckle.speckle-unity/package.json +++ b/Packages/systems.speckle.speckle-unity/package.json @@ -1,6 +1,6 @@ { "name": "systems.speckle.speckle-unity", - "version": "2.15.2", + "version": "2.15.3", "displayName": "Speckle Unity Connector", "description": "AEC Interoperability for Unity through Speckle", "unity": "2021.1",