Esempio n. 1
0
        protected virtual void DrawSelectedPointInspector()
        {
            GUILayout.Label("Selected Point", EditorStyles.boldLabel);
            EditorGUI.BeginChangeCheck();
            Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Move Point");
                EditorUtility.SetDirty(spline);
                spline.SetControlPoint(selectedIndex, point, true);
            }

            EditorGUI.BeginChangeCheck();
            BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(spline, "Change Point Mode");
                spline.SetControlPointMode(selectedIndex, mode);
                EditorUtility.SetDirty(spline);
            }

            // Draw Node Data if ADV SPLINE
            // Would be in AdvSplineInspector, except AdvSpline is generic meaning
            // we can't use the CustomEditor attribute and force child types to use its inspector
            // which means either this is here or every AdvSpline child needs an associated TypeInspector script
            if (selectedIndex % 3 == 0)
            {
                int advNodeIndex                = selectedIndex / 3;
                SerializedObject   so           = serializedObject;
                SerializedProperty nodeDataProp = so.FindProperty(string.Format("{0}.Array.data[{1}]", "_nodeData", advNodeIndex));
                if (nodeDataProp != null)
                {
                    EditorGUI.BeginChangeCheck();

                    EditorGUILayout.PropertyField(nodeDataProp, new GUIContent("Node Data"), true);

                    if (EditorGUI.EndChangeCheck())
                    {
                        so.ApplyModifiedProperties();
                    }
                }
            }
        }
Esempio n. 2
0
        protected virtual void OnSceneGUI()
        {
            spline          = target as SplinePath;
            handleTransform = spline.transform;

            if (currentTool != Tools.current ||
                currentPivotRotation != Tools.pivotRotation)
            {
                currentTool          = Tools.current;
                currentPivotRotation = Tools.pivotRotation;

                ResetHandleSettings();
            }

            Vector3 p0 = ShowPoint(0);

            for (int i = 1; i < spline.ControlPointCount; i += 3)
            {
                Vector3 p1 = ShowPoint(i);
                Vector3 p2 = ShowPoint(i + 1);
                Vector3 p3 = ShowPoint(i + 2);

                Handles.color = Color.gray;
                Handles.DrawLine(p0, p1);
                Handles.DrawLine(p2, p3);

                Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
                p0 = p3;
            }

            Handles.color = Color.green.SetA(0.3f);
            Handles.SphereHandleCap(0, spline.GetPoint(0f), Quaternion.identity, 0.1f, EventType.Repaint);

            Handles.color = Color.red.SetA(0.3f);
            Handles.SphereHandleCap(0, spline.GetPoint(1f), Quaternion.identity, 0.1f, EventType.Repaint);

            if (spline.NormalType == NormalType.Perpendicular)
            {
                for (int i = 0; i < spline.Normals.Length; i++)
                {
                    if (i % 3 == 0)
                    {
                        Vector3 pos    = spline.GetControlPoint(i);
                        Vector3 normal = spline.GetControlNormal(i);

                        Handles.color = Color.red;
                        Handles.DrawLine(pos, pos + normal * 0.8f);
                    }
                }
            }

            int numIterations = 10 * spline.ControlPointCount;

            for (int i = 1; i < numIterations; i++)
            {
                float alpha = i / (float)numIterations;

                Vector3 pos    = spline.GetPoint(alpha);
                Vector3 normal = spline.GetNormal(alpha);

                Handles.color = Color.green;
                Handles.DrawLine(pos, pos + normal * 0.4f);
            }
        }