private void SendMouseEvent(IMouseEvent evt, MousePhase phase)
        {
            if (!activators.Any(filter => filter.Matches(evt)))
            {
                return;
            }

            var position = previewImageRendererSpaceToScreenSpace.MultiplyPoint(evt.localMousePosition);

            TouchFromMouse(position, phase);
        }
Пример #2
0
    private void Awake()
    {
        instance   = this;
        mousePhase = MousePhase.IDLE;

        character = transform.Find("CharacterTrans");
        rigidbody = GetComponent <Rigidbody>();

        lineRender         = GetComponentInChildren <LineRenderer>();
        lineRender.enabled = false;

        spellAnchor = new GameObject("Spell Anchor").transform;

        Transform view = character.Find("View_Character");

        coreMaterial = view.GetChild(0).GetComponent <Renderer>().material;
        foreach (Transform t in view)
        {
            t.GetComponent <Renderer>().material = coreMaterial;
        }
        coreMaterial.SetInt("_ZWrite", 1); // Enable ZWrite so our material doesn't act weird with transparency on

        invincibilitySequence = DOTween.Sequence();
        for (int i = 0; i < invincibilityBlinkCount; i++)
        {
            invincibilitySequence.Append(coreMaterial.DOFade(0F, invincibilityDuration / invincibilityBlinkCount / 2));
            invincibilitySequence.Append(coreMaterial.DOFade(1F, invincibilityDuration / invincibilityBlinkCount / 2));
        }
        invincibilitySequence.Pause().SetAutoKill(false);

        // Unlocks all the elements
        if (unlockAll)
        {
            System.Enum.GetValues(typeof(ElementType)).Cast <ElementType>().ToList().ForEach(e => UnlockElement(e));
        }

        // Caches all the spells for quick access without the need to look them up every time
        foreach (ISpell spell in spells.Select(s => s.GetComponent <ISpell>()))
        {
            ElementType element = spell.GetElement();
            if (!spellCache.ContainsKey(element))
            {
                spellCache.Add(element, new Dictionary <SpellTargetType, ISpell>());
            }

            spellCache[element][spell.GetTargetType()] = spell;
        }
    }
Пример #3
0
    public static bool CheckMouseClick(RectTransform rect, int mouseButtonId = 0, MousePhase phase = MousePhase.Began)
    {
        var isInPhase = false;

        if (phase == MousePhase.Began)
        {
            isInPhase = Input.GetMouseButtonDown(mouseButtonId);
        }
        else if (phase == MousePhase.Ended)
        {
            isInPhase = Input.GetMouseButtonUp(mouseButtonId);
        }
        else if (phase == MousePhase.HoldDown)
        {
            isInPhase = Input.GetMouseButton(mouseButtonId);
        }
        return(isInPhase && RectTransformUtility.RectangleContainsScreenPoint(rect, Input.mousePosition, Camera.main));
    }
Пример #4
0
 public void ClearInput()
 {
     mousePhase = MousePhase.IDLE;
 }
