コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        control = transform.parent.GetComponent <couchPlayerMovement>().control;

        // Input names for holding and throwing objects
        interactButtonName = control.Interact + transform.parent.GetComponent <couchPlayerMovement>().playerNumber;
    }
コード例 #2
0
    public List<ControlKey> Keys;// = new List<ControlKey>();

    public Action(ControlScheme scheme, string name = "defaultAction")//:base(scheme, name)
    {
        Keys = new List<ControlKey>();

        this.scheme = scheme;
        this.Name = name;
    }
コード例 #3
0
        public bool IsLoadingGame(GameState state)
        {
            ControlScheme currentControlScheme = GetControlScheme();

            if (LastControlScheme != currentControlScheme)
            {
                ControllerCounter = 0;
            }
            LastControlScheme = currentControlScheme;
            ControllerCounter++;

            if (FrameCounter.GetPointer(Program) != IntPtr.Zero && fpsTimer.FPSShort == 0 && ControllerCounter > 30)
            {
                return(true);
            }

            //int m_isLoadingGame = FindIl2CppOffset.GetOffset(Program, "__mainWisp.GameController.m_isLoadingGame");
            int m_isLoadingGame = Version == PointerVersion.All ? 0x103 : 0x10b;

            //GameController.FreezeFixedUpdate || GameController.Instance.m_isLoadingGame
            if (GameController.Read <bool>(Program, 0xb8, 0xa) || GameController.Read <bool>(Program, 0xb8, 0x0, m_isLoadingGame))
            {
                return(true);
            }
            string scene = CurrentScene();

            return((state == OriWotW.GameState.TitleScreen || state == OriWotW.GameState.StartScreen) && scene == "wotwTitleScreen");
        }
コード例 #4
0
    // PUBLIC ACCESSORS

    public bool ValidControlChoices()
    {
        ControlScheme cs0 = (ControlScheme)InputExt.GetPlayerScheme(0);
        ControlScheme cs1 = (ControlScheme)InputExt.GetPlayerScheme(1);

        return((cs0 != ControlScheme.None && cs1 != ControlScheme.None) && (cs0 != cs1 || cs0 == ControlScheme.AI));
    }
コード例 #5
0
    void setUpInputs(int Number, ControlScheme selectedControlScheme)
    {
        switch (selectedControlScheme)
        {
        case ControlScheme.DS4:
            //left thumbstick
            leftVertical   = "J" + Number + "LVertical";
            leftHorizontal = "J" + Number + "LHorizontal";

            //right thumbstick
            rightVertical   = "J" + Number + "RVertical";
            rightHorizontal = "J" + Number + "RHorizontal";

            //dpad
            dPadVertical   = "J" + Number + "DPadVertical";
            dpadHorizontal = "J" + Number + "DPadHorizontal";

            //Buttons
            alternateFireButton = "J" + Number + "LTriggerButton";
            fireButton          = "J" + Number + "RTriggerButton";
            jumpButton          = "J" + Number + "XButton";
            swapWeaponsButton   = "J" + Number + "OButton";
            pickupButton        = "J" + Number + "TriangleButton";
            reloadButton        = "J" + Number + "SquareButton";
            pauseButton         = "J" + Number + "optionsButton";
            break;

        case ControlScheme.XBOX:
            // leaving this blank for some else to try out.
            break;

        case ControlScheme.Keyboard:
            //left thumbstick
            leftVertical   = "KVertical";
            leftHorizontal = "KHorizontal";

            //right thumbstick
            rightVertical   = "MVertical";
            rightHorizontal = "MHorizontal";

            //dpad
            dPadVertical   = "KVertical";
            dpadHorizontal = "KHorizontal";

            //Buttons
            alternateFireButton = "LMouse";
            fireButton          = "RMouse";
            jumpButton          = "SpaceBar";
            pickupButton        = "EButton";
            swapWeaponsButton   = "QButton";
            reloadButton        = "RButton";
            pauseButton         = "Esc";
            break;

        default:
            Debug.Log("Control Scheme was Not Set.");
            break;
        }
    }
コード例 #6
0
        protected override bool processInput(ControlScheme controlScheme)
        {
            bool flag = controlScheme.Profile.ProcessInput(mapResult.Profile);

            flag = controlScheme.Consumables.ProcessInput(mapResult.Consumables) || flag;
            flag = controlScheme.Quest.ProcessInput(mapResult.Quest) || flag;
            return(controlScheme.Map.ProcessInput(mapResult.Map) || flag);
        }
コード例 #7
0
    public Axis(ControlScheme scheme, string name = "defaultAxis")
    //: base(scheme, name)
    {
        AxisKeys = new List <AxisKey>();

        this.scheme = scheme;
        this.Name   = name;
    }
コード例 #8
0
    // -------------------------------------------------
    // Constructor
    // -------------------------------------------------
    public AttackMachine(ControlScheme cs, Attack[] attacks)
    {
        this.attacks       = attacks;
        this.controlScheme = cs;

        this.CurrentAttack = null;
        this.LastAttack    = null;
    }
コード例 #9
0
    public Axis(ControlScheme scheme, string name = "defaultAxis")
        //: base(scheme, name)
    {
        AxisKeys = new List<AxisKey>();

        this.scheme = scheme;
        this.Name = name;
    }
コード例 #10
0
 public PlayerData(int id, int carType, ControlScheme ctrlScheme, PlayerType playerType)
 {
     _carType    = carType;
     _ctrlScheme = ctrlScheme;
     _playerType = playerType;
     _lives      = 10;
     ID          = id;
 }
コード例 #11
0
 public void Init(ControlScheme controlScheme)
 {
     _controlScheme  = controlScheme;
     _rigidbody2d    = GetComponent <Rigidbody2D>();
     _spriteRenderer = GetComponent <SpriteRenderer>();
     _originalSprite = _spriteRenderer.sprite;
     Halt();
 }
コード例 #12
0
 public PlayerData(int id, int carType, ControlScheme ctrlScheme, PlayerType playerType)
 {
     _carType = carType;
     _ctrlScheme = ctrlScheme;
     _playerType = playerType;
     _lives = 10;
     ID = id;
 }
コード例 #13
0
 public override void Populate(ControlScheme controlScheme)
 {
     Jump    = getKeyCodeTranslation(controlScheme.Jump.PrimaryKey);
     Action1 = getKeyCodeTranslation(controlScheme.Action1.PrimaryKey);
     Action2 = getKeyCodeTranslation(controlScheme.Action2.PrimaryKey);
     Action3 = getKeyCodeTranslation(controlScheme.Action3.PrimaryKey);
     Cancel  = getKeyCodeTranslation(controlScheme.Cancel.PrimaryKey);
 }
コード例 #14
0
        public Guid AddPlayer(ControlScheme controlScheme)
        {
            inputService.AddController(controlScheme);
            var player = playerFactory.Create(controlScheme, playerColors[playerState.players.Count]);

            playerState.players.Add(player);
            return(player.id);
        }
