From 9d1ea5ef0fee41420b0b4ac3acaa141a9f027013 Mon Sep 17 00:00:00 2001 From: Jamie Brynes Date: Tue, 1 Sep 2020 15:11:44 +0100 Subject: [PATCH] One-to-one GameObject converter (#1472) --- .../io.improbable.gdk.core/AssemblyInfo.cs | 1 + .../Editor/SceneAuthoring.meta | 3 ++ .../ConvertToSingleEntityEditor.cs | 36 +++++++++++++++++++ .../ConvertToSingleEntityEditor.cs.meta | 3 ++ .../SceneAuthoring/ConvertToSingleEntity.cs | 32 +++++++++++++++++ .../ConvertToSingleEntity.cs.meta | 3 ++ 6 files changed, 78 insertions(+) create mode 100644 workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring.meta create mode 100644 workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring/ConvertToSingleEntityEditor.cs create mode 100644 workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring/ConvertToSingleEntityEditor.cs.meta create mode 100644 workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/ConvertToSingleEntity.cs create mode 100644 workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/ConvertToSingleEntity.cs.meta diff --git a/workers/unity/Packages/io.improbable.gdk.core/AssemblyInfo.cs b/workers/unity/Packages/io.improbable.gdk.core/AssemblyInfo.cs index 542317e7df..f2a7978ff0 100644 --- a/workers/unity/Packages/io.improbable.gdk.core/AssemblyInfo.cs +++ b/workers/unity/Packages/io.improbable.gdk.core/AssemblyInfo.cs @@ -1,6 +1,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Improbable.Gdk.Core.EditmodeTests")] +[assembly: InternalsVisibleTo("Improbable.Gdk.Core.Editor")] [assembly: InternalsVisibleTo("Improbable.Gdk.GameObjectCreation.EditmodeTests")] [assembly: InternalsVisibleTo("Improbable.Gdk.EditmodeTests")] [assembly: InternalsVisibleTo("Improbable.Gdk.PlaymodeTests")] diff --git a/workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring.meta b/workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring.meta new file mode 100644 index 0000000000..c9e904d5dd --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 316c6a68afff44428ba03d6c7a266b79 +timeCreated: 1598531927 \ No newline at end of file diff --git a/workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring/ConvertToSingleEntityEditor.cs b/workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring/ConvertToSingleEntityEditor.cs new file mode 100644 index 0000000000..2bad6c6598 --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring/ConvertToSingleEntityEditor.cs @@ -0,0 +1,36 @@ +using Improbable.Gdk.Core.SceneAuthoring; +using UnityEditor; + +namespace Improbable.Gdk.Core.Editor.SceneAuthoring +{ + [CustomEditor(typeof(ConvertToSingleEntity))] + public class ConvertToSingleEntityEditor : UnityEditor.Editor + { + private SerializedProperty useSpecificEntityIdProperty; + private SerializedProperty desiredEntityIdProperty; + private SerializedProperty readAclProperty; + + private void OnEnable() + { + useSpecificEntityIdProperty = serializedObject.FindProperty(nameof(ConvertToSingleEntity.UseSpecificEntityId)); + desiredEntityIdProperty = serializedObject.FindProperty(nameof(ConvertToSingleEntity.DesiredEntityId)); + readAclProperty = serializedObject.FindProperty(nameof(ConvertToSingleEntity.ReadAcl)); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.PropertyField(useSpecificEntityIdProperty); + + if (useSpecificEntityIdProperty.boolValue) + { + EditorGUILayout.PropertyField(desiredEntityIdProperty); + } + + EditorGUILayout.PropertyField(readAclProperty); + + serializedObject.ApplyModifiedProperties(); + } + } +} diff --git a/workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring/ConvertToSingleEntityEditor.cs.meta b/workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring/ConvertToSingleEntityEditor.cs.meta new file mode 100644 index 0000000000..96129820b4 --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/Editor/SceneAuthoring/ConvertToSingleEntityEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: eee1b103019f40859ad28ff35dde8f47 +timeCreated: 1598531934 \ No newline at end of file diff --git a/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/ConvertToSingleEntity.cs b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/ConvertToSingleEntity.cs new file mode 100644 index 0000000000..1a03241168 --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/ConvertToSingleEntity.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Improbable.Gdk.Core.SceneAuthoring +{ + [AddComponentMenu("SpatialOS/Authoring Components/Convert to Single Entity")] + public class ConvertToSingleEntity : MonoBehaviour, IConvertGameObjectToSpatialOsEntity + { + [SerializeField] internal bool UseSpecificEntityId; + [SerializeField] internal long DesiredEntityId; + [SerializeField] internal string[] ReadAcl = { }; + + public List Convert() + { + var components = GetComponents(); + var template = new EntityTemplate(); + + foreach (var component in components) + { + component.WriteTo(template); + } + + template.SetReadAccess(ReadAcl); + + var entity = UseSpecificEntityId + ? new ConvertedEntity(new EntityId(DesiredEntityId), template) + : new ConvertedEntity(template); + + return new List { entity }; + } + } +} diff --git a/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/ConvertToSingleEntity.cs.meta b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/ConvertToSingleEntity.cs.meta new file mode 100644 index 0000000000..939caaa693 --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/ConvertToSingleEntity.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 71b18e76249b449bb116778890de4f6b +timeCreated: 1598531592 \ No newline at end of file