Esempio n. 1
0
        private void FinalizeStairs()
        {
            Undo.SetCurrentGroupName("Finalize stairs");
            BoxStairs   script = (BoxStairs)target;
            GameObject  go     = script.gameObject;
            BoxCollider bc     = go.GetComponent <BoxCollider>();

            if (bc != null)
            {
                Undo.DestroyObjectImmediate(bc);
            }
            Undo.DestroyObjectImmediate(target);
        }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(Pivot);       // Property: Pivot
            EditorGUILayout.PropertyField(StairsWidth); // Property: StairsWidth

            if (StairsHeightDrivedBySteps.boolValue)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(StairsHeight); // Property: StairsHeight
            GUI.enabled = true;                          // Restore GUI default state

            if (StairsDepthDrivedBySteps.boolValue)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(StairsDepth); // Property: StairsDepth
            GUI.enabled = true;                         // Restore GUI default state

            GUI.enabled = false;                        // Only show the steps number
            EditorGUILayout.PropertyField(StepsNumber); // Property: StepsNumber
            GUI.enabled = true;                         // Restore GUI default state

            // Show buttons to control steps number

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("+1"))
            {
                StepsNumber.intValue++;
            }
            if (GUILayout.Button("+10"))
            {
                StepsNumber.intValue += 10;
            }
            if (GUILayout.Button("-1"))
            {
                StepsNumber.intValue--;
            }
            if (GUILayout.Button("-10"))
            {
                StepsNumber.intValue -= 10;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.PropertyField(ThreeSides); // Property: ThreeSides

            // Steps height

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            bool heightFoldout = HeightFoldout.boolValue;

            HeightFoldout.boolValue = EditorGUILayout.Foldout(heightFoldout, "Steps Height");

            if (HeightFoldout.boolValue)
            {
                EditorGUILayout.PropertyField(StairsHeightDrivedBySteps); // Property: StairsHeightDrivedBySteps

                for (int i = 0; i < StepsHeight.arraySize - 1; i++)
                {
                    EditorGUILayout.PropertyField(StepsHeight.GetArrayElementAtIndex(i)); // Property: StepsHeight
                }

                if (!StairsHeightDrivedBySteps.boolValue)
                {
                    GUI.enabled = false;
                }
                EditorGUILayout.PropertyField(StepsHeight.GetArrayElementAtIndex(StepsHeight.arraySize - 1));
                GUI.enabled = true;                                    // Restore GUI default state

                EditorGUILayout.PropertyField(KeepCustomHeightValues); // Property: KeepCustomHeightValues
            }

            // Steps depth

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            bool depthFoldout = DepthFoldout.boolValue;

            DepthFoldout.boolValue = EditorGUILayout.Foldout(depthFoldout, "Steps Depth");

            if (DepthFoldout.boolValue)
            {
                EditorGUILayout.PropertyField(StairsDepthDrivedBySteps); // Property: StairsDepthDrivedBySteps

                for (int i = 0; i < StepsDepth.arraySize - 1; i++)
                {
                    EditorGUILayout.PropertyField(StepsDepth.GetArrayElementAtIndex(i)); // Property: StepsDepth
                }

                if (!StairsDepthDrivedBySteps.boolValue)
                {
                    GUI.enabled = false;
                }
                EditorGUILayout.PropertyField(StepsDepth.GetArrayElementAtIndex(StepsDepth.arraySize - 1));
                GUI.enabled = true;                                   // Restore GUI default state

                EditorGUILayout.PropertyField(KeepCustomDepthValues); // Property: KeepCustomDepthValues
            }

            // Stairs Material

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(StairsMaterial); // Property: StairsMaterial

            // Steps Materials

            bool materialsfoldout = MaterialsFoldout.boolValue;

            MaterialsFoldout.boolValue = EditorGUILayout.Foldout(materialsfoldout, "Steps Materials");

            if (MaterialsFoldout.boolValue)
            {
                for (int i = 0; i < StepsMaterials.arraySize; i++)
                {
                    EditorGUILayout.PropertyField(StepsMaterials.GetArrayElementAtIndex(i)); // Property: StepsMaterials
                }
            }

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                BoxStairs script = (BoxStairs)target;
                Undo.SetCurrentGroupName("BoxStairs parameter change");
                Undo.undoRedoPerformed += script.CreateStairs;
                script.CreateStairs();
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            if (GUILayout.Button("Finalize stairs"))
            {
                FinalizeButtonPressed = true;
            }
        }