Beispiel #1
0
        static void setBrightness(string name, float value, InterFace activeInterface)
        {
            Button theButton;

            activeInterface.uiButtons.TryGetValue(name, out theButton);

            if (theButton != null)
            {
                theButton.SetBrightness(value);
            }
        }
Beispiel #2
0
        // ------------------------------------------------------------------------------------------------------------------------------------------


        void setRaycastActive(string name, bool value, InterFace activeInterface)
        {
            Button theButton;

            activeInterface.uiButtons.TryGetValue(name, out theButton);

            if (theButton != null)
            {
                theButton.image.raycastTarget = value;
            }
        }
Beispiel #3
0
        // ------------------------------------------------------------------------------------------------------------------
        // OLD CODE, from Fabric

        /*
         *
         *
         * void TerrainClamp{
         *
         *  // this clamps the camera to a lowest point (from fabric). based on geometry. however, it's not generic right now -> refactor.
         *
         *  //              Vector3 newCameraPosition = state.cameraInterest.transform.position + orientation * new Vector3 (0, 0, -distanceToInterest);
         *
         *  Vector3 newCameraPosition = ci.transform.position + orientation * new Vector3(0, 0, -distanceToInterest);
         *
         *
         *  float hh = 0;
         *  //          float hh = cc.getActiveLandscape ().getHeight (cp.x, cp.z) + minimumHeight;
         *
         *  if (newCameraPosition.y < hh)
         *  {
         *      //                  float pitch = Mathf.Asin ((hh - TPObject.transform.position.y) / distanceToInterest) * Mathf.Rad2Deg;
         *      float pitch = Mathf.Asin((hh - 0) / distanceToInterest) * Mathf.Rad2Deg;
         *
         *      //Debug.Log ("orbitcam under hull, locking pitch to: " + pitch);
         *      euler.x = pitch;
         *  }
         *
         * }
         *
         * void HullClamp{
         * // control for camera hitting the hull. camera will be pushed up and when possible it'll smoothly lower back along the hull towards its original y.
         *
         *  // !!!!!!!!!!!!!!!!!!!!!
         *  //          float hullHeight = cc.getActiveLandscape ().getHeight (cameraPositionOut.x, cameraPositionOut.z) + minimumHeight;
         *
         *
         *      if (false)
         *      {
         *
         *          float lockValueY = 0;
         *          bool lockY = false;
         *          float hullHeight = 0;
         *
         *
         *
         *
         *          bool yUnlocked = false;
         *          bool yIsTooLow = false;
         *          bool hullHigherThanLockvalue = false;
         *          float modifY = 0f;
         *
         *          if (cameraPositionOut.y > lockValueY)
         *              yUnlocked = true;
         *
         *          if (cameraPositionOut.y <= hullHeight)
         *              yIsTooLow = true;
         *
         *          if (lockValueY <= hullHeight)
         *              hullHigherThanLockvalue = true;
         *
         *          if (yIsTooLow)
         *          {
         *              // find out how much y needs to go up and create a correction vector along the vertical axis to do it. (thus controlling x and z as well)
         *              modifY = hullHeight - cameraPositionOut.y;
         *              float factor = modifY / vertical.y;
         *              Vector3 yCorrection = factor * vertical;
         *              cameraPositionOut += yCorrection;
         *
         *              if (!yUnlocked)
         *              {
         *                  // store unmodified y value. effectively this stores the lock value only the first time the cam gets bumped up
         *                  lockValueY = cameraPositionIn.y;
         *              }
         *          }
         *
         *          if (!yIsTooLow && yUnlocked && hullHigherThanLockvalue && lockY)
         *          {
         *
         *              // smooth towards hull y
         *              float cameraVel = 0f;
         *              cameraPositionOut.y = Mathf.SmoothDamp(cameraPositionIn.y, hullHeight, ref cameraVel, 0.25f);
         *          }
         *
         *          if (!yIsTooLow && yUnlocked && !hullHigherThanLockvalue && lockY)
         *          {
         *              // smooth towards unmodified y value
         *              float cameraVel = 0f;
         *              cameraPositionOut.y = Mathf.SmoothDamp(cameraPositionIn.y, lockValueY, ref cameraVel, 0.25f);
         *              if (Mathf.Abs(cameraPositionOut.y - lockValueY) < 0.1f)
         *              {
         *                  // snap value
         *                  cameraPositionOut.y = lockValueY;
         *                  yUnlocked = false;// this is redundant
         *              }
         *          }
         *
         *          //          Log.Message ( "ytoolow " + yIsTooLow.ToString () + " y modded " + yUnlocked.ToString ());
         *          //          Log.Message ( "y: " + cameraPositionOut.y + " unmod y: " + state.lockValueY);
         *
         *      }
         *
         * }
         */

        // ------------------------------------------------------------------------------------------------------------------



        public static void clearSelectedObjects(object sender, UIArgs uxArgs)
        {
            InterFace interFace = uxArgs.uiEvent.plane.interFace;

            foreach (GameObject go in interFace.selectedObjects)
            {
                go.GetComponent <MeshRenderer>().material = interFace.defaultMat;
            }

            interFace.selectedObjects.Clear();
        }
