예제 #1
0
    void InitializeInteractInputs()
    {
        InputGroup group = new InputGroup();

        //push 'E' -> item pick up executes
        InputUnit unit = new InputUnit {
            InputCheckerByKey = Input.GetKeyDown, Key = KeyCode.E
        };

        unit.Pushed += m_interactor.Interact;
        group.m_inputUnits.Add(InputManager.Interaction, unit);

        //click -> call item interaction
        unit = new InputUnit {
            InputCheckerByKey = (k) => !m_isInMenu && Input.GetKey(k), Key = KeyCode.Mouse0
        };
        unit.Pushed += new Action(() => { if (m_toolActionController)
                                          {
                                              m_toolActionController.Hit();
                                          }
                                  });
        group.m_inputUnits.Add(InputManager.InteractionHit, unit);

        m_inputGroups.Add(InputManager.InteractGroup, group);
    }
예제 #2
0
        public void DoesSimulateWork()
        {
            InputUnit input = new InputUnit();

            input.Simulate();
            Assert.AreEqual(1, input.nextState);
        }
예제 #3
0
        public void DoesUpdateCurrentStateWork()
        {
            InputUnit input = new InputUnit();

            input.Simulate();
            input.UpdateCurrentState();
            Assert.AreEqual(1, input.currentState);
        }
예제 #4
0
 void Start()
 {
     m_currentObject            = null;
     m_objectToHit              = null;
     m_interactionKey           = m_inputManager.GetInputUnit(InputManager.InteractGroup, InputManager.Interaction);
     m_interactionHintText.text = "";
     m_inventory = GetComponent <Inventory>();
 }
예제 #5
0
파일: BusTest.cs 프로젝트: gsp789/Projects
        public void DoesSimulateWork()
        {
            InputUnit input = new InputUnit();
            And       and   = new And();
            Bus       bus   = new Bus(input, and, and);

            bus.Simulate();
            Assert.AreEqual(1, bus.nextState);
        }
예제 #6
0
    private void RemoveInputUnit()
    {
        InputUnit inputUnit = inputs[count - 1];

        inputs.RemoveAt(count - 1);
        strings.RemoveAt(count - 1);
        Destroy(inputUnit.gameObject);

        count--;
    }
예제 #7
0
파일: AndTest.cs 프로젝트: gsp789/Projects
        public void DoesSimulateWork()
        {
            InputUnit input = new InputUnit();
            And       and   = new And();
            Bus       bus   = new Bus(input, and, and);

            and.AddInput(bus, bus);
            input.AddOutput(bus);

            and.Simulate();
            Assert.AreEqual(1, and.nextState);
        }
예제 #8
0
        public void DoesSimulateWork()
        {
            InputUnit input = new InputUnit();
            Not       not   = new Not();
            Bus       bus   = new Bus(input, not);

            not.AddInput(bus);
            input.AddOutput(bus);

            not.Simulate();
            Assert.AreEqual(0, not.nextState);
        }
예제 #9
0
        public void DoesSimulateWork()
        {
            InputUnit input = new InputUnit();
            Or        or    = new Or();
            Bus       bus   = new Bus(input, or, or);

            or.AddInput(bus, bus);
            input.AddOutput(bus);

            or.Simulate();
            Assert.AreEqual(1, or.nextState);
        }
예제 #10
0
        public void DoesSimulateWork()
        {
            InputUnit  input  = new InputUnit();
            And        and    = new And();
            OutputUnit output = new OutputUnit();
            Bus        bus1   = new Bus(input, and, and);
            Bus        bus2   = new Bus(and, output);

            and.AddInput(bus1, bus1);
            and.AddOutput(bus2);
            output.AddInput(bus2);
            input.AddOutput(bus1);

            output.Simulate();
            Assert.AreEqual(1, output.nextState);
        }