コード例 #15
0
ファイル: LinkControl.cs プロジェクト: iidioter/jazz2
 public override void OnUpdate()
 {
     if (ControlScheme.MenuActionHit(PlayerActions.Fire))
     {
         api.PlaySound("MenuSelect", 0.5f);
         action();
     }
 }
コード例 #16
0
ファイル: AboutSection.cs プロジェクト: ozgun-kara/jazz2
 public override void OnUpdate()
 {
     if (ControlScheme.MenuActionHit(PlayerActions.Menu))
     {
         api.PlaySound("MenuSelect", 0.5f);
         api.LeaveSection(this);
     }
 }
コード例 #17
0
 public Player(ControlScheme controlScheme, Color theme, Settings settings)
 {
     id = Guid.NewGuid();
     this.controlScheme = controlScheme;
     this.theme         = theme;
     maxHealth          = settings.startingHealth;
     health             = new AsyncReactiveProperty <float>(maxHealth);
 }
コード例 #18
0
 private void Update()
 {
     if (!handlesEvents)
     {
         return;
     }
     current = this;
     if (useTouch)
     {
         ProcessTouches();
     }
     else if (useMouse)
     {
         ProcessMouse();
     }
     if (onCustomInput != null)
     {
         onCustomInput();
     }
     if (useMouse && mCurrentSelection != null)
     {
         if (cancelKey0 != 0 && Input.GetKeyDown(cancelKey0))
         {
             currentScheme  = ControlScheme.Controller;
             currentKey     = cancelKey0;
             selectedObject = null;
         }
         else if (cancelKey1 != 0 && Input.GetKeyDown(cancelKey1))
         {
             currentScheme  = ControlScheme.Controller;
             currentKey     = cancelKey1;
             selectedObject = null;
         }
     }
     if (mCurrentSelection == null)
     {
         inputHasFocus = false;
     }
     if (mCurrentSelection != null)
     {
         ProcessOthers();
     }
     if (useMouse && mHover != null)
     {
         float num = ((!string.IsNullOrEmpty(scrollAxisName)) ? Input.GetAxis(scrollAxisName) : 0f);
         if (num != 0f)
         {
             Notify(mHover, "OnScroll", num);
         }
         if (showTooltips && mTooltipTime != 0f && (mTooltipTime < RealTime.time || Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
         {
             mTooltip = mHover;
             ShowTooltip(val: true);
         }
     }
     current = null;
 }
コード例 #19
0
        public override void OnUpdate()
        {
#if !PLATFORM_WASM
            if (ControlScheme.MenuActionHit(PlayerActions.Menu))
            {
                DualityApp.Terminate();
            }
#endif
        }
コード例 #20
0
        protected override bool processInput(ControlScheme controlScheme)
        {
            bool flag = controlScheme.Locomotion.ProcessInput(mapResult.Locomotion);

            flag = controlScheme.Back.ProcessInput(mapResult.Back) || flag;
            flag = controlScheme.SendChat.ProcessInput(mapResult.Send) || flag;
            flag = controlScheme.QuickChat.ProcessInput(mapResult.QuickChat) || flag;
            return(controlScheme.QuickEmote.ProcessInput(mapResult.QuickEmote) || flag);
        }
コード例 #21
0
ファイル: UICamera.cs プロジェクト: collierscott/TradeSpace
	/// <summary>
	/// Clear all active press states when the application gets paused.
	/// </summary>

	void OnApplicationPause ()
	{
		MouseOrTouch prev = currentTouch;

		if (useTouch)
		{
			BetterList<int> ids = new BetterList<int>();

			foreach (KeyValuePair<int, MouseOrTouch> pair in mTouches)
			{
				if (pair.Value != null && pair.Value.pressed)
				{
					currentTouch = pair.Value;
					currentTouchID = pair.Key;
					currentScheme = ControlScheme.Touch;
					currentTouch.clickNotification = ClickNotification.None;
					ProcessTouch(false, true);
					ids.Add(currentTouchID);
				}
			}

			for (int i = 0; i < ids.size; ++i)
				RemoveTouch(ids[i]);
		}

		if (useMouse)
		{
			for (int i = 0; i < 3; ++i)
			{
				if (mMouse[i].pressed)
				{
					currentTouch = mMouse[i];
					currentTouchID = -1 - i;
					currentKey = KeyCode.Mouse0 + i;
					currentScheme = ControlScheme.Mouse;
					currentTouch.clickNotification = ClickNotification.None;
					ProcessTouch(false, true);
				}
			}
		}

		if (useController)
		{
			if (controller.pressed)
			{
				currentTouch = controller;
				currentTouchID = -100;
				currentScheme = ControlScheme.Controller;
				currentTouch.last = currentTouch.current;
				currentTouch.current = mCurrentSelection;
				currentTouch.clickNotification = ClickNotification.None;
				ProcessTouch(false, true);
				currentTouch.last = null;
			}
		}
		currentTouch = prev;
	}
コード例 #22
0
    protected override bool processInput(ControlScheme controlScheme)
    {
        bool anyKey = Input.anyKey;

        mapResult.AnyKey.WasJustPressed  = (anyKey && !mapResult.AnyKey.IsHeld);
        mapResult.AnyKey.WasJustReleased = (!anyKey && mapResult.AnyKey.IsHeld);
        mapResult.AnyKey.IsHeld          = anyKey;
        return(mapResult.AnyKey.IsHeld || mapResult.AnyKey.WasJustReleased);
    }
コード例 #23
0
    public string GetActionText(string action)
    {
        ControlScheme scheme        = InputManager.PlayerOneControlScheme;
        InputAction   inputAction   = scheme.GetAction(action);
        InputBinding  actionBinding = inputAction.GetBinding(0);
        KeyCode       code          = actionBinding.Positive;

        return(GetInputText(code));
    }
コード例 #24
0
 public bool IsDown(KeyboardState kbState, GamePadState gpState, ControlScheme controlScheme)
 {
     return(controlScheme switch
     {
         ControlScheme.Keyboard => Keyboard != null && kbState.IsKeyDown(Keyboard.Value),
         ControlScheme.MouseKeyboard => MouseKeyboard != null && kbState.IsKeyDown(MouseKeyboard.Value),
         ControlScheme.GamePad => GamePad != null && gpState.IsButtonDown(GamePad.Value),
         _ => throw new NotImplementedException(),
     });
コード例 #25
0
 // Use this for initialization
 void Start()
 {
     controlScheme = ControlManager.Instance.ControlSchemes[0];
     InstrumentInHand = ((GameObject)GameObject.Instantiate(InstrumentsInCollection.First().gameObject)).GetComponent<Instrument>();
     InstrumentInHand.gameObject.SetActive(true);
     InstrumentInHand.transform.position = transform.position;
     InstrumentInHand.transform.parent = transform;
     player = transform.parent.Find("PlayerCharacter");
 }
コード例 #26
0
 private void OnUpdate()
 {
     if (ControlScheme.MenuActionPressed(PlayerActions.Menu) ||
         ControlScheme.MenuActionPressed(PlayerActions.Fire))
     {
         framesLeft = 0;
         OnCinematicsEnd(false);
     }
 }
コード例 #27
0
ファイル: MainMenu.cs プロジェクト: MihaiChirculete/jazz2
        private void OnUpdate()
        {
            ControlScheme.UpdateAnalogPressed();

            if (sectionStack.Count > 0)
            {
                sectionStack.Peek().OnUpdate();
            }
        }
コード例 #28
0
    public void SetActiveControlScheme(EStationID newStationID)
    {
        currentlyActiveControlScheme?.SetActiveControl(false);


        //Debug.Log(stations[(int)newStationID].controlScheme);
        currentlyActiveControlScheme = stations[(int)newStationID].controlScheme;
        currentlyActiveControlScheme.SetActiveControl(true);
    }
コード例 #29
0
 void SwapActions(ControlScheme scheme, int fromIndex, int toIndex)
 {
     if (fromIndex >= 0 && fromIndex < scheme.Actions.Count && toIndex >= 0 && toIndex < scheme.Actions.Count)
     {
         var temp = scheme.Actions[toIndex];
         scheme.Actions[toIndex]   = scheme.Actions[fromIndex];
         scheme.Actions[fromIndex] = temp;
     }
 }
コード例 #30
0
    void RemoveDevice()
    {
        ControlScheme scheme = m_ActionMapEditCopy.controlSchemes[selectedScheme];

        if (m_SelectedDeviceIndex >= 0 && m_SelectedDeviceIndex < scheme.deviceSlots.Count)
        {
            scheme.deviceSlots.RemoveAt(m_SelectedDeviceIndex);
        }
    }
コード例 #31
0
        public static ControlScheme LoadDefaultScheme(string controlSchemeName)
        {
            ControlScheme r = null;

            using (StringReader reader = new StringReader(xmlAsset.text)) {
                r = new InputLoaderXML(reader).Load(controlSchemeName);
            }
            return(r);
        }
コード例 #32
0
    void AddControlScheme()
    {
        var controlScheme = new ControlScheme("New Control Scheme", m_ActionMapEditCopy);

        m_ActionMapEditCopy.controlSchemes.Add(controlScheme);
        m_ActionMapEditCopy.EnforceBindingsTypeConsistency();

        selectedScheme = m_ActionMapEditCopy.controlSchemes.Count - 1;
    }
コード例 #33
0
ファイル: Entity.cs プロジェクト: rimij405/Asteroids
 public Entity(State _state, Texture2D _image, string _tag = "Entity [Default]",
               Vector2?_pos    = null, float _size          = 0.0f,
               float _rotation = 0f, ScrollBehavior _scroll = ScrollBehavior.Wrap,
               CollisionBehavior _collision = CollisionBehavior.Null,
               bool _enabled = false, bool _visible         = false,
               bool _drawGUI = false, ControlScheme _schema = null,
               ColorSet _set = null)
 {
     Initialize(_state, _image, _tag, _pos, _size, _rotation, _set, _scroll, _collision, _enabled, _visible, _drawGUI, _schema);
 }
コード例 #34
0
    void AddDevice()
    {
        ControlScheme scheme     = m_ActionMapEditCopy.controlSchemes[selectedScheme];
        var           deviceSlot = new DeviceSlot()
        {
            key = GetNextDeviceKey()
        };

        scheme.deviceSlots.Add(deviceSlot);
    }
コード例 #35
0
    // Use this for initialization
    void Start()
    {
        movPhysics = this.GetComponent<DirectMovementPhysics>();
        spellController = this.GetComponent<SpellController>();
        stats = this.GetComponent<Stats>();

        controlScheme = ControlManager.GetControlScheme(1);
        //Spells = new List<ISpellBase>();
        //Actions = new List<Action>();
    }
コード例 #36
0
ファイル: Controls.cs プロジェクト: julesbriquet/Almarach
    public static Vector2 GetDirection(ControlScheme controlScheme)
    {
        if (!controlsEnabled)
            return Vector2.zero;

        Vector2 direction = Vector2.zero;

        switch (controlScheme)
        {
            case ControlScheme.KeyboardZQSD:
                if (Input.GetKey(KeyCode.Z))
                    direction.y = 1;
                else if (Input.GetKey(KeyCode.S))
                    direction.y = -1;
                if (Input.GetKey(KeyCode.Q))
                    direction.x = -1;
                else if (Input.GetKey(KeyCode.D))
                    direction.x = 1;
                break;
            case ControlScheme.KeyboardOKLM:
                if (Input.GetKey(KeyCode.O))
                    direction.y = 1;
                else if (Input.GetKey(KeyCode.L))
                    direction.y = -1;
                if (Input.GetKey(KeyCode.K))
                    direction.x = -1;
                else if (Input.GetKey(KeyCode.M))
                    direction.x = 1;
                break;
            case ControlScheme.Keyboard5123:
                if (Input.GetKey(KeyCode.Keypad5))
                    direction.y = 1;
                else if (Input.GetKey(KeyCode.Keypad2))
                    direction.y = -1;
                if (Input.GetKey(KeyCode.Keypad1))
                    direction.x = -1;
                else if (Input.GetKey(KeyCode.Keypad3))
                    direction.x = 1;
                break;
            case ControlScheme.Gamepad1:
                direction = GetJoystickAxis(1);
                break;
            case ControlScheme.Gamepad2:
                direction = GetJoystickAxis(2);
                break;
            case ControlScheme.Gamepad3:
                direction = GetJoystickAxis(3);
                break;
            default:
                break;
        }

        return direction;
    }
コード例 #37
0
ファイル: Player.cs プロジェクト: EnigmaBADGER/DropTheGoat
 //Cycle through control schemes.
 public void changeControlScheme()
 {
     if ((int)controlScheme == 5)
     {
         controlScheme = ControlScheme.Unspecified;
     }
     else
     {
         controlScheme = (ControlScheme)((int)controlScheme + 1);
     }
 }
コード例 #38
0
    public void Update(ControlScheme inputScheme = null)
    {
        if (scheme == null && inputScheme != null)
            scheme = inputScheme;

        foreach (ControlKey key in Keys)
        {
            key.LastState   = key.CurState;
            key.CurState    = IsCKDown(key);
            
            if(key.LastState && scheme != null)
                scheme.InputType = key.Type;
        }
    }
コード例 #39
0
	// Use this for initialization
	void Start ()
    {
        cc = gameObject.GetComponent<Iso2DCharacterController>();

        if (ControlScheme == null)
        {
            ControlScheme = ControlScheme.CreateScheme<PlayerActions>();
            ControlScheme.Actions[(int)PlayerActions.PickPocket].Keys.Add(ControlKey.PCKey(KeyCode.Space));
            ControlScheme.Actions[(int)PlayerActions.PickPocket].Keys.Add(ControlKey.XboxButton(XboxCtrlrInput.XboxButton.A));
            ControlScheme.Actions[(int)PlayerActions.Dance].Keys.Add(ControlKey.PCKey(KeyCode.Q));
            ControlScheme.Actions[(int)PlayerActions.Dance].Keys.Add(ControlKey.XboxButton(XboxCtrlrInput.XboxButton.B));
            ScriptableObjectHelper.SaveAssetAutoNaming(ControlScheme);
            //ControlScheme.hideFlags = HideFlags.DontSave;

        }
	}
コード例 #40
0
    void CheckInPlayer(ControlScheme scheme)
    {
        var newPlayer = new Player() { id = players.Count + 1, controls = scheme };
        players.Add(newPlayer);

        bool isPad = scheme.ToString().StartsWith("Gamepad");

        // show his key mapping :
        schemeSelection[newPlayer.id - 1].GetComponent<Image>().overrideSprite =
            buttonConfigs[(newPlayer.id - 1) * 4 + GetMappingIndex(scheme)];
        //if (isPad)
        //    playerGamepadMappings[newPlayer.id - 1].gameObject.SetActive(true);
        //else
        //    playerKeyMappings[newPlayer.id - 1].gameObject.SetActive(true);

        playerOverlays[newPlayer.id - 1].gameObject.SetActive(true);
    }
コード例 #41
0
	// Use this for initialization
	void Start () 
    {
        cc = gameObject.GetComponent<SimpleIsoCharacterController>();
        pp = gameObject.GetComponent<PickPocket>();
        anim = new AnimationSwapAnimatorWrapper(gameObject);

        if(ControlScheme == null)
        {
            ControlScheme = ControlScheme.CreateScheme<PlayerActions>();
            ControlScheme.Actions[(int)PlayerActions.PickPocket].Keys.Add(ControlKey.PCKey(KeyCode.Space));
            ControlScheme.Actions[(int)PlayerActions.PickPocket].Keys.Add(ControlKey.XboxButton(XboxCtrlrInput.XboxButton.A));

            ScriptableObjectHelper.SaveAssetAutoNaming(ControlScheme);
            //ControlScheme.hideFlags = HideFlags.DontSave;

        }
        
	}
コード例 #42
0
 private IEnumerator SelectControlsCoroutine()
 {
     while (true)
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             _selectedControl = ControlScheme.Keyboard;
             StartCoroutine(FadeOutTitleCoroutine());
             yield break;
         }
         if (STMReceiver.Instance.Buttons.BreakButtonDown)
         {
             _selectedControl = ControlScheme.Stm;
             StartCoroutine(FadeOutTitleCoroutine());
             yield break;
         }
         yield return null;
     }
 }
コード例 #43
0
    void ChooseCharacter(ControlScheme scheme, float leftRight)
    {
        var player = players.First(p => p.controls == scheme);
        var rect = playerOverlays[player.id - 1].gameObject.GetComponent<RectTransform>();

        var currentPos = rect.anchorMax;
        if (leftRight < 0)
        {
            //move left
            _audioSource.PlayOneShot(moveSound);
            currentPos.x = currentPos.x == 0f ? 1f : currentPos.x - 0.5f;
        }
        else
        {
            //move right
            _audioSource.PlayOneShot(moveSound);
            currentPos.x = currentPos.x == 1f ? 0f : currentPos.x + 0.5f;
        }
        rect.anchorMax = currentPos;
        rect.anchorMin = currentPos;
    }
コード例 #44
0
ファイル: Controls.cs プロジェクト: julesbriquet/Almarach
    public static bool UsePowerUp(ControlScheme controlScheme)
    {
        if (!controlsEnabled)
            return false;

        switch (controlScheme)
        {
            case ControlScheme.KeyboardZQSD:
                return Input.GetKey(KeyCode.LeftShift);
            case ControlScheme.KeyboardOKLM:
                return Input.GetKey(KeyCode.Return);
            case ControlScheme.Keyboard5123:
                return Input.GetKey(KeyCode.KeypadEnter);
            case ControlScheme.Gamepad1:
                return GetJoystickButton(1);
            case ControlScheme.Gamepad2:
                return GetJoystickButton(2);
            case ControlScheme.Gamepad3:
                return GetJoystickButton(3);
        }
        return false;
    }
コード例 #45
0
ファイル: Tank.cs プロジェクト: kralle333/TankGame
        public Tank(int playerIndex, Vector2 position, int team, ControlScheme controlScheme, Rectangle screenBounds)
            : base("Sprites", position, Map.TileSize, Map.TileSize, true, SpriteHelper.GetDefaultDepth(SpriteHelper.SpriteDepth.Middle))
        {
            _playerIndex = playerIndex;
            _team = team;
            _screenBounds = screenBounds;
            _usedControlScheme = controlScheme;
            if ((int)_usedControlScheme > 2)
            {
                _gamePadIndex = (PlayerIndex)_usedControlScheme - 3;
            }

            //Cannon
            SetOrigin(16, 16);
            cannon = new Sprite("Sprites", position, 26, 16, false, SpriteHelper.GetDefaultDepth(SpriteHelper.SpriteDepth.Middle) + 0.1f);
            cannon.SetTextureRectangle(new Rectangle(96 + (32 * _team), 64, 26, 16));
            cannon.SetOrigin(8f, 8f);
            cannon.position = position;
            _spriteOverlays.Add(cannon);

            //Animation
            AddAnimationState(new SpriteState("MovingHorizontal", SpriteHelper.GetSpriteRectangleStrip(32, 32, 0, 3 + _team, 3 + _team, 0, 2), _animationSpeed));
            _orientation = new Vector2(1, 0);
            _currentAnimationState = "MovingHorizontal";
            SetCurrentAnimationState(_currentAnimationState);
            InitiateAnimationStates();

            //Statbar
            statsBarPosition = new Vector2(20 + (playerIndex * 290), 24);
            if (playerIndex > 1)
            {
                statsBarPosition.X -= 90;
            }
            tankSprite = new Sprite("Sprites", (int)statsBarPosition.X, (int)statsBarPosition.Y, new Rectangle(96 + (32 * team), 112, 32, 32), 1);
            _healthBar = new HealthBar((int)statsBarPosition.X + 42, (int)statsBarPosition.Y, 116, 30, Color.Green, Color.Red, Color.Black);
            powerupRectangle = new Sprite("Sprites", _healthBar.x+100+32,21, 1);
            powerupRectangle.SetTextureRectangle(new Rectangle(0, 176, 36, 36));
        }
コード例 #46
0
    // Use this for initialization
    void Awake()
    {
        platformer = GetComponent<PlatformerPhysics>();

        #region Controls

        if (ControlScheme == null)
        {
            ControlScheme = ControlScheme.CreateScheme<JazzClimbingPlayerActions>();

            // Make this into a nice function
            ControlScheme.Actions[(int)JazzClimbingPlayerActions.Jump].Keys.Add(ControlKey.PCKey(KeyCode.Space));
            ControlScheme.Actions[(int)JazzClimbingPlayerActions.Jump].Keys.Add(ControlKey.XboxButton(XboxCtrlrInput.XboxButton.A));

            ControlScheme.Actions[(int)JazzClimbingPlayerActions.PlayInstrument].Keys.Add(ControlKey.PCKey(KeyCode.E));
            ControlScheme.Actions[(int)JazzClimbingPlayerActions.PlayInstrument].Keys.Add(ControlKey.XboxButton(XboxCtrlrInput.XboxButton.B));
        }

        ControlManager.Instance.ControlSchemes[0] = ControlScheme;

        DontDestroyOnLoad(ControlManager.Instance);

        #endregion
    }
コード例 #47
0
ファイル: UICamera.cs プロジェクト: satela/xjhU3d
	/// <summary>
	/// Process keyboard and joystick events.
	/// </summary>

	public void ProcessOthers ()
	{
		currentTouchID = -100;
		currentTouch = controller;

		bool submitKeyDown = false;
		bool submitKeyUp = false;

		if (submitKey0 != KeyCode.None && Input.GetKeyDown(submitKey0))
		{
			currentKey = submitKey0;
			submitKeyDown = true;
		}

		if (submitKey1 != KeyCode.None && Input.GetKeyDown(submitKey1))
		{
			currentKey = submitKey1;
			submitKeyDown = true;
		}

		if (submitKey0 != KeyCode.None && Input.GetKeyUp(submitKey0))
		{
			currentKey = submitKey0;
			submitKeyUp = true;
		}

		if (submitKey1 != KeyCode.None && Input.GetKeyUp(submitKey1))
		{
			currentKey = submitKey1;
			submitKeyUp = true;
		}

		if (submitKeyDown || submitKeyUp)
		{
			currentScheme = ControlScheme.Controller;
			currentTouch.last = currentTouch.current;
			currentTouch.current = mCurrentSelection;
			ProcessTouch(submitKeyDown, submitKeyUp);
			currentTouch.last = null;
		}

		int vertical = 0;
		int horizontal = 0;

		if (useKeyboard)
		{
			if (inputHasFocus)
			{
				vertical += GetDirection(KeyCode.UpArrow, KeyCode.DownArrow);
				horizontal += GetDirection(KeyCode.RightArrow, KeyCode.LeftArrow);
			}
			else
			{
				vertical += GetDirection(KeyCode.W, KeyCode.UpArrow, KeyCode.S, KeyCode.DownArrow);
				horizontal += GetDirection(KeyCode.D, KeyCode.RightArrow, KeyCode.A, KeyCode.LeftArrow);
			}
		}

		if (useController)
		{
			if (!string.IsNullOrEmpty(verticalAxisName)) vertical += GetDirection(verticalAxisName);
			if (!string.IsNullOrEmpty(horizontalAxisName)) horizontal += GetDirection(horizontalAxisName);
		}

		// Send out key notifications
		if (vertical != 0)
		{
			currentScheme = ControlScheme.Controller;
			Notify(mCurrentSelection, "OnKey", vertical > 0 ? KeyCode.UpArrow : KeyCode.DownArrow);
		}
		
		if (horizontal != 0)
		{
			currentScheme = ControlScheme.Controller;
			Notify(mCurrentSelection, "OnKey", horizontal > 0 ? KeyCode.RightArrow : KeyCode.LeftArrow);
		}
		
		if (useKeyboard && Input.GetKeyDown(KeyCode.Tab))
		{
			currentKey = KeyCode.Tab;
			currentScheme = ControlScheme.Controller;
			Notify(mCurrentSelection, "OnKey", KeyCode.Tab);
		}

		// Send out the cancel key notification
		if (cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0))
		{
			currentKey = cancelKey0;
			currentScheme = ControlScheme.Controller;
			Notify(mCurrentSelection, "OnKey", KeyCode.Escape);
		}

		if (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1))
		{
			currentKey = cancelKey1;
			currentScheme = ControlScheme.Controller;
			Notify(mCurrentSelection, "OnKey", KeyCode.Escape);
		}

		currentTouch = null;
		currentKey = KeyCode.None;
	}
