// ---------------------
    private void Update()
    {
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            DemoSwipeMenuCS.LoadMenuScene();
            //DemoMenu.LoadMenuLevel();
            return;
        }


        // Popup box update...

        if (this.popupBox != null)
        {
            if (!this.popupBox.IsVisible())
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    this.popupBox.Show(
                        INSTRUCTIONS_TITLE,
                        INSTRUCTIONS_TEXT,
                        INSTRUCTIONS_BUTTON_TEXT);
                }
            }
            else
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    this.popupBox.Hide();
                }
            }
        }


        // Touch controls...

        // Get first zone, since there's only one...

        TouchZone zone = this.touchCtrl.GetZone(0);


        // If two fingers are touching, handle twisting and pinching...

        if (zone.MultiPressed(false, true))
        {
            // Get current mulit-touch position (center) as a pivot point for zoom and rotation...

            Vector2 pivot = zone.GetMultiPos(TouchCoordSys.SCREEN_PX);


            // If pinched, scale map by non-raw relative pinch scale..

            if (zone.Pinched())
            {
                this.ScaleMap(zone.GetPinchRelativeScale(false), pivot);
            }


            // If twisted, rotate map by this frame's angle delta...

            if (zone.Twisted())
            {
                this.RotateMap(zone.GetTwistDelta(false), pivot);
            }
        }

        // If one finger is touching the screen...

        else
        {
            // Single touch...

            if (zone.UniPressed(false, true))
            {
                if (zone.UniDragged())
                {
                    // Drag the map by this frame's unified touch drag delta...

                    Vector2 delta = zone.GetUniDragDelta(TouchCoordSys.SCREEN_PX, false);

                    this.SetMapOffset(this.mapOfs + delta);
                }
            }

            // Double tap with two fingers to zoom-out...

            if (zone.JustMultiDoubleTapped())
            {
                this.ScaleMap(0.5f, zone.GetMultiTapPos(TouchCoordSys.SCREEN_PX));
            }

            // Double tap with one finger to zoom in...

            else if (zone.JustDoubleTapped())
            {
                this.ScaleMap(2.0f, zone.GetTapPos(TouchCoordSys.SCREEN_PX));
            }
        }



        // Keep map on the screen...

        if (this.keepMapInside)
        {
            this.marginFactor = Mathf.Clamp(this.marginFactor, 0, 0.5f);

            Rect safeRect = new Rect(
                Screen.width * this.marginFactor,
                Screen.height * this.marginFactor,
                Screen.width * (1.0f - (2.0f * this.marginFactor)),
                Screen.height * (1.0f - (2.0f * this.marginFactor)));


            Rect mapRect = this.GetMapBoundingBox();


            if (mapRect.xMax < safeRect.xMin)
            {
                this.mapOfs.x -= (mapRect.xMax - safeRect.xMin);
            }

            else if (mapRect.xMin > safeRect.xMax)
            {
                this.mapOfs.x -= (mapRect.xMin - safeRect.xMax);
            }

            if (mapRect.yMax < safeRect.yMin)
            {
                this.mapOfs.y -= (mapRect.yMax - safeRect.yMin);
            }

            else if (mapRect.yMin > safeRect.yMax)
            {
                this.mapOfs.y -= (mapRect.yMin - safeRect.yMax);
            }
        }



        // Smooth map transform...

        if ((Time.deltaTime >= this.smoothingTime))
        {
            this.SnapDisplayTransform();
        }
        else
        {
            float st = (Time.deltaTime / this.smoothingTime);

            this.displayOfs   = Vector2.Lerp(this.displayOfs, this.mapOfs, st);
            this.displayScale = Mathf.Lerp(this.displayScale, this.mapScale, st);
            this.displayAngle = Mathf.Lerp(this.displayAngle, this.mapAngle, st);
        }

        //this.TransformMap();
    }
