Exemple #1
0
        void DrawComponents()
        {
            var count = _entity.World.GetComponents(_entity.Id, 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);
                if (!EcsComponentInspectors.Render(type.Name, type, component))
                {
                    EditorGUILayout.LabelField(type.Name, EditorStyles.boldLabel);
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel++;
                    foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public))
                    {
                        DrawTypeField(component, field);
                    }
                    EditorGUI.indentLevel = indent;
                }
                GUILayout.EndVertical();
                EditorGUILayout.Space();
            }
        }
Exemple #2
0
        void DrawTypeField(object instance, FieldInfo field)
        {
            var fieldValue = field.GetValue(instance);
            var fieldType  = field.FieldType;

            if (!EcsComponentInspectors.Render(field.Name, fieldType, fieldValue))
            {
                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";

                EditorGUILayout.TextField(field.Name, strVal);
            }
        }