This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transform Authoring Component (#1474)
- Loading branch information
Jamie Brynes
authored
Sep 3, 2020
1 parent
ff684b4
commit a9e1e7d
Showing
8 changed files
with
63 additions
and
33 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
....gdk.transformsynchronization/MonoBehaviours/TransformFromGameObjectAuthoringComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...transformsynchronization/MonoBehaviours/TransformFromGameObjectAuthoringComponent.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
...ers/unity/Packages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems.meta
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...ages/io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems/TickSystemTests.cs
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...io.improbable.gdk.transformsynchronization/Tests/Editmode/Systems/TickSystemTests.cs.meta
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...io.improbable.gdk.transformsynchronization/Tests/Editmode/TransformFromGameObjectTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TransformFromGameObjectAuthoringComponent>(); | ||
|
||
var entityTemplate = new EntityTemplate(); | ||
transformFromGameObject.WriteTo(entityTemplate); | ||
|
||
Assert.IsTrue(entityTemplate.TryGetComponent<TransformInternal.Snapshot>(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); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...probable.gdk.transformsynchronization/Tests/Editmode/TransformFromGameObjectTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.