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

Commit

Permalink
One-to-one GameObject converter (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Brynes authored Sep 1, 2020
1 parent dbf6c0d commit 9d1ea5e
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Improbable.Gdk.Core.EditmodeTests")]
[assembly: InternalsVisibleTo("Improbable.Gdk.Core.Editor")]
[assembly: InternalsVisibleTo("Improbable.Gdk.GameObjectCreation.EditmodeTests")]
[assembly: InternalsVisibleTo("Improbable.Gdk.EditmodeTests")]
[assembly: InternalsVisibleTo("Improbable.Gdk.PlaymodeTests")]
Expand Down

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,36 @@
using Improbable.Gdk.Core.SceneAuthoring;
using UnityEditor;

namespace Improbable.Gdk.Core.Editor.SceneAuthoring
{
[CustomEditor(typeof(ConvertToSingleEntity))]
public class ConvertToSingleEntityEditor : UnityEditor.Editor
{
private SerializedProperty useSpecificEntityIdProperty;
private SerializedProperty desiredEntityIdProperty;
private SerializedProperty readAclProperty;

private void OnEnable()
{
useSpecificEntityIdProperty = serializedObject.FindProperty(nameof(ConvertToSingleEntity.UseSpecificEntityId));
desiredEntityIdProperty = serializedObject.FindProperty(nameof(ConvertToSingleEntity.DesiredEntityId));
readAclProperty = serializedObject.FindProperty(nameof(ConvertToSingleEntity.ReadAcl));
}

public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(useSpecificEntityIdProperty);

if (useSpecificEntityIdProperty.boolValue)
{
EditorGUILayout.PropertyField(desiredEntityIdProperty);
}

EditorGUILayout.PropertyField(readAclProperty);

serializedObject.ApplyModifiedProperties();
}
}
}

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,32 @@
using System.Collections.Generic;
using UnityEngine;

namespace Improbable.Gdk.Core.SceneAuthoring
{
[AddComponentMenu("SpatialOS/Authoring Components/Convert to Single Entity")]
public class ConvertToSingleEntity : MonoBehaviour, IConvertGameObjectToSpatialOsEntity
{
[SerializeField] internal bool UseSpecificEntityId;
[SerializeField] internal long DesiredEntityId;
[SerializeField] internal string[] ReadAcl = { };

public List<ConvertedEntity> Convert()
{
var components = GetComponents<ISpatialOsAuthoringComponent>();
var template = new EntityTemplate();

foreach (var component in components)
{
component.WriteTo(template);
}

template.SetReadAccess(ReadAcl);

var entity = UseSpecificEntityId
? new ConvertedEntity(new EntityId(DesiredEntityId), template)
: new ConvertedEntity(template);

return new List<ConvertedEntity> { entity };
}
}
}

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

0 comments on commit 9d1ea5e

Please sign in to comment.