コード例 #48
0
ファイル: UICamera.cs プロジェクト: satela/xjhU3d
	/// <summary>
	/// Update touch-based events.
	/// </summary>

	public void ProcessTouches ()
	{
		currentScheme = ControlScheme.Touch;

		for (int i = 0; i < Input.touchCount; ++i)
		{
			Touch touch = Input.GetTouch(i);

			currentTouchID = allowMultiTouch ? touch.fingerId : 1;
			currentTouch = GetTouch(currentTouchID);

			bool pressed = (touch.phase == TouchPhase.Began) || currentTouch.touchBegan;
			bool unpressed = (touch.phase == TouchPhase.Canceled) || (touch.phase == TouchPhase.Ended);
			currentTouch.touchBegan = false;

			// Although input.deltaPosition can be used, calculating it manually is safer (just in case)
			currentTouch.delta = pressed ? Vector2.zero : touch.position - currentTouch.pos;
			currentTouch.pos = touch.position;

			// Raycast into the screen
			if (!Raycast(currentTouch.pos)) hoveredObject = fallThrough;
			if (hoveredObject == null) hoveredObject = genericEventHandler;
			currentTouch.last = currentTouch.current;
			currentTouch.current = hoveredObject;
			lastTouchPosition = currentTouch.pos;

			// We don't want to update the last camera while there is a touch happening
			if (pressed) currentTouch.pressedCam = currentCamera;
			else if (currentTouch.pressed != null) currentCamera = currentTouch.pressedCam;

			// Double-tap support
			if (touch.tapCount > 1) currentTouch.clickTime = RealTime.time;

			// Process the events from this touch
			ProcessTouch(pressed, unpressed);

			// If the touch has ended, remove it from the list
			if (unpressed) RemoveTouch(currentTouchID);
			currentTouch.last = null;
			currentTouch = null;

			// Don't consider other touches
			if (!allowMultiTouch) break;
		}

		if (Input.touchCount == 0)
		{
			if (useMouse) ProcessMouse();
#if UNITY_EDITOR
			else ProcessFakeTouches();
#endif
		}
	}
