/// <summary> /// Creates a new virtual button and adds it to the ImageTarget /// Returns NULL if the corresponding DataSet is currently active. /// </summary> public VirtualButton CreateVirtualButton(string name, VirtualButton.RectangleData area) { VirtualButton virtualButton = CreateNewVirtualButtonInNative(name, area); if (virtualButton == null) { Debug.LogError("Could not create Virtual Button."); } else { Debug.Log("Created Virtual Button successfully."); } return virtualButton; }
/// <summary> /// /// </summary> public override void StartInput() { // m_Axis = CrossInputManager.VirtualAxisReference( this, string.Format(device.fmtJoy, axisName), true ); // m_Button = CrossInputManager.VirtualButtonReference( this, string.Format(device.fmtJoy, buttonName), true ); // device.axes.Add(axisName); device.buttons.Add(buttonName); }
public static VirtualButton VirtualButtonReference(object caller, string name, bool canAdd = false) { VirtualButton item = null; if (ButtonExists(name)) { item = VirtualButtonReference(name); } else { RegisterVirtualButton(item = new VirtualButton(name)); } if (item != null) { item.AddRef(caller); } return(item); }
private void OnReset() { camera = SceneObject.GetComponent <Camera>(); camera.NoLighting = true; moveForwardBtn = new VirtualButton(MoveForwardBinding); moveLeftBtn = new VirtualButton(MoveLeftBinding); moveRightBtn = new VirtualButton(MoveRightBinding); moveBackwardBtn = new VirtualButton(MoveBackBinding); moveUpBtn = new VirtualButton(MoveUpBinding); moveDownBtn = new VirtualButton(MoveDownBinding); fastMoveBtn = new VirtualButton(FastMoveBinding); activeBtn = new VirtualButton(RotateBinding); panBtn = new VirtualButton(PanBinding); horizontalAxis = new VirtualAxis(HorizontalAxisBinding); verticalAxis = new VirtualAxis(VerticalAxisBinding); scrollAxis = new VirtualAxis(ScrollAxisBinding); }
/// <summary> /// Checks whether VirtualButton.Find works for Keyboard, Mouse and GamePad. /// </summary> void TestVirtualButtonFind() { // Test Keyboard Keys Assert.Equal(VirtualButton.Keyboard.A, VirtualButton.Find("Keyboard.a")); Assert.Equal(VirtualButton.Keyboard.Z, VirtualButton.Find("Keyboard.z")); Assert.Equal(VirtualButton.Keyboard.LeftCtrl, VirtualButton.Find("Keyboard.leftctrl")); Assert.Equal(VirtualButton.Keyboard.LeftShift, VirtualButton.Find("Keyboard.leftshift")); // Test Mouse Buttons Assert.Equal(VirtualButton.Mouse.Left, VirtualButton.Find("Mouse.Left")); Assert.Equal(VirtualButton.Mouse.PositionX, VirtualButton.Find("Mouse.PositionX")); Assert.Equal(VirtualButton.Mouse.DeltaY, VirtualButton.Find("Mouse.DeltaY")); // Test GamePad Buttons Assert.Equal(VirtualButton.GamePad.LeftThumbAxisX, VirtualButton.Find("GamePad.LeftThumbAxisX")); Assert.Equal(VirtualButton.GamePad.RightThumb, VirtualButton.Find("GamePad.RightThumb")); Assert.Equal(VirtualButton.GamePad.A, VirtualButton.Find("GamePad.A")); }
public override void initialize() { base.initialize(); addRenderer(new RenderLayerRenderer(0, actorMoveLayer, tiledMapLayer)); addRenderer(new RenderLayerRenderer(1, debugRenderLayer)); //addSceneComponent<SceneEventComponent>(); coroutine = Core.getGlobalManager <CoroutineManager>(); var texture = content.Load <Texture2D>("Images/Enemys/enemy"); entity = createEntity("mover"); entity.addComponent(new Sprite(texture)); var player = addEntity(new Player()).setPosition(200, 200); startCoroutineButton = new VirtualButton(); startCoroutineButton.nodes.Add(new KeyboardKey(Keys.X)); }
/// <summary> /// Needs a better way to bind keys, just hard bind for now /// </summary> public void SetupInput() { _axialInput = Vector2.Zero; // horizontal input from dpad, left stick or keyboard left/right _xAxisInput = new VirtualIntegerAxis(); _xAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadDpadLeftRight(gamepadIndex)); _xAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadLeftStickX(gamepadIndex)); for (int i = 0; i < mapping.Left.Length; i++) { _xAxisInput.nodes.Add(new Nez.VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, (Keys)mapping.Left[i], (Keys)mapping.Right[i])); } // vertical input from dpad, left stick or keyboard up/down _yAxisInput = new VirtualIntegerAxis(); _yAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadDpadUpDown(gamepadIndex)); _yAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadLeftStickY(gamepadIndex)); for (int i = 0; i < mapping.Up.Length; i++) { _yAxisInput.nodes.Add(new Nez.VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, (Keys)mapping.Up[i], (Keys)mapping.Down[i])); } //action buttons _jumpButton = new VirtualButton(); foreach (var key in mapping.jumpKey) { _jumpButton.nodes.Add(new Nez.VirtualButton.KeyboardKey((Keys)key)); } foreach (var button in mapping.jumpButton) { _jumpButton.nodes.Add(new Nez.VirtualButton.GamePadButton(gamepadIndex, (Buttons)button)); } _shootButton = new VirtualButton(); foreach (var key in mapping.shootKey) { _shootButton.nodes.Add(new Nez.VirtualButton.KeyboardKey((Keys)key)); } foreach (var button in mapping.shootButton) { _shootButton.nodes.Add(new Nez.VirtualButton.GamePadButton(gamepadIndex, (Buttons)button)); } }
void IEditorImageTargetBehaviour.AssociateExistingVirtualButtonBehaviour(VirtualButtonAbstractBehaviour virtualButtonBehaviour) { VirtualButton virtualButtonByName = this.mImageTarget.GetVirtualButtonByName(virtualButtonBehaviour.VirtualButtonName); if (virtualButtonByName == null) { Vector2 vector; Vector2 vector2; virtualButtonBehaviour.CalculateButtonArea(out vector, out vector2); RectangleData area = new RectangleData { leftTopX = vector.x, leftTopY = vector.y, rightBottomX = vector2.x, rightBottomY = vector2.y }; virtualButtonByName = this.mImageTarget.CreateVirtualButton(virtualButtonBehaviour.VirtualButtonName, area); if (virtualButtonByName != null) { Debug.Log("Successfully created virtual button " + virtualButtonBehaviour.VirtualButtonName + " at startup"); virtualButtonBehaviour.UnregisterOnDestroy = true; } else { Debug.LogError("Failed to create virtual button " + virtualButtonBehaviour.VirtualButtonName + " at startup"); } } if ((virtualButtonByName != null) && !this.mVirtualButtonBehaviours.ContainsKey(virtualButtonByName.ID)) { IEditorVirtualButtonBehaviour behaviour = virtualButtonBehaviour; behaviour.InitializeVirtualButton(virtualButtonByName); this.mVirtualButtonBehaviours.Add(virtualButtonByName.ID, virtualButtonBehaviour); Debug.Log(string.Concat(new object[] { "Found VirtualButton named ", virtualButtonBehaviour.VirtualButton.Name, " with id ", virtualButtonBehaviour.VirtualButton.ID })); virtualButtonBehaviour.UpdatePose(); if (!virtualButtonBehaviour.UpdateAreaRectangle() || !virtualButtonBehaviour.UpdateSensitivity()) { Debug.LogError("Failed to update virtual button " + virtualButtonBehaviour.VirtualButton.Name + " at startup"); } else { Debug.Log("Updated virtual button " + virtualButtonBehaviour.VirtualButton.Name + " at startup"); } } }
public void LoadContent() { _cursorSprite = _manager.EngineContentManager.Load <Texture2D>("Textures/Cursor"); _cursorSpriteClicked = _manager.EngineContentManager.Load <Texture2D>("Textures/Cursor"); #if WINDOWS_PHONE // virtual stick content _phoneStick = new VirtualStick(_manager.Content.Load <Texture2D>("Common/socket"), _manager.Content.Load <Texture2D>("Common/stick"), new Vector2(80f, 400f)); Texture2D temp = _manager.Content.Load <Texture2D>("Common/buttons"); _phoneA = new VirtualButton(temp, new Vector2(695f, 380f), new Rectangle(0, 0, 40, 40), new Rectangle(0, 40, 40, 40)); _phoneB = new VirtualButton(temp, new Vector2(745f, 360f), new Rectangle(40, 0, 40, 40), new Rectangle(40, 40, 40, 40)); #endif _viewport = _manager.GraphicsDevice.Viewport; TouchPanel.EnabledGestures = GestureType.Tap; PreviousScrollWheel = MouseState.ScrollWheelValue; }
void setupInput() { // setup input for shooting a fireball. we will allow z on the keyboard or a on the gamepad _fireInput = new VirtualButton(); _fireInput.nodes.Add(new Nez.VirtualButton.KeyboardKey(Keys.Z)); _fireInput.nodes.Add(new Nez.VirtualButton.GamePadButton(0, Buttons.A)); // horizontal input from dpad, left stick or keyboard left/right _xAxisInput = new VirtualIntegerAxis(); _xAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadDpadLeftRight()); _xAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadLeftStickX()); _xAxisInput.nodes.Add(new Nez.VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.Left, Keys.Right)); // vertical input from dpad, left stick or keyboard up/down _yAxisInput = new VirtualIntegerAxis(); _yAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadDpadUpDown()); _yAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadLeftStickY()); _yAxisInput.nodes.Add(new Nez.VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.Up, Keys.Down)); }
override protected void Initialize() { base.Initialize(); // Toggles ImGui Inspector DebugToggle = new VirtualButton().AddKeyboardKey(Keys.F1); // Adding the ImGui manager with a minimal approach. var mgr = new ImGuiManager(); mgr.ShowSeperateGameWindow = false; mgr.ShowCoreWindow = false; RegisterGlobalManager(mgr); mgr.SetEnabled(false); // Finally move into the example scene. Change this to wherever you wanna go! Scene = new ExampleScene(); }
/// <summary> /// Map the list of buttons to the given virtual button. /// </summary> /// <param name="vbtn">The virtual button to map the buttons to.</param> /// <param name="buttons">The buttons to map.</param> public static void AddButtons(this VirtualButton vbtn, List <Buttons> buttons) { foreach (Buttons btn in buttons) { if (btn == Buttons.LeftTrigger) { vbtn.Nodes.Add(new VirtualButton.PadLeftTrigger(Input.Gamepad, 0.25f)); continue; } if (btn == Buttons.RightTrigger) { vbtn.Nodes.Add(new VirtualButton.PadRightTrigger(Input.Gamepad, 0.25f)); continue; } vbtn.Nodes.Add(new VirtualButton.PadButton(Input.Gamepad, btn)); } }
// Registers a Virtual Button at native code. private VirtualButton CreateNewVirtualButtonInNative(string name, VirtualButton.RectangleData rectangleData) { // virtual buttons cannot be registered for user defined targets: if (ImageTargetType != ImageTargetType.PREDEFINED) { Debug.LogError("DataSet.RegisterVirtualButton: virtual button '" + name + "' cannot be registered for a user defined target."); return(null); } IntPtr rectPtr = Marshal.AllocHGlobal( Marshal.SizeOf(typeof(VirtualButton.RectangleData))); Marshal.StructureToPtr(rectangleData, rectPtr, false); bool registerWorked = (QCARWrapper.Instance.ImageTargetCreateVirtualButton(mDataSet.DataSetPtr, Name, name, rectPtr) != 0); VirtualButton vb = null; if (registerWorked) { int id = QCARWrapper.Instance.VirtualButtonGetId(mDataSet.DataSetPtr, Name, name); // Check we don't have an entry for this id: if (!mVirtualButtons.ContainsKey(id)) { // Add: vb = new VirtualButtonImpl(name, id, rectangleData, this, mDataSet); mVirtualButtons.Add(id, vb); } else { vb = mVirtualButtons[id]; } } return(vb); }
void setupInput() { //setup input for flying space or a on gamepad _flyInput = new VirtualButton(); _flyInput.nodes.Add(new VirtualButton.KeyboardKey(Microsoft.Xna.Framework.Input.Keys.Space)); _flyInput.nodes.Add(new VirtualButton.GamePadButton(0, Buttons.A)); // horizontal input from dpad left stidk or keyboard left rights or a d _xAxisInput = new VirtualIntegerAxis(); _xAxisInput.nodes.Add(new VirtualAxis.GamePadDpadLeftRight()); _xAxisInput.nodes.Add(new VirtualAxis.GamePadLeftStickX()); _xAxisInput.nodes.Add(new VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.Left, Keys.Right)); _xAxisInput.nodes.Add(new VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.A, Keys.D)); // setup vertical input _yAxisInput = new VirtualIntegerAxis(); _yAxisInput.nodes.Add(new VirtualAxis.GamePadDpadUpDown()); _yAxisInput.nodes.Add(new VirtualAxis.GamePadLeftStickY()); _yAxisInput.nodes.Add(new VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.Up, Keys.Down)); _yAxisInput.nodes.Add(new VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.W, Keys.S)); }
static void WriteInput(VirtualButton b1, VirtualButton b2) { p.X = TopLeft.X; Write(b1.Name, p, Color.White); p.X = Column1; SubWrite("P", b1.Pressed); SubWrite("JP", b1.JustPressed); SubWrite("R", b1.Released); SubWrite("JR", b1.JustReleased); p.X = Column2; SubWrite("P", b2.Pressed); SubWrite("JP", b2.JustPressed); SubWrite("R", b2.Released); SubWrite("JR", b2.JustReleased); p.X = TopLeft.X; p.Y += 50f; }
/// <summary> /// Removes and destroys one of the ImageTarget's virtual buttons /// Returns false if the corresponding DataSet is currently active. /// </summary> public bool DestroyVirtualButton(VirtualButton vb) { bool success = false; ImageTracker imageTracker = (ImageTracker) TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER); if (imageTracker != null) { bool isActiveDataSet = false; foreach (DataSet ads in imageTracker.GetActiveDataSets()) { if (mDataSet == ads) { isActiveDataSet = true; } } if (isActiveDataSet) { imageTracker.DeactivateDataSet(mDataSet); } if (UnregisterVirtualButtonInNative(vb)) { Debug.Log("Unregistering virtual button successfully"); success = true; mVirtualButtons.Remove(vb.ID); } else { Debug.LogError("Failed to unregister virtual button."); } if (isActiveDataSet) { imageTracker.ActivateDataSet(mDataSet); } } return(success); }
protected override void AssembleComponent() { VirtualButton virtualButton = GetComponent <VirtualButton>(); if (virtualButton != null) { virtualButton.OnButtonEnter += startAction; virtualButton.OnButtonExit += endAction; } TouchRayButton rayTouchButton = GetComponent <TouchRayButton>(); if (rayTouchButton != null) { rayTouchButton.OnButtonEnter += startAction; rayTouchButton.OnButtonExit += endAction; return; } RayCastButton rcButton = GetComponent <RayCastButton>(); if (rcButton != null) { rcButton.OnButtonEnter += startAction; rcButton.OnButtonExit += endAction; } TouchButton touchButton = GetComponent <TouchButton>(); if (touchButton != null) { touchButton.OnButtonEnter += startAction; touchButton.OnButtonExit += endAction; } if (State != 2) { State = 0; } }
void Controles() { _xAxisInput = new VirtualIntegerAxis(); _xAxisInput.AddKeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.A, Keys.D); _yAxisInput = new VirtualIntegerAxis(); _yAxisInput.AddKeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.W, Keys.S); _fireInput = new VirtualButton(); _fireInput.AddMouseLeftButton(); _runInput = new VirtualButton(); _runInput.AddKeyboardKey(Keys.Space); _weapon1Input = new VirtualButton(); _weapon1Input.AddKeyboardKey(Keys.D1); _weapon2Input = new VirtualButton(); _weapon2Input.AddKeyboardKey(Keys.D2); _weapon3Input = new VirtualButton(); _weapon3Input.AddKeyboardKey(Keys.D3); }
static InputManager() { xAxis = new VirtualAxis(); xAxis.Nodes.Add(new VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.A, Keys.D)); xAxis.Nodes.Add(new VirtualAxis.GamePadLeftStickX()); yAxis = new VirtualAxis(); yAxis.Nodes.Add(new VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.W, Keys.S)); yAxis.Nodes.Add(new VirtualAxis.GamePadLeftStickY()); joystick = new VirtualJoystick(false); joystick.AddKeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.A, Keys.D, Keys.W, Keys.S); joystick.AddGamePadLeftStick(); brake = new VirtualButton(); brake.AddKeyboardKey(Keys.LeftShift); // TODO: add gamepad button for braking dash = new VirtualButton(); dash.AddKeyboardKey(Keys.Space); // TODO: add gamepad button for dashing dispense = new VirtualButton(); dispense.AddKeyboardKey(Keys.F); // TODO: add gamepad button for dispensing shoot = new VirtualButton(); shoot.AddMouseLeftButton(); shoot.AddGamePadRightTrigger(0, 0.2f); var prevKey = new VirtualButton(new VirtualButton.KeyboardKey(Keys.Q)); var nextKey = new VirtualButton(new VirtualButton.KeyboardKey(Keys.E)); var prevGamepad = new VirtualButton(new VirtualButton.GamePadButton(0, Buttons.X)); var nextGamepad = new VirtualButton(new VirtualButton.GamePadButton(0, Buttons.A)); switchWeapon = new VirtualIntegerAxis(); switchWeapon.Nodes.Add(new ButtonAxis(prevKey, nextKey)); switchWeapon.Nodes.Add(new ScrollAxis()); switchWeapon.Nodes.Add(new ButtonAxis(prevGamepad, nextGamepad)); }
public InputManager() { _interactionButton = new VirtualButton(); _interactionButton .addKeyboardKey(Keys.A) .addKeyboardKey(Keys.Enter) .addGamePadButton(0, Buttons.A); _attackButton = new VirtualButton(); _attackButton .addKeyboardKey(Keys.Z) .addGamePadButton(0, Buttons.X); _jumpButton = new VirtualButton(); _jumpButton .addKeyboardKey(Keys.X) .addGamePadButton(0, Buttons.A); _upButton = new VirtualButton(); _upButton .addKeyboardKey(Keys.Up) .addGamePadButton(0, Buttons.DPadUp); _downButton = new VirtualButton(); _downButton .addKeyboardKey(Keys.Down) .addGamePadButton(0, Buttons.DPadDown); _movementAxis = new VirtualIntegerAxis(); _movementAxis .addKeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.Left, Keys.Right) .addGamePadLeftStickX() .addGamePadDPadLeftRight(); _selectButton = new VirtualButton(); _selectButton .addKeyboardKey(Keys.Enter) .addGamePadButton(0, Buttons.A) .addGamePadButton(0, Buttons.Start); }
public override void onAddedToEntity() { _mState = EntityConstants.MovementStates.JUMP; _mDirection = EntityConstants.MovementDirection.RIGHT; _velocity = new Vector2(0, 0); _sprite = this.getComponent <Sprite>(); _jumpInput = new VirtualButton(); _jumpInput.nodes.Add(new Nez.VirtualButton.KeyboardKey(Keys.W)); _fireInput = new VirtualButton(); _fireInput.nodes.Add(new Nez.VirtualButton.KeyboardKey(Keys.S)); _movementInput = new VirtualIntegerAxis(); _movementInput.nodes.Add(new Nez.VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.A, Keys.D)); //_moveComp = new MovementComponent(); //this.entity.addComponent(_moveComp); _moveComp = this.entity.getComponent <MovementComponent>(); }
// Unregister a Virtual Button at native code. private bool UnregisterVirtualButtonInNative(VirtualButton vb) { int id = QCARWrapper.Instance.VirtualButtonGetId(mDataSet.DataSetPtr, Name, vb.Name); bool unregistered = false; if (QCARWrapper.Instance.ImageTargetDestroyVirtualButton(mDataSet.DataSetPtr, Name, vb.Name) != 0) { if (mVirtualButtons.Remove(id)) { unregistered = true; } } if (!unregistered) { Debug.LogError("UnregisterVirtualButton: Failed to destroy " + "the Virtual Button."); } return(unregistered); }
private void SetControlOutput(ref VirtualButton button, KeyCode key1, KeyCode key2, string axis, bool negative = false) { string newAxis = "None"; for (int i = 0; i < Input.GetJoystickNames().Length; i++) { if (Input.GetJoystickNames()[i].Contains("Xbox")) { newAxis = axis + "_Xbox"; } else if (Input.GetJoystickNames()[i].Contains("Wireless")) { newAxis = axis + "_PS"; } else { continue; } break; } if (Input.GetKey(key1) || Input.GetKey(key2) || Input.GetAxisRaw(newAxis) * (negative ? -1f : 1f) > 0f) { if (button.Value) { button.Press = false; } else { button.Value = true; button.Press = true; } } else { button.Value = false; button.Press = false; } }
public void OnInputInitialize() { ButtonPlayerList = new VirtualButton( new VirtualButton.KeyboardKey(Keys.Tab), new VirtualButton.PadButton(Input.Gamepad, Buttons.Back) ); AddButtonsTo(ButtonPlayerList, Settings.ButtonPlayerList); JoystickEmoteWheel = new VirtualJoystick(true, new VirtualJoystick.PadRightStick(Input.Gamepad, 0.2f) ); ButtonEmoteSend = new VirtualButton( new VirtualButton.KeyboardKey(Keys.Q), new VirtualButton.PadButton(Input.Gamepad, Buttons.RightStick) ); AddButtonsTo(ButtonEmoteSend, Settings.ButtonEmoteSend); ButtonChat = new VirtualButton( new VirtualButton.KeyboardKey(Keys.T) ); AddButtonsTo(ButtonEmoteSend, Settings.ButtonChat); }
private static void AddButtonsTo(VirtualButton vbtn, List <Buttons> buttons) { if (buttons == null) { return; } foreach (Buttons button in buttons) { if (button == Buttons.LeftTrigger) { vbtn.Nodes.Add(new VirtualButton.PadLeftTrigger(Input.Gamepad, 0.25f)); } else if (button == Buttons.RightTrigger) { vbtn.Nodes.Add(new VirtualButton.PadRightTrigger(Input.Gamepad, 0.25f)); } else { vbtn.Nodes.Add(new VirtualButton.PadButton(Input.Gamepad, button)); } } }
/// <summary> /// Triggered when the user presses a virtual button. /// </summary> /// <param name="btn">Button that was pressed.</param> /// <param name="deviceIdx">Index of the device it was pressed on. </param> private void OnButtonUp(VirtualButton btn, int deviceIdx) { if (!HasFocus) { return; } IGlobalShortcuts shortcuts = this; if (btn == EditorApplication.CopyKey) { shortcuts.OnCopyPressed(); } else if (btn == EditorApplication.CutKey) { shortcuts.OnCutPressed(); } else if (btn == EditorApplication.PasteKey) { shortcuts.OnPastePressed(); } else if (btn == EditorApplication.DuplicateKey) { shortcuts.OnDuplicatePressed(); } else if (btn == EditorApplication.RenameKey) { shortcuts.OnRenamePressed(); } else if (btn == EditorApplication.DeleteKey) { shortcuts.OnDeletePressed(); } else if (btn == EditorApplication.PasteKey) { shortcuts.OnPastePressed(); } }
/// <summary> /// Needs a better way to bind keys, just hard bind for now /// </summary> public void SetupInput() { _axialInput = Vector2.Zero; // horizontal input from dpad, left stick or keyboard left/right _xAxisInput = new VirtualIntegerAxis(); _xAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadDpadLeftRight(gamepadIndex)); _xAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadLeftStickX(gamepadIndex)); _xAxisInput.nodes.Add(new Nez.VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, (Keys)mapping.Left, (Keys)mapping.Right)); // vertical input from dpad, left stick or keyboard up/down _yAxisInput = new VirtualIntegerAxis(); _yAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadDpadUpDown(gamepadIndex)); _yAxisInput.nodes.Add(new Nez.VirtualAxis.GamePadLeftStickY(gamepadIndex)); _yAxisInput.nodes.Add(new Nez.VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, (Keys)mapping.Up, (Keys)mapping.Down)); //action buttons _button1 = new VirtualButton(); _button1.nodes.Add(new Nez.VirtualButton.KeyboardKey((Keys)mapping.key1)); _button1.nodes.Add(new Nez.VirtualButton.GamePadButton(gamepadIndex, (Buttons)mapping.button1)); _button2 = new VirtualButton(); _button2.nodes.Add(new Nez.VirtualButton.KeyboardKey((Keys)mapping.key2)); _button2.nodes.Add(new Nez.VirtualButton.GamePadButton(gamepadIndex, (Buttons)mapping.button2)); _button3 = new VirtualButton(); _button3.nodes.Add(new Nez.VirtualButton.KeyboardKey((Keys)mapping.key3)); _button3.nodes.Add(new Nez.VirtualButton.GamePadButton(gamepadIndex, (Buttons)mapping.button3)); _button4 = new VirtualButton(); _button4.nodes.Add(new Nez.VirtualButton.KeyboardKey((Keys)mapping.key4)); _button4.nodes.Add(new Nez.VirtualButton.GamePadButton(gamepadIndex, (Buttons)mapping.button4)); _button5 = new VirtualButton(); _button5.nodes.Add(new Nez.VirtualButton.KeyboardKey((Keys)mapping.key5)); _button5.nodes.Add(new Nez.VirtualButton.GamePadButton(gamepadIndex, (Buttons)mapping.button5)); }
public PlayerInput(PlayerIndex playerIdx) { playerIndex = playerIdx; Left = new VirtualButton(this, delegate() { return istate.keystate.IsKeyDown(Keys.Left) || (istate.padstate.DPad.Left == ButtonState.Pressed); }); Right = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.Right) || (istate.padstate.DPad.Right == ButtonState.Pressed); }); Down = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.Down) || (istate.padstate.DPad.Down == ButtonState.Pressed); }); Up = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.Up) || (istate.padstate.DPad.Up == ButtonState.Pressed); }); Confirm = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.Z) || (istate.padstate.Buttons.B == ButtonState.Pressed); }); Cancel = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.X) || (istate.padstate.Buttons.A == ButtonState.Pressed); }); A = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.Z) || (istate.padstate.Buttons.B == ButtonState.Pressed); }); B = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.X) || (istate.padstate.Buttons.A == ButtonState.Pressed); }); BX = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.Z) || (istate.padstate.Buttons.Y == ButtonState.Pressed) || istate.keystate.IsKeyDown(Keys.S) || (istate.padstate.Buttons.A== ButtonState.Pressed); }); AY = new VirtualButton(this, delegate() { return istate.keystate.IsKeyDown(Keys.X) || (istate.padstate.Buttons.B == ButtonState.Pressed) || istate.keystate.IsKeyDown(Keys.A) || (istate.padstate.Buttons.X == ButtonState.Pressed); }); MenuX = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.A) || (istate.padstate.Buttons.Y == ButtonState.Pressed); }); MenuY = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.S) || (istate.padstate.Buttons.X == ButtonState.Pressed); }); DebugPrint = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.Scroll); }); F5 = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.F5); }); F10 = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.F10); }); LShoulder = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.OemTilde) || (istate.padstate.Buttons.LeftShoulder == ButtonState.Pressed); }); RShoulder = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.D1) || (istate.padstate.Buttons.RightShoulder == ButtonState.Pressed); }); LeftMouse = new VirtualButton(this,delegate() { return istate.mousestate.LeftButton == ButtonState.Pressed; }); RightMouse = new VirtualButton(this,delegate() { return istate.mousestate.RightButton == ButtonState.Pressed; }); LTrigger = new VirtualButton(this,delegate() { return istate.padstate.Triggers.Left > 0.5f; }); RTrigger = new VirtualButton(this,delegate() { return istate.padstate.Triggers.Right > 0.5f; }); NumPad9 = new VirtualButton(this,delegate() { return istate.keystate.IsKeyDown(Keys.NumPad9); }); NumPad8 = new VirtualButton(this, delegate() { return istate.keystate.IsKeyDown(Keys.NumPad8); }); NumPad7 = new VirtualButton(this, delegate() { return istate.keystate.IsKeyDown(Keys.NumPad7); }); NumPad1 = new VirtualButton(this, delegate() { return istate.keystate.IsKeyDown(Keys.NumPad1); }); NumPad4 = new VirtualButton(this, delegate() { return istate.keystate.IsKeyDown(Keys.NumPad4); }); LeftCtrl = new VirtualButton(this, delegate() { return istate.keystate.IsKeyDown(Keys.LeftControl); }); }
public InputManager() { _interactionButton = new VirtualButton(); _interactionButton.nodes.Add(new VirtualButton.KeyboardKey(Keys.F)); _jumpButton = new VirtualButton(); _jumpButton.nodes.Add(new VirtualButton.KeyboardKey(Keys.Z)); _movementAxis = new VirtualIntegerAxis(); _movementAxis.nodes.Add(new VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.Left, Keys.Right)); _leftButton = new VirtualButton(); _leftButton.nodes.Add(new VirtualButton.KeyboardKey(Keys.Left)); _rightButton = new VirtualButton(); _rightButton.nodes.Add(new VirtualButton.KeyboardKey(Keys.Right)); _upButton = new VirtualButton(); _upButton.nodes.Add(new VirtualButton.KeyboardKey(Keys.Up)); _downButton = new VirtualButton(); _downButton.nodes.Add(new VirtualButton.KeyboardKey(Keys.Down)); }
public bool DestroyVirtualButton(VirtualButton vb) { bool flag = false; ImageTracker tracker = TrackerManager.Instance.GetTracker <ImageTracker>(); if (tracker != null) { bool flag2 = false; foreach (DataSet set in tracker.GetActiveDataSets()) { if (this.mDataSet == set) { flag2 = true; } } if (flag2) { tracker.DeactivateDataSet(this.mDataSet); } if (this.UnregisterVirtualButtonInNative(vb)) { Debug.Log("Unregistering virtual button successfully"); flag = true; this.mVirtualButtons.Remove(vb.ID); } else { Debug.LogError("Failed to unregister virtual button."); } if (flag2) { tracker.ActivateDataSet(this.mDataSet); } } return(flag); }
void SetupInput() { // horizontal input from dpad, left stick or keyboard left/right _xAxisInput = new VirtualIntegerAxis(); _xAxisInput.Nodes.Add(new VirtualAxis.GamePadDpadLeftRight()); _xAxisInput.Nodes.Add(new VirtualAxis.GamePadLeftStickX()); _xAxisInput.Nodes.Add(new VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.Left, Keys.Right)); // vertical input from dpad, left stick or keyboard up/down _yAxisInput = new VirtualIntegerAxis(); _yAxisInput.Nodes.Add(new VirtualAxis.GamePadDpadUpDown()); _yAxisInput.Nodes.Add(new VirtualAxis.GamePadLeftStickY()); _yAxisInput.Nodes.Add(new VirtualAxis.KeyboardKeys(VirtualInput.OverlapBehavior.TakeNewer, Keys.Up, Keys.Down)); // kick input from gamepad A press, or keyboard space _kickInput = new VirtualButton(); _kickInput.Nodes.Add(new VirtualButton.KeyboardKey(Keys.Space)); _kickInput.Nodes.Add(new VirtualButton.GamePadButton(0, Buttons.A)); // crouch input from gamepad B press, or keyboard shift _crouchInput = new VirtualButton(); _crouchInput.Nodes.Add(new VirtualButton.KeyboardKey(Keys.LeftShift)); _crouchInput.Nodes.Add(new VirtualButton.GamePadButton(0, Buttons.B)); }
public static void RegisterVirtualButton(VirtualButton button) { activeInput.RegisterVirtualButton(button); }
// sets the sensitivity. At runtime the VirtualButton object should be used to change sensibility. bool IEditorVirtualButtonBehaviour.SetSensitivitySetting(VirtualButton.Sensitivity sensibility) { if (mVirtualButton == null) { mSensitivity = sensibility; mSensitivityDirty = true; return true; } return false; }
// Initializes the Virtual Button runtime object void IEditorVirtualButtonBehaviour.InitializeVirtualButton(VirtualButton virtualButton) { mVirtualButton = virtualButton; }
public override bool SetSensitivity(VirtualButton.Sensitivity sensitivity) { int success = QCARWrapper.Instance.VirtualButtonSetSensitivity(mParentDataSet.DataSetPtr, mParentImageTarget.Name, mName, (int)sensitivity); if (success == 0) { Debug.LogError("Virtual Button sensitivity could not be set."); return false; } return true; }
/// <summary> /// Removes and destroys one of the ImageTarget's virtual buttons /// Returns false if the corresponding DataSet is currently active. /// </summary> public bool DestroyVirtualButton(VirtualButton vb) { bool success = false; ImageTracker imageTracker = (ImageTracker) TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER); if (imageTracker != null) { bool isActiveDataSet = false; foreach(DataSet ads in imageTracker.GetActiveDataSets()) if (mDataSet == ads) isActiveDataSet = true; if (isActiveDataSet) { imageTracker.DeactivateDataSet(mDataSet); } if (UnregisterVirtualButtonInNative(vb)) { Debug.Log("Unregistering virtual button successfully"); success = true; mVirtualButtons.Remove(vb.ID); } else { Debug.LogError("Failed to unregister virtual button."); } if (isActiveDataSet) { imageTracker.ActivateDataSet(mDataSet); } } return success; }
//================================================================================ public override void OnInspectorGUI() { virtualButtonScript = target as VirtualButton; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel (" "); AddButton (); ToggleHelp (); } EditorGUILayout.EndHorizontal(); ShowHelp (); int i = 0; bool removeItem = false; int itemToRemove = -1; bool moveItem = false; int itemToMove = -1; int itemMoveDirection = 0; foreach (VirtualButton.Button button in virtualButtonScript.virtualButtons) { if (!button.isActive && !Application.isPlaying) { button.center = button.centerDefault; button.centerNew = button.centerDefault; button.touchID = -1; } EditorGUILayout.BeginHorizontal(); { button.showSettingsInInspector = EditorGUILayout.Foldout (button.showSettingsInInspector, "[" + (i+1) + "] " + button.name); button.enabled = EditorGUILayout.Toggle(" " ,button.enabled); if (GUILayout.Button("<")) { moveItem = true; itemToMove = i; itemMoveDirection = -1; } if (GUILayout.Button(">")) { moveItem = true; itemToMove = i; itemMoveDirection = 1; } EditorGUILayout.LabelField (" ", GUILayout.Width (8)); if (GUILayout.Button("-")) { removeItem = true; itemToRemove = i; } } EditorGUILayout.EndHorizontal(); if (button.showSettingsInInspector) { button.name = EditorGUILayout.TextField ("Name", button.name); EditorGUILayout.BeginHorizontal (); { EditorGUILayout.PrefixLabel ("Texture Unpressed"); button.textureUnpressed = EditorGUILayout.ObjectField(button.textureUnpressed,typeof(Texture),false) as Texture; if (!Application.isPlaying) button.buttonTexture = button.textureUnpressed; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal (); { EditorGUILayout.PrefixLabel ("Texture Pressed"); button.texturePressed = EditorGUILayout.ObjectField(button.texturePressed,typeof(Texture),false) as Texture; } EditorGUILayout.EndHorizontal(); if (button.textureUnpressed && button.texturePressed) { if (button.forceSquareButton) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Size"); button.buttonSize.x = EditorGUILayout.Slider(button.buttonSize.x,0f,1f); button.buttonSize.y = button.buttonSize.x; button.forceSquareButton = EditorGUILayout.ToggleLeft("Square",button.forceSquareButton,GUILayout.Width(80)); } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Size Horizontal"); button.buttonSize.x = EditorGUILayout.Slider(button.buttonSize.x,0f,1f); button.forceSquareButton = EditorGUILayout.ToggleLeft("Square",button.forceSquareButton,GUILayout.Width(80)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Size Vertical"); button.buttonSize.y = EditorGUILayout.Slider(button.buttonSize.y,0f,1f); EditorGUILayout.LabelField (" ",GUILayout.Width(80)); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); { button.centerDefault = EditorGUILayout.Vector2Field("Center", button.centerDefault); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Center X"); button.centerDefault.x = EditorGUILayout.Slider(button.centerDefault.x,0f,1f); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Center Y"); button.centerDefault.y = EditorGUILayout.Slider(button.centerDefault.y,0f,1f); } EditorGUILayout.EndHorizontal(); if (button.moveWithTouch) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Move With Touch: Smoothness"); button.moveWithTouch = EditorGUILayout.ToggleLeft("",button.moveWithTouch,GUILayout.Width(12)); button.smoothingTime = EditorGUILayout.Slider(button.smoothingTime,0f,1f); } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Move With Touch"); button.moveWithTouch = EditorGUILayout.ToggleLeft("",button.moveWithTouch,GUILayout.Width(12)); } EditorGUILayout.EndHorizontal(); } button.useAsSwitch = EditorGUILayout.Toggle("Use As Switch",button.useAsSwitch); button.autoUpdateEnabled = EditorGUILayout.Toggle("Auto Update",button.autoUpdateEnabled); if (button.autoUpdateEnabled) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button ("+")) { button.autoUpdateButtonDownMessageReceivers.Add(new VirtualButton.SendMessageReceiver()); int last = button.autoUpdateButtonDownMessageReceivers.Count-1; button.autoUpdateButtonDownMessageReceivers[last].messageReceiver = null; button.autoUpdateButtonDownMessageReceivers[last].functionName = "Function to call"; } EditorGUILayout.LabelField ("SendMessage: Down"); } EditorGUILayout.EndHorizontal(); // int j = 0; bool removeReceiver = false; int receiverToRemove = -1; foreach (VirtualButton.SendMessageReceiver receiver in button.autoUpdateButtonDownMessageReceivers) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("-")) { removeReceiver = true; receiverToRemove = j; } receiver.messageReceiver = EditorGUILayout.ObjectField(receiver.messageReceiver,typeof(GameObject),true) as GameObject; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); EditorGUILayout.LabelField ("",GUILayout.Width(20)); receiver.functionName = EditorGUILayout.TextField ("", receiver.functionName); } EditorGUILayout.EndHorizontal(); j++; } if (removeReceiver) { button.autoUpdateButtonDownMessageReceivers.RemoveAt(receiverToRemove); } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button ("+")) { button.autoUpdateButtonUpMessageReceivers.Add(new VirtualButton.SendMessageReceiver()); int last = button.autoUpdateButtonUpMessageReceivers.Count-1; button.autoUpdateButtonUpMessageReceivers[last].messageReceiver = null; button.autoUpdateButtonUpMessageReceivers[last].functionName = "Function to call"; } EditorGUILayout.LabelField ("SendMessage: Up"); } EditorGUILayout.EndHorizontal(); // j = 0; removeReceiver = false; receiverToRemove = -1; foreach (VirtualButton.SendMessageReceiver receiver in button.autoUpdateButtonUpMessageReceivers) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("-")) { removeReceiver = true; receiverToRemove = j; } receiver.messageReceiver = EditorGUILayout.ObjectField(receiver.messageReceiver,typeof(GameObject),true) as GameObject; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); EditorGUILayout.LabelField ("",GUILayout.Width(20)); receiver.functionName = EditorGUILayout.TextField ("", receiver.functionName); } EditorGUILayout.EndHorizontal(); j++; } if (removeReceiver) { button.autoUpdateButtonUpMessageReceivers.RemoveAt(receiverToRemove); } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button ("+")) { button.autoUpdateButtonGoingDownMessageReceivers.Add(new VirtualButton.SendMessageReceiver()); int last = button.autoUpdateButtonGoingDownMessageReceivers.Count-1; button.autoUpdateButtonGoingDownMessageReceivers[last].messageReceiver = null; button.autoUpdateButtonGoingDownMessageReceivers[last].functionName = "Function to call"; } EditorGUILayout.LabelField ("SendMessage: Going Down"); } EditorGUILayout.EndHorizontal(); // j = 0; removeReceiver = false; receiverToRemove = -1; foreach (VirtualButton.SendMessageReceiver receiver in button.autoUpdateButtonGoingDownMessageReceivers) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("-")) { removeReceiver = true; receiverToRemove = j; } receiver.messageReceiver = EditorGUILayout.ObjectField(receiver.messageReceiver,typeof(GameObject),true) as GameObject; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); EditorGUILayout.LabelField ("",GUILayout.Width(20)); receiver.functionName = EditorGUILayout.TextField ("", receiver.functionName); } EditorGUILayout.EndHorizontal(); j++; } if (removeReceiver) { button.autoUpdateButtonGoingDownMessageReceivers.RemoveAt(receiverToRemove); } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button ("+")) { button.autoUpdateButtonGoingUpMessageReceivers.Add(new VirtualButton.SendMessageReceiver()); int last = button.autoUpdateButtonGoingUpMessageReceivers.Count-1; button.autoUpdateButtonGoingUpMessageReceivers[last].messageReceiver = null; button.autoUpdateButtonGoingUpMessageReceivers[last].functionName = "Function to call"; } EditorGUILayout.LabelField ("SendMessage: Going Up"); } EditorGUILayout.EndHorizontal(); // j = 0; removeReceiver = false; receiverToRemove = -1; foreach (VirtualButton.SendMessageReceiver receiver in button.autoUpdateButtonGoingUpMessageReceivers) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("-")) { removeReceiver = true; receiverToRemove = j; } receiver.messageReceiver = EditorGUILayout.ObjectField(receiver.messageReceiver,typeof(GameObject),true) as GameObject; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(" "); EditorGUILayout.LabelField ("",GUILayout.Width(20)); receiver.functionName = EditorGUILayout.TextField ("", receiver.functionName); } EditorGUILayout.EndHorizontal(); j++; } if (removeReceiver) { button.autoUpdateButtonGoingUpMessageReceivers.RemoveAt(receiverToRemove); } } } if (Application.isPlaying) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel ("Debug Info"); EditorGUILayout.LabelField ("Button Status = " + button.status); } EditorGUILayout.EndHorizontal(); } // if (button.showDebugInfoInInspector) } // if (button.showSettingsInInspector) EditorGUILayout.Space(); i++; } if (removeItem) { virtualButtonScript.virtualButtons.RemoveAt(itemToRemove); } if (moveItem) { int itemToSwap = Mathf.Clamp (itemToMove + itemMoveDirection, 0, i - 1); VirtualButton.Button tmpItem = virtualButtonScript.virtualButtons[itemToSwap]; virtualButtonScript.virtualButtons[itemToSwap] = virtualButtonScript.virtualButtons[itemToMove]; virtualButtonScript.virtualButtons[itemToMove] = tmpItem; } EditorGUILayout.Space (); if (GUI.changed) { EditorUtility.SetDirty(virtualButtonScript); } if (!Application.isPlaying) { foreach (VirtualButton.Button button in virtualButtonScript.virtualButtons) { button.center = button.centerDefault; button.centerNew = button.centerDefault; button.touchID = -1; } virtualButtonScript.CalculateRects (); } }
// creates the specified VirtualButtonBehaviour for this ImageTarget private void CreateVirtualButtonFromNative(VirtualButton virtualButton) { GameObject virtualButtonObject = new GameObject(virtualButton.Name); VirtualButtonBehaviour newVBB = virtualButtonObject.AddComponent<VirtualButtonBehaviour>(); // We need to set the Image Target as a parent BEFORE we set the size // of the Virtual Button. newVBB.transform.parent = transform; IEditorVirtualButtonBehaviour newEditorVBB = newVBB; Debug.Log("Creating Virtual Button with values: " + "\n ID: " + virtualButton.ID + "\n Name: " + virtualButton.Name + "\n Rectangle: " + virtualButton.Area.leftTopX + "," + virtualButton.Area.leftTopY + "," + virtualButton.Area.rightBottomX + "," + virtualButton.Area.rightBottomY); newEditorVBB.SetVirtualButtonName(virtualButton.Name); newEditorVBB.SetPosAndScaleFromButtonArea(new Vector2(virtualButton.Area.leftTopX, virtualButton.Area.leftTopY), new Vector2(virtualButton.Area.rightBottomX, virtualButton.Area.rightBottomY)); // This button is part of a data set and should therefore not be // unregistered in native only because the Unity object is destroyed. newEditorVBB.UnregisterOnDestroy = false; newEditorVBB.InitializeVirtualButton(virtualButton); mVirtualButtonBehaviours.Add(virtualButton.ID, newVBB); }
// Registers a Virtual Button at native code. private VirtualButton CreateNewVirtualButtonInNative(string name, VirtualButton.RectangleData rectangleData) { // virtual buttons cannot be registered for user defined targets: if (ImageTargetType != ImageTargetType.PREDEFINED) { Debug.LogError("DataSet.RegisterVirtualButton: virtual button '" + name + "' cannot be registered for a user defined target."); return null; } IntPtr rectPtr = Marshal.AllocHGlobal( Marshal.SizeOf(typeof(VirtualButton.RectangleData))); Marshal.StructureToPtr(rectangleData, rectPtr, false); bool registerWorked = (QCARWrapper.Instance.ImageTargetCreateVirtualButton(mDataSet.DataSetPtr, Name, name, rectPtr) != 0); VirtualButton vb = null; if (registerWorked) { int id = QCARWrapper.Instance.VirtualButtonGetId(mDataSet.DataSetPtr, Name, name); // Check we don't have an entry for this id: if (!mVirtualButtons.ContainsKey(id)) { // Add: vb = new VirtualButtonImpl(name, id, rectangleData, this, mDataSet); mVirtualButtons.Add(id, vb); } else { vb = mVirtualButtons[id]; } } return vb; }
public void LoadContent() { // _cursorSprite = new Sprite(_manager.Content.Load<Texture2D>("Common/cursor")); #if WINDOWS_PHONE // virtual stick content _phoneStick = new VirtualStick(_manager.Content.Load<Texture2D>("Common/socket"), _manager.Content.Load<Texture2D>("Common/stick"), new Vector2(80f, 400f)); Texture2D temp = _manager.Content.Load<Texture2D>("Common/buttons"); _phoneA = new VirtualButton(temp, new Vector2(695f, 380f), new Rectangle(0, 0, 40, 40), new Rectangle(0, 40, 40, 40)); _phoneB = new VirtualButton(temp, new Vector2(745f, 360f), new Rectangle(40, 0, 40, 40), new Rectangle(40, 40, 40, 40)); #endif _viewport = _manager.GraphicsDevice.Viewport; }
// Add Virtual Button to the Image Target with the given imageTargetName. public bool AddVirtualButton(VirtualButton item, string imageTargetName) { try { ImageTarget it = imageTargets[imageTargetName]; it.virtualButtons.Add(item); } catch { return false; } return true; }
public static void RegisterVirtualButton(VirtualButton button) { virtualInput.RegisterVirtualButton(button); }
/// <summary> /// Removes and destroys one of the ImageTarget's virtual buttons /// This is not supported for CloudReco targets. /// </summary> public bool DestroyVirtualButton(VirtualButton vb) { Debug.LogError("Virtual buttons are currently not supported for cloud reco targets."); return false; }
/// <summary> /// Creates a new virtual button and adds it to the ImageTarget /// This is not supported for CloudReco targets. /// </summary> public VirtualButton CreateVirtualButton(string name, VirtualButton.RectangleData area) { Debug.LogError("Virtual buttons are currently not supported for cloud reco targets."); return null; }
// Creates a new Virtual Button with the data of the Virtual Button with the // given name that is a child of the Image Target with the name // imageTargetName. // Returns false if Virtual Button does not exist. public void GetVirtualButton(string name, string imageTargetName, out VirtualButton vb) { vb = new VirtualButton(); try { ImageTarget it; GetImageTarget(imageTargetName, out it); List<VirtualButton> vbs = it.virtualButtons; for (int i = 0; i < vbs.Count; ++i) { if (vbs[i].name == name) { vb = vbs[i]; } } } catch { throw; } }
// Creates a new Virtual Button with the data of the Virtual Button with the // given name that is a child of the Image Target with the name // imageTargetName. // Returns false if Virtual Button does not exist. public bool GetVirtualButton(string name, string imageTargetName, out VirtualButton vb) { vb = new VirtualButton(); try { ImageTarget it; if (!GetImageTarget(imageTargetName, out it)) { return false; } List<VirtualButton> vbs = it.virtualButtons; for (int i = 0; i < vbs.Count; ++i) { if (vbs[i].name == name) { vb = vbs[i]; return true; } } } catch {} return false; }
// Unregister a Virtual Button at native code. private bool UnregisterVirtualButtonInNative(VirtualButton vb) { int id = QCARWrapper.Instance.VirtualButtonGetId(mDataSet.DataSetPtr, Name, vb.Name); bool unregistered = false; if (QCARWrapper.Instance.ImageTargetDestroyVirtualButton(mDataSet.DataSetPtr, Name, vb.Name) != 0) { if (mVirtualButtons.Remove(id)) { unregistered = true; } } if (!unregistered) { Debug.LogError("UnregisterVirtualButton: Failed to destroy " + "the Virtual Button."); } return unregistered; }
// Add Virtual Button to the Image Target with the given imageTargetName. public void AddVirtualButton(VirtualButton item, string imageTargetName) { try { ImageTarget it = imageTargets[imageTargetName]; it.virtualButtons.Add(item); } catch { throw; } }