void Awake() { animator = this.GetComponent <Animator>(); boxCollider = this.GetComponent <BoxCollider2D>(); inputReceiver = this.GetComponent <BaseInputReceiver>(); //IsBlocked = false; }
private void Update() { TouchPhase touchPhase = TouchPhase.Moved; if (Input.GetMouseButtonDown(0)) { touchPhase = TouchPhase.Began; } else if (Input.GetMouseButtonUp(0)) { touchPhase = TouchPhase.Ended; } Vector3 touchPosition = Input.mousePosition; if (TouchPhase.Began == touchPhase) { // Check if selecting anything that is a input receiver // If so, redirect all input to that input receiver Ray ray = Camera.main.ScreenPointToRay(touchPosition); int numHits = Physics2D.RaycastNonAlloc(ray.origin, ray.direction, _raycastResults, raycastDistance, raycastLayerMask); for (int hitIdx = 0; hitIdx < numHits; ++hitIdx) { RaycastHit2D hit = _raycastResults[hitIdx]; BaseInputReceiver inputReceiver = hit.collider.GetComponent <BaseInputReceiver>(); if (null != inputReceiver) { _currentReceiver = inputReceiver; break; } } } if (null == _currentReceiver) { return; } // Gather mouse position and give it to the current input receiver TouchEventInfo eventInfo = new TouchEventInfo() { touchPositionPix = touchPosition }; switch (touchPhase) { case TouchPhase.Began: _currentReceiver.OnTouchBegan(eventInfo); break; case TouchPhase.Moved: _currentReceiver.OnTouchMoved(eventInfo); break; case TouchPhase.Ended: _currentReceiver.OnTouchEnded(eventInfo); _currentReceiver = null; break; } }
/// <summary> /// pReceiver gains focus and previous focus object goes on a stack. /// </summary> /// <param name="pReceiver"></param> public void Push(BaseInputReceiver pReceiver) { receiverInFocus.SetIsFocus(false); pReceiver.SetIsFocus(true); receiverInFocus = pReceiver; receiverList.Add(receiverInFocus); }
/// <summary> /// Current focus object is removed and the new current focus object is /// </summary> public void Pop(BaseInputReceiver pReceiver) //public void Pop() { int lastIndex = receiverList.Count - 1; if (!(receiverList[lastIndex] == pReceiver)) { return; } Pop(); }
public void Pop() { int lastIndex = receiverList.Count - 1; //Remove from list receiverInFocus.SetIsFocus(false); receiverList.RemoveAt(lastIndex); //Set last receiver in list as current. If the list is now empty then the receiverInFocus becomes null. if (receiverList.Count > lastIndex - 1) { receiverInFocus = receiverList[lastIndex - 1]; receiverInFocus.SetIsFocus(true); } else { receiverInFocus = null; } }