Ejemplo n.º 1
0
    /// <summary>
    /// Update touch-based events.
    /// </summary>
    void ProcessTouches()
    {
        for (int i = 0; i < Input.touchCount; ++i)
        {
            Touch input = Input.GetTouch(i);
            currentTouchID = input.fingerId;
            currentTouch = GetTouch(currentTouchID);

            bool pressed = (input.phase == TouchPhase.Began);
            bool unpressed = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended);

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

            currentTouch.pos = input.position;
            currentTouch.current = Raycast(currentTouch.pos, ref lastHit) ? lastHit.collider.gameObject : fallThrough;
            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;

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

            // If the touch has ended, remove it from the list
            if (unpressed) RemoveTouch(currentTouchID);
            currentTouch = null;
        }
    }
Ejemplo n.º 2
0
	/// <summary>
	/// Get or create a touch event.
	/// </summary>

	static public MouseOrTouch GetTouch (int id)
	{
		MouseOrTouch touch = null;

		if (id < 0) return GetMouse(-id - 1);

		if (!mTouches.TryGetValue(id, out touch))
		{
			touch = new MouseOrTouch();
			touch.pressTime = RealTime.time;
			touch.touchBegan = true;
			mTouches.Add(id, touch);
		}
		return touch;
	}
Ejemplo n.º 3
0
    /// <summary>
    /// Update mouse input.
    /// </summary>
    void ProcessMouse()
    {
        bool updateRaycast = (Time.timeScale < 0.9f);

        if (!updateRaycast)
        {
            for (int i = 0; i < 3; ++i)
            {
                if (Input.GetMouseButton(i) || Input.GetMouseButtonUp(i))
                {
                    updateRaycast = true;
                    break;
                }
            }
        }

        // Update the position and delta
        mMouse[0].pos = Input.mousePosition;
        mMouse[0].delta = mMouse[0].pos - lastTouchPosition;

        bool posChanged = (mMouse[0].pos != lastTouchPosition);
        lastTouchPosition = mMouse[0].pos;

        // Update the object under the mouse
        if (updateRaycast) mMouse[0].current = Raycast(Input.mousePosition, ref lastHit) ? lastHit.collider.gameObject : fallThrough;

        // 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;
            mMouse[i].current = mMouse[0].current;
        }

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

        for (int i = 0; i < 3; ++i)
        {
            if (Input.GetMouseButton(i))
            {
                isPressed = true;
                break;
            }
        }

        // If the position changed, reset the tooltip
        if (posChanged)
        {
            if (mTooltipTime != 0f) mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
            else if (mTooltip != null) ShowTooltip(false);
        }

        // The button was released over a different object -- remove the highlight from the previous
        if (!isPressed && mHover != null && mHover != mMouse[0].current)
        {
            if (mTooltip != null) ShowTooltip(false);
            Highlight(mHover, 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);

            currentTouch = mMouse[i];
            currentTouchID = -1 - 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);
        }
        currentTouch = null;

        // If nothing is pressed and there is an object under the touch, highlight it
        if (!isPressed && mHover != mMouse[0].current)
        {
            mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
            mHover = mMouse[0].current;
            Highlight(mHover, true);
        }
    }
Ejemplo n.º 4
0
	/// <summary>
	/// Process fake touch events where the mouse acts as a touch device.
	/// Useful for testing mobile functionality in the editor.
	/// </summary>

	void ProcessFakeTouches ()
	{
		bool pressed = Input.GetMouseButtonDown(0);
		bool unpressed = Input.GetMouseButtonUp(0);
		bool held = Input.GetMouseButton(0);

		if (pressed || unpressed || held)
		{
			currentTouchID = 1;
			currentTouch = mMouse[0];
			currentTouch.touchBegan = pressed;

			if (pressed)
			{
				currentTouch.pressTime = RealTime.time;
				activeTouches.Add(currentTouch);
			}

			Vector2 pos = Input.mousePosition;
			currentTouch.delta = pos - currentTouch.pos;
			currentTouch.pos = pos;

			// Raycast into the screen
			Raycast(currentTouch);

			// 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 events from this touch
			currentKey = KeyCode.None;
			ProcessTouch(pressed, unpressed);

			// If the touch has ended, remove it from the list
			if (unpressed) activeTouches.Remove(currentTouch);
			currentTouch.last = null;
			currentTouch = null;
		}
	}
Ejemplo n.º 5
0
	/// <summary>
	/// Get or create a touch event. If you are trying to iterate through a list of active touches, use activeTouches instead.
	/// </summary>

	static public MouseOrTouch GetTouch (int id, bool createIfMissing = false)
	{
		if (id < 0) return GetMouse(-id - 1);

		for (int i = 0, imax = mTouchIDs.Count; i < imax; ++i)
			if (mTouchIDs[i] == id) return activeTouches[i];

		if (createIfMissing)
		{
			MouseOrTouch touch = new MouseOrTouch();
			touch.pressTime = RealTime.time;
			touch.touchBegan = true;
			activeTouches.Add(touch);
			mTouchIDs.Add(id);
			return touch;
		}
		return null;
	}
Ejemplo n.º 6
0
	/// <summary>
	/// Update touch-based events.
	/// </summary>

	public void ProcessTouches ()
	{
		for (int i = 0; i < Input.touchCount; ++i)
		{
			Touch input = Input.GetTouch(i);

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

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

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

			currentTouch.pos = input.position;
			if (!Raycast(currentTouch.pos, out lastHit)) hoveredObject = fallThrough;
			if (hoveredObject == null) hoveredObject = genericEventHandler;
			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 (input.tapCount > 1) currentTouch.clickTime = Time.realtimeSinceStartup;

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

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

			// Don't consider other touches
			if (!allowMultiTouch) break;
		}
	}
Ejemplo n.º 7
0
	/// <summary>
	/// Raycast into the screen underneath the touch and update its 'current' value.
	/// </summary>

	static public void Raycast (MouseOrTouch touch)
	{
		if (!Raycast(touch.pos)) mRayHitObject = fallThrough;
		if (mRayHitObject == null) mRayHitObject = mGenericHandler;
		touch.last = touch.current;
		touch.current = mRayHitObject;
		mLastPos = touch.pos;
	}
