Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        spline = (Spline)target;

        EditorGUILayout.BeginVertical();
        uMode = (Spline.UpdateMode)EditorGUILayout.EnumPopup("   Update Mode", spline.updateMode);

        if (uMode == Spline.UpdateMode.EveryXFrames)
        {
            deltaFrames = EditorGUILayout.IntField("   Delta Frames", spline.deltaFrames);
            EditorGUILayout.Space();
        }
        else if (uMode == Spline.UpdateMode.EveryXSeconds)
        {
            deltaSeconds = EditorGUILayout.FloatField("   Delta Seconds", spline.deltaSeconds);
            EditorGUILayout.Space();
        }

        nMode = (Spline.ControlNodeMode)EditorGUILayout.EnumPopup("   Control Nodes", spline.nodeMode);
        iMode = (Spline.InterpolationMode)EditorGUILayout.EnumPopup("   Interpolation", spline.interpolationMode);

        if (iMode == Spline.InterpolationMode.Hermite)
        {
            tMode = (Spline.TangentMode)EditorGUILayout.EnumPopup("   Tangent Mode", spline.tangentMode);
        }

        rMode = (Spline.RotationMode)EditorGUILayout.EnumPopup("   Rotation Mode", spline.rotationMode);

        EditorGUILayout.Space();

        accuarcy = Mathf.Clamp(EditorGUILayout.IntField("   Accuracy", spline.interpolationAccuracy), 1, 20);

        EditorGUILayout.Space();

        if (iMode == Spline.InterpolationMode.Hermite)
        {
            tension = EditorGUILayout.FloatField("   Spline Tension", spline.tension);
        }

        if (rMode == Spline.RotationMode.Tangent)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("   Up-Vector");
            tanUpVector.x = EditorGUILayout.FloatField(spline.tanUpVector.x, GUILayout.MinWidth(10));
            tanUpVector.y = EditorGUILayout.FloatField(spline.tanUpVector.y, GUILayout.MinWidth(10));
            tanUpVector.z = EditorGUILayout.FloatField(spline.tanUpVector.z, GUILayout.MinWidth(10));
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();

        if (iMode != Spline.InterpolationMode.Bezier)
        {
            autoClose = EditorGUILayout.Toggle("   Auto Close", spline.autoClose);
        }

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.Space();
        bool isAddNodePressed = GUILayout.Button("Add Spline Node", GUILayout.MinWidth(250f));

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

        bool isAddNodeControllersPressed = false;

        if (spline.nodeMode == Spline.ControlNodeMode.UseChildren)
        {
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            isAddNodeControllersPressed = GUILayout.Button("Add CtrlNode-Component To Children", GUILayout.MinWidth(250f));
            EditorGUILayout.Space();
            EditorGUILayout.EndHorizontal();
        }

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

        //Draw Array-GUI
        if (nMode == Spline.ControlNodeMode.UseArray)
        {
            showNodeArray = EditorGUILayout.Foldout(showNodeArray, " Spline Nodes");

            if (showNodeArray)
            {
                numTransformNodes = EditorGUILayout.IntField("      Size", spline.splineNodesTransform.Length);

                for (int i = 0; i < spline.splineNodesTransform.Length; i++)
                {
                    spline.splineNodesTransform[i] = (Transform)EditorGUILayout.ObjectField("      Element " + i.ToString(), spline.splineNodesTransform[i], typeof(Transform), true);
                }
            }

            DragAndDrop.activeControlID = 0;
            DragAndDrop.visualMode      = DragAndDropVisualMode.Copy;
            if (Event.current.type == EventType.DragPerform && DragAndDrop.objectReferences[0].GetType() == typeof(GameObject))
            {
                DragAndDrop.AcceptDrag();

                Undo.RecordObject(target, "Add Node To " + spline.name);

                AddTransformNode(((GameObject)DragAndDrop.objectReferences[0]).transform);

                UpdateSplineComponents();

                EditorUtility.SetDirty(target);
            }
        }



        EditorGUILayout.Space();

        EditorGUILayout.EndVertical();

        if (isAddNodePressed)
        {
            AddSplineNode();
        }

        if (isAddNodeControllersPressed)
        {
            AddCtrlCmpntToChildren();
        }

        //Apply changes
        if (GUI.changed)
        {
            Undo.RecordObject(target, "Change Spline Settings");

            spline.updateMode        = uMode;
            spline.nodeMode          = nMode;
            spline.rotationMode      = rMode;
            spline.tangentMode       = tMode;
            spline.interpolationMode = iMode;

            spline.interpolationAccuracy = accuarcy;

            if (uMode == Spline.UpdateMode.EveryXFrames)
            {
                spline.deltaFrames = deltaFrames;
            }
            else if (uMode == Spline.UpdateMode.EveryXSeconds)
            {
                spline.deltaSeconds = deltaSeconds;
            }

            if (iMode == Spline.InterpolationMode.Hermite)
            {
                spline.tension = tension;
            }

            if (iMode != Spline.InterpolationMode.Bezier)
            {
                spline.autoClose = autoClose;
            }

            if (rMode == Spline.RotationMode.Tangent)
            {
                spline.tanUpVector = tanUpVector;
            }

            //check for errors
            if (nMode == Spline.ControlNodeMode.UseChildren)
            {
                if (spline.transform.childCount == 0)
                {
                    if (!errorNoChildrenShown)
                    {
                        Debug.LogWarning(errorNoChildren, spline.gameObject);
                    }

                    errorNoChildrenShown = true;
                }
                else
                {
                    errorNoChildrenShown = false;
                }
            }
            else
            {
                if (numTransformNodes == 0)
                {
                    if (!errorNoNodesShown)
                    {
                        Debug.LogWarning(errorNoNodes, spline.gameObject);
                    }
                    errorNoNodesShown = true;
                }
                else
                {
                    errorNoNodesShown = false;
                }
            }

            if (nMode == Spline.ControlNodeMode.UseArray && showNodeArray)
            {
                ResizeTransformNodeArray();

                bool nullReference = false;

                //Check for null references and inform the user if any have been found
                foreach (Transform item in spline.splineNodesTransform)
                {
                    if (item == null)
                    {
                        nullReference = true;
                    }
                }

                if (nullReference)
                {
                    if (!errorNullNodesShown)
                    {
                        Debug.LogWarning(errorNullNodes, spline.gameObject);
                    }
                    errorNullNodesShown = true;
                }
                else
                {
                    errorNullNodesShown = false;
                }
            }

            UpdateSplineComponents();

            EditorUtility.SetDirty(target);
        }
    }
