ScreenPad.Update C# (CSharp) Метод

Update() приватный Метод

private Update ( ) : void
Результат void
	void Update () {
        // minus shoot duration
        if ( this.shootCounter > 0.0f )
            this.shootCounter -= Time.deltaTime;

        // NOTE: you can use this to check your count. if ( touches.Count == 1 ) {
        this.moveDir = Vector2.zero;
#if UNITY_IPHONE
        this.availableTouches.Clear();
#endif

        this.reloadButtonStat = 0;
        this.meleeButtonStat = 0;
        this.aimingZoneStat = 0;
        this.moveZoneStat = 0;

        if ( this.acceptInput == false ) {
#if UNITY_IPHONE
            this.moveID = -1;
            this.aimingID = -1;
#endif
            return;
        }

        if ( this.useRemoteTouch ) {
#if UNITY_IPHONE
            // first check if move finger invalid
            Touch move_finger = new Touch();
            Touch aiming_finger = new Touch();
            foreach ( Touch t in Input.touches ) {
                // if we just touch the zone
                if ( t.phase == TouchPhase.Began ) 
                {
                    if ( this.moveID == -1 && this.moveZone.Contains(t.position) ) {
                        this.moveID = t.fingerId;
                        move_finger = t;
                        this.moveZoneStat = 1;
                        continue;
                    }
                    else if ( this.aimingID == -1 && this.aimingZone.Contains(t.position) ) {
                        this.aimingID = t.fingerId;
                        aiming_finger = t;
                        this.aimingZoneStat = 1;
                        continue;
                    }
                    else if ( this.meleeID == -1 && this.meleeZone.Contains(t.position) ) {
                        this.meleeID = t.fingerId;
                        this.meleeButtonStat = 1;
                        continue;
                    }
                    else if ( this.reloadID == -1 && this.reloadZone.Contains(t.position) ) {
                        this.reloadID = t.fingerId;
                        this.reloadButtonStat = 1;
                        continue;
                    }
                }

                // check fingerId
                if ( t.fingerId == this.moveID ) {
                    if ( t.phase == TouchPhase.Ended ) {
                        this.moveID = -1;
                        this.moveZoneStat = 2;
                    }
                    else
                        move_finger = t;
                }
                else if ( t.fingerId == this.aimingID ) {
                    if ( t.phase == TouchPhase.Ended ) {
                        this.aimingID = -1;
                        this.aimingZoneStat = 2;
                    }
                    else
                        aiming_finger = t;
                }
                else if ( t.fingerId == this.meleeID ) {
                    if ( t.phase == TouchPhase.Ended ) {
                        this.meleeID = -1;
                        this.meleeButtonStat = 2;
                    }
                }
                else if ( t.fingerId == this.reloadID ) {
                    if ( t.phase == TouchPhase.Ended ) {
                        this.reloadID = -1;
                        this.reloadButtonStat = 2;
                    }
                }
                // if none of them are the above IDs, add them to availableTouches.
                else {
                    this.availableTouches.Add(t);
                }
            }

            // process move by move_finger
            if ( this.moveID != -1 ) {
                HandleMove( move_finger.position );
            }

            // process aiming by first check if we have screenPad, then aimingID.
            HandleAiming(aiming_finger.position);

            // DEBUG { 
            // foreach ( Touch t in Input.touches ) {
            //     DebugHelper.ScreenPrint("touch position: " + t.position);
            // }
            // } DEBUG end 
#endif
            } else {
                // handle keyboard move
                float moveFB = Input.GetAxisRaw("Vertical");
                float moveLR = Input.GetAxisRaw("Horizontal");
                Vector2 dir = new Vector2(moveLR,moveFB);
                Vector2 screenPos = this.moveLimitation * dir.normalized + this.moveZone.center;
                HandleMove(screenPos);
                HandleAiming(Vector2.zero);
                if ( Input.GetButton("Fire") )
                    this.shootCounter = this.shootingDuration;

                if ( Input.GetKeyDown(KeyCode.Space) )
                    this.meleeButtonStat = 1;
                else if ( Input.GetKeyUp(KeyCode.Space) )
                    this.meleeButtonStat = 2;

                if ( Input.GetKeyDown(KeyCode.R) )
                    this.reloadButtonStat = 1;
                else if ( Input.GetKeyUp(KeyCode.R) )
                    this.reloadButtonStat = 2;
                this.reloadID = Input.GetKey(KeyCode.R) ? 1:-1; 
                this.meleeID = Input.GetKey(KeyCode.Space) ? 1:-1; 
            } // end if ( !this.useRemoteTouch )

            // if there is no move, keep the moveAnalog at the center of the moveZone. 
            if ( MathHelper.IsZerof(this.moveDir.sqrMagnitude) ) {
                Vector3 worldpos = this.hudCamera.ScreenToWorldPoint( new Vector3( this.moveZone.center.x, this.moveZone.center.y, 1 ) );
                // moveAnalog.transform.position = new Vector3( worldpos.x, worldpos.y, moveAnalog.transform.position.z ); 

                Hashtable args = iTween.Hash( "position", worldpos,
                                              "time", 0.1f,
                                              "easetype", iTween.EaseType.easeInCubic 
                                            );
                // iTween.MoveTo ( moveAnalog, worldpos, 0.2f );
                iTween.MoveTo ( this.moveAnalog.gameObject, args );
            }
        }

Usage Example

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (xInput.GamePad.GetState(PlayerIndex.One).Buttons.Back == xInput.ButtonState.Pressed)
            {
                Application.Current.Exit();
            }

#if WINDOWS_APP
            var keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            //if (keyboardState.IsKeyUp())
#endif

#if WINDOWS_PHONE_APP
            if (screenPad.GetState().Buttons.B == ButtonState.Pressed)
            {
                buttonBPressed = true;
            }
            else if (screenPad.GetState().Buttons.B == ButtonState.Released && buttonBPressed)
            {
                buttonBPressed = false;
                var reviewHelper = BaseVerticalShooter.Resolver.Instance.Resolve <IReviewHelper>();
                reviewHelper.MarketPlaceReviewTask();
            }

            screenPad.Update();
#endif

            currentView.Update(gameTime);

            base.Update(gameTime);
        }
All Usage Examples Of ScreenPad::Update