-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
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,123 @@ | ||
// ---------------------------------------------------------------------------- | ||
// The MIT License | ||
// UnityEditor integration https://github.com/Leopotam/ecslite-unityeditor | ||
// for LeoECS Lite https://github.com/Leopotam/ecslite | ||
// Copyright (c) 2021 Leopotam <[email protected]> | ||
// ---------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Leopotam.EcsLite.UnityEditor { | ||
[CustomEditor (typeof (EcsEntityObserver))] | ||
sealed class EcsEntityObserverInspector : Editor { | ||
const int MaxFieldToStringLength = 128; | ||
|
||
static object[] _componentsCache = new object[32]; | ||
|
||
EcsEntityObserver _observer; | ||
|
||
public override void OnInspectorGUI () { | ||
if (_observer.World != null) { | ||
var guiEnabled = GUI.enabled; | ||
GUI.enabled = true; | ||
DrawComponents (); | ||
GUI.enabled = guiEnabled; | ||
EditorUtility.SetDirty (target); | ||
} | ||
} | ||
|
||
void OnEnable () { | ||
_observer = target as EcsEntityObserver; | ||
} | ||
|
||
void OnDisable () { | ||
_observer = null; | ||
} | ||
|
||
void DrawComponents () { | ||
if (_observer.gameObject.activeSelf) { | ||
var count = _observer.World.GetComponents (_observer.Entity, ref _componentsCache); | ||
for (var i = 0; i < count; i++) { | ||
var component = _componentsCache[i]; | ||
_componentsCache[i] = null; | ||
var type = component.GetType (); | ||
GUILayout.BeginVertical (GUI.skin.box); | ||
var typeName = EditorHelpers.GetCleanGenericTypeName (type); | ||
if (!EcsComponentInspectors.Render (typeName, type, component, _observer)) { | ||
EditorGUILayout.LabelField (typeName, EditorStyles.boldLabel); | ||
var indent = EditorGUI.indentLevel; | ||
EditorGUI.indentLevel++; | ||
foreach (var field in type.GetFields (BindingFlags.Instance | BindingFlags.Public)) { | ||
DrawTypeField (component, field, _observer); | ||
} | ||
EditorGUI.indentLevel = indent; | ||
} | ||
GUILayout.EndVertical (); | ||
EditorGUILayout.Space (); | ||
} | ||
} | ||
} | ||
|
||
void DrawTypeField (object instance, FieldInfo field, EcsEntityObserver entity) { | ||
var fieldValue = field.GetValue (instance); | ||
var fieldType = field.FieldType; | ||
if (!EcsComponentInspectors.Render (field.Name, fieldType, fieldValue, entity)) { | ||
if (fieldType == typeof (UnityEngine.Object) || fieldType.IsSubclassOf (typeof (UnityEngine.Object))) { | ||
GUILayout.BeginHorizontal (); | ||
EditorGUILayout.LabelField (field.Name, GUILayout.MaxWidth (EditorGUIUtility.labelWidth - 16)); | ||
var guiEnabled = GUI.enabled; | ||
GUI.enabled = false; | ||
EditorGUILayout.ObjectField (fieldValue as UnityEngine.Object, fieldType, false); | ||
GUI.enabled = guiEnabled; | ||
GUILayout.EndHorizontal (); | ||
return; | ||
} | ||
var strVal = fieldValue != null ? string.Format (System.Globalization.CultureInfo.InvariantCulture, "{0}", fieldValue) : "null"; | ||
if (strVal.Length > MaxFieldToStringLength) { | ||
strVal = strVal.Substring (0, MaxFieldToStringLength); | ||
} | ||
GUILayout.BeginHorizontal (); | ||
EditorGUILayout.LabelField (field.Name, GUILayout.MaxWidth (EditorGUIUtility.labelWidth - 16)); | ||
EditorGUILayout.SelectableLabel (strVal, GUILayout.MaxHeight (EditorGUIUtility.singleLineHeight)); | ||
GUILayout.EndHorizontal (); | ||
} | ||
} | ||
} | ||
|
||
static class EcsComponentInspectors { | ||
static readonly Dictionary<Type, IEcsComponentInspector> Inspectors = new Dictionary<Type, IEcsComponentInspector> (); | ||
|
||
static EcsComponentInspectors () { | ||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies ()) { | ||
foreach (var type in assembly.GetTypes ()) { | ||
if (typeof (IEcsComponentInspector).IsAssignableFrom (type) && !type.IsInterface) { | ||
if (Activator.CreateInstance (type) is IEcsComponentInspector inspector) { | ||
var componentType = inspector.GetFieldType (); | ||
if (Inspectors.ContainsKey (componentType)) { | ||
Debug.LogWarningFormat ("Inspector for \"{0}\" already exists, new inspector will be used instead.", componentType.Name); | ||
} | ||
Inspectors[componentType] = inspector; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static bool Render (string label, Type type, object value, EcsEntityObserver observer) { | ||
if (Inspectors.TryGetValue (type, out var inspector)) { | ||
inspector.OnGUI (label, value, observer.World, observer.Entity); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
public interface IEcsComponentInspector { | ||
Type GetFieldType (); | ||
void OnGUI (string label, object value, EcsWorld world, int entityId); | ||
} | ||
} |
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,28 @@ | ||
// ---------------------------------------------------------------------------- | ||
// The MIT License | ||
// UnityEditor integration https://github.com/Leopotam/ecslite-unityeditor | ||
// for LeoECS Lite https://github.com/Leopotam/ecslite | ||
// Copyright (c) 2021 Leopotam <[email protected]> | ||
// ---------------------------------------------------------------------------- | ||
|
||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Leopotam.EcsLite.UnityEditor { | ||
[CustomEditor (typeof (EcsWorldObserver))] | ||
sealed class EcsWorldObserverInspector : Editor { | ||
public override void OnInspectorGUI () { | ||
// var observer = (Runtime.EcsWorldObserver) target; | ||
// var stats = observer.GetStats (); | ||
var guiEnabled = GUI.enabled; | ||
GUI.enabled = true; | ||
GUILayout.BeginVertical (GUI.skin.box); | ||
// EditorGUILayout.LabelField ("Components", stats.Components.ToString ()); | ||
// EditorGUILayout.LabelField ("Filters", stats.Filters.ToString ()); | ||
// EditorGUILayout.LabelField ("Active entities", stats.ActiveEntities.ToString ()); | ||
// EditorGUILayout.LabelField ("Reserved entities", stats.ReservedEntities.ToString ()); | ||
GUILayout.EndVertical (); | ||
GUI.enabled = guiEnabled; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,22 @@ | ||
// ---------------------------------------------------------------------------- | ||
// The MIT License | ||
// UnityEditor integration https://github.com/Leopotam/ecslite-unityeditor | ||
// for LeoECS Lite https://github.com/Leopotam/ecslite | ||
// Copyright (c) 2021 Leopotam <[email protected]> | ||
// ---------------------------------------------------------------------------- | ||
|
||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Leopotam.EcsLite.UnityEditor.Inspectors { | ||
sealed class QuaternionInspector : IEcsComponentInspector { | ||
public Type GetFieldType () { | ||
return typeof (Quaternion); | ||
} | ||
|
||
public void OnGUI (string label, object value, EcsWorld world, int entityId) { | ||
EditorGUILayout.Vector3Field (label, ((Quaternion) value).eulerAngles); | ||
} | ||
} | ||
} |
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,22 @@ | ||
// ---------------------------------------------------------------------------- | ||
// The MIT License | ||
// UnityEditor integration https://github.com/Leopotam/ecslite-unityeditor | ||
// for LeoECS Lite https://github.com/Leopotam/ecslite | ||
// Copyright (c) 2021 Leopotam <[email protected]> | ||
// ---------------------------------------------------------------------------- | ||
|
||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Leopotam.EcsLite.UnityEditor.Inspectors { | ||
sealed class Vector3Inspector : IEcsComponentInspector { | ||
public Type GetFieldType () { | ||
return typeof (Vector3); | ||
} | ||
|
||
public void OnGUI (string label, object value, EcsWorld world, int entityId) { | ||
EditorGUILayout.Vector3Field (label, (Vector3) value); | ||
} | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"name": "Leopotam.EcsLite.UnityEditor", | ||
"rootNamespace": "Leopotam.EcsLite.UnityEditor", | ||
"references": [ | ||
"Leopotam.EcsLite", | ||
"Leopotam.EcsLite.UnityEditor.Runtime" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"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.
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,5 @@ | ||
namespace #NS# { | ||
struct #SCRIPTNAME# { | ||
// add your data here. | ||
} | ||
} |
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,9 @@ | ||
using Leopotam.EcsLite; | ||
|
||
namespace #NS# { | ||
sealed class #SCRIPTNAME# : IEcsInitSystem { | ||
public void Init (EcsSystems systems) { | ||
// add your initialize code here. | ||
} | ||
} | ||
} |
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,9 @@ | ||
using Leopotam.EcsLite; | ||
|
||
namespace #NS# { | ||
sealed class #SCRIPTNAME# : IEcsRunSystem { | ||
public void Run (EcsSystems systems) { | ||
// add your run code here. | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.