コード例 #1
0
    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("TARGET THIS OBJECT"))
        {
            targetedObject = (RoadBit)target;
            validateUpdate = true;
        }

        if (targetedObject != null)
        {
            GUILayout.Label("Got targ obj: " + targetedObject);

            RoadBit targ = (RoadBit)target;

            if (targetedObject != targ)
            {
                if (GUILayout.Button("Add targeted to end..."))
                {
                    targ.nextRoad           = targetedObject;
                    targetedObject.lastRoad = targ;
                    targetedObject.updateAll();
                    validateUpdate = true;
                    targetedObject = null;
                }

                if (GUILayout.Button("Add targeted to start..."))
                {
                    targetedObject.nextRoad = targ;
                    targ.lastRoad           = targetedObject;
                    targetedObject.updateAll();
                    validateUpdate = true;
                    targetedObject = null;
                }
            }
        }

        if (GUILayout.Button("Lightmap Everything"))
        {
            RoadBit[] allRoads = GameObject.FindObjectsOfType <RoadBit>();
            foreach (RoadBit r in allRoads)
            {
                r.updateLightmap();
            }
        }

        bool willUpdate = !Application.isPlaying && !((RoadBit)target).DISABLE_UPDATES;

        if (willUpdate)
        {
            RoadBit targ = (RoadBit)target;

            if (GUILayout.Button("Flip End Angle"))
            {
                targ.endRotation = Quaternion.Euler(Quaternion.identity * Vector3.up * -90);
                validateUpdate   = true;
            }
            if (GUILayout.Button("Reset End Angle"))
            {
                targ.endRotation = Quaternion.Euler(Quaternion.identity * Vector3.up);
                validateUpdate   = true;
            }

            if (GUILayout.Button("Flip Start Angle"))
            {
                targ.startRotation = Quaternion.Euler(Quaternion.identity * Vector3.up * -90);
                validateUpdate     = true;
            }
            if (GUILayout.Button("Reset Start Angle"))
            {
                targ.startRotation = Quaternion.Euler(Quaternion.identity * Vector3.up);
                validateUpdate     = true;
            }
        }

        DrawDefaultInspector();

        if (willUpdate)
        {
            RoadBit targ = (RoadBit)target;

            if (GUILayout.Button("Filthy"))
            {
                validateUpdate = true;                 //update next frame
            }

            if (GUILayout.Button("Flatten All"))
            {
                targ.startRotation = Quaternion.Euler(Quaternion.identity * Vector3.up * 90);
                targ.endRotation   = Quaternion.Euler(Quaternion.identity * Vector3.up * 90);
                targ.endPos.Scale(new Vector3(1, 0, 1));
                validateUpdate = true;                 //update next frame
                //then apply flatten middle
                targ.handle1Pos.Scale(new Vector3(1, 0, 1));
                targ.handle2Pos.Scale(new Vector3(1, 0, 1));
                targ.bankStart = 0;
                targ.bankEnd   = 0;
                validateUpdate = true;                 //update next frame
            }

            if (GUILayout.Button("Flatten Middle"))
            {
                targ.handle1Pos.Scale(new Vector3(1, 0, 1));
                targ.handle2Pos.Scale(new Vector3(1, 0, 1));
                targ.bankStart = 0;
                targ.bankEnd   = 0;
                validateUpdate = true;                 //update next frame
            }

            if (GUILayout.Button("Straighten"))
            {
                float endDistance = targ.endPos.magnitude;
                //targ.endPos = targ.transform.forward * endDistance;
                targ.worldEndPosInverse = targ.transform.position + (targ.transform.forward * endDistance);
                //targ.endPos.Scale(  new Vector3( 1, 0, 1 ) );
                targ.handle1Pos = (targ.endPos) * 0.33333f;
                targ.handle2Pos = (targ.endPos) * 0.66666f;
                //validateUpdate = true;
            }

            if (GUILayout.Button("Update IDs"))
            {
                targ.updateIDs();
            }

            if (GUILayout.Button("Disconnect"))
            {
                if (targ.nextRoad)
                {
                    targ.nextRoad.lastRoad = null;
                    targ.nextRoad          = null;
                }
                if (targ.lastRoad)
                {
                    targ.lastRoad.nextRoad = null;
                    targ.lastRoad          = null;
                }
            }

            if (GUILayout.Button("Add Section"))
            {
                RoadBit newBit = (RoadBit)GameObject.Instantiate(targ);
                newBit.lastMesh = null;                 //force it to make a new mesh
                newBit.lastRoad = targ;
                targ.nextRoad   = newBit;
                newBit.updateStart();
                newBit.gameObject.layer    = targ.gameObject.layer;
                newBit.gameObject.tag      = targ.gameObject.tag;
                newBit.transform.parent    = targ.transform.parent;
                Selection.activeGameObject = newBit.gameObject;
                //float outAngle = targ.endRotation.eulerAngles.y;
                //Debug.Log("OO " + outAngle );
            }

            if (GUI.changed)
            {
                targ.updateAll();
            }
        }
    }
