Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bb1591624 | |||
| 5dd889c898 | |||
| 9c7d1deb0a | |||
| 106d4c8e73 | |||
| 7c8f70c0c0 |
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5627857f30c8994c87469d287b2d115
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
}
|
||||
@@ -21,7 +21,7 @@ namespace Speckle.ConnectorUnity
|
||||
/// that handles conversions and subscriptions for you
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(RecursiveConverter))]
|
||||
[Obsolete]
|
||||
[Obsolete("See " + nameof(SpeckleReceiver))]
|
||||
public class Receiver : MonoBehaviour
|
||||
{
|
||||
public string StreamId;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Speckle.ConnectorUnity
|
||||
/// that handles conversions for you
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(RecursiveConverter)), ExecuteAlways]
|
||||
[Obsolete]
|
||||
[Obsolete("See " + nameof(SpeckleSender))]
|
||||
public class Sender : MonoBehaviour
|
||||
{
|
||||
private ServerTransport transport;
|
||||
|
||||
+2
-1
@@ -6,7 +6,8 @@
|
||||
"GUID:eed1b8b83e2c0074d9e5de2348e3ff72",
|
||||
"GUID:13aec21e8e96f864bafd00df49f225fc",
|
||||
"GUID:d274441ecc3eb3f43b093eec1503d681",
|
||||
"GUID:50d889142fdf9de4b8501c6eaa4b3225"
|
||||
"GUID:50d889142fdf9de4b8501c6eaa4b3225",
|
||||
"GUID:7383cd71541a2aa48a7baf23f74b4d5f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -185,6 +185,13 @@ namespace Speckle.ConnectorUnity.Components
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current selection
|
||||
/// </summary>
|
||||
/// <param name="client">The selected Account's Client</param>
|
||||
/// <param name="stream">The selected <see cref="Stream"/></param>
|
||||
/// <param name="commit">The selected <see cref="Commit"/></param>
|
||||
/// <exception cref="InvalidOperationException">Selection was not complete or invalid</exception>
|
||||
public void ValidateSelection(out Client client, out Stream stream, out Commit commit)
|
||||
{
|
||||
Client? selectedClient = Account.Client;
|
||||
@@ -237,7 +244,7 @@ namespace Speckle.ConnectorUnity.Components
|
||||
/// <param name="onTotalChildrenCountKnown"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <exception cref="Exception">Throws various types of exceptions to indicate faliure</exception>
|
||||
/// <returns></returns>
|
||||
/// <returns>The requested Speckle object</returns>
|
||||
public static async Task<Base> ReceiveAsync(
|
||||
Client client,
|
||||
string streamId,
|
||||
@@ -301,7 +308,7 @@ namespace Speckle.ConnectorUnity.Components
|
||||
{ "hostPlatform", Application.platform.ToString() },
|
||||
{
|
||||
"isMultiplayer",
|
||||
commit != null && commit.authorId != client.Account.userInfo.id
|
||||
commit?.authorId != null && commit?.authorId != client.Account?.userInfo?.id
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
+26
-2
@@ -163,9 +163,24 @@ namespace Objects.Converter.Unity
|
||||
return go;
|
||||
}
|
||||
|
||||
public Dictionary<string, object?> GetProperties(Base o) => GetProperties(o, typeof(Base));
|
||||
/// <summary>Gets all properties of <paramref name="o"/> except ignored ones. <br/>
|
||||
/// Ignored properties include properties of <see cref="Base"/>
|
||||
/// And some hardcoded ones that are likely to be converted (such as material, elements, and name)
|
||||
/// </summary>
|
||||
/// <param name="o">The speckle object to grab properties from</param>
|
||||
/// <returns>The properties</returns>
|
||||
/// <remarks>If you don't want to filter any properties, simply use <see cref="Base.GetMembers"/></remarks>
|
||||
public static Dictionary<string, object?> GetProperties(Base o) =>
|
||||
GetProperties(o, typeof(Base));
|
||||
|
||||
public Dictionary<string, object?> GetProperties(Base o, Type excludeType)
|
||||
/// <summary>
|
||||
/// Gets all properties of <paramref name="o"/> except ignored ones.<br/>
|
||||
/// Ignored properties include properties of <paramref name="excludeType"/>
|
||||
/// And some hardcoded ones that are likely to be converted (such as material, elements, and name)
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="GetProperties(Base)"/>
|
||||
/// <param name="excludeType">A <see cref="Type"/> whose properties should be ignored</param>
|
||||
public static Dictionary<string, object?> GetProperties(Base o, Type excludeType)
|
||||
{
|
||||
var excludeProps = new HashSet<string>(
|
||||
excludeType
|
||||
@@ -178,8 +193,14 @@ namespace Objects.Converter.Unity
|
||||
excludeProps.Add(alias);
|
||||
}
|
||||
|
||||
excludeProps.Add("@Materials");
|
||||
excludeProps.Add("@Views");
|
||||
excludeProps.Add("renderMaterial");
|
||||
excludeProps.Add("typedDefinition");
|
||||
excludeProps.Add("definition");
|
||||
excludeProps.Add("geometry");
|
||||
excludeProps.Add("elements");
|
||||
excludeProps.Add("transform");
|
||||
excludeProps.Add("name");
|
||||
//excludeProps.Add("tag");
|
||||
excludeProps.Add("physicsLayer");
|
||||
@@ -294,6 +315,9 @@ namespace Objects.Converter.Unity
|
||||
: defName;
|
||||
|
||||
native.name = instanceName;
|
||||
|
||||
AttachSpeckleProperties(native, instance.GetType(), () => GetProperties(instance));
|
||||
|
||||
return native;
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace Objects.Converter.Unity
|
||||
}
|
||||
}
|
||||
|
||||
public IList<string> DisplayValuePropertyAliases { get; set; } =
|
||||
public static IList<string> DisplayValuePropertyAliases { get; set; } =
|
||||
new[] { "displayValue", "@displayValue", "displayMesh", "@displayMesh" };
|
||||
|
||||
public GameObject? DisplayValueToNative(Base @object)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "systems.speckle.speckle-unity",
|
||||
"version": "2.15.1",
|
||||
"version": "2.15.3",
|
||||
"displayName": "Speckle Unity Connector",
|
||||
"description": "AEC Interoperability for Unity through Speckle",
|
||||
"unity": "2021.1",
|
||||
|
||||
Reference in New Issue
Block a user