示例#2
0
    // ----------------
    public void ControlByTouch()
    {
        if (this.touchCtrl == null)
        {
            return;
        }

        // Get controls' references...

        TouchStick stickWalk  = this.touchCtrl.GetStick(DemoFppGameCS.STICK_WALK);
        TouchZone  zoneAim    = this.touchCtrl.GetZone(DemoFppGameCS.ZONE_AIM);
        TouchZone  zoneFire   = this.touchCtrl.GetZone(DemoFppGameCS.ZONE_FIRE);
        TouchZone  zoneZoom   = this.touchCtrl.GetZone(DemoFppGameCS.ZONE_ZOOM);
        TouchZone  zoneReload = this.touchCtrl.GetZone(DemoFppGameCS.ZONE_RELOAD);


        // If Walk stick is pressed...

        if (stickWalk.Pressed())
        {
            // ... use it's unnormalized direction vector to control walking.

            Vector2 moveVec = stickWalk.GetVec();

            this.SetWalkSpeed(moveVec.y, moveVec.x);
        }

        // Stop walking when stick is released...
        else
        {
            this.SetWalkSpeed(0, 0);
        }


        // Firing...
        // Set weapons trigger by getting the Fire zone pressed state
        // (include mid-frame press)

        this.SetTriggerState(zoneFire.UniPressed(true, false));


        // Reload on Reload zone press (including mid-frame press and release situations).

        if (zoneReload.JustUniPressed(true, true))
        {
            this.ReloadWeapon();
        }


        // Toggle zoom mode, when tapped on zoom-zone...

        if (zoneZoom.JustTapped())
        {
            this.zoomActive = !this.zoomActive;
        }

        // Zoom dragging...

        if (this.zoomActive &&
            zoneZoom.UniPressed(false, false))
        {
            // Store inital zoom factor...

            if (!this.isZoomDragging)
            {
                this.isZoomDragging = true;
                this.zoomFactorRaw  = this.zoomFactor;
            }

            // Change zoom factor by RAW vertical unified-touch drag delta
            // queried in centimeters and scaled...

            this.zoomFactorRaw += (this.zoomFactorPerCm *
                                   zoneZoom.GetUniDragDelta(TouchCoordSys.SCREEN_CM, true).y);

            this.zoomFactor = Mathf.Clamp(this.zoomFactorRaw, 0, 1);
        }
        else
        {
            this.isZoomDragging = false;
        }



        // Aim, when either aim or fire zone if pressed by at least one finger
        // (ignoring mid-frame presses and releases)...

        if (zoneAim.UniPressed(false, false) ||
            zoneFire.UniPressed(false, false))
        {
            // If just started aiming, store initial aim angles...

            if (!this.isAiming)
            {
                this.isAiming   = true;
                this.aimVertRaw = this.aimVert;
                this.aimHorzRaw = this.aimHorz;
            }

            // Get aim delta adding aim-zone and fire-zone's
            // unified-touch RAW drag deltas in centimeters...

            Vector2 aimDelta =
                zoneAim.GetUniDragDelta(TouchCoordSys.SCREEN_CM, true) +
                zoneFire.GetUniDragDelta(TouchCoordSys.SCREEN_CM, true);


            // Apply aim-sensitivity and speed...

            aimDelta *= Mathf.Lerp(0.1f, 1.0f, this.aimSensitivity);

            aimDelta.x *= this.horzAimSpeed;
            aimDelta.y *= this.vertAimSpeed;

            // Add calculated delta to current our raw, non-clamped aim angles
            // and pass them to Aim() function.
            // By keeping separate, non-clamped angles we prevent that
            // uncomfortable effect when dragging past the limit and back again.

            this.aimHorzRaw += aimDelta.x;
            this.aimVertRaw += aimDelta.y;

            //
            this.Aim(this.aimHorzRaw, this.aimVertRaw);
        }
        else
        {
            this.isAiming = false;
        }

        // When double tapped the aim zone - level horizonal aim angle...

        if (zoneAim.JustDoubleTapped())
        {
            this.Aim(this.aimHorz, 0);
        }
    }
示例#3
0
    // ---------------
    private void Update()
    {
        // If controller's layout changed, reset menu's width...

        if ((this.ctrl != null) && this.ctrl.LayoutChanged())
        {
            this.menu.SetWindowSize(Screen.width, this.ctrl.GetDPI());
        }


        // Fade-in phase...

        if (this.fadeInTimer.Enabled)
        {
            this.fadeInTimer.Update(Time.deltaTime);
            if (this.fadeInTimer.Completed)
            {
                this.fadeInTimer.Disable();
            }
        }

        // Control...
        else
        {
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                Application.LoadLevel(EXIT_SCREEN_SCENE_NAME);
                return;
                //Application.Quit();
            }

            // Get first and the only one touch zone (no need for IDs)...

            TouchZone zone = this.ctrl.GetZone(0);


            // Handle tap...

            if (zone.JustTapped())
            {
                this.menu.OnTap();
            }

            // Handle unified-touch press...

            if (zone.JustUniPressed())
            {
                this.menu.OnPress();
            }

            //  If unified-touch moved, use it's drag delta...

            if (zone.UniDragged())
            {
                this.menu.Move(-zone.GetUniDragDelta(TouchCoordSys.SCREEN_PX).x);
            }


            // On unfied-touch release, get released drag velocity to detect those quick swipes...

            else if (zone.JustUniReleased())
            {
                this.menu.OnRelease(-zone.GetReleasedUniDragVel().x);
            }
        }


        // If swipe-menu completed - go to selected mode...

        this.menu.UpdateMenu();
        if (this.menu.JustCompleted())
        {
            switch (this.menu.GetCurItem())
            {
            case ITEM_FPP:
                this.StartDemo(FPP_DEMO_SCENE_NAME);
                return;

            case ITEM_RPG:
                this.StartDemo(RPG_DEMO_SCENE_NAME);
                return;

            case ITEM_MAP:
                this.StartDemo(MAP_DEMO_SCENE_NAME);
                return;

            case ITEM_DSS:
                this.StartDemo(DUAL_STICK_DEMO_SCENE_NAME);
                return;
            }
        }
    }