Ejemplo n.º 8
0
    /// <summary>
    /// Get or create a touch event.
    /// </summary>
    MouseOrTouch GetTouch(int id)
    {
        if (!allowMultiTouch) id = 1;

        MouseOrTouch touch;

        if (!mTouches.TryGetValue(id, out touch))
        {
            touch = new MouseOrTouch();
            mTouches.Add(id, touch);
        }
        return touch;
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Update mouse input.
    /// </summary>

    void ProcessMouse()
    {
        if (useMouse && Application.isPlaying && handlesEvents)
        {
            GameObject go = Raycast(Frontiers.InterfaceActionManager.MousePosition /*Input.mousePosition*/, ref lastHit) ? lastHit.collider.gameObject : fallThrough;
            for (int i = 0; i < 3; ++i)
            {
                mMouse[i].current = go;
            }
        }

        bool updateRaycast = (Time.timeScale < 0.9f);

        if (!updateRaycast)
        {
            /*
             * for (int i = 0; i < 3; ++i) {
             *              if (Input.GetMouseButton(i) || Input.GetMouseButtonUp(i)) {
             *                              updateRaycast = true;
             *                              break;
             *              }
             * }
             */
            //now using action mananger
            if ((Frontiers.InterfaceActionManager.Get.CursorClickDown || Frontiers.InterfaceActionManager.Get.CursorClickUp) ||
                (Frontiers.InterfaceActionManager.Get.CursorRightClickDown || Frontiers.InterfaceActionManager.Get.CursorRightClickUp))
            {
                updateRaycast = true;
            }
        }

        // Update the position and delta
        mMouse[0].pos   = Frontiers.InterfaceActionManager.MousePosition;                      //Input.mousePosition;
        mMouse[0].delta = mMouse[0].pos - lastTouchPosition;

        bool posChanged = (mMouse[0].pos != lastTouchPosition);

        lastTouchPosition = mMouse[0].pos;

        // Update the object under the mouse
        if (updateRaycast)
        {
            mMouse[0].current = Raycast(Frontiers.InterfaceActionManager.MousePosition /*Input.mousePosition*/, ref lastHit) ? lastHit.collider.gameObject : fallThrough;
        }

        // 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;
            mMouse[i].current = mMouse[0].current;
        }

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

        /*
         * for (int i = 0; i < 3; ++i) {
         *              if (Input.GetMouseButton(i)) {
         *                              isPressed = true;
         *                              break;
         *              }
         * }
         */
        //Changed
        isPressed = Frontiers.InterfaceActionManager.Get.CursorClickDown | Frontiers.InterfaceActionManager.Get.CursorRightClickDown;

        if (isPressed)
        {
            // A button was pressed -- cancel the tooltip
            mTooltipTime = 0f;
        }
        else if (posChanged && (!stickyTooltip || mHover != mMouse[0].current))
        {
            if (mTooltipTime != 0f)
            {
                // Delay the tooltip
                mTooltipTime = Frontiers.WorldClock.RTDeltaTime + 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 (!isPressed && mHover != null && mHover != mMouse[0].current)
        {
            if (mTooltip != null)
            {
                ShowTooltip(false);
            }
            Highlight(mHover, 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);
         *
         *              currentTouch = mMouse[i];
         *              currentTouchID = -1 - 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);
         * }
         */

        //this now uses interface action manager
        #region left click
        bool pressed   = Frontiers.InterfaceActionManager.Get.CursorClickDown;
        bool unpressed = Frontiers.InterfaceActionManager.Get.CursorClickUp;

        currentTouch   = mMouse[0];
        currentTouchID = -1;

        // 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);
        #endregion

        #region cursor right click
        pressed   = Frontiers.InterfaceActionManager.Get.CursorRightClickDown;
        unpressed = Frontiers.InterfaceActionManager.Get.CursorRightClickUp;

        currentTouch   = mMouse[1];
        currentTouchID = -1;

        // 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);
        #endregion

        currentTouch = null;

        // If nothing is pressed and there is an object under the touch, highlight it
        if (!isPressed && mHover != mMouse[0].current)
        {
            mTooltipTime = Frontiers.WorldClock.RealTime + tooltipDelay;
            mHover       = mMouse[0].current;
            Highlight(mHover, true);
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Process keyboard and joystick events.
    /// </summary>

    void ProcessOthers()
    {
        currentTouchID = -100;
        currentTouch   = mController;

        // If this is an input field, ignore WASD and Space key presses
        bool hasInput = (mSel != null && mSel.GetComponent <UIInput>() != null);

        // Enter key and joystick button 1 keys are treated the same -- as a "click"
        bool returnKeyDown = (useKeyboard && (Input.GetKeyDown(KeyCode.Return) || (!hasInput && Input.GetKeyDown(KeyCode.Space))));
        bool buttonKeyDown = (useController && Input.GetKeyDown(KeyCode.JoystickButton0));
        bool returnKeyUp   = (useKeyboard && (Input.GetKeyUp(KeyCode.Return) || (!hasInput && Input.GetKeyUp(KeyCode.Space))));
        bool buttonKeyUp   = (useController && Input.GetKeyUp(KeyCode.JoystickButton0));

        bool down = returnKeyDown || buttonKeyDown;
        bool up   = returnKeyUp || buttonKeyUp;

        if (down || up)
        {
            currentTouch.current = mSel;
            ProcessTouch(down, up);
        }

        int vertical   = 0;
        int horizontal = 0;

        if (useKeyboard)
        {
            if (hasInput)
            {
                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)
        {
            mSel.SendMessage("OnKey", vertical > 0 ? KeyCode.UpArrow : KeyCode.DownArrow, SendMessageOptions.DontRequireReceiver);
        }
        if (horizontal != 0)
        {
            mSel.SendMessage("OnKey", horizontal > 0 ? KeyCode.RightArrow : KeyCode.LeftArrow, SendMessageOptions.DontRequireReceiver);
        }
        if (useKeyboard && Input.GetKeyDown(KeyCode.Tab))
        {
            mSel.SendMessage("OnKey", KeyCode.Tab, SendMessageOptions.DontRequireReceiver);
        }
        if (useController && Input.GetKeyUp(KeyCode.JoystickButton1))
        {
            mSel.SendMessage("OnKey", KeyCode.Escape, SendMessageOptions.DontRequireReceiver);
        }

        currentTouch = null;
    }
    protected virtual void OnMouseClick(MouseOrTouch touch, bool isPressed) {
        if (isPressed || touch.dragStarted || UICamera.isOverUI) { return; }
        if (touch.fingerId != 0 || city.HoveredCityObject == null) { return; }
        if (!IsInteractable(city.HoveredCityObject)) { return; }

        // When the player clicks the lion, add some money
        if (city.HoveredCityObject is CityLion) {
            (city.HoveredCityObject as CityLion).Cheat();
            return;
        }

        stateManager.SetStateWithData<EditCityObjectState>(city.HoveredCityObject);
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Update touch-based events.
    /// </summary>

    public void ProcessTouches()
    {
        for (int i = 0; i < Input.touchCount; ++i)
        {
            Touch input = Input.GetTouch(i);

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

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

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

            currentTouch.pos = input.position;
            hoveredObject    = Raycast(currentTouch.pos, ref lastHit) ? lastHit.collider.gameObject : fallThrough;
            if (hoveredObject == null)
            {
                hoveredObject = genericEventHandler;
            }
            currentTouch.current = hoveredObject;
            lastTouchPosition    = currentTouch.pos;

            //edit by zbz

            GameObject touchGameObj = Raycast(currentTouch.pos, ref touchInOrOutObj)?touchInOrOutObj.collider.gameObject : fallThrough;
            //currentTouch.delta.x >0  || currentTouch.delta.y >0   it means Current Phase is TouchPhase.Began.
            if (currentTouch.delta == Vector2.zero)
            {
                Debug.Log("currentTouch.delta  == Vector2.zero");
                currentTouch.touchPhase = TouchPhase.Began;
                //if touchInOrOutObj is null, it means that the figer touch nothing.
                if (touchGameObj == null)
                {
                    Debug.Log("touchGameObj == null");
                    currentTouch.curTouchInOrOut = TouchInSideOrOutSide.TouchOutSide;
                    currentTouch.btnMessage      = null;
                }
                else
                {
                    Debug.Log("touchGameObj != null");

                    GameObject      touchObj   = touchGameObj;
                    UIButtonMessage btnMessage = touchObj.GetComponent <UIButtonMessage>();

                    if (btnMessage == null)
                    {
                        Debug.Log("btnMessage == null");
                        currentTouch.curTouchInOrOut = TouchInSideOrOutSide.None;
                    }
                    else
                    {
                        Debug.Log("btnMessage != null");
                        currentTouch.touchInOrOutObj = touchObj;
                        currentTouch.curTouchInOrOut = TouchInSideOrOutSide.TouchInSide;
                    }
                }
            }
            else if (currentTouch.delta.x > 0 || currentTouch.delta.y > 0)
            {
                Debug.Log("currentTouch.delta.x > 0 || currentTouch.delta.y > 0");

                if (currentTouch.curTouchInOrOut != TouchInSideOrOutSide.None)
                {
                    if (currentTouch.curTouchInOrOut == TouchInSideOrOutSide.TouchInSide &&
                        touchGameObj == null)
                    {
                        currentTouch.OnMessageTouchInOrOut = TouchInSideOrOutSide.TouchOutSide;
                        currentTouch.curTouchInOrOut       = TouchInSideOrOutSide.TouchOutSide;
                        currentTouch.btnMessage            = null;
                    }
                    else if (currentTouch.curTouchInOrOut == TouchInSideOrOutSide.TouchOutSide &&
                             touchGameObj != null)
                    {
                        currentTouch.OnMessageTouchInOrOut = TouchInSideOrOutSide.TouchInSide;
                        currentTouch.curTouchInOrOut       = TouchInSideOrOutSide.TouchInSide;
                        GameObject touchObj = touchGameObj;
                        if (touchObj != null)
                        {
                            UIButtonMessage btnMessage = touchObj.GetComponent <UIButtonMessage>();
                            currentTouch.btnMessage      = btnMessage;
                            currentTouch.touchInOrOutObj = touchObj;
                        }
                    }
                }
                else
                {
                    Debug.Log("currentTouch.curTouchInOrOut == TouchInSideOrOutSide.None");
                }
            }


            //edit by zbz  touchover
            if (touchGameObj != null)
            {
                //Reset
                if (currentTouch.touchOverObj != null &&
                    currentTouch.touchOverObj != touchGameObj)
                {
                    currentTouch.nDelayOverTime     = -1;
                    currentTouch.touchOverObj       = null;
                    currentTouch.OnMessageTouchOver = TouchInSideOrOutSide.None;
                }

                if (currentTouch.OnMessageTouchOver == TouchInSideOrOutSide.None &&
                    currentTouch.nDelayOverTime < 0)
                {
                    currentTouch.touchOverObj       = touchGameObj;
                    currentTouch.OnMessageTouchOver = TouchInSideOrOutSide.TouchOver;
                    currentTouch.nDelayOverTime     = 0;
                }
                else if (currentTouch.OnMessageTouchOver == TouchInSideOrOutSide.None &&
                         currentTouch.nDelayOverTime >= MaxDelayOverTime)
                {
                    currentTouch.nDelayOverTime     = -1;
                    currentTouch.touchOverObj       = null;
                    currentTouch.OnMessageTouchOver = TouchInSideOrOutSide.None;
                }
                else
                {
                    currentTouch.OnMessageTouchOver = TouchInSideOrOutSide.None;
                    currentTouch.nDelayOverTime++;
                }
            }
            else
            {
                currentTouch.nDelayOverTime     = -1;
                currentTouch.touchOverObj       = null;
                currentTouch.OnMessageTouchOver = TouchInSideOrOutSide.None;
            }

            // 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 (input.tapCount > 1)
            {
                currentTouch.clickTime = Time.realtimeSinceStartup;
            }

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

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

            // Don't consider other touches
            if (!allowMultiTouch)
            {
                break;
            }
        }
    }
Ejemplo n.º 13
0
    public void ProcessMouse()
    {
        lastTouchPosition = Input.mousePosition;
        mMouse[0].delta   = lastTouchPosition - mMouse[0].pos;
        mMouse[0].pos     = lastTouchPosition;
        bool flag = mMouse[0].delta.sqrMagnitude > 0.001f;

        for (int i = 1; i < 3; i++)
        {
            mMouse[i].pos   = mMouse[0].pos;
            mMouse[i].delta = mMouse[0].delta;
        }
        bool flag2 = false;
        bool flag3 = false;

        for (int i = 0; i < 3; i++)
        {
            if (Input.GetMouseButtonDown(i))
            {
                currentScheme = ControlScheme.Mouse;
                flag3         = true;
                flag2         = true;
            }
            else if (Input.GetMouseButton(i))
            {
                currentScheme = ControlScheme.Mouse;
                flag2         = true;
            }
        }
        if (flag2 || flag || 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 flag4 = mMouse[0].last != mMouse[0].current;

        if (flag4)
        {
            currentScheme = ControlScheme.Mouse;
        }
        if (flag2)
        {
            mTooltipTime = 0f;
        }
        else if (flag && (!stickyTooltip || flag4))
        {
            if (mTooltipTime != 0f)
            {
                mTooltipTime = RealTime.time + tooltipDelay;
            }
            else if (mTooltip != null)
            {
                ShowTooltip(val: false);
            }
        }
        if ((flag3 || !flag2) && mHover != null && flag4)
        {
            currentScheme = ControlScheme.Mouse;
            if (mTooltip != null)
            {
                ShowTooltip(val: false);
            }
            Notify(mHover, "OnHover", false);
            mHover = null;
        }
        for (int i = 0; i < 3; i++)
        {
            bool mouseButtonDown = Input.GetMouseButtonDown(i);
            bool mouseButtonUp   = Input.GetMouseButtonUp(i);
            if (mouseButtonDown || mouseButtonUp)
            {
                currentScheme = ControlScheme.Mouse;
            }
            currentTouch   = mMouse[i];
            currentTouchID = -1 - i;
            currentKey     = (KeyCode)(323 + i);
            if (mouseButtonDown)
            {
                currentTouch.pressedCam = currentCamera;
            }
            else if (currentTouch.pressed != null)
            {
                currentCamera = currentTouch.pressedCam;
            }
            ProcessTouch(mouseButtonDown, mouseButtonUp);
            currentKey = KeyCode.None;
        }
        currentTouch = null;
        if (!flag2 && flag4)
        {
            currentScheme = ControlScheme.Mouse;
            mTooltipTime  = RealTime.time + tooltipDelay;
            mHover        = mMouse[0].current;
            Notify(mHover, "OnHover", true);
        }
        mMouse[0].last = mMouse[0].current;
        for (int i = 1; i < 3; i++)
        {
            mMouse[i].last = mMouse[0].last;
        }
    }
Ejemplo n.º 14
0
    public void ProcessOthers()
    {
        currentTouchID = -100;
        currentTouch   = controller;
        bool flag  = false;
        bool flag2 = false;

        if (submitKey0 != 0 && Input.GetKeyDown(submitKey0))
        {
            currentKey = submitKey0;
            flag       = true;
        }
        if (submitKey1 != 0 && Input.GetKeyDown(submitKey1))
        {
            currentKey = submitKey1;
            flag       = true;
        }
        if (submitKey0 != 0 && Input.GetKeyUp(submitKey0))
        {
            currentKey = submitKey0;
            flag2      = true;
        }
        if (submitKey1 != 0 && Input.GetKeyUp(submitKey1))
        {
            currentKey = submitKey1;
            flag2      = true;
        }
        if (flag || flag2)
        {
            currentScheme        = ControlScheme.Controller;
            currentTouch.last    = currentTouch.current;
            currentTouch.current = mCurrentSelection;
            ProcessTouch(flag, flag2);
            currentTouch.last = null;
        }
        int num  = 0;
        int num2 = 0;

        if (useKeyboard)
        {
            if (inputHasFocus)
            {
                num  += GetDirection(KeyCode.UpArrow, KeyCode.DownArrow);
                num2 += GetDirection(KeyCode.RightArrow, KeyCode.LeftArrow);
            }
            else
            {
                num  += GetDirection(KeyCode.W, KeyCode.UpArrow, KeyCode.S, KeyCode.DownArrow);
                num2 += GetDirection(KeyCode.D, KeyCode.RightArrow, KeyCode.A, KeyCode.LeftArrow);
            }
        }
        if (useController)
        {
            if (!string.IsNullOrEmpty(verticalAxisName))
            {
                num += GetDirection(verticalAxisName);
            }
            if (!string.IsNullOrEmpty(horizontalAxisName))
            {
                num2 += GetDirection(horizontalAxisName);
            }
        }
        if (num != 0)
        {
            currentScheme = ControlScheme.Controller;
            Notify(mCurrentSelection, "OnKey", (num > 0) ? KeyCode.UpArrow : KeyCode.DownArrow);
        }
        if (num2 != 0)
        {
            currentScheme = ControlScheme.Controller;
            Notify(mCurrentSelection, "OnKey", (num2 > 0) ? KeyCode.RightArrow : KeyCode.LeftArrow);
        }
        if (useKeyboard && Input.GetKeyDown(KeyCode.Tab))
        {
            currentKey    = KeyCode.Tab;
            currentScheme = ControlScheme.Controller;
            Notify(mCurrentSelection, "OnKey", KeyCode.Tab);
        }
        if (cancelKey0 != 0 && Input.GetKeyDown(cancelKey0))
        {
            currentKey    = cancelKey0;
            currentScheme = ControlScheme.Controller;
            Notify(mCurrentSelection, "OnKey", KeyCode.Escape);
        }
        if (cancelKey1 != 0 && Input.GetKeyDown(cancelKey1))
        {
            currentKey    = cancelKey1;
            currentScheme = ControlScheme.Controller;
            Notify(mCurrentSelection, "OnKey", KeyCode.Escape);
        }
        currentTouch = null;
        currentKey   = KeyCode.None;
    }
Ejemplo n.º 15
0
	/// <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
		}
	}
Ejemplo n.º 16
0
    /// <summary>
    /// Process keyboard and joystick events.
    /// </summary>

    void ProcessOthers()
    {
        currentTouchID = -100;
        currentTouch   = mController;

        // If this is an input field, ignore WASD and Space key presses
        inputHasFocus = (mSel != null && mSel.GetComponent <UIInput>() != null);

        bool submitKeyDown = (submitKey0 != KeyCode.None && Input.GetKeyDown(submitKey0)) || (submitKey1 != KeyCode.None && Input.GetKeyDown(submitKey1));
        bool submitKeyUp   = (submitKey0 != KeyCode.None && Input.GetKeyUp(submitKey0)) || (submitKey1 != KeyCode.None && Input.GetKeyUp(submitKey1));

        if (submitKeyDown || submitKeyUp)
        {
            currentTouch.current = mSel;
            ProcessTouch(submitKeyDown, submitKeyUp);
        }

        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)
        {
            mSel.SendMessage("OnKey", vertical > 0 ? KeyCode.UpArrow : KeyCode.DownArrow, SendMessageOptions.DontRequireReceiver);
        }
        if (horizontal != 0)
        {
            mSel.SendMessage("OnKey", horizontal > 0 ? KeyCode.RightArrow : KeyCode.LeftArrow, SendMessageOptions.DontRequireReceiver);
        }
        if (useKeyboard && Input.GetKeyDown(KeyCode.Tab))
        {
            mSel.SendMessage("OnKey", KeyCode.Tab, SendMessageOptions.DontRequireReceiver);
        }

        // Send out the cancel key notification
        if (cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0))
        {
            mSel.SendMessage("OnKey", KeyCode.Escape, SendMessageOptions.DontRequireReceiver);
        }
        if (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1))
        {
            mSel.SendMessage("OnKey", KeyCode.Escape, SendMessageOptions.DontRequireReceiver);
        }

        currentTouch = null;
    }
Ejemplo n.º 17
0
	/// <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;
	}
