Example #1
0
	// -----------------
	private void OnGUI()
		{
		GUI.skin = this.guiSkin;
		

		GUI.color = new Color(0.4f, 0.4f, 0.4f, 1.0f);

		//GUILayout.BeginArea(new Rect(0, Screen.height * 0.1f, Screen.width, 200));

		//GUI.Box(new Rect(0, Screen.height * 0.1f, Screen.width, 200), 
		GUI.Label(new Rect(0, Screen.height * 0.05f, Screen.width, 200), 
		//GUILayout.Box(	
			"Thank you for trying our demo!");
		
		//GUILayout.EndArea();


		GUI.color = Color.white;

		//if (GUI.Button(new Rect(Screen.width * 0.1f, Screen.height - 100,
		//	Screen.width * 0.8f, 80), "Go to Asset Store!"))
		//	{
		//	Application.OpenURL(this.siteUrl);
		//	Application.Quit();
		//	}  
		
		GUILayout.BeginArea(new Rect(Screen.width * 0.1f, Screen.height - 150,
			Screen.width * 0.8f, 130));

		//GUILayout.BeginHorizontal();
		
//#if (!UNITY_WEBPLAYER || UNITY_EDITOR)
		


		if (GUILayout.Button("Visit our Shop"))
			{
			Application.OpenURL(ExitScreenCS.siteUrl);
			Application.Quit();
			}  

		if (GUILayout.Button("Visit Asset Store"))
			{
			Application.OpenURL(ExitScreenCS.assetStoreUrl);
			Application.Quit();
			}  
//#endif
		
		if (GUILayout.Button("Return to Main Menu"))
			{	
			DemoSwipeMenuCS.LoadMenuScene();
			return;
			}

		GUILayout.EndArea();

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

        // Manually poll and update the controller...

        this.ctrl.PollController();
        this.ctrl.UpdateController();


        // Control and update the player controller...

        if (this.player != null)
        {
            this.player.ControlByTouch(this.ctrl, this);
            this.player.UpdateChara();
        }



        // 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();
                }
            }
        }



        // Control camera...

        TouchZone  zoneScreen = this.ctrl.GetZone(ZONE_SCREEN);
        TouchStick stickWalk  = this.ctrl.GetStick(STICK_WALK);



        // If screen is pressed by two fingers (excluding mid-frame press and release).

        if (zoneScreen.MultiPressed(false, true))
        {
            if (!this.isMultiTouching)
            {
                // If we just started multi-touch, store initial zoom factor.

                this.pinchStartZoom  = this.camZoom;
                this.isMultiTouching = true;

                // Cancel stick's touch if it's shared with our catch-all zone...

                zoneScreen.TakeoverTouches(stickWalk);
            }


            // If pinching is active...

            if (zoneScreen.Pinched())
            {
                // Get pinch distance delta in centimeters (screen-size independence!),
                // then add it to our non-clamped state variable...

                this.pinchStartZoom += this.zoomFactorPerCm *
                                       zoneScreen.GetPinchDistDelta(TouchCoordSys.SCREEN_CM);

                // ... and pass it to proper function when zoom factor will be clamped.

                this.SetZoom(this.pinchStartZoom);
            }
        }

        // If less than two fingers are touching the zone...
        else
        {
            this.isMultiTouching = false;
        }



        // Update camera...

        this.camZoom           = Mathf.Clamp01(this.camZoom);
        this.camZoomForDisplay = Mathf.SmoothDamp(this.camZoomForDisplay, this.camZoom,
                                                  ref this.camZoomVel, this.camSmoothingTime);



        // Place camera...

        this.PlaceCamera();
    }
    // ---------------------
    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();
    }