Beispiel #4
0
        public void AddInterface(InterFace _interface)
        {
            interFace       = _interface;
            interFace.plane = this;

            if (rt == null)
            {
                // there was no gameobject or somehow no recttransform on it, so we set the canvas rt as ref
                rt = interFace.canvasObject.GetComponent <RectTransform>();
            }
        }
Beispiel #5
0
        static void setTargetBrightness(string name, float value, float step, InterFace activeInterface)
        {
            Button theButton;

            activeInterface.uiButtons.TryGetValue(name, out theButton);

            if (theButton != null)
            {
                theButton.SetTargetBrightness(value, step);
                //theButton.targetBrightness = value;
            }
        }
Beispiel #6
0
        bool brightnessIsChanging(string name, InterFace activeInterface)
        {
            //bool result = false;
            Button theButton;

            activeInterface.uiButtons.TryGetValue(name, out theButton);

            if (theButton != null)
            {
                return(theButton.BrightnessChanging());
            }

            return(false);
        }
Beispiel #7
0
        static public void rotateCamera(object sender, UIArgs uxArgs)
        {
            InterFace interFace = uxArgs.uiEvent.plane.interFace;

            if (interFace.uiCam3D.control == CAMERACONTROL.ORBIT)
            {
                OrbitCamera(sender, uxArgs);
            }

            if (interFace.uiCam3D.control == CAMERACONTROL.TURN)
            {
                turnCamera(sender, uxArgs);
            }

            if (interFace.uiCam3D.control == CAMERACONTROL.GYRO)
            {
                gyroCamera(sender, uxArgs);
            }
        }
Beispiel #8
0
        public static void select3dObject(object sender, UIArgs uxArgs)
        {
            InterFace interFace = uxArgs.uiEvent.plane.interFace;

            Log("3d target: " + uxArgs.uiEvent.target3D.transform.name);

            if (interFace.selectedObjects.IndexOf(uxArgs.uiEvent.target3D) != -1)
            {
                // object was selected, deselect
                //   uxArgs.uiEvent.target3D.GetComponent<MeshRenderer>().material = interFace.defaultMat;
                interFace.selectedObjects.Remove(uxArgs.uiEvent.target3D);
            }
            else
            {
                // object was not selected, select
                //     uxArgs.uiEvent.target3D.GetComponent<MeshRenderer>().material = interFace.editMat;
                interFace.selectedObjects.Add(uxArgs.uiEvent.target3D);
            }
        }
Beispiel #9
0
        // --------------------------------------------   3D    ----------------------------------------------------------------------

        /*!\brief Dolly a 3d camera in and out by argument dd */

        public static void LongitudinalCamera(object sender, UIArgs uxArgs)
        {
            InterFace interFace = uxArgs.uiEvent.plane.interFace;

            GameObject cameraObject, cameraInterest;

            cameraObject   = interFace.uiCam3D.cameraObject;
            cameraInterest = interFace.uiCam3D.cameraInterest;

            float delta = uxArgs.delta.z;

            if (cameraInterest != null && cameraObject != null)
            {
                float unitsPerPixel = 10f / Screen.height;

                Quaternion cameraOrientation = cameraObject.transform.rotation;
                Vector3    forward           = cameraOrientation * Vector3.forward;
                //uxArgs.delta = unitsPerPixel * delta * forward;

                TranslateCamera(interFace.uiCam3D, unitsPerPixel * delta * forward);
            }
        }
