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

Commit

Permalink
Add PositionFromGameObject authoring component (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Brynes authored Sep 1, 2020
1 parent 7678247 commit dbf6c0d
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 1 deletion.

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
@@ -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<PositionFromGameObjectAuthoringComponent>();

var entityTemplate = new EntityTemplate();
positionFromGameObject.WriteTo(entityTemplate);

Assert.IsTrue(entityTemplate.HasComponent<Position.Snapshot>());

var position = entityTemplate.GetComponent<Position.Snapshot>().Value;
Assert.AreEqual(gameObject.transform.position, position.Coords.ToUnityVector());
}
}
}

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 @@ -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",
Expand Down Expand Up @@ -31,4 +32,4 @@
],
"versionDefines": [],
"noEngineReferences": false
}
}

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
@@ -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
}

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

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

0 comments on commit dbf6c0d

Please sign in to comment.