/// <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; }
public override void OnInspectorGUI() { GUILayout.Space(8); serializedObject.Update(); // Style Asset. var spStyleAsset = serializedObject.FindProperty("m_StyleAsset"); StyleAssetEditor.DrawStyleAssetField(spStyleAsset, style => { spStyleAsset.objectReferenceValue = style; spStyleAsset.serializedObject.ApplyModifiedProperties(); EditorApplication.delayCall += () => StyleAssetEditor.UpdateChangeListeners(style as StyleAsset); }); // Style Properties. if (!spStyleAsset.hasMultipleDifferentValues) { EditorGUI.BeginChangeCheck(); // Draw Toolbar. using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) { using (var cc = new EditorGUI.DisabledGroupScope(!current.styleAsset)) { // Save style property from target. if (GUILayout.Button(new GUIContent("Save"), EditorStyles.toolbarButton)) { foreach (var property in current.styleAsset.properties) { property.parameterList.FitSize(1); PropertyEditor.FillArgumentsByGetter(current, property.methodInfo, property.parameterList); } PropertyEditor.onPropertyChanged(); } // Load style property to target. if (GUILayout.Button(new GUIContent("Load"), EditorStyles.toolbarButton)) { current.LoadStyle(); } } GUILayout.FlexibleSpace(); // Default Toolbar. StyleAssetEditor.DrawStyleToolbar(current, current.styleAsset); } // Draw style detail. if (StyleAssetEditor.isShowProperties && current.styleAsset) { StyleAssetEditor.DrawProperties(current.styleAsset); } // When style has changed, apply the style to gameObject. if (EditorGUI.EndChangeCheck() && current.styleAsset) { Debug.Log("hogehoge"); EditorUtility.SetDirty(current.styleAsset); PropertyEditor.onPropertyChanged(); } } // Not support multiple StyleAssets. else { EditorGUILayout.HelpBox("Multi-StyleAssets editing is not supported.", MessageType.None); } // Ignore Properties. GUILayout.Space(6); EditorGUILayout.LabelField("Ignore Properties", EditorStyles.boldLabel); roIgnoreProperties.serializedProperty = serializedObject.FindProperty("m_IgnoreProperties"); roIgnoreProperties.DoLayoutList(); serializedObject.ApplyModifiedProperties(); }