Beispiel #10
0
        //        static readonly Quaternion landscapeRight = Quaternion.Euler(0, 0, 90);
        //       static readonly Quaternion landscapeLeft = Quaternion.Euler(0, 0, -90);
        //     static readonly Quaternion upsideDown = Quaternion.Euler(0, 0, 180);

        static public void gyroCamera(object sender, UIArgs uxArgs)
        {
            InterFace interFace = uxArgs.uiEvent.plane.interFace;

            GameObject co, ci;

            co = interFace.uiCam3D.cameraObject;
            ci = interFace.uiCam3D.cameraInterest;

            Vector3 startPosition = co.transform.position;

            Quaternion gyro = GyroToUnity(Input.gyro.attitude);

            //      Debug.Log ("gyro " + gyro.ToString());

            //      ci.transform.rotation = gyro * Quaternion.Euler (0, 0, -90); // landscape left
            ci.transform.rotation = baseIdentity * gyro;

            //      Quaternion landscapeLeft =  Quaternion.Euler(0, 0, -90);

            //      Debug.Log ("gyroToUnity " + ci.transform.rotation.ToString());

            //      ci.transform.rotation = Input.gyro.attitude;

            Vector3 endPosition = co.transform.position;

            ci.transform.position -= (endPosition - startPosition);



            //      Vector3 forward = ci.transform.rotation * Vector3.forward;
            //      Vector3 up = ci.transform.rotation * Vector3.up;
            //      Vector3 right = ci.transform.rotation * Vector3.right;
            //
            //      Debug.Log ("f " + forward.ToString () + "u " + forward.ToString () + "r " + forward.ToString ());
        }
Beispiel #11
0
        /*!\brief Pan a 3d camera laterally by arguments dx,dy */

        public static void LateralCamera(object sender, UIArgs uxArgs)
        {
            InterFace interFace = uxArgs.uiEvent.plane.interFace;

            GameObject cameraObject   = interFace.uiCam3D.cameraObject;
            GameObject cameraInterest = interFace.uiCam3D.cameraInterest;
            Constraint constraint     = interFace.uiCam3D.constraint;
            Vector3    delta          = -1f * uxArgs.delta;

            //Debug.Log(delta.ToString());

            Vector3 cameraPositionIn  = cameraObject.transform.position;
            Vector3 cameraPositionOut = cameraPositionIn;

            Quaternion cameraOrientation = cameraInterest.transform.rotation;
            Vector3    horizontal        = cameraOrientation * Vector3.right;
            Vector3    vertical          = cameraOrientation * Vector3.up;

            float unitsPerPixel = 10f / Screen.height; // feels random

            cameraPositionOut += (delta.x * unitsPerPixel * 1f) * horizontal;
            cameraPositionOut += (delta.y * unitsPerPixel * 1f) * vertical;

            // Constraint is applied to camera object.

            if (constraint != null && constraint.hardClamp)
            {
                cameraPositionOut.x = Mathf.Clamp(cameraPositionOut.x, constraint.hardClampMin.x, constraint.hardClampMax.x);
                cameraPositionOut.y = Mathf.Clamp(cameraPositionOut.y, constraint.hardClampMin.y, constraint.hardClampMax.y);
                cameraPositionOut.z = Mathf.Clamp(cameraPositionOut.z, constraint.hardClampMin.z, constraint.hardClampMax.z);
            }

            // Translation is applied to interest object.

            cameraInterest.transform.position += (cameraPositionOut - cameraPositionIn);
        }