Example #4
0
    // ------------------
    private void Update()
    {
        if (this.touchCtrl != null)
        {
            // Manually poll the controller...

            this.touchCtrl.PollController();

            // If controller's layout changed...

            if (this.touchCtrl.LayoutChanged())
            {
                // Set custom position to the Pause button...

                this.touchCtrl.GetZone(ZONE_PAUSE).SetRect(new Rect(5, 5, 32, 32));

                // Update camera's viewport to support screen-emulation.
                // This code can be excluded from release build...

                if ((this.chara != null) && (this.chara.playerViewCam != null))
                {
                    Rect r = this.touchCtrl.GetScreenEmuRect(true);

                    this.chara.playerViewCam.pixelRect = r;
                }

                // Indicate layout change handling.

                this.touchCtrl.LayoutChangeHandled();
            }
        }


        // Manually update the controller...

        if (this.touchCtrl != null)
        {
            this.touchCtrl.UpdateController();
        }


        // Pause menu active...

        if (this.IsPaused())
        {
            this.UpdatePauseMenu();
        }


        // Gameplay active...

        else
        {
            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();
                    }
                }
            }


            if (this.chara != null)
            {
                this.chara.UpdateChara();
            }


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

            // If the pause button just have been released (including mid-frame press)
            // show the Pause Menu...
            // Here you can see a method call on a returned zone object (in default safe-mode).

            if (this.touchCtrl.GetZone(ZONE_PAUSE).JustUniReleased(true, false))
            {
                this.StartPauseMenu();
            }
        }
    }
Example #5
0
    // ---------------
    void Update()
    {
        // If the game is paused...

        if ((this.popupBox != null) && this.popupBox.IsVisible())
        {
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                this.popupBox.End();
            }

            // Unpause...

            if (this.popupBox.IsComplete())
            {
                this.popupBox.Hide();

                // Enable controller...

                this.ctrl.EnableController();

                // Unpause the player...

                this.player.OnUnpause();
            }
        }

        // When not paused...
        else
        {
            // Return to Main menu...

            if (Input.GetKeyUp(KeyCode.Escape))
            {
                DemoSwipeMenuCS.LoadMenuScene();
                return;
            }


            // Handle input...

            if (this.ctrl)
            {
                // Get stick and zone references by IDs...

                TouchStick
                    walkStick = this.ctrl.GetStick(STICK_WALK),
                    fireStick = this.ctrl.GetStick(STICK_FIRE);
                TouchZone
                //screenZone	= this.ctrl.GetZone(ZONE_SCREEN),
                    pauseZone = this.ctrl.GetZone(ZONE_PAUSE);


                // If the PAUSE zone (or SPACEBAR) is released, show info box...

                if (pauseZone.JustUniReleased() || Input.GetKeyUp(KeyCode.Space))
                {
                    // Show popup box...

                    this.popupBox.Show(INFO_TITLE, INFO_BODY, INFO_BUTTON_TEXT);

                    // Disable controller to stop it from reacting to touch input...

                    this.ctrl.DisableController();

                    // Pause the game...

                    this.player.OnPause();
                }

                else
                {
                    // Walk when left stick is pressed...

                    if (walkStick.Pressed())
                    {
                        // Use stick's normalized XZ vector and tilt to move...

                        this.player.Move(walkStick.GetVec3d(true, 0), walkStick.GetTilt());
                    }

                    // Stop when stick is released...

                    else
                    {
                        this.player.Move(Vector3.zero, 0);
                    }


                    // Shoot when right stick is pressed...

                    if (fireStick.Pressed())
                    {
                        this.player.SetTriggerState(true);

                        // Get target angle and stick's tilt to determinate turning speed.

                        this.player.Aim(fireStick.GetAngle(), fireStick.GetTilt());
                    }

                    // ...or stop shooting and aiming when right stick is released.

                    else
                    {
                        this.player.SetTriggerState(false);
                        this.player.Aim(0, 0);
                    }
                }
            }
        }


        // Update character...

        this.player.UpdateChara();


        // Update camera...

        if (this.cam != null)
        {
            Transform camTf = this.cam.transform;
            camTf.position = this.player.transform.position + this.camOfs;
        }
    }