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.
Add
PositionFromGameObject
authoring component (#1471)
- Loading branch information
Jamie Brynes
authored
Sep 1, 2020
1 parent
7678247
commit dbf6c0d
Showing
9 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
workers/unity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...nity/Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.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,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()); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...Assets/Tests/EditmodeTests/Correctness/SceneAuthoring/PositionFromGameObjectTests.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: 8 additions & 0 deletions
8
workers/unity/Packages/io.improbable.gdk.core/SceneAuthoring/AuthoringComponents.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
...thoring/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef
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,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 | ||
} |
7 changes: 7 additions & 0 deletions
7
...ng/AuthoringComponents/Improbable.Gdk.Core.SceneAuthoring.AuthoringComponents.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...e.gdk.core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.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,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); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
....core/SceneAuthoring/AuthoringComponents/PositionFromGameObjectAuthoringComponent.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.