From dbf6c0d57d498a2c16df5179bf5632632aa51f8e Mon Sep 17 00:00:00 2001 From: Jamie Brynes Date: Tue, 1 Sep 2020 12:04:31 +0100 Subject: [PATCH] Add `PositionFromGameObject` authoring component (#1471) --- .../Correctness/SceneAuthoring.meta | 3 +++ .../PositionFromGameObjectTests.cs | 27 +++++++++++++++++++ .../PositionFromGameObjectTests.cs.meta | 3 +++ .../Improbable.Gdk.EditmodeTests.asmdef | 3 ++- .../SceneAuthoring/AuthoringComponents.meta | 8 ++++++ ....SceneAuthoring.AuthoringComponents.asmdef | 16 +++++++++++ ...eAuthoring.AuthoringComponents.asmdef.meta | 7 +++++ ...ositionFromGameObjectAuthoringComponent.cs | 18 +++++++++++++ ...onFromGameObjectAuthoringComponent.cs.meta | 3 +++ 9 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring.meta create mode 100644 workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.cs create mode 100644 workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.cs.meta create mode 100644 workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents.meta create mode 100644 workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef create mode 100644 workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef.meta create mode 100644 workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.cs create mode 100644 workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.cs.meta diff --git a/workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring.meta b/workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring.meta new file mode 100644 index 0000000000..e5a422441d --- /dev/null +++ b/workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3ef736ae3ee7472abe1eeee871f664fa +timeCreated: 1598616958 \ No newline at end of file diff --git a/workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.cs b/workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.cs new file mode 100644 index 0000000000..d1af099999 --- /dev/null +++ b/workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.cs @@ -0,0 +1,27 @@ +using Improbable.Gdk.Core; +using Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents; +using NUnit.Framework; +using UnityEngine; + +namespace Improbable.Gdk.EditmodeTests.SceneAuthoring +{ + [TestFixture] + public class PositionFromGameObjectTests + { + [Test] + public void WriteTo_uses_the_GameObject_position() + { + var gameObject = new GameObject(); + gameObject.transform.position = new Vector3(100, 100, 100); + var positionFromGameObject = gameObject.AddComponent(); + + var entityTemplate = new EntityTemplate(); + positionFromGameObject.WriteTo(entityTemplate); + + Assert.IsTrue(entityTemplate.HasComponent()); + + var position = entityTemplate.GetComponent().Value; + Assert.AreEqual(gameObject.transform.position, position.Coords.ToUnityVector()); + } + } +} diff --git a/workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.cs.meta b/workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.cs.meta new file mode 100644 index 0000000000..b202204bb7 --- /dev/null +++ b/workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f20f444437d44e8fba61701e9b88f80f +timeCreated: 1598616972 \ No newline at end of file diff --git a/workers/unity/Assets/Tests/EditmodeTests/Improbable.Gdk.EditmodeTests.asmdef b/workers/unity/Assets/Tests/EditmodeTests/Improbable.Gdk.EditmodeTests.asmdef index 06848cf557..84852107c1 100644 --- a/workers/unity/Assets/Tests/EditmodeTests/Improbable.Gdk.EditmodeTests.asmdef +++ b/workers/unity/Assets/Tests/EditmodeTests/Improbable.Gdk.EditmodeTests.asmdef @@ -2,6 +2,7 @@ "name": "Improbable.Gdk.EditmodeTests", "references": [ "Improbable.Gdk.Core", + "Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents", "Improbable.Gdk.Debug", "Improbable.Gdk.GameObjectCreation", "Improbable.Gdk.Generated", @@ -31,4 +32,4 @@ ], "versionDefines": [], "noEngineReferences": false -} \ No newline at end of file +} diff --git a/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents.meta b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents.meta new file mode 100644 index 0000000000..39a505c7ae --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ed0f8c41a7f886f4cbacfa1c98a4c310 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef new file mode 100644 index 0000000000..176dab6cdf --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef @@ -0,0 +1,16 @@ +{ + "name": "Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents", + "references": [ + "Improbable.Gdk.Core", + "Improbable.Gdk.Generated" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef.meta b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef.meta new file mode 100644 index 0000000000..fa8a9c8e55 --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 86c54450cd516d445a6481158fd2fca9 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.cs b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.cs new file mode 100644 index 0000000000..030ba48588 --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.cs @@ -0,0 +1,18 @@ +using UnityEngine; + +namespace Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents +{ + [AddComponentMenu("SpatialOS/Authoring Components/Position From GameObject Authoring Component")] + public class PositionFromGameObjectAuthoringComponent : MonoBehaviour, ISpatialOsAuthoringComponent + { +#pragma warning disable 649 + [SerializeField] private string writeAccess; +#pragma warning restore 649 + + public void WriteTo(EntityTemplate template) + { + var coords = Coordinates.FromUnityVector(transform.position); + template.AddComponent(new Position.Snapshot(coords), writeAccess); + } + } +} diff --git a/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.cs.meta b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.cs.meta new file mode 100644 index 0000000000..079ed97dda --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a5ce904b69284f0bbdd010431759880a +timeCreated: 1598531170 \ No newline at end of file