Beispiel #12
0
        // ------------------------------------------------------------------------------------------------------------------------------------------

        void processUiEvent(Event ui)
        {
            if (ui.plane == null || ui.plane.interFace == null)
            {
                return;
            }

            ui.callback = "";

            UIArgs args = new UIArgs();

            args.delta   = Vector3.zero;
            args.uiEvent = ui;

            InterFace interFace = ui.plane.interFace;

            switch (ui.action)
            {
            case ACTION.TAP:

                if (ui.targetJustTapped)
                {
                    Verbose("Double tap.");

                    if (ui.target2D != null)
                    {
                        interFace.doubletap_2d(this, args);
                    }
                    else if (ui.target3D != null)
                    {
                        interFace.doubletap_3d(this, args);
                    }
                    else
                    {
                        interFace.doubletap_none(this, args);
                    }

                    ui.action = ACTION.SINGLEDRAG;
                }
                else
                {
                    if (ui.tapTimeOut < float.Epsilon)
                    {
                        //       Log("Setting tap time out");
                        ui.tapTimeOut = Time.time + 0.1f;
                    }
                    else if (Time.time > ui.tapTimeOut)
                    {
                        Verbose("tap timed out, single tap.");
                        ui.tapTimeOut = 0;

                        if (ui.target2D != null)
                        {
                            interFace.tap_2d(this, args);
                        }
                        else if (ui.target3D != null)
                        {
                            interFace.tap_3d(this, args);
                        }
                        else
                        {
                            interFace.tap_none(this, args);
                        }

                        ui.action = ACTION.SINGLEDRAG;
                    }
                }


                // also perform single drag (which'll allow things like springs to work while waiting for timeout)

                args.delta = new Vector3(ui.scaledDx, ui.scaledDy, 0);

                if (ui.target2D != null)
                {
                    interFace.single_2d(this, args);
                }
                else if (ui.target3D != null)
                {
                    interFace.single_3d(this, args);
                }
                else
                {
                    interFace.single_none(this, args);
                }


                break;

            case ACTION.SINGLEDRAG:

                // If this is an orthodrag button, we need to set and lock the initial direction.
                // We also get the appropriate targets and constraints for that direction and load them into the uievent.

                if (ui.targetButton != null && ui.targetButton.orthoDragging && ui.direction == DIRECTION.FREE)
                {
                    if (Mathf.Abs(ui.scaledDx) > Mathf.Abs(ui.scaledDy))
                    {
                        ui.direction = DIRECTION.HORIZONTAL;
                        Verbose("Locking to drag horizontally");
                    }
                    if (Mathf.Abs(ui.scaledDx) < Mathf.Abs(ui.scaledDy))
                    {
                        ui.direction = DIRECTION.VERTICAL;
                        Verbose("Locking to drag vertically");
                    }
                }
                //Verbose("singledrag");
                args.delta = new Vector3(ui.scaledDx, ui.scaledDy, 0);

                if (ui.target2D != null)
                {
                    interFace.single_2d(this, args);
                }
                else if (ui.target3D != null)
                {
                    interFace.single_3d(this, args);
                }
                else
                {
                    interFace.single_none(this, args);
                }

                // interFace.AddMapping

                //      ui.isInert = false;
                //    ui.isSpringing = false;

                break;

            case ACTION.DOUBLEDRAG:

                args.delta = new Vector3(ui.scaledDx, ui.scaledDy, ui.scaledDd);

                if (ui.target2D != null)
                {
                    interFace.double_2d(this, args);
                }
                else if (ui.target3D != null)
                {
                    interFace.double_3d(this, args);
                }
                else
                {
                    interFace.double_none(this, args);
                }

                break;

            default:

                interFace.none(this, args);

                break;
            }


            ui.Inertia();
        }
