//bool bUnfolded = false;
        /// <summary>
        /// Draws the component.
        /// </summary>
        /// <param name="com">COM.</param>
        void DrawComponent(IZComponent com)
        {
            int iconSize = (int)EditorGUIUtility.singleLineHeight;
            //draw component member
            Rect rect        = EditorGUILayout.BeginVertical(entityStyle);
            Type ty          = com.GetType();
            var  memberInfos = ty.GetPublicMemberInfos();

            bool bUnfolded = poolConfig.unfoldMap.IsUnfold(curEntity.Name + ty.Name);

            //SerializedProperty unfoledObj = serializedObject.FindProperty ("unfoldMap");

            //draw component file info
            EditorGUILayout.BeginHorizontal();
            {
                if (memberInfos.Count == 0)
                {
                    EditorGUILayout.LabelField("    " + ty.Name, EditorStyles.boldLabel);
                }
                else
                {
                    bool bNewUnfold = EditorLayout.Foldout(bUnfolded, ty.Name, iconSize + 10);
                    //EditorGUILayout.LabelField(ty.Name, EditorStyles.boldLabel);
                    if (bNewUnfold != bUnfolded)
                    {
                        poolConfig.unfoldMap.SetUnfold(curEntity.Name + ty.Name, bNewUnfold);

//						unfoldObj.Update();
//						unfoldObj.ApplyModifiedProperties ();
                    }
                }
                if (EditorLayout.MiniButton("-"))
                {
                    //entity.RemoveComponent(index);
                    curEntity.DelComponent(com);
                }
            }
            EditorGUILayout.EndHorizontal();

            //Draw the icon
            if (ComponentsPool <IZComponent> .IsSystem(com))
            {
                GUI.DrawTexture(new Rect(rect.x + 1, rect.y + 1,
                                         iconSize - 2, iconSize - 2), IconHelper.SystemsHierarchyIcon);
            }
            else
            {
                GUI.DrawTexture(new Rect(rect.x + 1, rect.y + 1,
                                         iconSize - 2, iconSize - 2), IconHelper.EntityHierarchyIcon);
            }


            if (bUnfolded)
            {
                InspectorDrawer.DrawObjectMember(com);
            }

            EditorGUILayout.EndVertical();
        }
Exemple #2
0
        public static void DrawComponent(bool[] unfoldedComponents, string[] componentMemberSearch, IContext context, IEntity entity, int index, IComponent component)
        {
            var componentType = component.GetType();
            var componentName = componentType.Name.RemoveComponentSuffix();

            if (EditorLayout.MatchesSearchString(componentName.ToLower(), componentNameSearchString.ToLower()))
            {
                var boxStyle = getColoredBoxStyle(context, index);
                EditorGUILayout.BeginVertical(boxStyle);
                {
                    var memberInfos = componentType.GetPublicMemberInfos();
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (memberInfos.Count == 0)
                        {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        }
                        else
                        {
                            unfoldedComponents[index] = EditorLayout.Foldout(unfoldedComponents[index], componentName, foldoutStyle);
                            if (unfoldedComponents[index])
                            {
                                componentMemberSearch[index] = memberInfos.Count > 5
                                    ? EditorLayout.SearchTextField(componentMemberSearch[index])
                                    : string.Empty;
                            }
                        }
                        if (EditorLayout.MiniButton("-"))
                        {
                            entity.RemoveComponent(index);
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    if (unfoldedComponents[index])
                    {
                        var newComponent = entity.CreateComponent(index, componentType);
                        component.CopyPublicMemberValues(newComponent);

                        var changed         = false;
                        var componentDrawer = getComponentDrawer(componentType);
                        if (componentDrawer != null)
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                componentDrawer.DrawComponent(newComponent);
                            }
                            changed = EditorGUI.EndChangeCheck();
                        }
                        else
                        {
                            foreach (var info in memberInfos)
                            {
                                if (EditorLayout.MatchesSearchString(info.name.ToLower(), componentMemberSearch[index].ToLower()))
                                {
                                    var memberValue = info.GetValue(newComponent);
                                    var memberType  = memberValue == null ? info.type : memberValue.GetType();
                                    if (DrawObjectMember(memberType, info.name, memberValue, newComponent, info.SetValue))
                                    {
                                        changed = true;
                                    }
                                }
                            }
                        }

                        if (changed)
                        {
                            entity.ReplaceComponent(index, newComponent);
                        }
                        else
                        {
                            entity.GetComponentPool(index).Push(newComponent);
                        }
                    }
                }
                EditorLayout.EndVerticalBox();
            }
        }