Пример #5
0
    private void Update()
    {
        // Input handling
        bool b0Down = Input.GetMouseButtonDown(0);
        bool b0Up   = Input.GetMouseButtonUp(0);

        bool inActiveArea = Input.mousePosition.x / Screen.width < activeScreenWidth;

        switch (mousePhase)
        {
        case MousePhase.IDLE:
            if (inActiveArea && b0Down)
            {
                mouseInfoBuffer.Clear();
                AddMouseInfo();

                if (mouseInfoBuffer.FirstOrDefault().hit)
                {
                    MouseDown();
                    mousePhase = MousePhase.DOWN;
                }
            }
            break;

        case MousePhase.DOWN:
            MouseInfo lastMouseInfo = AddMouseInfo();
            if (b0Up)
            {
                MouseTap();
                mousePhase = MousePhase.IDLE;
            }
            else if (Time.time - mouseInfoBuffer.FirstOrDefault().time > mouseTapTime)
            {
                float dragDist = (lastMouseInfo.screenPos - mouseInfoBuffer.FirstOrDefault().screenPos).magnitude;
                if (dragDist >= mouseDragDistance || selectedElements.Count == 0)
                {
                    mousePhase = MousePhase.DRAG;
                }
            }
            break;

        case MousePhase.DRAG:
            AddMouseInfo();
            if (b0Up)
            {
                MouseDragUp();
                mousePhase = MousePhase.IDLE;
            }
            else
            {
                MouseDrag();
            }
            break;
        }

        OrbitSelectedElements();

        foreach (ElementType element in System.Enum.GetValues(typeof(ElementType)))
        {
            RecoverElementCharge(element, Mathf.RoundToInt(elementRecoverPerSecond[(int)element] * Time.deltaTime));
        }
    }
        public void TouchFromMouse(Vector2 position, MousePhase mousePhase)
        {
            if (!EditorApplication.isPlaying || EditorApplication.isPaused)
            {
                return;
            }

            // Clamping position inside the device screen. UI element that sends input events also includes the device border and we don't want to register inputs there.
            isPointerInsideDeviceScreen = true;
            if (position.x < 0)
            {
                position.x = 0;
                isPointerInsideDeviceScreen = false;
            }
            else if (position.x > m_ScreenData.width)
            {
                position.x = m_ScreenData.width;
                isPointerInsideDeviceScreen = false;
            }
            if (position.y < 0)
            {
                position.y = 0;
                isPointerInsideDeviceScreen = false;
            }
            else if (position.y > m_ScreenData.height)
            {
                position.y = m_ScreenData.height;
                isPointerInsideDeviceScreen = false;
            }

            pointerPosition = ScreenPixelToTouchCoordinate(position);

            // Test if the touch is over a cutout or notch using the texture (preferred) or the cutouts from the .device (fallback)
            // Texture check uses the originalTouchPosition as it assumes the touch and texture are in portrait regardless of orientation
            // Cutouts check uses the adjusted pointerPosition as we have different cutout positions for different orientations
            if (IsTouchOnCutout(position, pointerPosition))
            {
                isPointerInsideDeviceScreen = false;
            }

            if (!m_TouchFromMouseActive && mousePhase != MousePhase.Start)
            {
                return;
            }

            TouchPhase phase = TouchPhase.Canceled;

            if (!isPointerInsideDeviceScreen)
            {
                switch (mousePhase)
                {
                case MousePhase.Start:
                    return;

                case MousePhase.Move:
                case MousePhase.End:
                    phase = TouchPhase.Ended;
                    m_TouchFromMouseActive = false;
                    break;
                }
            }
            else
            {
                switch (mousePhase)
                {
                case MousePhase.Start:
                    phase = TouchPhase.Began;
                    m_TouchFromMouseActive = true;
                    break;

                case MousePhase.Move:
                    phase = TouchPhase.Moved;
                    break;

                case MousePhase.End:
                    phase = TouchPhase.Ended;
                    m_TouchFromMouseActive = false;
                    break;
                }
            }

            m_DeviceSimulator.OnTouchScreenInput(new TouchEvent(0, pointerPosition, phase));
            m_InputManagerBackend?.Touch(0, pointerPosition, phase);
        }
