예제 #1
0
        /// <summary>
        /// Draws the style sheet toolbar.
        /// </summary>
        /// <param name="behavior">Target behavior.</param>
        /// <param name="styleSheetAsset">Style sheet asset.</param>
        public static void DrawStyleToolbar(Style style, StyleAsset styleAsset)
        {
//			bool changed = GUI.changed;

            using (new EditorGUI.DisabledGroupScope(!styleAsset))
                using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Toggle(isShowProperties, new GUIContent("Show Detal"), EditorStyles.toolbarButton) != isShowProperties)
                    {
                        isShowProperties = !isShowProperties;
                    }

                    if (GUILayout.Button("Bake", EditorStyles.toolbarButton))
                    {
                        PropertyEditor.Bake(styleAsset.GetPropertyEnumerator());
                    }

                    if (GUILayout.Button("Add Property", EditorStyles.toolbarPopup))
                    {
                        IEnumerable <System.Type> availableTypes = Enumerable.Empty <System.Type>();
                        if (style)
                        {
                            availableTypes = availableTypes.Concat(style.GetComponents <Component>()
                                                                   .Where(x => x != style)
                                                                   .Select(x => x.GetType()));
                        }

                        if (styleAsset)
                        {
                            availableTypes = availableTypes.Concat(styleAsset.GetPropertyEnumerator()
                                                                   .Where(x => x.methodInfo != null)
                                                                   .Select(x => x.methodInfo.ReflectedType));
                        }

                        var menu = PropertyEditor.CreateTargetMenu(style, styleAsset.properties, availableTypes, 1);
                        AppendAvailableOptionToMenu(menu, style, styleAsset.properties).ShowAsContext();
                    }
                }
//			GUI.changed = changed;
        }
예제 #2
0
        /// <summary>
        /// Draws the style sheet toolbar.
        /// </summary>
        /// <param name="behavior">Target behavior.</param>
        /// <param name="styleSheetAsset">Style sheet asset.</param>
        void DrawToggleToolbar()
        {
            bool changed = GUI.changed;

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

            // Save style property from target behavior.
            using (var cc = new EditorGUI.DisabledGroupScope(!current || ValueType.Index < current.valueType))
            {
                if (GUILayout.Button(new GUIContent("Save"), EditorStyles.toolbarButton))
                {
                    foreach (var property in current.toggleProperties)
                    {
                        property.parameterList.FitSize(current.count);
                        PropertyEditor.FillArgumentsByGetter(current, property.methodInfo, property.parameterList, current.indexValue);
                    }
                }

                if (GUILayout.Button(new GUIContent("Load"), EditorStyles.toolbarButton))
                {
                    ResetToggleValue();
                }
            }

            GUILayout.Space(8);

            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Bake", EditorStyles.toolbarButton))
            {
                PropertyEditor.Bake(current.toggleProperties);
            }

            if (GUILayout.Button("Add Property", EditorStyles.toolbarPopup))
            {
                var menu = PropertyEditor.CreateTargetMenu(current, current.toggleProperties, current.count);
                AppendAvailableOptionToMenu(menu).ShowAsContext();
            }


            //自動構築ボタン.
            EditorGUI.BeginDisabledGroup(spGroupToggles.arraySize == 0 && spActivations.arraySize == 0);
            if (GUILayout.Button(contentHierarchy, EditorStyles.toolbarButton))
            {
                int count     = current.count;
                var sb        = new StringBuilder("Are you sure you want to reconstruct toggles based on child transforms as following?\n");
                var transform = current.transform;
                var children  = Enumerable.Range(0, transform.childCount)
                                .Select(i => transform.GetChild(i))
                                .ToList();

                var childToggles = children
                                   .Select(trans => trans.GetComponent <CompositeToggle>())
                                   .Where(toggle => toggle != null)
                                   .ToList();

                if (0 < spActivations.arraySize)
                {
                    count = Mathf.Max(count, children.Count);
                    sb.AppendFormat("\n{0} GameObjects for 'Set Activation' :\n{1}",
                                    children.Count,
                                    children.Aggregate(new StringBuilder(), (a, b) => a.AppendFormat(" - {0}\n", b.name))
                                    );
                }

                if (0 < spGroupToggles.arraySize)
                {
                    count = Mathf.Max(count, childToggles.Count);
                    sb.AppendFormat("\n{0} CompositeToggles for 'Toggle Grouping' :\n{1}",
                                    childToggles.Count,
                                    childToggles.Aggregate(new StringBuilder(), (a, b) => a.AppendFormat(" - {0}\n", b.name))
                                    );
                }

                if (EditorUtility.DisplayDialog("Auto-Construction Based on Children", sb.ToString(), "Yes", "No"))
                {
                    current.count = count;
                    serializedObject.Update();

                    for (int i = 0; i < Mathf.Min(spGroupToggles.arraySize, childToggles.Count); i++)
                    {
                        spGroupToggles.GetArrayElementAtIndex(i).objectReferenceValue = childToggles[i];
                    }

                    for (int i = 0; i < Mathf.Min(spActivations.arraySize, children.Count); i++)
                    {
                        spActivations.GetArrayElementAtIndex(i).objectReferenceValue = children[i].gameObject;
                    }
                }
            }
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();
            GUI.changed = changed;
        }