Ejemplo n.º 18
0
	/// <summary>
	/// Update mouse input.
	/// </summary>

	public void ProcessMouse ()
	{
		lastTouchPosition = Input.mousePosition;
		bool highlightChanged = (mMouse[0].last != mMouse[0].current);

		// Update the position and delta
		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;

		for (int i = 0; i < 3; ++i)
		{
			if (Input.GetMouseButton(i))
			{
				isPressed = true;
				break;
			}
		}

		if (isPressed)
		{
			// A button was pressed -- cancel the tooltip
			mTooltipTime = 0f;
		}
		else if (useMouse && 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 (useMouse && !isPressed && mHover != null && highlightChanged)
		{
			if (mTooltip != null) ShowTooltip(false);
			Highlight(mHover, false);
			mHover = null;
		}

		// Process all 3 mouse buttons as individual touches
		if (useMouse)
		{
			for (int i = 0; i < 3; ++i)
			{
				bool pressed = Input.GetMouseButtonDown(i);
				bool unpressed = Input.GetMouseButtonUp(i);
	
				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 (useMouse && !isPressed && highlightChanged)
		{
			mTooltipTime = RealTime.time + tooltipDelay;
			mHover = mMouse[0].current;
			Highlight(mHover, true);
		}

		// Update the last value
		mMouse[0].last = mMouse[0].current;
		for (int i = 1; i < 3; ++i) mMouse[i].last = mMouse[0].last;
	}
Ejemplo n.º 19
0
	/// <summary>
	/// Get or create a touch event.
	/// </summary>

	static public MouseOrTouch GetTouch (int id)
	{
		MouseOrTouch touch = null;

		if (!mTouches.TryGetValue(id, out touch))
		{
			touch = new MouseOrTouch();
			touch.touchBegan = true;
			mTouches.Add(id, touch);
		}
		return touch;
	}
Ejemplo n.º 20
0
    /// <summary>
    /// Update mouse input.
    /// </summary>

    public void ProcessMouse()
    {
        lastTouchPosition = Input.mousePosition;
        bool highlightChanged = (mMouse[0].last != mMouse[0].current);

        // Update the position and delta
        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;

        for (int i = 0; i < 3; ++i)
        {
            if (Input.GetMouseButton(i))
            {
                isPressed = true;
                break;
            }
        }

        if (isPressed)
        {
            // A button was pressed -- cancel the tooltip
            mTooltipTime = 0f;
        }
        else if (useMouse && 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 (useMouse && !isPressed && mHover != null && highlightChanged)
        {
            if (mTooltip != null)
            {
                ShowTooltip(false);
            }
            Highlight(mHover, false);
            mHover = null;
        }

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

                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 (useMouse && !isPressed && highlightChanged)
        {
            mTooltipTime = RealTime.time + tooltipDelay;
            mHover       = mMouse[0].current;
            Highlight(mHover, true);
        }

        // Update the last value
        mMouse[0].last = mMouse[0].current;
        for (int i = 1; i < 3; ++i)
        {
            mMouse[i].last = mMouse[0].last;
        }
    }
Ejemplo n.º 21
0
	/// <summary>
	/// Update mouse input.
	/// </summary>

	public void ProcessMouse ()
	{
		// Is any button currently pressed?
		bool isPressed = false;
		bool justPressed = false;

		for (int i = 0; i < 3; ++i)
		{
			if (Input.GetMouseButtonDown(i))
			{
				currentKey = KeyCode.Mouse0 + i;
				justPressed = true;
				isPressed = true;
			}
			else if (Input.GetMouseButton(i))
			{
				currentKey = KeyCode.Mouse0 + i;
				isPressed = true;
			}
		}

		// We're currently using touches -- do nothing
		if (currentScheme == ControlScheme.Touch) return;

		currentTouch = mMouse[0];

		// Update the position and delta
		Vector2 pos = Input.mousePosition;

		if (currentTouch.ignoreDelta == 0)
		{
			currentTouch.delta = pos - currentTouch.pos;
		}
		else
		{
			--currentTouch.ignoreDelta;
			currentTouch.delta.x = 0f;
			currentTouch.delta.y = 0f;
		}

		float sqrMag = currentTouch.delta.sqrMagnitude;
		currentTouch.pos = pos;
		mLastPos = pos;

		bool posChanged = false;

		if (currentScheme != ControlScheme.Mouse)
		{
			if (sqrMag < 0.001f) return; // Nothing changed and we are not using the mouse -- exit
			currentKey = KeyCode.Mouse0;
			posChanged = true;
		}
		else if (sqrMag > 0.001f) posChanged = true;

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

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

		bool highlightChanged = (currentTouch.last != currentTouch.current);
		bool wasPressed = (currentTouch.pressed != null);

		if (!wasPressed)
			hoveredObject = currentTouch.current;

		currentTouchID = -1;
		if (highlightChanged) currentKey = KeyCode.Mouse0;

		if (!isPressed && posChanged && (!stickyTooltip || highlightChanged))
		{
			if (mTooltipTime != 0f)
			{
				// Delay the tooltip
				mTooltipTime = Time.unscaledTime + tooltipDelay;
			}
			else if (mTooltip != null)
			{
				// Hide the tooltip
				ShowTooltip(null);
			}
		}

		// Generic mouse move notifications
		if (posChanged && onMouseMove != null)
		{
			onMouseMove(currentTouch.delta);
			currentTouch = null;
		}

		// The button was released over a different object -- remove the highlight from the previous
		if (highlightChanged && (justPressed || (wasPressed && !isPressed)))
			hoveredObject = 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) currentKey = KeyCode.Mouse0 + i;
			currentTouch = mMouse[i];

#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
			if (commandClick && i == 0 && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)))
			{
				currentTouchID = -2;
				currentKey = KeyCode.Mouse1;
			}
			else
#endif
			{
				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;
				currentTouch.pressTime = RealTime.time;
			}
			else if (currentTouch.pressed != null) currentCamera = currentTouch.pressedCam;
	
			// Process the mouse events
			ProcessTouch(pressed, unpressed);
		}

		// If nothing is pressed and there is an object under the touch, highlight it
		if (!isPressed && highlightChanged)
		{
			currentTouch = mMouse[0];
			mTooltipTime = Time.unscaledTime + tooltipDelay;
			currentTouchID = -1;
			currentKey = KeyCode.Mouse0;
			hoveredObject = currentTouch.current;
		}

		currentTouch = null;

		// Update the last value
		mMouse[0].last = mMouse[0].current;
		for (int i = 1; i < 3; ++i) mMouse[i].last = mMouse[0].last;
	}