Exemplo n.º 2
0
    public override void OnInspectorGUI( )
    {
        spline = (Spline) target;

        EditorGUILayout.BeginVertical( );
            uMode = (Spline.UpdateMode) EditorGUILayout.EnumPopup( "   Update Mode", spline.updateMode );

            if( uMode == Spline.UpdateMode.EveryXFrames )
            {
                deltaFrames = EditorGUILayout.IntField( "   Delta Frames", spline.deltaFrames );
                EditorGUILayout.Space( );
            }
            else if( uMode == Spline.UpdateMode.EveryXSeconds )
            {
                deltaSeconds = EditorGUILayout.FloatField( "   Delta Seconds", spline.deltaSeconds );
                EditorGUILayout.Space( );
            }

            nMode = (Spline.ControlNodeMode) EditorGUILayout.EnumPopup( "   Control Nodes", spline.nodeMode );
            iMode = (Spline.InterpolationMode) EditorGUILayout.EnumPopup( "   Interpolation", spline.interpolationMode );

            if( iMode == Spline.InterpolationMode.Hermite )
                tMode = (Spline.TangentMode) EditorGUILayout.EnumPopup( "   Tangent Mode", spline.tangentMode );

            rMode = (Spline.RotationMode) EditorGUILayout.EnumPopup( "   Rotation Mode", spline.rotationMode );

            EditorGUILayout.Space( );

            accuarcy = Mathf.Clamp( EditorGUILayout.IntField( "   Accuracy", spline.interpolationAccuracy ), 1, 20 );

            EditorGUILayout.Space( );

            if( iMode == Spline.InterpolationMode.Hermite )
                tension = EditorGUILayout.FloatField( "   Spline Tension", spline.tension );

            if( rMode == Spline.RotationMode.Tangent )
            {
                EditorGUILayout.BeginHorizontal( );
                    EditorGUILayout.PrefixLabel( "   Up-Vector" );
                    tanUpVector.x = EditorGUILayout.FloatField( spline.tanUpVector.x, GUILayout.MinWidth( 10 ) );
                    tanUpVector.y = EditorGUILayout.FloatField( spline.tanUpVector.y, GUILayout.MinWidth( 10 ) );
                    tanUpVector.z = EditorGUILayout.FloatField( spline.tanUpVector.z, GUILayout.MinWidth( 10 ) );
                EditorGUILayout.EndHorizontal( );
            }

            EditorGUILayout.Space( );

            if( iMode != Spline.InterpolationMode.Bezier )
                autoClose = EditorGUILayout.Toggle( "   Auto Close", spline.autoClose );

            EditorGUILayout.Space( );

            EditorGUILayout.BeginHorizontal( );
                EditorGUILayout.Space( );
                bool isAddNodePressed = GUILayout.Button( "Add Spline Node", GUILayout.MinWidth( 250f ) );
                EditorGUILayout.Space( );
            EditorGUILayout.EndHorizontal( );

            bool isAddNodeControllersPressed = false;

            if( spline.nodeMode == Spline.ControlNodeMode.UseChildren )
            {
                EditorGUILayout.Space( );

                EditorGUILayout.BeginHorizontal( );
                    EditorGUILayout.Space( );
                    isAddNodeControllersPressed = GUILayout.Button( "Add CtrlNode-Component To Children", GUILayout.MinWidth( 250f ) );
                    EditorGUILayout.Space( );
                EditorGUILayout.EndHorizontal( );
            }

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

            //Draw Array-GUI
            if( nMode == Spline.ControlNodeMode.UseArray )
            {
                showNodeArray = EditorGUILayout.Foldout( showNodeArray, " Spline Nodes" );

                if( showNodeArray )
                {
                    numTransformNodes = EditorGUILayout.IntField( "      Size", spline.splineNodesTransform.Length );

                    for( int i = 0; i < spline.splineNodesTransform.Length; i++ )
                        spline.splineNodesTransform[i] = (Transform) EditorGUILayout.ObjectField( "      Element " + i.ToString( ), spline.splineNodesTransform[i], typeof( Transform ), true );
                }

                DragAndDrop.activeControlID = 0;
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                if( Event.current.type == EventType.DragPerform && DragAndDrop.objectReferences[0].GetType( ) == typeof( GameObject ) )
                {
                    DragAndDrop.AcceptDrag( );

                    Undo.RegisterUndo( target, "Add Node To " + spline.name );

                    AddTransformNode( ((GameObject)DragAndDrop.objectReferences[0]).transform );

                    UpdateSplineComponents( );

                    EditorUtility.SetDirty( target );
                }
            }

            EditorGUILayout.Space( );

        EditorGUILayout.EndVertical( );

        if( isAddNodePressed )
            AddSplineNode( );

        if( isAddNodeControllersPressed )
            AddCtrlCmpntToChildren( );

        //Apply changes
        if( GUI.changed )
        {
            Undo.RegisterUndo( target, "Change Spline Settings" );

            spline.updateMode = uMode;
            spline.nodeMode = nMode;
            spline.rotationMode = rMode;
            spline.tangentMode = tMode;
            spline.interpolationMode = iMode;

            spline.interpolationAccuracy = accuarcy;

            if( uMode == Spline.UpdateMode.EveryXFrames )
                spline.deltaFrames = deltaFrames;
            else if( uMode == Spline.UpdateMode.EveryXSeconds )
                spline.deltaSeconds = deltaSeconds;

            if( iMode == Spline.InterpolationMode.Hermite )
                spline.tension = tension;

            if( iMode != Spline.InterpolationMode.Bezier )
                spline.autoClose = autoClose;

            if( rMode == Spline.RotationMode.Tangent )
                spline.tanUpVector = tanUpVector;

            //check for errors
            if( nMode == Spline.ControlNodeMode.UseChildren )
            {
                if( spline.transform.childCount == 0 )
                {
                    if( !errorNoChildrenShown )
                        Debug.LogWarning( errorNoChildren, spline.gameObject );

                    errorNoChildrenShown = true;
                }
                else
                {
                    errorNoChildrenShown = false;
                }
            }
            else
            {
                if( numTransformNodes == 0 )
                {
                    if( !errorNoNodesShown )
                        Debug.LogWarning( errorNoNodes, spline.gameObject );
                    errorNoNodesShown = true;
                }
                else
                {
                    errorNoNodesShown = false;
                }
            }

            if( nMode == Spline.ControlNodeMode.UseArray && showNodeArray )
            {
                ResizeTransformNodeArray( );

                bool nullReference = false;

                //Check for null references and inform the user if any have been found
                foreach( Transform item in spline.splineNodesTransform )
                    if( item == null )
                        nullReference = true;

                if( nullReference )
                {
                    if( !errorNullNodesShown )
                        Debug.LogWarning( errorNullNodes, spline.gameObject );
                    errorNullNodesShown = true;
                }
                else
                {
                    errorNullNodesShown = false;
                }
            }

            UpdateSplineComponents( );

            EditorUtility.SetDirty( target );
        }
    }