diff --git a/Packages/systems.speckle.speckle-unity/ConverterUnity.Geometry.cs b/Packages/systems.speckle.speckle-unity/ConverterUnity.Geometry.cs index 660ffa7..fe3c431 100644 --- a/Packages/systems.speckle.speckle-unity/ConverterUnity.Geometry.cs +++ b/Packages/systems.speckle.speckle-unity/ConverterUnity.Geometry.cs @@ -256,7 +256,6 @@ namespace Objects.Converter.Unity /// /// The element from which properties should be grabbed from /// Collection of es that shall be converted - /// If provided, will override the properties on the mesh itself /// A with the converted , , and public GameObject MeshesToNative(Base element, IReadOnlyCollection meshes) { @@ -292,7 +291,6 @@ namespace Objects.Converter.Unity /// Converts to a with a /// /// Mesh to convert - /// If provided, will override the properties on the mesh itself /// public GameObject MeshToNative(Mesh speckleMesh) { diff --git a/Packages/systems.speckle.speckle-unity/ConverterUnity.cs b/Packages/systems.speckle.speckle-unity/ConverterUnity.cs index 98fed72..6b2bcad 100644 --- a/Packages/systems.speckle.speckle-unity/ConverterUnity.cs +++ b/Packages/systems.speckle.speckle-unity/ConverterUnity.cs @@ -1,15 +1,8 @@ -using Objects.Geometry; -using Speckle.Core.Kits; +using Speckle.Core.Kits; using Speckle.Core.Models; using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using JetBrains.Annotations; -using Objects.BuiltElements; -using Unity.Plastic.Antlr3.Runtime.Debug; using UnityEngine; using Mesh = Objects.Geometry.Mesh; diff --git a/Packages/systems.speckle.speckle-unity/Parallel Extensions/CoordinationDataStructures.meta b/Packages/systems.speckle.speckle-unity/Parallel Extensions/CoordinationDataStructures.meta new file mode 100644 index 0000000..60e4270 --- /dev/null +++ b/Packages/systems.speckle.speckle-unity/Parallel Extensions/CoordinationDataStructures.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6f8fe4d403d6524498fe19d6a1f1e136 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/systems.speckle.speckle-unity/Parallel Extensions/CoordinationDataStructures/ObservableConcurrentDictionary.cs b/Packages/systems.speckle.speckle-unity/Parallel Extensions/CoordinationDataStructures/ObservableConcurrentDictionary.cs new file mode 100644 index 0000000..916a3b2 --- /dev/null +++ b/Packages/systems.speckle.speckle-unity/Parallel Extensions/CoordinationDataStructures/ObservableConcurrentDictionary.cs @@ -0,0 +1,199 @@ +//-------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// File: ObservableConcurrentDictionary.cs +// +//-------------------------------------------------------------------------- + +using System.Collections.Generic; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Threading; +using System.Diagnostics; + +namespace System.Collections.Concurrent +{ + /// + /// Provides a thread-safe dictionary for use with data binding. + /// + /// Specifies the type of the keys in this collection. + /// Specifies the type of the values in this collection. + [DebuggerDisplay("Count={Count}")] + public class ObservableConcurrentDictionary : + ICollection>, IDictionary, + INotifyCollectionChanged, INotifyPropertyChanged + { + private readonly SynchronizationContext _context; + private readonly ConcurrentDictionary _dictionary; + + /// + /// Initializes an instance of the ObservableConcurrentDictionary class. + /// + public ObservableConcurrentDictionary() + { + _context = AsyncOperationManager.SynchronizationContext; + _dictionary = new ConcurrentDictionary(); + } + + /// Event raised when the collection changes. + public event NotifyCollectionChangedEventHandler CollectionChanged; + /// Event raised when a property on the collection changes. + public event PropertyChangedEventHandler PropertyChanged; + + /// + /// Notifies observers of CollectionChanged or PropertyChanged of an update to the dictionary. + /// + private void NotifyObserversOfChange() + { + var collectionHandler = CollectionChanged; + var propertyHandler = PropertyChanged; + if (collectionHandler != null || propertyHandler != null) + { + _context.Post(s => + { + if (collectionHandler != null) + { + collectionHandler(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); + } + if (propertyHandler != null) + { + propertyHandler(this, new PropertyChangedEventArgs("Count")); + propertyHandler(this, new PropertyChangedEventArgs("Keys")); + propertyHandler(this, new PropertyChangedEventArgs("Values")); + } + }, null); + } + } + + /// Attempts to add an item to the dictionary, notifying observers of any changes. + /// The item to be added. + /// Whether the add was successful. + private bool TryAddWithNotification(KeyValuePair item) + { + return TryAddWithNotification(item.Key, item.Value); + } + + /// Attempts to add an item to the dictionary, notifying observers of any changes. + /// The key of the item to be added. + /// The value of the item to be added. + /// Whether the add was successful. + private bool TryAddWithNotification(TKey key, TValue value) + { + bool result = _dictionary.TryAdd(key, value); + if (result) NotifyObserversOfChange(); + return result; + } + + /// Attempts to remove an item from the dictionary, notifying observers of any changes. + /// The key of the item to be removed. + /// The value of the item removed. + /// Whether the removal was successful. + private bool TryRemoveWithNotification(TKey key, out TValue value) + { + bool result = _dictionary.TryRemove(key, out value); + if (result) NotifyObserversOfChange(); + return result; + } + + /// Attempts to add or update an item in the dictionary, notifying observers of any changes. + /// The key of the item to be updated. + /// The new value to set for the item. + /// Whether the update was successful. + private void UpdateWithNotification(TKey key, TValue value) + { + _dictionary[key] = value; + NotifyObserversOfChange(); + } + + #region ICollection> Members + void ICollection>.Add(KeyValuePair item) + { + TryAddWithNotification(item); + } + + void ICollection>.Clear() + { + ((ICollection>)_dictionary).Clear(); + NotifyObserversOfChange(); + } + + bool ICollection>.Contains(KeyValuePair item) + { + return ((ICollection>)_dictionary).Contains(item); + } + + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + { + ((ICollection>)_dictionary).CopyTo(array, arrayIndex); + } + + int ICollection>.Count + { + get { return ((ICollection>)_dictionary).Count; } + } + + bool ICollection>.IsReadOnly + { + get { return ((ICollection>)_dictionary).IsReadOnly; } + } + + bool ICollection>.Remove(KeyValuePair item) + { + TValue temp; + return TryRemoveWithNotification(item.Key, out temp); + } + #endregion + + #region IEnumerable> Members + IEnumerator> IEnumerable>.GetEnumerator() + { + return ((ICollection>)_dictionary).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((ICollection>)_dictionary).GetEnumerator(); + } + #endregion + + #region IDictionary Members + public void Add(TKey key, TValue value) + { + TryAddWithNotification(key, value); + } + + public bool ContainsKey(TKey key) + { + return _dictionary.ContainsKey(key); + } + + public ICollection Keys + { + get { return _dictionary.Keys; } + } + + public bool Remove(TKey key) + { + TValue temp; + return TryRemoveWithNotification(key, out temp); + } + + public bool TryGetValue(TKey key, out TValue value) + { + return _dictionary.TryGetValue(key, out value); + } + + public ICollection Values + { + get { return _dictionary.Values; } + } + + public TValue this[TKey key] + { + get { return _dictionary[key]; } + set { UpdateWithNotification(key, value); } + } + #endregion + } +} \ No newline at end of file diff --git a/Packages/systems.speckle.speckle-unity/Parallel Extensions/CoordinationDataStructures/ObservableConcurrentDictionary.cs.meta b/Packages/systems.speckle.speckle-unity/Parallel Extensions/CoordinationDataStructures/ObservableConcurrentDictionary.cs.meta new file mode 100644 index 0000000..f19d5e1 --- /dev/null +++ b/Packages/systems.speckle.speckle-unity/Parallel Extensions/CoordinationDataStructures/ObservableConcurrentDictionary.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fbc4646478df067419b8bc7844c0ebfd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.asmdef b/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.asmdef new file mode 100644 index 0000000..fe2b472 --- /dev/null +++ b/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.asmdef @@ -0,0 +1,14 @@ +{ + "name": "Speckle.ParallelExtensionsExtras", + "rootNamespace": "", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": true +} \ No newline at end of file diff --git a/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.asmdef.meta b/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.asmdef.meta new file mode 100644 index 0000000..ef33381 --- /dev/null +++ b/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 24f666972ea7e9149abddaae766b9c1d +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.dll b/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.dll deleted file mode 100644 index ca5a3ab..0000000 Binary files a/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.dll and /dev/null differ diff --git a/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.dll.meta b/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.dll.meta deleted file mode 100644 index 39ed4e9..0000000 --- a/Packages/systems.speckle.speckle-unity/Parallel Extensions/ParallelExtensionsExtras.dll.meta +++ /dev/null @@ -1,33 +0,0 @@ -fileFormatVersion: 2 -guid: 0706f206487a18346b0a60f8be817381 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 0 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - Any: - second: - enabled: 1 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - - first: - Windows Store Apps: WindowsStoreApps - second: - enabled: 0 - settings: - CPU: AnyCPU - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/systems.speckle.speckle-unity/Sender.cs b/Packages/systems.speckle.speckle-unity/Sender.cs index ca977fa..6347c6c 100644 --- a/Packages/systems.speckle.speckle-unity/Sender.cs +++ b/Packages/systems.speckle.speckle-unity/Sender.cs @@ -25,19 +25,25 @@ namespace Speckle.ConnectorUnity public class Sender : MonoBehaviour { - private ServerTransport trasnport; - + private ServerTransport transport; + /// /// Converts and sends the data of the last commit on the Stream /// /// ID of the stream to send to /// List of gameObjects to convert and send /// Account to use. If not provided the default account will be used + /// Name of branch to send to + /// When true, will create a commit using the root object /// Action to run after the data has been sent /// Action to run when there is download/conversion progress /// Action to run on error /// - public void Send(string streamId, List gameObjects, Account account = null, + public void Send(string streamId, + List gameObjects, + Account account = null, + string branchName = "main", + bool createCommit = true, Action onDataSentAction = null, Action> onProgressAction = null, Action onErrorAction = null) @@ -45,21 +51,36 @@ namespace Speckle.ConnectorUnity try { var data = ConvertRecursivelyToSpeckle(gameObjects); - - trasnport = new ServerTransport(account ?? AccountManager.GetDefaultAccount() , streamId); - + var client = new Client(account ?? AccountManager.GetDefaultAccount()); + transport = new ServerTransport(client.Account, streamId); + Task.Run(async () => { var res = await Operations.Send( data, - new List() { trasnport }, + new List() { transport }, useDefaultCache: true, disposeTransports: true, - onProgressAction: onProgressAction, + onProgressAction: onProgressAction, onErrorAction: onErrorAction ); - trasnport?.Dispose(); + Analytics.TrackEvent(client.Account, Analytics.Events.Send); + + if (createCommit) + { + await client.CommitCreate( + new CommitCreateInput + { + streamId = streamId, + branchName = branchName, + objectId = res, + message = "No message", + sourceApplication = VersionedHostApplications.Unity, + }); + } + + transport?.Dispose(); onDataSentAction?.Invoke(res); }); } @@ -71,7 +92,7 @@ namespace Speckle.ConnectorUnity private void OnDestroy() { - trasnport?.Dispose(); + transport?.Dispose(); } #region private methods diff --git a/Packages/systems.speckle.speckle-unity/Speckle.Connector.asmdef b/Packages/systems.speckle.speckle-unity/Speckle.Connector.asmdef index 5c4ca72..9918e17 100644 --- a/Packages/systems.speckle.speckle-unity/Speckle.Connector.asmdef +++ b/Packages/systems.speckle.speckle-unity/Speckle.Connector.asmdef @@ -1,3 +1,4 @@ { - "name": "Speckle.Connector" + "name": "Speckle.Connector", + "references":[ "GUID:24f666972ea7e9149abddaae766b9c1d" ] } diff --git a/ProjectSettings/UnityConnectSettings.asset b/ProjectSettings/UnityConnectSettings.asset index fa0b146..6125b30 100644 --- a/ProjectSettings/UnityConnectSettings.asset +++ b/ProjectSettings/UnityConnectSettings.asset @@ -9,6 +9,7 @@ UnityConnectSettings: m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events m_EventUrl: https://cdp.cloud.unity3d.com/v1/events m_ConfigUrl: https://config.uca.cloud.unity3d.com + m_DashboardUrl: https://dashboard.unity3d.com m_TestInitMode: 0 CrashReportingSettings: m_EventUrl: https://perf-events.cloud.unity3d.com