Ejemplo n.º 22
0
    public void ProcessOthers()
    {
        currentTouchID = -100;
        currentTouch   = mController;
        inputHasFocus  = mSel != null && mSel.GetComponent <UIInput>() != null;
        var pressed   = submitKey0 != KeyCode.None && Input.GetKeyDown(submitKey0) || submitKey1 != KeyCode.None && Input.GetKeyDown(submitKey1);
        var unpressed = submitKey0 != KeyCode.None && Input.GetKeyUp(submitKey0) || submitKey1 != KeyCode.None && Input.GetKeyUp(submitKey1);

        if (pressed || unpressed)
        {
            currentTouch.current = mSel;
            ProcessTouch(pressed, unpressed);
            currentTouch.current = null;
        }

        var num  = 0;
        var num2 = 0;

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

        if (useController)
        {
            if (!string.IsNullOrEmpty(verticalAxisName))
            {
                num += GetDirection(verticalAxisName);
            }

            if (!string.IsNullOrEmpty(horizontalAxisName))
            {
                num2 += GetDirection(horizontalAxisName);
            }
        }

        if (num != 0)
        {
            Notify(mSel, "OnKey", num <= 0 ? KeyCode.DownArrow : KeyCode.UpArrow);
        }

        if (num2 != 0)
        {
            Notify(mSel, "OnKey", num2 <= 0 ? KeyCode.LeftArrow : KeyCode.RightArrow);
        }

        if (useKeyboard && Input.GetKeyDown(KeyCode.Tab))
        {
            Notify(mSel, "OnKey", KeyCode.Tab);
        }

        if (cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0))
        {
            Notify(mSel, "OnKey", KeyCode.Escape);
        }

        if (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1))
        {
            Notify(mSel, "OnKey", KeyCode.Escape);
        }

        currentTouch = null;
    }