예제 #11
0
    void InitializeToolsActionsInputs()
    {
        InputGroup group   = new InputGroup();
        KeyCode    keyCode = KeyCode.Alpha1;
        InputUnit  unit;

        //push '1' -> select first item on tool panel
        //push '6' -> select 6th item
        for (int i = 1; i <= 8; ++i, ++keyCode)
        {
            unit = new InputUnit {
                InputCheckerByKey = Input.GetKeyDown, Key = keyCode
            };
            int j = i;
            unit.Pushed += () => m_controller.SetTool(j);
            group.m_inputUnits.Add(i.ToString(), unit);
        }

        //scroll down -> select next item on tool panel
        //scroll up -> select previous item on tool panel
        unit         = new InputUnit();
        unit.Pushed += () =>
        {
            float scroll = Input.GetAxis("Mouse ScrollWheel");
            if (scroll > 0)
            {
                m_controller.SelectPreviousTool();
            }
            else if (scroll < 0)
            {
                m_controller.SelectNextTool();
            }
        };
        group.m_inputUnits.Add(InputManager.SelectToolWithScroll, unit);

        //push 'Q' -> drop item in hands
        unit = new InputUnit {
            InputCheckerByKey = Input.GetKeyDown, Key = KeyCode.Q
        };
        unit.Pushed += m_controller.DropSelectedItem;
        group.m_inputUnits.Add(InputManager.DropItem, unit);

        m_inputGroups.Add(InputManager.ToolsActionsGroup, group);
    }
예제 #12
0
    private void AddInputUnit()
    {
        GameObject unitObject = GameObject.Instantiate(InputPrefab.gameObject);

        unitObject.transform.SetParent(transform, false);
        InputUnit inputUnit = unitObject.GetComponent <InputUnit>();

        inputUnit.Init();

        RectTransform unitRT = unitObject.GetComponent <RectTransform>();

        float posX = unitSize * count;

        unitRT.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, posX, unitSize);
        inputs.Add(inputUnit);

        count++;
        strings.Add("");
    }
예제 #13
0
        private void btnSimulate1_Click(object sender, EventArgs e)
        {
            InputUnit  input1 = new InputUnit();
            InputUnit  input2 = new InputUnit();
            InputUnit  input3 = new InputUnit();
            And        gate1  = new And();
            And        gate2  = new And();
            OutputUnit output = new OutputUnit();
            Bus        bus1   = new Bus(input1, gate1);
            Bus        bus2   = new Bus(input2, gate1);
            Bus        bus3   = new Bus(input3, gate2);
            Bus        bus4   = new Bus(gate1, gate2);
            Bus        bus5   = new Bus(gate2, output);

            gate1.AddInput(bus1, bus2);
            gate2.AddInput(bus3, bus4);
            gate1.AddOutput(bus4);
            gate2.AddOutput(bus5);
            input1.AddOutput(bus1);
            input2.AddOutput(bus2);
            input3.AddOutput(bus3);
            output.AddInput(bus5);
            Circuit circuit = new Circuit();

            circuit.AddGates(gate1, gate2, input1, input2, input3, output);
            circuit.AddBuses(bus1, bus2, bus3, bus4, bus5);
            if (circuit.IsValid())
            {
                circuit.Simulate();
                if (output.currentState == 1)
                {
                    picOutput1.ImageLocation = @"..\..\src\GUI\Images\OnBulb.jpg";
                }
                else
                {
                    picOutput1.ImageLocation = @"..\..\src\GUI\Images\OffBulb.jpg";
                }
            }
            else
            {
                picOutput1.ImageLocation = @"..\..\src\GUI\Images\InvalidCircuit.png";
            }
        }
예제 #14
0
    void InitializeMenuInputs()
    {
        InputGroup group = new InputGroup();

        //push escape -> call EscapeHandler
        InputUnit unit = new InputUnit {
            InputCheckerByKey = Input.GetKeyDown, Key = KeyCode.Escape
        };

        unit.Pushed += EscapeHandler;
        group.m_inputUnits.Add(InputManager.Escape, unit);

        //push Tab -> call InventoryHandler
        unit = new InputUnit {
            InputCheckerByKey = Input.GetKeyDown, Key = KeyCode.Tab
        };
        unit.Pushed += InventoryHandler;
        group.m_inputUnits.Add(InputManager.Inventory, unit);

        m_inputGroups.Add(InputManager.MenuGroup, group);
    }