コード例 #2
0
    public void OnSceneGUI()
    {
        //DrawDefaultInspector();

        if (!Application.isPlaying && !((RoadBit)target).DISABLE_UPDATES)
        {
            RoadBit targ = (RoadBit)target;

            DupeCleanup(targ);

            //Vector3 handleStart = UnityEditor.Handles.PositionHandle( targ.startPos, Quaternion.identity );

            //UnityEditor.Handles.RotationHandle( targ.startRotationInverse, targ.startPos  + Vector3.up * 6 );

            Quaternion rotStart = UnityEditor.Handles.RotationHandle(targ.startRotation, targ.startPos + Vector3.up * 2);
            Quaternion rotEnd   = UnityEditor.Handles.RotationHandle(targ.endRotation, targ.worldEndPosInverse);
            //Vector3 posEnd = UnityEditor.Handles.PositionHandle( targ.worldEndPos, targ.endRotation );
            //Vector3 handle1 = UnityEditor.Handles.PositionHandle( targ.worldHandle1Pos, Quaternion.identity );
            //Vector3 handle2 = UnityEditor.Handles.PositionHandle( targ.worldHandle2Pos, Quaternion.identity );

            Vector3 posEnd  = UnityEditor.Handles.PositionHandle(targ.worldEndPosInverse, targ.endRotation);
            Vector3 handle1 = UnityEditor.Handles.PositionHandle(targ.worldHandle1PosInverse, Quaternion.identity);
            Vector3 handle2 = UnityEditor.Handles.PositionHandle(targ.worldHandle2PosInverse, Quaternion.identity);

            bool isFilthy = false || validateUpdate;             //isDirty
            validateUpdate = false;

            //if ( !posEnd.Equals( targ.worldEndPos ) ){
            if (!posEnd.Equals(targ.worldEndPosInverse))
            {
                //Debug.Log("moved end");
                targ.worldEndPosInverse = posEnd;
                isFilthy = true;
            }


            //if ( !handle1.Equals( targ.worldHandle1Pos ) ){
            if (!handle1.Equals(targ.worldHandle1PosInverse))
            {
                //Debug.Log("moved handle 1");
                //targ.worldHandle1Pos = handle1;
                targ.worldHandle1PosInverse = handle1;
                isFilthy = true;
            }

            //if ( !handle2.Equals( targ.worldHandle2Pos ) ){
            if (!handle2.Equals(targ.worldHandle2PosInverse))
            {
                //Debug.Log("moved handle 2");
                //targ.worldHandle2Pos = handle2;
                targ.worldHandle2PosInverse = handle2;
                isFilthy = true;
            }


            if (!rotEnd.Equals(targ.endRotation) || !rotStart.Equals(targ.startRotation))
            {
                //Debug.Log("rotated handle");
                targ.endRotation   = rotEnd;
                targ.startRotation = rotStart;
                isFilthy           = true;
            }

            if (!lastPos.Equals(targ.startPos) || !lastRot.Equals(targ.transform.rotation))
            {
                isFilthy = true;
            }

            if (GUI.changed)
            {
                //Debug.Log("guichange");
            }

            if (isFilthy)
            {
                targ.updateAll();
            }

            drawtheLines(targ);

            lastPos = targ.startPos;
            lastRot = targ.transform.rotation;
        }
    }