Ejemplo n.º 23
0
    /// <summary>
    /// Process keyboard and joystick events.
    /// </summary>
    void ProcessOthers()
    {
        currentTouchID = -100;
        currentTouch = mJoystick;

        // Enter key and joystick button 1 keys are treated the same -- as a "click"
        bool returnKeyDown	= (useKeyboard	 && (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space)));
        bool buttonKeyDown	= (useController &&  Input.GetKeyDown(KeyCode.JoystickButton0));
        bool returnKeyUp	= (useKeyboard	 && (Input.GetKeyUp(KeyCode.Return) || Input.GetKeyUp(KeyCode.Space)));
        bool buttonKeyUp	= (useController &&  Input.GetKeyUp(KeyCode.JoystickButton0));

        bool down	= returnKeyDown || buttonKeyDown;
        bool up		= returnKeyUp || buttonKeyUp;

        if (down || up)
        {
            currentTouch.hover = mSel;
            currentTouch.current = mSel;
            ProcessTouch(down, up);
        }

        int vertical = 0;
        int horizontal = 0;

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

        if (useController)
        {
            vertical += GetDirection("Vertical");
            horizontal += GetDirection("Horizontal");
        }

        // Send out key notifications
        if (vertical != 0) mSel.SendMessage("OnKey", vertical > 0 ? KeyCode.UpArrow : KeyCode.DownArrow, SendMessageOptions.DontRequireReceiver);
        if (horizontal != 0) mSel.SendMessage("OnKey", horizontal > 0 ? KeyCode.RightArrow : KeyCode.LeftArrow, SendMessageOptions.DontRequireReceiver);
        if (useKeyboard && Input.GetKeyDown(KeyCode.Tab)) mSel.SendMessage("OnKey", KeyCode.Tab, SendMessageOptions.DontRequireReceiver);
        if (useController && Input.GetKeyUp(KeyCode.JoystickButton1)) mSel.SendMessage("OnKey", KeyCode.Escape, SendMessageOptions.DontRequireReceiver);

        currentTouch = null;
    }
Ejemplo n.º 24
0
    /// <summary>
    /// Process the events of the specified touch.
    /// </summary>

    void ProcessTouch(MouseOrTouch touch, bool pressed, bool unpressed)
    {
        // If we're using the mouse for input, we should send out a hover(false) message first
        if (touch.pressed == null && touch.hover != touch.current && touch.hover != null)
        {
            if (mTooltip != null)
            {
                ShowTooltip(false);
            }
            Highlight(touch.hover, false);
        }

        // Send the drag notification, intentionally before the pressed object gets changed
        if (touch.pressed != null && touch.delta.magnitude != 0f)
        {
            if (mTooltip != null)
            {
                ShowTooltip(false);
            }
            touch.totalDelta += touch.delta;
            touch.pressed.SendMessage("OnDrag", touch.delta, SendMessageOptions.DontRequireReceiver);

            float threshold = (touch == mMouse) ? 5f : 40f;
            if (touch.totalDelta.magnitude > threshold)
            {
                touch.considerForClick = false;
            }
        }

        // Send out the press message
        if (pressed)
        {
            if (mTooltip != null)
            {
                ShowTooltip(false);
            }
            touch.pressed          = touch.current;
            touch.considerForClick = true;
            touch.totalDelta       = Vector2.zero;
            if (touch.pressed != null)
            {
                touch.pressed.SendMessage("OnPress", true, SendMessageOptions.DontRequireReceiver);
            }

            // Clear the selection
            if (touch.pressed != mSel)
            {
                if (mTooltip != null)
                {
                    ShowTooltip(false);
                }
                selectedObject = null;
            }
        }

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

            if (touch.pressed != null)
            {
                touch.pressed.SendMessage("OnPress", false, SendMessageOptions.DontRequireReceiver);

                // Send a hover message to the object, but don't add it to the list of hovered items as it's already present
                if (touch.pressed == touch.hover)
                {
                    touch.pressed.SendMessage("OnHover", true, SendMessageOptions.DontRequireReceiver);
                }

                // If the button/touch was released on the same object, consider it a click and select it
                if (touch.pressed == touch.current)
                {
                    if (touch.pressed != mSel)
                    {
                        mSel = touch.pressed;
                        touch.pressed.SendMessage("OnSelect", true, SendMessageOptions.DontRequireReceiver);
                    }
                    else
                    {
                        mSel = touch.pressed;
                    }
                    if (touch.considerForClick)
                    {
                        touch.pressed.SendMessage("OnClick", touch.pressed, SendMessageOptions.DontRequireReceiver);
                    }
                }
                else                 // The button/touch was released on a different object
                {
                    // Send a drop notification (for drag & drop)
                    if (touch.current != null)
                    {
                        touch.current.SendMessage("OnDrop", touch.pressed, SendMessageOptions.DontRequireReceiver);
                    }

                    // If we're using mouse-based input, send a hover notification
                    Highlight(touch.pressed, false);
                }
            }
            touch.pressed = null;
        }

        // Send out a hover(true) message last
        if (useMouse && touch.pressed == null && touch.hover != touch.current)
        {
            mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
            touch.hover  = touch.current;
            Highlight(touch.hover, true);
        }
    }
Ejemplo n.º 25
0
	/// <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;
		NGUIDebug.debugRaycast = debug;

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

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

		// Update the keyboard and joystick events
		if ((useKeyboard || useController) && !disableController) 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) ? GetAxis(scrollAxisName) : 0f;

			if (scroll != 0f)
			{
				if (onScroll != null) onScroll(mHover, scroll);
				Notify(mHover, "OnScroll", scroll);
			}

			if (showTooltips && mTooltipTime != 0f && !UIPopupList.isOpen && mMouse[0].dragged == null &&
				(mTooltipTime < RealTime.time || GetKey(KeyCode.LeftShift) || GetKey(KeyCode.RightShift)))
			{
				currentTouch = mMouse[0];
				currentTouchID = -1;
				ShowTooltip(mHover);
			}
		}

		if (mTooltip != null && !NGUITools.GetActive(mTooltip))
			ShowTooltip(null);

		current = null;
		currentTouchID = -100;
	}
Ejemplo n.º 26
0
    public void ProcessMouse()
    {
        bool flag;

        if (!(flag = this.useMouse && (Time.timeScale < 0.9f)))
        {
            for (int k = 0; k < 3; k++)
            {
                if (Input.GetMouseButton(k) || Input.GetMouseButtonUp(k))
                {
                    flag = true;
                    break;
                }
            }
        }
        mMouse[0].pos   = Input.mousePosition;
        mMouse[0].delta = mMouse[0].pos - lastTouchPosition;
        bool flag2 = mMouse[0].pos != lastTouchPosition;

        lastTouchPosition = mMouse[0].pos;
        if (flag)
        {
            hoveredObject = !Raycast(Input.mousePosition, ref lastHit) ? fallThrough : lastHit.collider.gameObject;
            if (hoveredObject == null)
            {
                hoveredObject = genericEventHandler;
            }
            mMouse[0].current = hoveredObject;
        }
        for (int i = 1; i < 3; i++)
        {
            mMouse[i].pos     = mMouse[0].pos;
            mMouse[i].delta   = mMouse[0].delta;
            mMouse[i].current = mMouse[0].current;
        }
        bool flag3 = false;

        for (int j = 0; j < 3; j++)
        {
            if (Input.GetMouseButton(j))
            {
                flag3 = true;
                break;
            }
        }
        if (flag3)
        {
            this.mTooltipTime = 0f;
        }
        else if ((this.useMouse && flag2) && (!this.stickyTooltip || (mHover != mMouse[0].current)))
        {
            if (this.mTooltipTime != 0f)
            {
                this.mTooltipTime = Time.realtimeSinceStartup + this.tooltipDelay;
            }
            else if (this.mTooltip != null)
            {
                this.ShowTooltip(false);
            }
        }
        if ((this.useMouse && !flag3) && ((mHover != null) && (mHover != mMouse[0].current)))
        {
            if (this.mTooltip != null)
            {
                this.ShowTooltip(false);
            }
            Highlight(mHover, false);
            mHover = null;
        }
        if (this.useMouse)
        {
            for (int m = 0; m < 3; m++)
            {
                bool mouseButtonDown = Input.GetMouseButtonDown(m);
                bool mouseButtonUp   = Input.GetMouseButtonUp(m);
                currentTouch   = mMouse[m];
                currentTouchID = -1 - m;
                if (mouseButtonDown)
                {
                    currentTouch.pressedCam = currentCamera;
                }
                else if (currentTouch.pressed != null)
                {
                    currentCamera = currentTouch.pressedCam;
                }
                this.ProcessTouch(mouseButtonDown, mouseButtonUp);
            }
            currentTouch = null;
        }
        if ((this.useMouse && !flag3) && (mHover != mMouse[0].current))
        {
            this.mTooltipTime = Time.realtimeSinceStartup + this.tooltipDelay;
            mHover            = mMouse[0].current;
            Highlight(mHover, true);
        }
    }