예제 #15
0
    void InitializePlacementInputs()
    {
        InputGroup group = new InputGroup();

        //push 'F' -> call placement method
        InputUnit unit = new InputUnit {
            InputCheckerByKey = Input.GetKeyDown, Key = KeyCode.F
        };

        unit.Pushed += m_controller.ObjectPlacement;
        group.m_inputUnits.Add(InputManager.PlaceObject, unit);

        //push 'R' -> call rotating method in placement mode
        unit = new InputUnit {
            InputCheckerByKey = Input.GetKey, Key = KeyCode.R
        };
        unit.Pushed += m_controller.ObjectRotating;
        group.m_inputUnits.Add(InputManager.RotateObject, unit);

        m_inputGroups.Add(InputManager.PlacementGroup, group);
    }
예제 #16
0
    public void Awake()
    {
        inputs = new Dictionary <string, InputUnit>();

        InputUnit unit = new InputUnit(axisL_1);

        inputs.Add(Input_Axis11, unit);

        unit = new InputUnit(axisL_2);
        inputs.Add(Input_Axis12, unit);

        unit = new InputUnit(axisR_1);
        inputs.Add(Input_Axis21, unit);

        unit = new InputUnit(axisR_2);
        inputs.Add(Input_Axis22, unit);

        unit = new InputUnit(axisScroll);
        inputs.Add(Input_AxisScroll, unit);

        unit = new InputUnit(fire1);
        inputs.Add(Input_Fire1, unit);
        unit = new InputUnit(fire2);
        inputs.Add(Input_Fire2, unit);
        unit = new InputUnit(character);
        inputs.Add(Input_Character, unit);
        unit = new InputUnit(favorites);
        inputs.Add(Input_Favorites, unit);
        unit = new InputUnit(menu);
        inputs.Add(Input_Menu, unit);
        unit = new InputUnit(p1_A);
        inputs.Add(Input_A, unit);
        unit = new InputUnit(p1_B);
        inputs.Add(Input_B, unit);
        unit = new InputUnit(p1_C);
        inputs.Add(Input_C, unit);
        unit = new InputUnit(p1_D);
        inputs.Add(Input_D, unit);
    }
예제 #17
0
        public Emulator(GraphicsBackend graphics, AudioBackend audio, InputBackend input)
        {
            GraphicsBackend = graphics;
            AudioBackend    = audio;
            InputBackend    = input;

            graphics.Emulator = this;
            audio.Emulator    = this;
            input.Emulator    = this;

            units.Add(Memory          = new MemoryUnit(this));
            units.Add(Graphics        = new GraphicsUnit(this));
            units.Add(Audio           = new AudioUnit(this));
            units.Add(Math            = new MathUnit(this));
            units.Add(Input           = new InputUnit(this));
            units.Add(CartridgeLoader = new CartridgeUnit(this));

            foreach (var unit in units)
            {
                unit.Init();
            }
        }
예제 #18
0
    void InitializeMovingInputs()
    {
        InputGroup group = new InputGroup();

        InputUnit unit = new InputUnit {
            InputCheckerByKey = Input.GetKey, Key = KeyCode.W
        };

        unit.Pushed += m_movingController.MoveForward;
        group.m_inputUnits.Add(InputManager.MoveForward, unit);

        unit = new InputUnit {
            InputCheckerByKey = Input.GetKey, Key = KeyCode.S
        };
        unit.Pushed += m_movingController.MoveBack;
        group.m_inputUnits.Add(InputManager.MoveBack, unit);

        unit = new InputUnit {
            InputCheckerByKey = Input.GetKey, Key = KeyCode.A
        };
        unit.Pushed += m_movingController.MoveLeft;
        group.m_inputUnits.Add(InputManager.MoveLeft, unit);

        unit = new InputUnit {
            InputCheckerByKey = Input.GetKey, Key = KeyCode.D
        };
        unit.Pushed += m_movingController.MoveRight;
        group.m_inputUnits.Add(InputManager.MoveRight, unit);

        unit = new InputUnit {
            InputCheckerByKey = Input.GetKeyDown, Key = KeyCode.Space
        };
        unit.Pushed += m_movingController.Jump;
        group.m_inputUnits.Add(InputManager.Jump, unit);

        m_inputGroups.Add(InputManager.MovingGroup, group);
    }
