Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();
            BezierSpline curve = (BezierSpline)target;

            serializedObject.Update();

            /*
             * EditorGUILayout.PropertyField(points, new GUIContent("Segments"));
             * if (points.isExpanded)
             * {
             *  EditorGUI.indentLevel += 1;
             *  for (int i = 0; i < points.arraySize; i++)
             *  {
             *      EditorGUILayout.BeginHorizontal();
             *      EditorGUILayout.LabelField(new GUIContent("P" + i), GUILayout.Width(55));
             *      EditorGUILayout.PropertyField(points.GetArrayElementAtIndex(i), GUIContent.none, GUILayout.Width(250));
             *      EditorGUILayout.EndHorizontal();
             *  }
             *  EditorGUI.indentLevel -= 1;
             * }
             */

            EditorGUILayout.LabelField(new GUIContent("Selected Point"), EditorStyles.boldLabel);
            SerializedProperty points     = serializedObject.FindProperty("points");
            SerializedProperty continuity = serializedObject.FindProperty("continuity");

            if (selectedIndex > -1 && selectedIndex < curve.points.Count)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(new GUIContent("P" + selectedIndex), GUILayout.Width(35));
                EditorGUILayout.PropertyField(points.GetArrayElementAtIndex(selectedIndex), GUIContent.none);
                EditorGUILayout.EndHorizontal();

                int cornerIndex = selectedIndex;
                if (selectedIndex % 3 == 1)
                {
                    cornerIndex = selectedIndex - 1;
                }
                else if (selectedIndex % 3 == 2)
                {
                    cornerIndex = selectedIndex + 1;
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(new GUIContent("Continuity Type:"), GUILayout.Width(100));
                EditorGUILayout.PropertyField(continuity.GetArrayElementAtIndex(cornerIndex), GUIContent.none);
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.LabelField(new GUIContent("No Point Selected"));
            }

            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Number of Segments: "), EditorStyles.boldLabel, GUILayout.Width(150));
            EditorGUILayout.LabelField(new GUIContent("" + curve.points.Count / 3), GUILayout.Width(25));
            if (GUILayout.Button("+", EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(curve, "Add Segment");
                curve.AddSegment();
                EditorUtility.SetDirty(curve);
            }
            if (GUILayout.Button("-", EditorStyles.miniButtonRight))
            {
                if (curve.points.Count >= 7)
                {
                    Undo.RecordObject(curve, "Remove Segment");
                    curve.RemoveSegment();
                    EditorUtility.SetDirty(curve);
                }
            }
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("Recompute Curve Approximation"))
            {
                Undo.RecordObject(curve, "Recompute Curve Approximation");
                curve.RecomputeApproximateCurve();
                EditorUtility.SetDirty(curve);
            }


            EditorGUILayout.Separator();
            EditorGUILayout.LabelField(new GUIContent("Display Options"), EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("curveColor"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("tangentColor"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("uniformSamplingColor"));

            serializedObject.ApplyModifiedProperties();
        }