Ejemplo n.º 27
0
    /// <summary>
    /// Get or create a touch event.
    /// </summary>
    MouseOrTouch GetTouch(int id)
    {
        MouseOrTouch touch;

        if (!mTouches.TryGetValue(id, out touch))
        {
            touch = new MouseOrTouch();
            mTouches.Add(id, touch);
        }
        return touch;
    }
Ejemplo n.º 28
0
    public void ProcessOthers()
    {
        currentTouchID = -100;
        currentTouch   = mController;
        inputHasFocus  = (mSel != null) && (mSel.GetComponent <UIInput>() != null);
        bool pressed   = ((this.submitKey0 == KeyCode.None) || !Input.GetKeyDown(this.submitKey0)) ? ((this.submitKey1 != KeyCode.None) && Input.GetKeyDown(this.submitKey1)) : true;
        bool unpressed = ((this.submitKey0 == KeyCode.None) || !Input.GetKeyUp(this.submitKey0)) ? ((this.submitKey1 != KeyCode.None) && Input.GetKeyUp(this.submitKey1)) : true;

        if (pressed || unpressed)
        {
            currentTouch.current = mSel;
            this.ProcessTouch(pressed, unpressed);
            currentTouch.current = null;
        }
        int num  = 0;
        int num2 = 0;

        if (this.useKeyboard)
        {
            if (inputHasFocus)
            {
                num  += GetDirection(KeyCode.UpArrow, KeyCode.DownArrow);
                num2 += GetDirection(KeyCode.RightArrow, KeyCode.LeftArrow);
            }
            else
            {
                num  += GetDirection(KeyCode.W, KeyCode.UpArrow, KeyCode.S, KeyCode.DownArrow);
                num2 += GetDirection(KeyCode.D, KeyCode.RightArrow, KeyCode.A, KeyCode.LeftArrow);
            }
        }
        if (this.useController)
        {
            if (!string.IsNullOrEmpty(this.verticalAxisName))
            {
                num += GetDirection(this.verticalAxisName);
            }
            if (!string.IsNullOrEmpty(this.horizontalAxisName))
            {
                num2 += GetDirection(this.horizontalAxisName);
            }
        }
        if (num != 0)
        {
            Notify(mSel, "OnKey", (num <= 0) ? KeyCode.DownArrow : KeyCode.UpArrow);
        }
        if (num2 != 0)
        {
            Notify(mSel, "OnKey", (num2 <= 0) ? KeyCode.LeftArrow : KeyCode.RightArrow);
        }
        if (this.useKeyboard && Input.GetKeyDown(KeyCode.Tab))
        {
            Notify(mSel, "OnKey", KeyCode.Tab);
        }
        if ((this.cancelKey0 != KeyCode.None) && Input.GetKeyDown(this.cancelKey0))
        {
            Notify(mSel, "OnKey", KeyCode.Escape);
        }
        if ((this.cancelKey1 != KeyCode.None) && Input.GetKeyDown(this.cancelKey1))
        {
            Notify(mSel, "OnKey", KeyCode.Escape);
        }
        currentTouch = null;
    }
Ejemplo n.º 29
0
    /// <summary>
    /// Process keyboard and joystick events.
    /// </summary>
    void ProcessOthers()
    {
        currentTouchID = -100;
        currentTouch = mController;

        // If this is an input field, ignore WASD and Space key presses
        bool hasInput = (mSel != null && mSel.GetComponent<UIInput>() != null);

        // Enter key and joystick button 1 keys are treated the same -- as a "click"
        bool returnKeyDown	= (useKeyboard	 && (Input.GetKeyDown(KeyCode.Return) || (!hasInput && Input.GetKeyDown(KeyCode.Space))));
        bool buttonKeyDown	= (useController &&  Input.GetKeyDown(KeyCode.JoystickButton0));
        bool returnKeyUp	= (useKeyboard	 && (Input.GetKeyUp(KeyCode.Return) || (!hasInput && Input.GetKeyUp(KeyCode.Space))));
        bool buttonKeyUp	= (useController &&  Input.GetKeyUp(KeyCode.JoystickButton0));

        bool down	= returnKeyDown || buttonKeyDown;
        bool up		= returnKeyUp || buttonKeyUp;

        if (down || up)
        {
            currentTouch.current = mSel;
            ProcessTouch(down, up);
        }

        int vertical = 0;
        int horizontal = 0;

        if (useKeyboard)
        {
            if (hasInput)
            {
                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) mSel.SendMessage("OnKey", vertical > 0 ? KeyCode.UpArrow : KeyCode.DownArrow, SendMessageOptions.DontRequireReceiver);
        if (horizontal != 0) mSel.SendMessage("OnKey", horizontal > 0 ? KeyCode.RightArrow : KeyCode.LeftArrow, SendMessageOptions.DontRequireReceiver);
        if (useKeyboard && Input.GetKeyDown(KeyCode.Tab)) mSel.SendMessage("OnKey", KeyCode.Tab, SendMessageOptions.DontRequireReceiver);
        if (useController && Input.GetKeyUp(KeyCode.JoystickButton1)) mSel.SendMessage("OnKey", KeyCode.Escape, SendMessageOptions.DontRequireReceiver);

        currentTouch = null;
    }
Ejemplo n.º 30
0
    /// <summary>
    /// Process the events of the specified touch.
    /// </summary>
    void ProcessTouch(MouseOrTouch touch, bool pressed, bool unpressed)
    {
        // If we're using the mouse for input, we should send out a hover(false) message first
        if (touch.pressed == null && touch.hover != touch.current && touch.hover != null)
        {
            if (mTooltip != null) ShowTooltip(false);
            Highlight(touch.hover, false);
        }

        // Send the drag notification, intentionally before the pressed object gets changed
        if (touch.pressed != null && touch.delta.magnitude != 0f)
        {
            if (mTooltip != null) ShowTooltip(false);
            touch.totalDelta += touch.delta;
            touch.pressed.SendMessage("OnDrag", touch.delta, SendMessageOptions.DontRequireReceiver);

            float threshold = (touch == mMouse) ? 5f : 30f;
            if (touch.totalDelta.magnitude > threshold) touch.considerForClick = false;
        }

        // Send out the press message
        if (pressed)
        {
            if (mTooltip != null) ShowTooltip(false);
            touch.pressed = touch.current;
            touch.considerForClick = true;
            touch.totalDelta = Vector2.zero;
            if (touch.pressed != null) touch.pressed.SendMessage("OnPress", true, SendMessageOptions.DontRequireReceiver);

            // Clear the selection
            if (touch.pressed != mSel)
            {
                if (mTooltip != null) ShowTooltip(false);
                selectedObject = null;
            }
        }

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

            if (touch.pressed != null)
            {
                touch.pressed.SendMessage("OnPress", false, SendMessageOptions.DontRequireReceiver);

                // Send a hover message to the object, but don't add it to the list of hovered items as it's already present
                if (touch.pressed == touch.hover) touch.pressed.SendMessage("OnHover", true, SendMessageOptions.DontRequireReceiver);

                // If the button/touch was released on the same object, consider it a click and select it
                if (touch.pressed == touch.current)
                {
                    if (touch.pressed != mSel)
                    {
                        mSel = touch.pressed;
                        touch.pressed.SendMessage("OnSelect", true, SendMessageOptions.DontRequireReceiver);
                    }
                    else
                    {
                        mSel = touch.pressed;
                    }
                    if (touch.considerForClick) touch.pressed.SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
                }
                else // The button/touch was released on a different object
                {
                    // Send a drop notification (for drag & drop)
                    if (touch.current != null) touch.current.SendMessage("OnDrop", touch.pressed, SendMessageOptions.DontRequireReceiver);

                    // If we're using mouse-based input, send a hover notification
                    Highlight(touch.pressed, false);
                }
            }
            touch.pressed = null;
        }

        // Send out a hover(true) message last
        if (useMouse && touch.pressed == null && touch.hover != touch.current)
        {
            mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
            touch.hover = touch.current;
            Highlight(touch.hover, true);
        }
    }
Ejemplo n.º 31
0
	/// <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;
	}
Ejemplo n.º 32
0
    /// <summary>
    /// Update touch-based events.
    /// </summary>

    public void ProcessTouches()
    {
        for (int i = 0; i < Input.touchCount; ++i)
        {
            Touch input = Input.GetTouch(i);

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

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

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

            currentTouch.pos = input.position;
            hoveredObject    = Raycast(currentTouch.pos, out lastHit) ? lastHit.collider.gameObject : fallThrough;
            if (hoveredObject == null)
            {
                hoveredObject = genericEventHandler;
            }
            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 (input.tapCount > 1)
            {
                currentTouch.clickTime = Time.realtimeSinceStartup;
            }

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

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

            // Don't consider other touches
            if (!allowMultiTouch)
            {
                break;
            }
        }
    }