コード例 #49
0
ファイル: UICamera.cs プロジェクト: satela/xjhU3d
	/// <summary>
	/// Update mouse input.
	/// </summary>

	public void ProcessMouse ()
	{
		// Update the position and delta
		lastTouchPosition = Input.mousePosition;
		mMouse[0].delta = lastTouchPosition - mMouse[0].pos;
		mMouse[0].pos = lastTouchPosition;
		bool posChanged = mMouse[0].delta.sqrMagnitude > 0.001f;

		// Propagate the updates to the other mouse buttons
		for (int i = 1; i < 3; ++i)
		{
			mMouse[i].pos = mMouse[0].pos;
			mMouse[i].delta = mMouse[0].delta;
		}

		// Is any button currently pressed?
		bool isPressed = false;
		bool justPressed = false;

		for (int i = 0; i < 3; ++i)
		{
			if (Input.GetMouseButtonDown(i))
			{
				currentScheme = ControlScheme.Mouse;
				justPressed = true;
				isPressed = true;
			}
			else if (Input.GetMouseButton(i))
			{
				currentScheme = ControlScheme.Mouse;
				isPressed = true;
			}
		}

		// No need to perform raycasts every frame
		if (isPressed || posChanged || mNextRaycast < RealTime.time)
		{
			mNextRaycast = RealTime.time + 0.02f;
			if (!Raycast(Input.mousePosition)) hoveredObject = fallThrough;
			if (hoveredObject == null) hoveredObject = genericEventHandler;
			for (int i = 0; i < 3; ++i) mMouse[i].current = hoveredObject;
		}

		bool highlightChanged = (mMouse[0].last != mMouse[0].current);
		if (highlightChanged) currentScheme = ControlScheme.Mouse;

		if (isPressed)
		{
			// A button was pressed -- cancel the tooltip
			mTooltipTime = 0f;
		}
		else if (posChanged && (!stickyTooltip || highlightChanged))
		{
			if (mTooltipTime != 0f)
			{
				// Delay the tooltip
				mTooltipTime = RealTime.time + tooltipDelay;
			}
			else if (mTooltip != null)
			{
				// Hide the tooltip
				ShowTooltip(false);
			}
		}

		// The button was released over a different object -- remove the highlight from the previous
		if ((justPressed || !isPressed) && mHover != null && highlightChanged)
		{
			currentScheme = ControlScheme.Mouse;
			if (mTooltip != null) ShowTooltip(false);
			Notify(mHover, "OnHover", false);
			mHover = null;
		}

		// Process all 3 mouse buttons as individual touches
		for (int i = 0; i < 3; ++i)
		{
			bool pressed = Input.GetMouseButtonDown(i);
			bool unpressed = Input.GetMouseButtonUp(i);

			if (pressed || unpressed) currentScheme = ControlScheme.Mouse;

			currentTouch = mMouse[i];
			currentTouchID = -1 - i;
			currentKey = KeyCode.Mouse0 + i;
	
			// We don't want to update the last camera while there is a touch happening
			if (pressed) currentTouch.pressedCam = currentCamera;
			else if (currentTouch.pressed != null) currentCamera = currentTouch.pressedCam;
	
			// Process the mouse events
			ProcessTouch(pressed, unpressed);
			currentKey = KeyCode.None;
		}
		currentTouch = null;

		// If nothing is pressed and there is an object under the touch, highlight it
		if (!isPressed && highlightChanged)
		{
			currentScheme = ControlScheme.Mouse;
			mTooltipTime = RealTime.time + tooltipDelay;
			mHover = mMouse[0].current;
			Notify(mHover, "OnHover", true);
		}

		// Update the last value
		mMouse[0].last = mMouse[0].current;
		for (int i = 1; i < 3; ++i) mMouse[i].last = mMouse[0].last;
	}
