private void LoadControls() { var k = this.Keycosystem.GetController <StandardKeyboard>(1); var m = this.Keycosystem.GetController <StandardMouse>(1); this.Keycosystem.AddControlScheme("DebugNav", ControlSchemes.DebugNavigation(this.DebugLogger, k)); var context = new ControlScheme() .AddControl(() => k.ArrowKeys.IsPressed, () => { var p = this.Player; if ((k.ArrowKeys.Direction & Direction2d.Up) > 0) { p.Speed.X = 2; p.Speed.Y = -1; p.Facing.Direction = Direction2d.Up; } if ((k.ArrowKeys.Direction & Direction2d.Right) > 0) { p.Speed.X = 2; p.Speed.Y = 1; p.Facing.Direction = Direction2d.Right; } if ((k.ArrowKeys.Direction & Direction2d.Down) > 0) { p.Speed.X = -2; p.Speed.Y = 1; p.Facing.Direction = Direction2d.Down; } if ((k.ArrowKeys.Direction & Direction2d.Left) > 0) { p.Speed.X = -2; p.Speed.Y = -1; p.Facing.Direction = Direction2d.Left; } }) .AddControl(() => !k.ArrowKeys.IsPressed, () => { var speed = this.Player.Speed; speed.X = 0; speed.Y = 0; }) .AddControl(() => k.WASD.IsPressed, () => ControlSchemes.PanCamera(this.Camera, k.WASD)) .AddControl(() => m.Scroll.Y.JustMoved, () => { var zoom = m.Scroll.Y.PositionDelta > 0 ? 0.25f : -0.25f; this.Camera.Zoom += zoom; }) .AddControl(() => m.MiddleClick.JustPressed, () => this.Camera.Zoom = 1.000f) .AddControl(() => k.F.JustPressed, () => this.Camera.Focus = () => this.Player.Space.GetOriginPosition()) .AddControl(() => k.G.JustPressed, () => this.Camera.Focus = null) .AddControl(() => k.LeftShift.DurationPressed > TimeSpan.FromSeconds(1).Ticks&& k.Z.DurationPressed > TimeSpan.FromSeconds(1).Ticks, () => { this.Director.LoadScene(Scenes.SceneSelect); }); var pauseContext = new ControlScheme(); pauseContext .AddControl(() => k.P.JustPressed, () => { context.Enabled = !context.Enabled; }); this.Keycosystem .AddControlScheme("TestMapScene", context) .AddControlScheme("Paused", pauseContext); }
private void LoadEntities() { var drawnKeys = KeySizes .Where(kvp => kvp.Value != null) .Select(kvp => { var kdd = kvp.Value.Value; kdd.KeyToRead = kvp.Key; return(kdd); }) .OrderBy(kdd => kdd.Row) .ThenBy(kdd => kdd.Col); foreach (var drawnKey in drawnKeys) { if (!this.DrawnKeysByRow.TryGetValue(drawnKey.Row, out var keys)) { keys = new List <KeyDrawData>(); this.DrawnKeysByRow[drawnKey.Row] = keys; } keys.Add(drawnKey); } var keyboard = this.Keycosystem.GetController <StandardKeyboard>(1); var controlScheme = new ControlScheme(); foreach (var kvp in this.DrawnKeysByRow) { var row = kvp.Key; var x = 0; foreach (var kdd in kvp.Value) { var keyEntity = new Entity(); var rect = new Rect2d(x, row * (HT + SPC), kdd.Width, HT); keyEntity.Space = rect; keyEntity.AddComponent(new PolygonComponent { Polygon = new Rect2d(0, 0, rect.Width, rect.Height).ToPolygon(), Color = new ColorRGBA(255, 255, 255) }); this.Ecosystem.AddEntity($"KB_{kdd.KeyToRead}", keyEntity); var keyboardKey = kdd.KeyboardKey(keyboard); controlScheme.AddControl(() => keyboardKey.JustPressed, () => keyEntity.GetComponent <PolygonComponent>().Color = new ColorRGBA(255, 0, 0)); controlScheme.AddControl(() => keyboardKey.JustReleased, () => keyEntity.GetComponent <PolygonComponent>().Color = new ColorRGBA(255, 255, 255)); x += kdd.Width + SPC; } } this.Keycosystem.AddControlScheme("KeyHighlighter", controlScheme); this.Ecosystem .AddHandler <PolygonHandler>(); // todo: none of this works to move the camera? // this.Camera.Lens.Pan = new Vector2d(200, 100); this.Camera.Space.X += 200; this.Camera.Space.Y += 100; }
// Use this for initialization void Start() { m_holdAccum = 0.0f; m_LeftTransform = m_LeftPart.GetComponent<RectTransform>() as RectTransform; m_RightTransform = m_RightPart.GetComponent<RectTransform>() as RectTransform; float speed = Screen.width / 55.0f; float magnetForce = 15.0f; Behavior p1Mag = new MagneticBehavior("player1 magnetic", m_LeftPart, magnetForce); Behavior p1Up = new RectTranslateBehavior("player1 move up", m_LeftPart, new Vector3( 0, 1, 0) * speed); Behavior p1Down = new RectTranslateBehavior("player1 move down", m_LeftPart, new Vector3( 0, -1, 0) * speed); Behavior p1Left = new RectTranslateBehavior("player1 move left", m_LeftPart, new Vector3(-1, 0, 0) * speed); Behavior p1Right = new RectTranslateBehavior("player1 move right", m_LeftPart, new Vector3( 1, 0, 0) * speed); Behavior p2Mag = new MagneticBehavior("player2 magnetic", m_RightPart, magnetForce); Behavior p2Up = new RectTranslateBehavior("player2 move up", m_RightPart, new Vector3( 0, 1, 0) * speed); Behavior p2Down = new RectTranslateBehavior("player2 move down", m_RightPart, new Vector3( 0, -1, 0) * speed); Behavior p2Left = new RectTranslateBehavior("player2 move left", m_RightPart, new Vector3(-1, 0, 0) * speed); Behavior p2Right = new RectTranslateBehavior("player2 move right", m_RightPart, new Vector3( 1, 0, 0) * speed); m_Controls = new ControlScheme(); m_Controls.AddControl(new TrueSignal(), p1Mag ); m_Controls.AddControl(new KeyCodeControlSignal(KeyCode.W, new KeyCode[] { KeyCode.A, KeyCode.D }), p1Up ); m_Controls.AddControl(new KeyCodeControlSignal(KeyCode.S, new KeyCode[] { KeyCode.A, KeyCode.D }), p1Down ); m_Controls.AddControl(new KeyCodeControlSignal(KeyCode.A, new KeyCode[] { KeyCode.W, KeyCode.S }), p1Left ); m_Controls.AddControl(new KeyCodeControlSignal(KeyCode.D, new KeyCode[] { KeyCode.W, KeyCode.S }), p1Right); m_Controls.AddControl(new TrueSignal(), p2Mag ); m_Controls.AddControl(new KeyCodeControlSignal(KeyCode.UpArrow , new KeyCode[] { KeyCode.A, KeyCode.D }), p2Up ); m_Controls.AddControl(new KeyCodeControlSignal(KeyCode.DownArrow , new KeyCode[] { KeyCode.A, KeyCode.D }), p2Down ); m_Controls.AddControl(new KeyCodeControlSignal(KeyCode.LeftArrow , new KeyCode[] { KeyCode.W, KeyCode.S }), p2Left ); m_Controls.AddControl(new KeyCodeControlSignal(KeyCode.RightArrow, new KeyCode[] { KeyCode.W, KeyCode.S }), p2Right); m_Controls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.One, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.Y, 1.0f, true), p1Up ); m_Controls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.One, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.Y, -1.0f, true), p1Down ); m_Controls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.One, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.X, -1.0f, true), p1Left ); m_Controls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.One, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.X, 1.0f, true), p1Right ); m_Controls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.Two, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.Y, 1.0f, true), p2Up ); m_Controls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.Two, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.Y, -1.0f, true), p2Down ); m_Controls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.Two, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.X, -1.0f, true), p2Left ); m_Controls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.Two, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.X, 1.0f, true), p2Right ); }
// Use this for initialization void Start() { // create mock scene with two player objects mPlayer1 = GameObject.CreatePrimitive(PrimitiveType.Cube); mPlayer2 = GameObject.Find("CubeHand"); Vector3 scale = new Vector3(0.1f, 0.1f, 0.1f); mPlayer1.transform.localScale = scale; mPlayer2.transform.localScale = scale; // find the camera and man mCamera = GameObject.Find("Main Camera"); mMan = GameObject.Find("Man"); //RuntimeAnimatorController animCtrl = mMan.AddComponent("RuntimeAnimatorController") as RuntimeAnimatorController; // //RuntimeAnimatorController anim = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("myAnimation", typeof(RuntimeAnimatorController))); AnimatorOverrideController overrideController = new AnimatorOverrideController(); //Animator manimator = mMan.GetComponent<Animator>(); //manimator.runtimeAnimatorController = overrideController; // mLeftHand = GameObject.FindWithTag("LeftHand"); mRightHand = GameObject.FindWithTag("RightHand"); mRightShoulder = GameObject.FindWithTag("RightShoulder"); // hook up the IK if (mRightShoulder != null) { //IKControl ik = mRightShoulder.GetComponent<IKControl>(); //ik.target = mPlayer2.transform; //ik.ikActive = true; //IKCtrl ik = mRightShoulder.GetComponent<IKCtrl>(); //ik.rightHandObj = mPlayer2.transform; //ik.ikActive = true; //ikLimb2 ik = mRightShoulder.GetComponent<ikLimb2>(); //IKLimb ik = mRightShoulder.GetComponent<IKLimb>(); IKScriptNew ik = mRightShoulder.GetComponent<IKScriptNew>(); //ik.target = mPlayer2.transform; ik.IsEnabled = true; } // restart the scene Restart(); // create the behaviors in this scene float speed = 0.025f; Behavior p1Up = new TranslateBehavior("player1 move up", mPlayer1, new Vector3( 0, 1, 0) * speed); Behavior p1Down = new TranslateBehavior("player1 move down", mPlayer1, new Vector3( 0, -1, 0) * speed); Behavior p1Left = new TranslateBehavior("player1 move left", mPlayer1, new Vector3(-1, 0, 0) * speed); Behavior p1Right = new TranslateBehavior("player1 move right", mPlayer1, new Vector3( 1, 0, 0) * speed); Behavior p2Up = new TranslateBehavior("player2 move up", mPlayer2, new Vector3( 0, 1, 0) * speed); Behavior p2Down = new TranslateBehavior("player2 move down", mPlayer2, new Vector3( 0, -1, 0) * speed); Behavior p2Left = new TranslateBehavior("player2 move left", mPlayer2, new Vector3(-1, 0, 0) * speed); Behavior p2Right = new TranslateBehavior("player2 move right", mPlayer2, new Vector3( 1, 0, 0) * speed); // create the control scheme that maps inputs to these behaviors mControls = new ControlScheme(); mControls.AddControl(new KeyCodeControlSignal(KeyCode.W), p1Up ); mControls.AddControl(new KeyCodeControlSignal(KeyCode.S), p1Down ); mControls.AddControl(new KeyCodeControlSignal(KeyCode.A), p1Left ); mControls.AddControl(new KeyCodeControlSignal(KeyCode.D), p1Right); mControls.AddControl(new KeyCodeControlSignal(KeyCode.UpArrow), p2Up ); mControls.AddControl(new KeyCodeControlSignal(KeyCode.DownArrow), p2Down ); mControls.AddControl(new KeyCodeControlSignal(KeyCode.LeftArrow), p2Left ); mControls.AddControl(new KeyCodeControlSignal(KeyCode.RightArrow), p2Right); // mControls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.One, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.Y, 1.0f), p1Up ); mControls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.One, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.Y, -1.0f), p1Down ); mControls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.One, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.X, -1.0f), p1Left ); mControls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.One, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.X, 1.0f), p1Right ); mControls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.Two, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.Y, 1.0f), p2Up ); mControls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.Two, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.Y, -1.0f), p2Down ); mControls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.Two, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.X, -1.0f), p2Left ); mControls.AddControl(new GamepadAxisControlSignal(GamepadInput.GamePad.Index.Two, GamepadInput.GamePad.Axis.LeftStick, GamepadAxisControlSignal.Dimension.X, 1.0f), p2Right ); }