void DrawTypeField(object instance, FieldInfo field, EntityObserver 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();
            }
        }
        public static bool Render(string label, Type type, object value, EntityObserver entity)
        {
            IComponentInspector inspector;

            if (_inspectors.TryGetValue(type, out inspector))
            {
                inspector.OnGUI(label, value, entity.World, entity.Id);
                return(true);
            }
            return(false);
        }
示例#3
0
        public override void OnInspectorGUI()
        {
            EntityObserver entityObserver = target as EntityObserver;

            if (mCurrSelectedEntity != entityObserver)
            {
                Array.Clear(mComponentsFoldOutInfo, 0, mComponentsFoldOutInfo.Length);

                mCurrSelectedEntity = entityObserver;
            }

            IEntity entity = entityObserver.Entity;

            EditorGUILayout.BeginVertical(GUI.skin.box);

            EditorGUILayout.LabelField("Entity Info:", EditorStyles.boldLabel);

            EditorGUILayout.LabelField("Id", entity.Id.ToString());
            EditorGUILayout.LabelField("Name", entity.Name);

            EditorGUILayout.Separator();
            GUILayout.Space(20.0f);

            // display all components that are attached to the entity
            IComponentIterator componentIter = entity.GetComponentsIterator();

            int i = 0;

            while (componentIter.MoveNext())
            {
                _displayComponent(componentIter.Get(), i++, ref mComponentsFoldOutInfo);
            }

            EditorGUILayout.EndVertical();

            Repaint();
        }
 void OnDisable()
 {
     _entity = null;
 }
 void OnEnable()
 {
     _entity = target as EntityObserver;
 }