コード例 #50
0
ファイル: UICamera.cs プロジェクト: satela/xjhU3d
	/// <summary>
	/// Check the input and send out appropriate events.
	/// </summary>

	void Update ()
	{
		// Only the first UI layer should be processing events
#if UNITY_EDITOR
		if (!Application.isPlaying || !handlesEvents) return;
#else
		if (!handlesEvents) return;
#endif
		current = this;

		// Process touch events first
		if (useTouch) ProcessTouches ();
		else if (useMouse) ProcessMouse();

		// Custom input processing
		if (onCustomInput != null) onCustomInput();

		// Clear the selection on the cancel key, but only if mouse input is allowed
		if (useMouse && mCurrentSelection != null)
		{
			if (cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0))
			{
				currentScheme = ControlScheme.Controller;
				currentKey = cancelKey0;
				selectedObject = null;
			}
			else if (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1))
			{
				currentScheme = ControlScheme.Controller;
				currentKey = cancelKey1;
				selectedObject = null;
			}
		}

		// If nothing is selected, input focus is lost
		if (mCurrentSelection == null) inputHasFocus = false;

		// Update the keyboard and joystick events
		if (mCurrentSelection != null) ProcessOthers();

		// If it's time to show a tooltip, inform the object we're hovering over
		if (useMouse && mHover != null)
		{
			float scroll = !string.IsNullOrEmpty(scrollAxisName) ? Input.GetAxis(scrollAxisName) : 0f;
			if (scroll != 0f) Notify(mHover, "OnScroll", scroll);

			if (showTooltips && mTooltipTime != 0f && (mTooltipTime < RealTime.time ||
				Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
			{
				mTooltip = mHover;
				ShowTooltip(true);
			}
		}
		current = null;
	}
コード例 #51
0
ファイル: UICamera.cs プロジェクト: satela/xjhU3d
	/// <summary>
	/// Change the selection.
	/// </summary>

	static protected void SetSelection (GameObject go, ControlScheme scheme)
	{
		if (mNextSelection != null)
		{
			mNextSelection = go;
		}
		else if (mCurrentSelection != go)
		{
			mNextSelection = go;
			mNextScheme = scheme;

			if (UICamera.list.size > 0)
			{
				UICamera cam = (mNextSelection != null) ? FindCameraForLayer(mNextSelection.layer) : UICamera.list[0];
				if (cam != null) cam.StartCoroutine(cam.ChangeSelection());
			}
		}
	}
コード例 #52
0
ファイル: UICamera.cs プロジェクト: 10people/UnityLibrary
	/// <summary>
	/// Change the selection.
	/// </summary>

	static protected void SetSelection (GameObject go, ControlScheme scheme)
	{
		if (mNextSelection != null)
		{
			mNextSelection = go;
		}
		else if (mCurrentSelection != go)
		{
			if (mCurrentSelection != null)
			{
				UICamera uicam = FindCameraForLayer(mCurrentSelection.layer);

				if (uicam != null)
				{
					current = uicam;
					currentCamera = uicam.mCam;
					UICamera.currentScheme = scheme;
					Notify(mCurrentSelection, "OnSelect", false);
					current = null;
				}
			}

			mCurrentSelection = null;
			mNextSelection = go;
			mNextScheme = scheme;

			if (UICamera.list.size > 0)
			{
				UICamera cam = (mNextSelection != null) ? FindCameraForLayer(mNextSelection.layer) : UICamera.list[0];
				if (cam != null) cam.StartCoroutine(cam.ChangeSelection());
			}
		}
	}
コード例 #53
0
	/// <summary>
	/// Update touch-based events.
	/// </summary>

	public void ProcessTouches ()
	{
		currentScheme = ControlScheme.Touch;
		int count = (GetInputTouchCount == null) ? Input.touchCount : GetInputTouchCount();

		for (int i = 0; i < count; ++i)
		{
			int fingerId;
			TouchPhase phase;
			Vector2 position;
			int tapCount;

			if (GetInputTouch == null)
			{
				UnityEngine.Touch touch = Input.GetTouch(i);
				phase = touch.phase;
				fingerId = touch.fingerId;
				position = touch.position;
				tapCount = touch.tapCount;
			}
			else
			{
				Touch touch = GetInputTouch(i);
				phase = touch.phase;
				fingerId = touch.fingerId;
				position = touch.position;
				tapCount = touch.tapCount;
			}

			currentTouchID = allowMultiTouch ? fingerId : 1;
			currentTouch = GetTouch(currentTouchID);

			bool pressed = (phase == TouchPhase.Began) || currentTouch.touchBegan;
			bool unpressed = (phase == TouchPhase.Canceled) || (phase == TouchPhase.Ended);
			currentTouch.touchBegan = false;

			// Although input.deltaPosition can be used, calculating it manually is safer (just in case)
			currentTouch.delta = pressed ? Vector2.zero : position - currentTouch.pos;
			currentTouch.pos = position;

			// Raycast into the screen
			if (!Raycast(currentTouch.pos)) hoveredObject = fallThrough;
			if (hoveredObject == null) hoveredObject = mGenericHandler;
			currentTouch.last = currentTouch.current;
			currentTouch.current = hoveredObject;
			lastTouchPosition = currentTouch.pos;

			// We don't want to update the last camera while there is a touch happening
			if (pressed) currentTouch.pressedCam = currentCamera;
			else if (currentTouch.pressed != null) currentCamera = currentTouch.pressedCam;

			// Double-tap support
			if (tapCount > 1) currentTouch.clickTime = RealTime.time;

			// Process the events from this touch
			ProcessTouch(pressed, unpressed);

			// If the touch has ended, remove it from the list
			if (unpressed) RemoveTouch(currentTouchID);
			currentTouch.last = null;
			currentTouch = null;

			// Don't consider other touches
			if (!allowMultiTouch) break;
		}

		if (count == 0)
		{
			// Skip the first frame after using touch events
			if (mUsingTouchEvents)
			{
				mUsingTouchEvents = false;
				return;
			}

			if (useMouse) ProcessMouse();
#if UNITY_EDITOR
			else ProcessFakeTouches();
#endif
		}
		else mUsingTouchEvents = true;
	}
コード例 #54
0
ファイル: Ship.cs プロジェクト: knexer/VNReduxMiningPrototype
 // Use this for initialization
 void Start()
 {
     ControlScheme = gameObject.GetComponent<ShipControlScheme>();
     Rigidbody rigidbody = GetComponent<Rigidbody>();
     if (null != rigidbody) rigidbody.sleepThreshold = 0;
 }
コード例 #55
0
ファイル: UICamera.cs プロジェクト: satela/xjhU3d
	/// <summary>
	/// Process the events of the specified touch.
	/// </summary>

	public void ProcessTouch (bool pressed, bool unpressed)
	{
		// Whether we're using the mouse
		bool isMouse = (currentScheme == ControlScheme.Mouse);
		float drag   = isMouse ? mouseDragThreshold : touchDragThreshold;
		float click  = isMouse ? mouseClickThreshold : touchClickThreshold;

		// So we can use sqrMagnitude below
		drag *= drag;
		click *= click;

		// Send out the press message
		if (pressed)
		{
			if (mTooltip != null) ShowTooltip(false);

			currentTouch.pressStarted = true;
			Notify(currentTouch.pressed, "OnPress", false);
			currentTouch.pressed = currentTouch.current;
			currentTouch.dragged = currentTouch.current;
			currentTouch.clickNotification = ClickNotification.BasedOnDelta;
			currentTouch.totalDelta = Vector2.zero;
			currentTouch.dragStarted = false;
			Notify(currentTouch.pressed, "OnPress", true);

			// Update the selection
			if (currentTouch.pressed != mCurrentSelection)
			{
				if (mTooltip != null) ShowTooltip(false);
				currentScheme = ControlScheme.Touch;
				selectedObject = currentTouch.pressed;
			}
		}
		else if (currentTouch.pressed != null && (currentTouch.delta.sqrMagnitude != 0f || currentTouch.current != currentTouch.last))
		{
			// Keep track of the total movement
			currentTouch.totalDelta += currentTouch.delta;
			float mag = currentTouch.totalDelta.sqrMagnitude;
			bool justStarted = false;

			// If the drag process hasn't started yet but we've already moved off the object, start it immediately
			if (!currentTouch.dragStarted && currentTouch.last != currentTouch.current)
			{
				currentTouch.dragStarted = true;
				currentTouch.delta = currentTouch.totalDelta;

				// OnDragOver is sent for consistency, so that OnDragOut is always preceded by OnDragOver
				isDragging = true;
				Notify(currentTouch.dragged, "OnDragStart", null);
				Notify(currentTouch.last, "OnDragOver", currentTouch.dragged);
				isDragging = false;
			}
			else if (!currentTouch.dragStarted && drag < mag)
			{
				// If the drag event has not yet started, see if we've dragged the touch far enough to start it
				justStarted = true;
				currentTouch.dragStarted = true;
				currentTouch.delta = currentTouch.totalDelta;
			}

			// If we're dragging the touch, send out drag events
			if (currentTouch.dragStarted)
			{
				if (mTooltip != null) ShowTooltip(false);

				isDragging = true;
				bool isDisabled = (currentTouch.clickNotification == ClickNotification.None);

				if (justStarted)
				{
					Notify(currentTouch.dragged, "OnDragStart", null);
					Notify(currentTouch.current, "OnDragOver", currentTouch.dragged);
				}
				else if (currentTouch.last != currentTouch.current)
				{
					Notify(currentTouch.last, "OnDragOut", currentTouch.dragged);
					Notify(currentTouch.current, "OnDragOver", currentTouch.dragged);
				}

				Notify(currentTouch.dragged, "OnDrag", currentTouch.delta);

				currentTouch.last = currentTouch.current;
				isDragging = false;

				if (isDisabled)
				{
					// If the notification status has already been disabled, keep it as such
					currentTouch.clickNotification = ClickNotification.None;
				}
				else if (currentTouch.clickNotification == ClickNotification.BasedOnDelta && click < mag)
				{
					// We've dragged far enough to cancel the click
					currentTouch.clickNotification = ClickNotification.None;
				}
			}
		}

		// Send out the unpress message
		if (unpressed)
		{
			currentTouch.pressStarted = false;
			if (mTooltip != null) ShowTooltip(false);

			if (currentTouch.pressed != null)
			{
				// If there was a drag event in progress, make sure OnDragOut gets sent
				if (currentTouch.dragStarted)
				{
					Notify(currentTouch.last, "OnDragOut", currentTouch.dragged);
					Notify(currentTouch.dragged, "OnDragEnd", null);
				}

				// Send the notification of a touch ending
				Notify(currentTouch.pressed, "OnPress", false);

				// Send a hover message to the object
				if (isMouse) Notify(currentTouch.current, "OnHover", true);
				mHover = currentTouch.current;

				// If the button/touch was released on the same object, consider it a click and select it
				if (currentTouch.dragged == currentTouch.current ||
					(currentScheme != ControlScheme.Controller &&
					currentTouch.clickNotification != ClickNotification.None &&
					currentTouch.totalDelta.sqrMagnitude < drag))
				{
					if (currentTouch.pressed != mCurrentSelection)
					{
						mNextSelection = null;
						mCurrentSelection = currentTouch.pressed;
						Notify(currentTouch.pressed, "OnSelect", true);
					}
					else
					{
						mNextSelection = null;
						mCurrentSelection = currentTouch.pressed;
					}

					// If the touch should consider clicks, send out an OnClick notification
					if (currentTouch.clickNotification != ClickNotification.None && currentTouch.pressed == currentTouch.current)
					{
						float time = RealTime.time;

						Notify(currentTouch.pressed, "OnClick", null);

						if (currentTouch.clickTime + 0.35f > time)
						{
							Notify(currentTouch.pressed, "OnDoubleClick", null);
						}
						currentTouch.clickTime = time;
					}
				}
				else if (currentTouch.dragStarted) // The button/touch was released on a different object
				{
					// Send a drop notification (for drag & drop)
					Notify(currentTouch.current, "OnDrop", currentTouch.dragged);
				}
			}
			currentTouch.dragStarted = false;
			currentTouch.pressed = null;
			currentTouch.dragged = null;
		}
	}
コード例 #56
0
ファイル: UICamera.cs プロジェクト: 10people/UnityLibrary
	/// <summary>
	/// Selection change is delayed on purpose. This way selection changes during event processing won't cause
	/// the newly selected widget to continue processing when it is it's turn. Example: pressing 'tab' on one
	/// button selects the next button, and then it also processes its 'tab' in turn, selecting the next one.
	/// </summary>

	System.Collections.IEnumerator ChangeSelection ()
	{
		yield return new WaitForEndOfFrame();
		mCurrentSelection = mNextSelection;
		mNextSelection = null;

		if (mCurrentSelection != null)
		{
			current = this;
			currentCamera = mCam;
			UICamera.currentScheme = mNextScheme;
			Notify(mCurrentSelection, "OnSelect", true);
			current = null;
		}
	}
コード例 #57
0
ファイル: UICamera.cs プロジェクト: satela/xjhU3d
	/// <summary>
	/// Clear all active press states when the application gets paused.
	/// </summary>

	void OnApplicationPause ()
	{
		MouseOrTouch prev = currentTouch;

		if (useTouch)
		{
			BetterList<int> ids = new BetterList<int>();

			foreach (KeyValuePair<int, MouseOrTouch> pair in mTouches)
			{
				if (pair.Value != null && pair.Value.pressed)
				{
					currentTouch = pair.Value;
					currentTouchID = pair.Key;
					currentScheme = ControlScheme.Touch;
					currentTouch.clickNotification = ClickNotification.None;
					ProcessTouch(false, true);
					ids.Add(currentTouchID);
				}
			}

			for (int i = 0; i < ids.size; ++i)
				RemoveTouch(ids[i]);
		}

		if (useMouse)
		{
			for (int i = 0; i < 3; ++i)
			{
				if (mMouse[i].pressed)
				{
					currentTouch = mMouse[i];
					currentTouchID = -1 - i;
					currentKey = KeyCode.Mouse0 + i;
					currentScheme = ControlScheme.Mouse;
					currentTouch.clickNotification = ClickNotification.None;
					ProcessTouch(false, true);
				}
			}
		}

		if (useController)
		{
			if (controller.pressed)
			{
				currentTouch = controller;
				currentTouchID = -100;
				currentScheme = ControlScheme.Controller;
				currentTouch.last = currentTouch.current;
				currentTouch.current = mCurrentSelection;
				currentTouch.clickNotification = ClickNotification.None;
				ProcessTouch(false, true);
				currentTouch.last = null;
			}
		}
		currentTouch = prev;
	}
コード例 #58
0
ファイル: UICamera.cs プロジェクト: 10people/UnityLibrary
	/// <summary>
	/// Check the input and send out appropriate events.
	/// </summary>

	void Update ()
	{
		// Only the first UI layer should be processing events
		if (!Application.isPlaying || !handlesEvents) return;

		current = this;

		int w = Screen.width;
		int h = Screen.height;

		if (w != mWidth || h != mHeight)
		{
			mWidth = w;
			mHeight = h;
			if (onScreenResize != null)
				onScreenResize();
		}

		// Process touch events first
		if (useTouch) ProcessTouches ();
		else if (useMouse) ProcessMouse();

		// Custom input processing
		if (onCustomInput != null) onCustomInput();

		// Clear the selection on the cancel key, but only if mouse input is allowed
		if (useMouse && mCurrentSelection != null)
		{
			if (cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0))
			{
				currentScheme = ControlScheme.Controller;
				currentKey = cancelKey0;
				selectedObject = null;
			}
			else if (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1))
			{
				currentScheme = ControlScheme.Controller;
				currentKey = cancelKey1;
				selectedObject = null;
			}
		}

		// Forward the input to the selected object
		if (mCurrentSelection != null)
		{
			string input = Input.inputString;

			// Adding support for some macs only having the "Delete" key instead of "Backspace"
			if (useKeyboard && Input.GetKeyDown(KeyCode.Delete)) input += "\b";

			if (input.Length > 0)
			{
				if (!stickyTooltip && mTooltip != null) ShowTooltip(false);
				Notify(mCurrentSelection, "OnInput", input);
			}
		}
		else inputHasFocus = false;

		// Update the keyboard and joystick events
		if (mCurrentSelection != null) ProcessOthers();

		// If it's time to show a tooltip, inform the object we're hovering over
		if (useMouse && mHover != null)
		{
			float scroll = !string.IsNullOrEmpty(scrollAxisName) ? Input.GetAxis(scrollAxisName) : 0f;
			if (scroll != 0f) Notify(mHover, "OnScroll", scroll);

			if (showTooltips && mTooltipTime != 0f && (mTooltipTime < RealTime.time ||
				Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
			{
				mTooltip = mHover;
				ShowTooltip(true);
			}
		}
		current = null;
	}
コード例 #59
0
ファイル: UICamera.cs プロジェクト: satela/xjhU3d
	/// <summary>
	/// Selection change is delayed on purpose. This way selection changes during event processing won't cause
	/// the newly selected widget to continue processing when it is it's turn. Example: pressing 'tab' on one
	/// button selects the next button, and then it also processes its 'tab' in turn, selecting the next one.
	/// </summary>

	System.Collections.IEnumerator ChangeSelection ()
	{
		yield return new WaitForEndOfFrame();
		Notify(mCurrentSelection, "OnSelect", false);
		mCurrentSelection = mNextSelection;
		mNextSelection = null;

		if (mCurrentSelection != null)
		{
			current = this;
			currentCamera = mCam;
			UICamera.currentScheme = mNextScheme;
			inputHasFocus = (mCurrentSelection.GetComponent<UIInput>() != null);
			Notify(mCurrentSelection, "OnSelect", true);
			current = null;
		}
		else inputHasFocus = false;
	}
コード例 #60
0
ファイル: TitleScreen.cs プロジェクト: Danathus/ggj-2015-oj
    // 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 );
    }