void FixedUpdate() { VCAnalogJoystickBase moveJoystick = VCAnalogJoystickBase.GetInstance("MoveJoyStick"); VCButtonBase actionButton = VCButtonBase.GetInstance("Action"); Vector2 directionVector = new Vector2(moveJoystick.AxisX, moveJoystick.AxisY); if (directionVector != Vector2.zero) { // Get the length of the directon vector and then normalize it // Dividing by the length is cheaper than normalizing when we already have the length anyway var directionLength = directionVector.magnitude; directionVector = directionVector / directionLength; // Make sure the length is no bigger than 1 directionLength = Mathf.Min(1.0f, directionLength); // Make the input vector more sensitive towards the extremes and less sensitive in the middle // This makes it easier to control slow speeds when using analog sticks directionLength = directionLength * directionLength; // Multiply the normalized direction vector by the modified length directionVector = directionVector * directionLength; } GetComponent <NetworkView>().RPC("SendInput", RPCMode.Server, directionVector.x, directionVector.y, actionButton.Pressed, Input.touchCount > 0); }
// utility to tell if a button is non null and pressed protected bool ButtonExistsAndIsPressed(VCButtonBase button) { if (button == null) return false; return button.Pressed; }
// utility to tell if a button is non null and pressed protected bool ButtonExistsAndIsPressed(VCButtonBase button) { if (button == null) { return(false); } return(button.Pressed); }
void Update() { if (isPlayer) { abtn = VCButtonBase.GetInstance("A"); abtn.OnPress = ButtonPress; bbtn = VCButtonBase.GetInstance("B"); bbtn.OnPress = ButtonPress; cbtn = VCButtonBase.GetInstance("C"); cbtn.OnPress = ButtonPress; } }
void Start() { if (button == null) { // try to find it on this gameObject. button = gameObject.GetComponent <VCButtonBase>(); if (button == null) { VCUtils.DestroyWithError(gameObject, "You must specify a button for VCButtonPlaymakerUpdater to function. Destroying this object."); return; } } }
void OnGUI() { // if there's an analog joystick, output some info if (VCAnalogJoystickBase.GetInstance("stick") != null) { GUI.Label(new Rect(10, 10, 300, 20), "Joystick Axes: " + VCAnalogJoystickBase.GetInstance("stick").AxisX + " " + VCAnalogJoystickBase.GetInstance("stick").AxisY); } // if there's an a button, output some info if (VCButtonBase.GetInstance("A") != null) { GUI.Label(new Rect(10, 30, 300, 20), "Button Hold (s): " + VCButtonBase.GetInstance("A").HoldTime.ToString()); } // if there's a dpad, output some info VCDPadBase dpad = VCDPadBase.GetInstance("dpad"); if (dpad != null) { string str = "DPad: "; if (dpad.Left) { str += "Left "; } if (dpad.Right) { str += "Right "; } if (dpad.Up) { str += "Up "; } if (dpad.Down) { str += "Down "; } if (dpad.Pressed(VCDPadBase.EDirection.None)) { str += "(No Direction)"; } GUI.Label(new Rect(10, 50, 300, 20), str); } GUI.Label(new Rect(10, 70, 300, 20), "Move cube using controls"); GUI.Label(new Rect(10, 90, 300, 20), "Double tap joystick / Press A for particles"); }
void OnGUI() { // if there's an analog joystick, output some info if (VCAnalogJoystickBase.GetInstance("stick") != null) { GUI.Label(new Rect(10, 10, 300, 20), VCAnalogJoystickBase.GetInstance("stick").AxisX + " " + VCAnalogJoystickBase.GetInstance("stick").AxisY); } // if there's an a button, output some info if (VCButtonBase.GetInstance("BtnA") != null) { GUI.Label(new Rect(10, 30, 300, 20), "aaaaaaaaaa"); } else { GUI.Label(new Rect(10, 30, 300, 20), "nullllll"); } // if there's a dpad, output some info VCDPadBase dpad = VCDPadBase.GetInstance("dpad"); if (dpad != null) { string str = ""; if (dpad.Left) { str += "Left "; } if (dpad.Right) { str += "Right "; } if (dpad.Up) { str += "Up "; } if (dpad.Down) { str += "Down "; } GUI.Label(new Rect(10, 50, 300, 20), str); } GUI.Label(new Rect(10, 70, 300, 20), "Move cube using controls"); GUI.Label(new Rect(10, 90, 300, 20), "Double tap joystick / Press A for particles"); }
void Update() { // Use the DPad to move the cube container if (cubeContainer) { // try and get the dpad VCDPadBase dpad = VCDPadBase.GetInstance("dpad"); // if we got one, perform movement if (dpad) { if (dpad.Left) { cubeContainer.transform.Translate(-moveSpeed * Time.deltaTime, 0.0f, 0.0f); } if (dpad.Right) { cubeContainer.transform.Translate(moveSpeed * Time.deltaTime, 0.0f, 0.0f); } if (dpad.Up) { cubeContainer.transform.Translate(0.0f, moveSpeed * Time.deltaTime, 0.0f); } if (dpad.Down) { cubeContainer.transform.Translate(0.0f, -moveSpeed * Time.deltaTime, 0.0f); } } // do the same for the analog joystick VCAnalogJoystickBase joy = VCAnalogJoystickBase.GetInstance("stick"); if (joy != null) { cubeContainer.transform.Translate(moveSpeed * Time.deltaTime * joy.AxisX, moveSpeed * Time.deltaTime * joy.AxisY, 0.0f); } } // rotate the cube for coolness effect if (cube) { cube.transform.RotateAroundLocal(new Vector3(1.0f, 1.0f, 0.0f), Time.deltaTime); } // and emit particles based on the time we've held down our A button (if we have one) VCButtonBase abtn = VCButtonBase.GetInstance("A"); if (abtn != null && cubeContainer) { ParticleSystem particles = cubeContainer.GetComponentInChildren <ParticleSystem>(); if (particles != null) { particles.emissionRate = abtn.HoldTime * 50.0f; } // emit some particles whenever joystick is double clicked VCAnalogJoystickBase joy = VCAnalogJoystickBase.GetInstance("stick"); if (joy != null && particles != null && joy.TapCount > 1) { particles.emissionRate = 150.0f; } } // example of how to detect if press began or ended exactly on this frame if (abtn != null) { if (abtn.PressBeganThisFrame) { Debug.Log("Press began on frame " + Time.frameCount); } if (abtn.PressEndedThisFrame) { Debug.Log("Press ended on frame " + Time.frameCount); } } }
protected override bool Init() { if (!base.Init ()) return false; if (leftVCButtonObject) LeftButton = leftVCButtonObject.GetComponent<VCButtonBase>(); if (rightVCButtonObject) RightButton = rightVCButtonObject.GetComponent<VCButtonBase>(); if (upVCButtonObject) UpButton = upVCButtonObject.GetComponent<VCButtonBase>(); if (downVCButtonObject) DownButton = downVCButtonObject.GetComponent<VCButtonBase>(); // intialize to non pressed SetPressedGraphics(VCDPadBase.EDirection.Left, false); SetPressedGraphics(VCDPadBase.EDirection.Right, false); SetPressedGraphics(VCDPadBase.EDirection.Up, false); SetPressedGraphics(VCDPadBase.EDirection.Down, false); #region error checking if (JoystickMode) { if (LeftButton && !LeftButton.skipCollisionDetection) { Debug.LogWarning("When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for LeftButton"); LeftButton.skipCollisionDetection = true; } if (RightButton && !RightButton.skipCollisionDetection) { Debug.LogWarning("When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for RightButton"); RightButton.skipCollisionDetection = true; } if (DownButton && !DownButton.skipCollisionDetection) { Debug.LogWarning("When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for DownButton"); DownButton.skipCollisionDetection = true; } if (UpButton && !UpButton.skipCollisionDetection) { Debug.LogWarning("When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for UpButton"); UpButton.skipCollisionDetection = true; } } #endregion return true; }
protected override bool Init() { if (!base.Init()) { return(false); } if (leftVCButtonObject) { LeftButton = leftVCButtonObject.GetComponent <VCButtonBase>(); } if (rightVCButtonObject) { RightButton = rightVCButtonObject.GetComponent <VCButtonBase>(); } if (upVCButtonObject) { UpButton = upVCButtonObject.GetComponent <VCButtonBase>(); } if (downVCButtonObject) { DownButton = downVCButtonObject.GetComponent <VCButtonBase>(); } // intialize to non pressed SetPressedGraphics(VCDPadBase.EDirection.Left, false); SetPressedGraphics(VCDPadBase.EDirection.Right, false); SetPressedGraphics(VCDPadBase.EDirection.Up, false); SetPressedGraphics(VCDPadBase.EDirection.Down, false); #region error checking if (JoystickMode) { if (LeftButton && !LeftButton.skipCollisionDetection) { Debug.LogWarning("When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for LeftButton"); LeftButton.skipCollisionDetection = true; } if (RightButton && !RightButton.skipCollisionDetection) { Debug.LogWarning("When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for RightButton"); RightButton.skipCollisionDetection = true; } if (DownButton && !DownButton.skipCollisionDetection) { Debug.LogWarning("When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for DownButton"); DownButton.skipCollisionDetection = true; } if (UpButton && !UpButton.skipCollisionDetection) { Debug.LogWarning("When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for UpButton"); UpButton.skipCollisionDetection = true; } } #endregion return(true); }
void Update() { if(isPlayer){ abtn = VCButtonBase.GetInstance("A"); abtn.OnPress = ButtonPress; bbtn = VCButtonBase.GetInstance("B"); bbtn.OnPress = ButtonPress; cbtn = VCButtonBase.GetInstance("C"); cbtn.OnPress = ButtonPress; } }
void ButtonPress(VCButtonBase button) { if(button == abtn){ switch(states){ case PlayerStates.idle: player.Play("attack"); states = PlayerStates.attacking; break; case PlayerStates.walk: player.Play("attack"); states = PlayerStates.attacking; break; case PlayerStates.grab: if(dpad && dpad.Left || dpad && dpad.Right){ player.Play("throw"); states = PlayerStates.grabthrow; } else{ player.Play("attackgrab"); states = PlayerStates.attackgrab; } break; case PlayerStates.attacking:nextAttack=true;break; case PlayerStates.jump:states = PlayerStates.jumpattack;break; } } if(button == bbtn){ switch(states){ case PlayerStates.idle: PrepareJump(); states = PlayerStates.jump; break; case PlayerStates.walk: PrepareJump(); states = PlayerStates.jump; break; case PlayerStates.attacking: nextAttack=false; PrepareJump(); states = PlayerStates.jump; break; } } if(button == cbtn && life>1){ switch(states){ case PlayerStates.idle: player.Play("specialattack");states = PlayerStates.specialattack;SpecialAttackLifePenalty();break; case PlayerStates.walk: player.Play("specialattack");states = PlayerStates.specialattack;SpecialAttackLifePenalty();break; case PlayerStates.hit: player.Play("specialattack");states = PlayerStates.specialattack;SpecialAttackLifePenalty();break; case PlayerStates.attacking: nextAttack=false; player.Play("specialattack");states = PlayerStates.specialattack;SpecialAttackLifePenalty();break; case PlayerStates.grab: DetachGrabbedEnemy(); player.Play("specialattack");states = PlayerStates.specialattack;SpecialAttackLifePenalty();break; } } }
protected override bool Init() { if (!base.Init()) { return(false); } if (this.leftVCButtonObject) { this.LeftButton = this.leftVCButtonObject.GetComponent <VCButtonBase>(); } if (this.rightVCButtonObject) { this.RightButton = this.rightVCButtonObject.GetComponent <VCButtonBase>(); } if (this.upVCButtonObject) { this.UpButton = this.upVCButtonObject.GetComponent <VCButtonBase>(); } if (this.downVCButtonObject) { this.DownButton = this.downVCButtonObject.GetComponent <VCButtonBase>(); } this.SetPressedGraphics(VCDPadBase.EDirection.Left, false); this.SetPressedGraphics(VCDPadBase.EDirection.Right, false); this.SetPressedGraphics(VCDPadBase.EDirection.Up, false); this.SetPressedGraphics(VCDPadBase.EDirection.Down, false); if (base.JoystickMode) { if (this.LeftButton && !this.LeftButton.skipCollisionDetection) { LogSystem.LogWarning(new object[] { "When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for LeftButton" }); this.LeftButton.skipCollisionDetection = true; } if (this.RightButton && !this.RightButton.skipCollisionDetection) { LogSystem.LogWarning(new object[] { "When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for RightButton" }); this.RightButton.skipCollisionDetection = true; } if (this.DownButton && !this.DownButton.skipCollisionDetection) { LogSystem.LogWarning(new object[] { "When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for DownButton" }); this.DownButton.skipCollisionDetection = true; } if (this.UpButton && !this.UpButton.skipCollisionDetection) { LogSystem.LogWarning(new object[] { "When DPad is in JoystickMode, Buttons should have skipCollisionDetection set to true. Setting it automatically for UpButton" }); this.UpButton.skipCollisionDetection = true; } } return(true); }
protected bool ButtonExistsAndIsPressed(VCButtonBase button) { return(!(button == null) && button.Pressed); }