Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
Transform Authoring Component (#1474)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Brynes authored Sep 3, 2020
1 parent ff684b4 commit a9e1e7d
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 33 deletions.
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);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"Improbable.Gdk.TransformSynchronization",
"Unity.Entities",
"UnityEngine.TestRunner",
"UnityEditor.TestRunner"
"UnityEditor.TestRunner",
"Improbable.Gdk.Generated",
"Improbable.Gdk.Core"
],
"includePlatforms": [
"Editor"
Expand All @@ -19,5 +21,6 @@
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": []
"versionDefines": [],
"noEngineReferences": false
}

This file was deleted.

This file was deleted.

This file was deleted.

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);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9e1e7d

Please sign in to comment.