diff --git a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformFromGameObjectAuthoringComponent.cs b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformFromGameObjectAuthoringComponent.cs new file mode 100644 index 0000000000..0bb55a68fa --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformFromGameObjectAuthoringComponent.cs @@ -0,0 +1,20 @@ +using Improbable.Gdk.Core; +using Improbable.Gdk.Core.SceneAuthoring; +using UnityEngine; + +namespace Improbable.Gdk.TransformSynchronization +{ + [AddComponentMenu("SpatialOS/Authoring Components/Transform From GameObject Authoring Component")] + public class TransformFromGameObjectAuthoringComponent : MonoBehaviour, ISpatialOsAuthoringComponent + { +#pragma warning disable 649 + [SerializeField] private string writeAccess; +#pragma warning restore 649 + + public void WriteTo(EntityTemplate template) + { + var transformSnapshot = TransformUtils.CreateTransformSnapshot(transform.position, transform.rotation); + template.AddComponent(transformSnapshot, writeAccess); + } + } +} diff --git a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformFromGameObjectAuthoringComponent.cs.meta b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformFromGameObjectAuthoringComponent.cs.meta new file mode 100644 index 0000000000..c8bfd52fa2 --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/MonoBehaviours/TransformFromGameObjectAuthoringComponent.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 740c35be06a04ad9bf5e3f3ebe30f86a +timeCreated: 1598959466 \ No newline at end of file diff --git a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Improbable.Gdk.TransformSynchronization.EditmodeTests.asmdef b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Improbable.Gdk.TransformSynchronization.EditmodeTests.asmdef index 4cc60bbf43..68c3975a58 100644 --- a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Improbable.Gdk.TransformSynchronization.EditmodeTests.asmdef +++ b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Improbable.Gdk.TransformSynchronization.EditmodeTests.asmdef @@ -4,7 +4,9 @@ "Improbable.Gdk.TransformSynchronization", "Unity.Entities", "UnityEngine.TestRunner", - "UnityEditor.TestRunner" + "UnityEditor.TestRunner", + "Improbable.Gdk.Generated", + "Improbable.Gdk.Core" ], "includePlatforms": [ "Editor" @@ -19,5 +21,6 @@ "defineConstraints": [ "UNITY_INCLUDE_TESTS" ], - "versionDefines": [] + "versionDefines": [], + "noEngineReferences": false } \ No newline at end of file diff --git a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems.meta b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems.meta deleted file mode 100644 index c599c2b0d5..0000000000 --- a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ad6bf40aa9874424ead5c4e34969997c -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems/TickSystemTests.cs b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems/TickSystemTests.cs deleted file mode 100644 index e3df0581f7..0000000000 --- a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems/TickSystemTests.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Improbable.Gdk.TransformSynchronization; -using NUnit.Framework; -using Unity.Entities; - -namespace Improbable.Gdk.EditmodeTests.TransformSynchronization.Systems -{ - [TestFixture] - // todo write tests - public class InterpolationTests - { - } -} diff --git a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems/TickSystemTests.cs.meta b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems/TickSystemTests.cs.meta deleted file mode 100644 index e772c9924d..0000000000 --- a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems/TickSystemTests.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 22075104a9a74ca286d780e9bb24a6d5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/TransformFromGameObjectTests.cs b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/TransformFromGameObjectTests.cs new file mode 100644 index 0000000000..781bbf3049 --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/TransformFromGameObjectTests.cs @@ -0,0 +1,32 @@ +using Improbable.Gdk.Core; +using NUnit.Framework; +using UnityEngine; + +namespace Improbable.Gdk.TransformSynchronization.EditmodeTests +{ + [TestFixture] + public class TransformFromGameObjectTests + { + [Test] + public void WriteTo_uses_the_GameObject_position_and_rotation() + { + var gameObject = new GameObject(); + gameObject.transform.position = new Vector3(100, 100, 100); + gameObject.transform.rotation = Quaternion.Euler(90, 0, 0); + var transformFromGameObject = gameObject.AddComponent(); + + var entityTemplate = new EntityTemplate(); + transformFromGameObject.WriteTo(entityTemplate); + + Assert.IsTrue(entityTemplate.TryGetComponent(out var transform)); + + var position = transform.Location.ToUnityVector(); + var positionDifference = Vector3.Distance(gameObject.transform.position, position); + Assert.AreEqual(0.0, positionDifference, float.Epsilon); + + var rotation = transform.Rotation.ToUnityQuaternion(); + var rotationDifference = Quaternion.Angle(gameObject.transform.rotation, rotation); + Assert.AreEqual(0.0, rotationDifference, float.Epsilon); + } + } +} diff --git a/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/TransformFromGameObjectTests.cs.meta b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/TransformFromGameObjectTests.cs.meta new file mode 100644 index 0000000000..35bf1be9ce --- /dev/null +++ b/workers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/TransformFromGameObjectTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2e10cb5f0b5b4f1bb99a4517718c2fdf +timeCreated: 1598959692 \ No newline at end of file