Ejemplo n.º 33
0
	/// <summary>
	/// Process fake touch events where the mouse acts as a touch device.
	/// Useful for testing mobile functionality in the editor.
	/// </summary>

	void ProcessFakeTouches ()
	{
		bool pressed = Input.GetMouseButtonDown(0);
		bool unpressed = Input.GetMouseButtonUp(0);
		bool held = Input.GetMouseButton(0);

		if (pressed || unpressed || held)
		{
			currentTouchID = 1;
			currentTouch = mMouse[0];
			currentTouch.touchBegan = pressed;

			Vector2 pos = Input.mousePosition;
			currentTouch.delta = pressed ? Vector2.zero : pos - currentTouch.pos;
			currentTouch.pos = pos;

			// 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;

			// 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;
		}
	}
Ejemplo n.º 34
0
    /// <summary>
    /// Update mouse input.
    /// </summary>

    public void ProcessMouse()
    {
        bool updateRaycast = (useMouse && Time.timeScale < 0.9f);

        if (!updateRaycast)
        {
            for (int i = 0; i < 3; ++i)
            {
                if (Input.GetMouseButton(i) || Input.GetMouseButtonUp(i))
                {
                    updateRaycast = true;
                    break;
                }
            }
        }

        // Update the position and delta
        mMouse[0].pos   = Input.mousePosition;
        mMouse[0].delta = mMouse[0].pos - lastTouchPosition;

        bool posChanged = (mMouse[0].pos != lastTouchPosition);

        lastTouchPosition = mMouse[0].pos;

        // Update the object under the mouse
        if (updateRaycast)
        {
            hoveredObject = Raycast(Input.mousePosition, out lastHit) ? lastHit.collider.gameObject : fallThrough;
            if (hoveredObject == null)
            {
                hoveredObject = genericEventHandler;
            }
            mMouse[0].current = hoveredObject;
        }

        // 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;
            mMouse[i].current = mMouse[0].current;
        }

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

        for (int i = 0; i < 3; ++i)
        {
            if (Input.GetMouseButton(i))
            {
                isPressed = true;
                break;
            }
        }

        if (isPressed)
        {
            // A button was pressed -- cancel the tooltip
            mTooltipTime = 0f;
        }
        else if (useMouse && posChanged && (!stickyTooltip || mHover != mMouse[0].current))
        {
            if (mTooltipTime != 0f)
            {
                // Delay the tooltip
                mTooltipTime = Time.realtimeSinceStartup + 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 (useMouse && !isPressed && mHover != null && mHover != mMouse[0].current)
        {
            if (mTooltip != null)
            {
                ShowTooltip(false);
            }
            Highlight(mHover, false);
            mHover = null;
        }

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

                currentTouch   = mMouse[i];
                currentTouchID = -1 - 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);
            }
            currentTouch = null;
        }

        // If nothing is pressed and there is an object under the touch, highlight it
        if (useMouse && !isPressed && mHover != mMouse[0].current)
        {
            mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
            mHover       = mMouse[0].current;
            Highlight(mHover, true);
        }
    }
Ejemplo n.º 35
0
	/// <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;
	}
Ejemplo n.º 36
0
    /// <summary>
    /// Process keyboard and joystick events.
    /// </summary>

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

        // If this is an input field, ignore WASD and Space key presses
        inputHasFocus = (mCurrentSelection != null && mCurrentSelection.GetComponent <UIInput>() != null);

        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;
    }
Ejemplo n.º 37
0
	/// <summary>
	/// Process keyboard and joystick events.
	/// </summary>

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

		// If this is an input field, ignore WASD and Space key presses
		inputHasFocus = (mSel != null && mSel.GetComponent<UIInput>() != null);

		bool submitKeyDown = (submitKey0 != KeyCode.None && Input.GetKeyDown(submitKey0)) || (submitKey1 != KeyCode.None && Input.GetKeyDown(submitKey1));
		bool submitKeyUp = (submitKey0 != KeyCode.None && Input.GetKeyUp(submitKey0)) || (submitKey1 != KeyCode.None && Input.GetKeyUp(submitKey1));

		if (submitKeyDown || submitKeyUp)
		{
			currentTouch.current = mSel;
			ProcessTouch(submitKeyDown, submitKeyUp);
			currentTouch.current = 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) Notify(mSel, "OnKey", vertical > 0 ? KeyCode.UpArrow : KeyCode.DownArrow);
		if (horizontal != 0) Notify(mSel, "OnKey", horizontal > 0 ? KeyCode.RightArrow : KeyCode.LeftArrow);
		if (useKeyboard && Input.GetKeyDown(KeyCode.Tab)) Notify(mSel, "OnKey", KeyCode.Tab);

		// Send out the cancel key notification
		if (cancelKey0 != KeyCode.None && Input.GetKeyDown(cancelKey0)) Notify(mSel, "OnKey", KeyCode.Escape);
		if (cancelKey1 != KeyCode.None && Input.GetKeyDown(cancelKey1)) Notify(mSel, "OnKey", KeyCode.Escape);

		currentTouch = null;
	}
Ejemplo n.º 38
0
    /// <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, out lastHit))
            {
                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;
        }
    }
Ejemplo n.º 39
0
	/// <summary>
	/// Update mouse input.
	/// </summary>

	public void ProcessMouse ()
	{
		bool updateRaycast = (useMouse && Time.timeScale < 0.9f);

		if (!updateRaycast)
		{
			for (int i = 0; i < 3; ++i)
			{
				if (Input.GetMouseButton(i) || Input.GetMouseButtonUp(i))
				{
					updateRaycast = true;
					break;
				}
			}
		}

		// Update the position and delta
		mMouse[0].pos = Input.mousePosition;
		mMouse[0].delta = mMouse[0].pos - lastTouchPosition;

		bool posChanged = (mMouse[0].pos != lastTouchPosition);
		lastTouchPosition = mMouse[0].pos;

		// Update the object under the mouse
		if (updateRaycast)
		{
			if (!Raycast(Input.mousePosition, out lastHit)) hoveredObject = fallThrough;
			if (hoveredObject == null) hoveredObject = genericEventHandler;
			mMouse[0].current = hoveredObject;
		}

		// 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;
			mMouse[i].current = mMouse[0].current;
		}

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

		for (int i = 0; i < 3; ++i)
		{
			if (Input.GetMouseButton(i))
			{
				isPressed = true;
				break;
			}
		}

		if (isPressed)
		{
			// A button was pressed -- cancel the tooltip
			mTooltipTime = 0f;
		}
		else if (useMouse && posChanged && (!stickyTooltip || mHover != mMouse[0].current))
		{
			if (mTooltipTime != 0f)
			{
				// Delay the tooltip
				mTooltipTime = Time.realtimeSinceStartup + 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 (useMouse && !isPressed && mHover != null && mHover != mMouse[0].current)
		{
			if (mTooltip != null) ShowTooltip(false);
			Highlight(mHover, false);
			mHover = null;
		}

		// Process all 3 mouse buttons as individual touches
		if (useMouse)
		{
			for (int i = 0; i < 3; ++i)
			{
				bool pressed = Input.GetMouseButtonDown(i);
				bool unpressed = Input.GetMouseButtonUp(i);
	
				currentTouch = mMouse[i];
				currentTouchID = -1 - 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);
			}
			currentTouch = null;
		}

		// If nothing is pressed and there is an object under the touch, highlight it
		if (useMouse && !isPressed && mHover != mMouse[0].current)
		{
			mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
			mHover = mMouse[0].current;
			Highlight(mHover, true);
		}
	}
Ejemplo n.º 40
0
    /// <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, out lastHit))
            {
                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
        }
    }
Ejemplo n.º 41
0
	/// <summary>
	/// Process all events.
	/// </summary>

	void ProcessEvents ()
	{
		current = this;
		NGUIDebug.debugRaycast = debug;

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

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

		// Update the keyboard and joystick events
		if ((useKeyboard || useController) && !disableController && !ignoreControllerInput) 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) ? GetAxis(scrollAxisName) : 0f;

			if (scroll != 0f)
			{
				if (onScroll != null) onScroll(mHover, scroll);
				Notify(mHover, "OnScroll", scroll);
			}

			if (currentScheme == ControlScheme.Mouse && showTooltips && mTooltipTime != 0f && !UIPopupList.isOpen && mMouse[0].dragged == null &&
				(mTooltipTime < RealTime.time || GetKey(KeyCode.LeftShift) || GetKey(KeyCode.RightShift)))
			{
				currentTouch = mMouse[0];
				currentTouchID = -1;
				ShowTooltip(mHover);
			}
		}

		if (mTooltip != null && !NGUITools.GetActive(mTooltip))
			ShowTooltip(null);

		current = null;
		currentTouchID = -100;
	}