Beispiel #13
0
        static public void turnCamera(object sender, UIArgs uxArgs)
        {
            // Create direct references for ease of use.
            InterFace interFace = uxArgs.uiEvent.plane.interFace;

            GameObject co, ci;

            co = interFace.uiCam3D.cameraObject;
            ci = interFace.uiCam3D.cameraInterest;


            if (ci != null && co != null)
            {
                Vector3 startPosition = co.transform.position;


                // we need a gameobject to be the interest, and a gameobject that holds the camera.

                float degreesPerPixel = 360f / Screen.height;
                //        float distanceToInterest = -1f * co.transform.localPosition.z;

                // delta.x -> YAW. rotate around (world) y axis.
                Quaternion orientation = co.transform.rotation;
                Quaternion yawRotation = Quaternion.AngleAxis(uxArgs.delta.x * degreesPerPixel, Vector3.up);
                orientation = yawRotation * orientation;

                // delta.y -> PITCH. rotate around (relative) x axis
                Vector3    cameraDirection = co.transform.rotation * Vector3.forward;
                Vector3    pitchAxis       = Vector3.Cross(cameraDirection, Vector3.up);
                Quaternion pitchRotation   = Quaternion.AngleAxis(uxArgs.delta.y * degreesPerPixel, pitchAxis);
                orientation = pitchRotation * orientation;

                // neutralise roll, clamp pitch, leave yaw unchanged
                Vector3 euler = orientation.eulerAngles;

                euler.z = 0;

                if (euler.x > 70 && euler.x <= 180)
                {
                    euler.x = 70;
                }
                if (euler.x < 290 && euler.x > 180)
                {
                    euler.x = 290;
                }


                if (false)
                {
                }

                orientation = Quaternion.Euler(euler);

                ci.transform.rotation = orientation;

                Vector3 endPosition = co.transform.position;

                ci.transform.position -= (endPosition - startPosition);

                //          co.transform.position = startPosition;
            }
        }
Beispiel #14
0
        public static void stopControls(object sender, UIArgs uxArgs)
        {
            InterFace interFace = uxArgs.uiEvent.plane.interFace;

            setTargetBrightness(interFace.getButtonNames(), 0.75f, interFace);
        }
Beispiel #15
0
        /*! \brief Add an interface directly to the root plane of this layout. This is usually for single plane layouts. */

        public void AddInterface(InterFace _interface)
        {
            rootPlane.AddInterface(_interface);
        }
Beispiel #16
0
        // ------------------------------------------------------------------------------------------------------------------------------------------

        void processUiEvent(Event ui)
        {
            if (ui.plane == null || ui.plane.interFace == null)
            {
                return;
            }

            ui.callback = "";

            UIArgs args = new UIArgs();

            args.delta   = Vector3.zero;
            args.uiEvent = ui;

            InterFace interFace = ui.plane.interFace;

            switch (ui.action)
            {
            case ACTION.TAP:

                ui.action = ACTION.SINGLEDRAG;

                if (ui.target2D != null)
                {
                    interFace.tap_2d(this, args);
                }
                else if (ui.target3D != null)
                {
                    interFace.tap_3d(this, args);
                }
                else
                {
                    interFace.tap_none(this, args);
                }

                break;

            case ACTION.SINGLEDRAG:

                // If this is an orthodrag button, we need to set and lock the initial direction.
                // We also get the appropriate targets and constraints for that direction and load them into the uievent.

                if (ui.targetButton != null && ui.targetButton.orthoDragging && ui.direction == DIRECTION.FREE)
                {
                    if (Mathf.Abs(ui.scaledDx) > Mathf.Abs(ui.scaledDy))
                    {
                        ui.direction = DIRECTION.HORIZONTAL;
                        Verbose("Locking to drag horizontally");
                    }
                    if (Mathf.Abs(ui.scaledDx) < Mathf.Abs(ui.scaledDy))
                    {
                        ui.direction = DIRECTION.VERTICAL;
                        Verbose("Locking to drag vertically");
                    }
                }
                //      Verbose("singledrag");
                args.delta = new Vector3(ui.scaledDx, ui.scaledDy, 0);

                if (ui.target2D != null)
                {
                    interFace.single_2d(this, args);
                }
                else if (ui.target3D != null)
                {
                    interFace.single_3d(this, args);
                }
                else
                {
                    interFace.single_none(this, args);
                }

                // interFace.AddMapping

                //      ui.isInert = false;
                //    ui.isSpringing = false;

                break;

            case ACTION.DOUBLEDRAG:

                args.delta = new Vector3(ui.scaledDx, ui.scaledDy, ui.scaledDd);

                if (ui.target2D != null)
                {
                    interFace.double_2d(this, args);
                }
                else if (ui.target3D != null)
                {
                    interFace.double_3d(this, args);
                }
                else
                {
                    interFace.double_none(this, args);
                }

                break;

            default:

                interFace.none(this, args);

                break;
            }


            ui.Inertia();
        }