Пример #1
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (boxStyle == null)
            {
                boxStyle = new GUIStyle(GUI.skin.GetStyle("box"));
                boxStyle.normal.background = DreamteckEditorGUI.blankImage;
                boxStyle.margin            = new RectOffset(0, 0, 0, 2);
            }

            string saveText   = "Save";
            string saveAsText = "Save As";

            if (allSegments.Length > 1)
            {
                saveText   = "Save All";
                saveAsText = "Save All As";
            }
            if (sceneSegments.Length > 0 && !Application.isPlaying && !PrefabStageCheck.open)
            {
                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button(saveText, GUILayout.Height(40)))
                {
                    WritePrefabs();
                    return;
                }
                if (GUILayout.Button(saveAsText, GUILayout.Height(40), GUILayout.Width(70)))
                {
                    WritePrefabs(true);
                    return;
                }
                EditorGUILayout.EndHorizontal();
            }

            if (allSegments.Length > 1)
            {
                EditorGUILayout.HelpBox("Property editing unavailable with multiple selection", MessageType.Info);
                return;
            }

            LevelSegment segment = (LevelSegment)target;

            segment.type = (LevelSegment.Type)EditorGUILayout.EnumPopup("Type", segment.type);
            if (segment.type == LevelSegment.Type.Extruded)
            {
                segment.axis = (LevelSegment.Axis)EditorGUILayout.EnumPopup("Extrude Axis", segment.axis);
                ExtrusionUI();
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                segment.customEntrance = (Transform)EditorGUILayout.ObjectField("Entrance", segment.customEntrance, typeof(Transform), true);
                if (segment.customEntrance == null)
                {
                    if (GUILayout.Button("Create", GUILayout.Width(50)))
                    {
                        GameObject go = new GameObject("Entrance");
                        go.transform.parent    = segment.transform;
                        segment.customEntrance = go.transform;
                    }
                }
                else if (!IsChildOrSubchildOf(segment.customEntrance, segment.transform))
                {
                    Debug.LogError(segment.customEntrance.name + " must be a child of " + segment.name);
                    segment.customEntrance = null;
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                segment.customExit = (Transform)EditorGUILayout.ObjectField("Exit", segment.customExit, typeof(Transform), true);
                if (segment.customExit == null)
                {
                    if (GUILayout.Button("Create", GUILayout.Width(50)))
                    {
                        GameObject go = new GameObject("Exit");
                        go.transform.parent = segment.transform;
                        segment.customExit  = go.transform;
                    }
                }
                else if (!IsChildOrSubchildOf(segment.customExit, segment.transform))
                {
                    Debug.LogError(segment.customExit.name + " must be a child of " + segment.name);
                    segment.customExit = null;
                }
                EditorGUILayout.EndHorizontal();
                segment.customKeepUpright = EditorGUILayout.Toggle("Keep Upright", segment.customKeepUpright);
            }
            EditorGUILayout.Space();

            int childCount = 0;

            TransformUtility.GetChildCount(segment.transform, ref childCount);
            if (segment.editorChildCount != childCount && !Application.isPlaying)
            {
                segment.UpdateReferences();
                selectedProperties.Clear();
            }

            CustomPathUI();

            EditorGUILayout.Space();
            debugFoldout = EditorGUILayout.Foldout(debugFoldout, "Debug");
            if (debugFoldout)
            {
                if (!Application.isPlaying)
                {
                    segment.drawBounds = EditorGUILayout.Toggle("Draw Bounds", segment.drawBounds);
                }
                if (segment.type == LevelSegment.Type.Custom)
                {
                    segment.drawEntranceAndExit = EditorGUILayout.Toggle("Draw Entrance / Exit", segment.drawEntranceAndExit);
                }
                segment.drawGeneratedSpline  = EditorGUILayout.Toggle("Draw Generated Points", segment.drawGeneratedSpline);
                segment.drawGeneratedSamples = EditorGUILayout.Toggle("Draw Generated Samples", segment.drawGeneratedSamples);
                if (segment.drawGeneratedSamples)
                {
                    EditorGUI.indentLevel++;
                    segment.drawSampleScale = EditorGUILayout.FloatField("Sample Scale", segment.drawSampleScale);
                    EditorGUI.indentLevel--;
                }
                segment.drawCustomPaths = EditorGUILayout.Toggle("Draw Custom Paths", segment.drawCustomPaths);
                EditorGUILayout.HelpBox(segment.GetBounds().size.ToString(), MessageType.Info);
            }
        }
Пример #2
0
            private void OnGUI()
            {
                if (selectedProperties.Count == 0)
                {
                    return;
                }
                if (selectedProperties.Count == 1)
                {
                    titleContent = new GUIContent(segment.objectProperties[selectedProperties[0]].transform.name + " - Extrusion Settings");
                }
                else
                {
                    titleContent = new GUIContent("Multiple Objects - Extrusion Settings");
                }
                GUILayout.BeginVertical();
                int overrideCount          = 0;
                int settingsComponentCount = 0;

                ExtrusionSettings[] settings = new ExtrusionSettings[selectedProperties.Count];
                for (int i = 0; i < settings.Length; i++)
                {
                    settings[i] = segment.objectProperties[selectedProperties[i]].extrusionSettings;
                    if (segment.objectProperties[selectedProperties[i]].overrideSettingsComponent)
                    {
                        overrideCount++;
                    }
                    if (segment.objectProperties[selectedProperties[i]].hasSettingsComponent)
                    {
                        settingsComponentCount++;
                    }
                }

                if (selectedProperties.Count > 1)
                {
                    bool averageOverride = overrideCount == selectedProperties.Count;
                    bool lastOverride    = averageOverride;
                    if (settingsComponentCount > 0)
                    {
                        EditorGUILayout.HelpBox("One or more of the objects have a Settings Component attached. The components' extrusion settings will be used.", MessageType.Info);
                        averageOverride = EditorGUILayout.Toggle("Override Settings Component", averageOverride);
                        if (lastOverride != averageOverride)
                        {
                            for (int i = 0; i < selectedProperties.Count; i++)
                            {
                                segment.objectProperties[selectedProperties[i]].overrideSettingsComponent = averageOverride;
                                segment.UpdateReferences();
                            }
                        }
                    }
                    if (averageOverride || settingsComponentCount == 0)
                    {
                        EditorGUILayout.Space();
                        if (ExtrusionSettingsEditor.Draw(settings))
                        {
                            segment.UpdateReferences();
                        }
                    }
                }
                else if (selectedProperties.Count == 1)
                {
                    if (settingsComponentCount > 0)
                    {
                        EditorGUILayout.HelpBox("Object has a Settings Component attached. The component's extrusion settings will be used.", MessageType.Info);
                        segment.objectProperties[selectedProperties[0]].overrideSettingsComponent = EditorGUILayout.Toggle("Override Settings Component", segment.objectProperties[selectedProperties[0]].overrideSettingsComponent);
                    }
                    if (segment.objectProperties[selectedProperties[0]].overrideSettingsComponent || !segment.objectProperties[selectedProperties[0]].hasSettingsComponent)
                    {
                        EditorGUILayout.Space();
                        if (ExtrusionSettingsEditor.Draw(settings[0]))
                        {
                            segment.UpdateReferences();
                        }
                    }
                    if (GUILayout.Button("Select Object"))
                    {
                        Selection.activeGameObject = segment.objectProperties[selectedProperties[0]].transform.gameObject;
                        Close();
                    }

                    GUILayout.EndVertical();
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (rect.x + rect.height > position.height)
                    {
                        position = new Rect(position.x, position.y, position.width, rect.height + 10);
                    }
                }
            }