Ejemplo n.º 42
0
	/// <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 && GetKeyDown(cancelKey0))
			{
				currentScheme = ControlScheme.Controller;
				currentKey = cancelKey0;
				selectedObject = null;
			}
			else if (cancelKey1 != KeyCode.None && GetKeyDown(cancelKey1))
			{
				currentScheme = ControlScheme.Controller;
				currentKey = cancelKey1;
				selectedObject = null;
			}
		}

		// If nothing is selected, input focus is lost
		if (mCurrentSelection == null)
		{
			inputHasFocus = false;
		}
		else if (!mCurrentSelection || !mCurrentSelection.activeInHierarchy)
		{
			inputHasFocus = false;
			mCurrentSelection = null;
		}

		// Update the keyboard and joystick events
		if ((useKeyboard || useController) && 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) ? GetAxis(scrollAxisName) : 0f;

			if (scroll != 0f)
			{
				if (onScroll != null) onScroll(mHover, scroll);
				Notify(mHover, "OnScroll", scroll);
			}

			if (showTooltips && mTooltipTime != 0f && (mTooltipTime < RealTime.time ||
				GetKey(KeyCode.LeftShift) || GetKey(KeyCode.RightShift)))
			{
				mTooltip = mHover;
				currentTouch = mMouse[0];
				currentTouchID = -1;
				ShowTooltip(true);
			}
		}

		current = null;
		currentTouchID = -100;
	}
Ejemplo n.º 43
0
	/// <summary>
	/// Update touch-based events.
	/// </summary>

	public void ProcessTouches ()
	{
		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;
#if UNITY_WIIU && !UNITY_EDITOR
				// Unity bug: http://www.tasharen.com/forum/index.php?topic=5821.0
				position.y = Screen.height - position.y;
#endif
			}
			else
			{
				Touch touch = GetInputTouch(i);
				phase = touch.phase;
				fingerId = touch.fingerId;
				position = touch.position;
				tapCount = touch.tapCount;
			}

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

			bool pressed = (phase == TouchPhase.Began) || currentTouch.touchBegan;
			bool unpressed = (phase == TouchPhase.Canceled) || (phase == TouchPhase.Ended);
			currentTouch.delta = position - currentTouch.pos;
			currentTouch.pos = position;
			currentKey = KeyCode.None;

			// Raycast into the screen
			Raycast(currentTouch);

			// 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.touchBegan = false;
			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 if (GetInputTouch == null) ProcessFakeTouches();
#endif
		}
		else mUsingTouchEvents = true;
	}
Ejemplo n.º 44
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;
	}
Ejemplo n.º 45
0
	/// <summary>
	/// Process keyboard and joystick events.
	/// </summary>

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

		bool submitKeyDown = false;
		bool submitKeyUp = false;

		if (submitKey0 != KeyCode.None && GetKeyDown(submitKey0))
		{
			currentKey = submitKey0;
			submitKeyDown = true;
		}
		else if (submitKey1 != KeyCode.None && GetKeyDown(submitKey1))
		{
			currentKey = submitKey1;
			submitKeyDown = true;
		}
		else if ((submitKey0 == KeyCode.Return || submitKey1 == KeyCode.Return) && GetKeyDown(KeyCode.KeypadEnter))
		{
			currentKey = submitKey0;
			submitKeyDown = true;
		}

		if (submitKey0 != KeyCode.None && GetKeyUp(submitKey0))
		{
			currentKey = submitKey0;
			submitKeyUp = true;
		}
		else if (submitKey1 != KeyCode.None && GetKeyUp(submitKey1))
		{
			currentKey = submitKey1;
			submitKeyUp = true;
		}
		else if ((submitKey0 == KeyCode.Return || submitKey1 == KeyCode.Return) && GetKeyUp(KeyCode.KeypadEnter))
		{
			currentKey = submitKey0;
			submitKeyUp = true;
		}

		if (submitKeyDown) currentTouch.pressTime = RealTime.time;

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

		KeyCode lastKey = KeyCode.None;

		// Handle controller events
		if (useController && !ignoreControllerInput)
		{
			// Automatically choose the first available selection object
			if (!disableController && currentScheme == ControlScheme.Controller && (currentTouch.current == null || !currentTouch.current.activeInHierarchy))
				currentTouch.current = controllerNavigationObject;

			if (!string.IsNullOrEmpty(verticalAxisName))
			{
				int vertical = GetDirection(verticalAxisName);

				if (vertical != 0)
				{
					ShowTooltip(null);
					currentScheme = ControlScheme.Controller;
					currentTouch.current = controllerNavigationObject;

					if (currentTouch.current != null)
					{
						lastKey = vertical > 0 ? KeyCode.UpArrow : KeyCode.DownArrow;
						if (onNavigate != null) onNavigate(currentTouch.current, lastKey);
						Notify(currentTouch.current, "OnNavigate", lastKey);
					}
				}
			}

			if (!string.IsNullOrEmpty(horizontalAxisName))
			{
				int horizontal = GetDirection(horizontalAxisName);

				if (horizontal != 0)
				{
					ShowTooltip(null);
					currentScheme = ControlScheme.Controller;
					currentTouch.current = controllerNavigationObject;

					if (currentTouch.current != null)
					{
						lastKey = horizontal > 0 ? KeyCode.RightArrow : KeyCode.LeftArrow;
						if (onNavigate != null) onNavigate(currentTouch.current, lastKey);
						Notify(currentTouch.current, "OnNavigate", lastKey);
					}
				}
			}

			float x = !string.IsNullOrEmpty(horizontalPanAxisName) ? GetAxis(horizontalPanAxisName) : 0f;
			float y = !string.IsNullOrEmpty(verticalPanAxisName) ? GetAxis(verticalPanAxisName) : 0f;

			if (x != 0f || y != 0f)
			{
				ShowTooltip(null);
				currentScheme = ControlScheme.Controller;
				currentTouch.current = controllerNavigationObject;

				if (currentTouch.current != null)
				{
					Vector2 delta = new Vector2(x, y);
					delta *= Time.unscaledDeltaTime;
					if (onPan != null) onPan(currentTouch.current, delta);
					Notify(currentTouch.current, "OnPan", delta);
				}
			}
		}

		// Send out all key events
		if (GetAnyKeyDown != null ? GetAnyKeyDown() : Input.anyKeyDown)
		{
			for (int i = 0, imax = NGUITools.keys.Length; i < imax; ++i)
			{
				KeyCode key = NGUITools.keys[i];
				if (lastKey == key) continue;
				if (!GetKeyDown(key)) continue;

				if (!useKeyboard && key < KeyCode.Mouse0) continue;
				if ((!useController || ignoreControllerInput) && key >= KeyCode.JoystickButton0) continue;
				if (!useMouse && (key >= KeyCode.Mouse0 && key <= KeyCode.Mouse6)) continue;

				currentKey = key;
				if (onKey != null) onKey(currentTouch.current, key);
				Notify(currentTouch.current, "OnKey", key);
			}
		}

		currentTouch = null;
	}
Ejemplo n.º 46
0
    /// <summary>
    /// Update mouse input.
    /// </summary>
    void ProcessMouse()
    {
        currentTouch = mMouse;
        lastTouchPosition = Input.mousePosition;
        currentTouch.delta = lastTouchPosition - currentTouch.pos;

        bool updateRaycast = (Time.timeScale < 0.9f);

        if (!updateRaycast)
        {
            for (int i = 0; i < 3; ++i)
            {
                if (Input.GetMouseButton(i) || Input.GetMouseButtonUp(i))
                {
                    updateRaycast = true;
                    break;
                }
            }
        }

        if (updateRaycast)
        {
            currentTouch.current = Raycast(lastTouchPosition, ref lastHit) ? lastHit.collider.gameObject : fallThrough;
        }

        for (int i = 0; i < 3; ++i)
        {
            bool pressed = Input.GetMouseButtonDown(i);
            bool unpressed = Input.GetMouseButtonUp(i);

            currentTouchID = -1 - 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;

            if (i == 0 && currentTouch.pos != lastTouchPosition)
            {
                if (mTooltipTime != 0f) mTooltipTime = Time.realtimeSinceStartup + tooltipDelay;
                else if (mTooltip != null) ShowTooltip(false);
                currentTouch.pos = lastTouchPosition;
            }

            // Process the mouse events
            ProcessTouch(pressed, unpressed);
        }
        currentTouch = null;
    }