Пример #7
0
    void OnMouseUpAsButton()
    {
        if (GameManager.Instance.isGamePaused == false)
        {
            //#if UNITY_EDITOR

            if (GameManager.Instance.DebugMode_PC == true)
            {
                //Used to be mouseIsDown == true (Test Code)
                //When mouse button is released, if there is a reflector 'attached' to the mouse, run this code
                if (reflectorAttached == true)
                {
                    mousePhase = MousePhase.ENDED;

                    #region MOUSE PHASE ENDED CODE
                    // hit = Physics.Raycast(transform.position, -transform.up, rayLength, layerMask);

                    if (Physics.Raycast(transform.position, Vector3.forward, out RaycastHit hit, rayLength, layerMask))
                    {
                        Debug.Log("HIT OBJ: " + hit.transform.name);
                        if (hit.collider.tag == "Grid")
                        {
                            if (hit.transform.gameObject.GetComponent <Proto_Grid>().IsOccupied == false)
                            {
                                transform.position = hit.transform.position;

                                hit.transform.gameObject.GetComponent <Proto_Grid>().IsOccupied           = true;
                                hit.transform.gameObject.GetComponent <Proto_Grid>().reflectorStored_Grid = this.gameObject;
                                hit.transform.gameObject.GetComponent <BoxCollider2D>().enabled           = false;
                                tempColor   = hit.transform.gameObject.GetComponent <SpriteRenderer>().color;
                                tempColor.a = 0.0f;
                                hit.transform.gameObject.GetComponent <SpriteRenderer>().color = tempColor;

                                isOccupied    = true;
                                gridReference = hit.transform.gameObject;

                                inGrid = true;

                                gameObject.GetComponent <ReflectorAnimation>().activateBuildAnimation(gameObject.transform.rotation.eulerAngles.z); //Displays the hammer building animation
                            }
                        }
                        else
                        {
                            inGrid = false;
                            //Remove Reflector from allReflectorsInScene List from GameManager before destroying it
                            GameManager.Instance.removeReflector(gameObject);
                            //Check which Reflector it is and return it to the stock / return back to the pool
                            GameManager.Instance.returnReflectorToStock(gameObject);

                            GameManager.Instance.resetReflectorColliders(); //If the reflector hits an invalid spot, we need to reset the colliders
                            //for any reflectors that are still in the scene before this object gets
                            //destroyed, else player cannot control the reflectors that are in the scene
                            //since their Box Colliders have not been reenabled.

                            //Destroy(gameObject); //Uncomment if using traditional Instantiate & Destroy. Object Pooling technique does not require this
                            Debug.Log(hit.transform.name);
                        }
                    }
                    else
                    {
                        inGrid = false;
                        //Remove Reflector from allReflectorsInScene List from GameManager before destroying it
                        GameManager.Instance.removeReflector(gameObject);
                        //Check which Reflector it is and return it to the stock / return back to the pool
                        GameManager.Instance.returnReflectorToStock(gameObject);

                        GameManager.Instance.resetReflectorColliders(); //If the reflector hits an invalid spot, we need to reset the colliders
                        //for any reflectors that are still in the scene before this object gets
                        //destroyed, else player cannot control the reflectors that are in the scene
                        //since their Box Colliders have not been reenabled.

                        //Destroy(gameObject); //Uncomment if using traditional Instantiate & Destroy. Object Pooling technique does not require this
                    }

                    #endregion

                    if (GameManager.Instance.activationToggle_Reflector == true)
                    {
                        GameManager.Instance.resetReflectorColliders();
                    }

                    GameManager.Instance.activationToggle_Grid = false;

                    isHoldingDown = false;
                    mouseIsDown   = false;

                    reflectorAttached = false;
                }

                //Used to be mouseIsDown == false (Test Code).
                //When mouse button is released, if there is no reflector 'attached' to the mouse, run this code
                else if (reflectorAttached == false)
                {
                    mouseIsDown   = true;
                    isHoldingDown = true;

                    mousePhase = MousePhase.BEGAN;

                    if (GameManager.Instance.activationToggle_Grid == false)
                    {
                        //If this shape is currently attached to a grid
                        if (isOccupied == true)
                        {
                            gridReference.GetComponent <Proto_Grid>().reflectorStored_Grid = null;
                            gridReference.GetComponent <Proto_Grid>().IsOccupied           = false;
                            gridReference.GetComponent <SpriteRenderer>().color            = Color.white;

                            inGrid        = false;
                            gridReference = null;
                            isOccupied    = false;
                        }
                        else if (isOccupied == false)
                        {
                            ;
                        }

                        GameManager.Instance.toggleGridColliders();

                        GameManager.Instance.activationToggle_Grid = true;
                    }

                    if (GameManager.Instance.activationToggle_Reflector == false)
                    {
                        GameManager.Instance.toggleReflectorColliders();
                    }

                    reflectorAttached = true; //Test Code
                }
            }

            if (GameManager.Instance.DebugMode_PC == false)
            {
                if (inGrid && !isHoldingDown)
                {
                    if (gameObject.name.Contains("ThreeWay"))
                    {
                        //Do nothing
                    }
                    else
                    {
                        rotateReflector(transform.rotation.eulerAngles.z);
                    }
                }
            }

            //#endif
        }