예제 #19
0
 public static int ToInt(this InputUnit e)
 {
     return((int)e);
 }
예제 #20
0
 public void init()
 {
     input = new InputUnit();
 }
예제 #21
0
        public static bool IsPushed(InputUnit u)
        {
            AxisType      ax  = AxisType.None;
            JoypadButtons btn = JoypadButtons.None;

            for (int i = 0; i < JoystickCount; i++)
            {
                if (!joystickAvailable[i])
                {
                    continue;
                }
                switch (u)
                {
                case InputUnit.Up:
                    ax = Program.Configuration.Input.UpAxis;
                    break;

                case InputUnit.Down:
                    ax = Program.Configuration.Input.UpAxis.Invert();
                    break;

                case InputUnit.Left:
                    ax = Program.Configuration.Input.LeftAxis;
                    break;

                case InputUnit.Right:
                    ax = Program.Configuration.Input.LeftAxis.Invert();
                    break;

                case InputUnit.MainAction:
                    btn = Program.Configuration.Input.MainActionButton;
                    break;

                case InputUnit.Subaction:
                    btn = Program.Configuration.Input.SubActionButton;
                    break;

                case InputUnit.Optional:
                    btn = Program.Configuration.Input.OptionalButton;
                    break;

                case InputUnit.Menu:
                    btn = Program.Configuration.Input.MenuButton;
                    break;
                }

                float threshold = Program.Configuration.Input.AxisDigitalThreshold;

                if ((joystickState[i].Buttons & btn) != JoypadButtons.None)
                {
                    return(true);
                }
                else if (joystickState[i].Axis.Get((JoystickID)i, ax) > threshold)
                {
                    return(true);
                }
                else if ((joystickState[i].Flags & JoyInfoFlags.ReturnPOV) != 0)
                {
                    Program.AddStatistics("POV", "[#{0}]{1}", i, joystickState[i].POV);
                    if (joystickState[i].POV != 0xffff)
                    {
                        double povAngle = joystickState[i].POV / 18000.0 * Math.PI;
                        // (0, -1)を0度として右回り
                        double x = Math.Sin(povAngle);
                        double y = -Math.Cos(povAngle);
                        switch (ax)
                        {
                        case AxisType.XPlus:
                            if (x > threshold)
                            {
                                return(true);
                            }
                            break;

                        case AxisType.XMinus:
                            if (-x > threshold)
                            {
                                return(true);
                            }
                            break;

                        case AxisType.YPlus:
                            if (y > threshold)
                            {
                                return(true);
                            }
                            break;

                        case AxisType.YMinus:
                            if (-y > threshold)
                            {
                                return(true);
                            }
                            break;
                        }
                    }
                }
            }


            Keys k = Keys.None;

            switch (u)
            {
            case InputUnit.Up:
                k = Program.Configuration.Input.UpKey;
                break;

            case InputUnit.Down:
                k = Program.Configuration.Input.DownKey;
                break;

            case InputUnit.Left:
                k = Program.Configuration.Input.LeftKey;
                break;

            case InputUnit.Right:
                k = Program.Configuration.Input.RightKey;
                break;

            case InputUnit.MainAction:
                k = Program.Configuration.Input.MainActionKey;
                break;

            case InputUnit.Subaction:
                k = Program.Configuration.Input.SubActionKey;
                break;

            case InputUnit.Optional:
                k = Program.Configuration.Input.OptionalKey;
                break;

            case InputUnit.Menu:
                k = Program.Configuration.Input.MenuKey;
                break;
            }

            return(stat.IsKeyDown(k));
        }