/// <summary> /// Restore the color of the touchable object that just leaves the picker. /// </summary> /// <param name="touchable">Touchable object whose color will be restored.</param> private void RestoreTouchableObjectColorUponExit(ITouchable touchable) { // Equals is overridden by MonoBehaviour, so can be used to check if the game object // has been destroyed. if (touchable == null || touchable.Equals(null)) { return; } Transform touchableTransform = touchable.BindedGameObject.transform; Renderer renderer = touchableTransform.GetComponent <Renderer>(); if (renderer != null && _rendererToRefCountDict.ContainsKey(renderer)) { RestoreRendererColor(renderer); } // Restore color for the renderers of the touchable and its children. foreach (Transform child in touchableTransform) { renderer = child.GetComponent <Renderer>(); if (renderer == null) { continue; } if (!_rendererToRefCountDict.ContainsKey(renderer)) { continue; } RestoreRendererColor(renderer); } }
/// <summary> /// Change the color of the touchable object that first comes into contact with /// the picker. /// </summary> /// <param name="touchable">The touchable that first comes into contact.</param> private void ChangeTouchableObjectColorUponEnter(ITouchable touchable) { if (touchable == null || touchable.Equals(null)) { // Touchable may have been destroyed return; } Transform touchableTransform = touchable.BindedGameObject.transform; Renderer renderer = touchableTransform.GetComponent <Renderer>(); // Change color for all renderers of the object and its children. if (renderer != null) { ChangeRendererColor(renderer, touchable.IndicatedColorOnTouching); } foreach (Transform child in touchableTransform) { renderer = child.GetComponent <Renderer>(); if (renderer == null) { continue; } ChangeRendererColor(renderer, touchable.IndicatedColorOnTouching); } }
public static void ClearElementClicked(ITouchable other) { if (instance.elementClicked == other) { ClearElementClicked(); } }
public override void onTouchMoved(Touch touch, Vector2 touchPos) #endif { // increment deltaTouch so we can pass on the touch if necessary _deltaTouch += touch.deltaPosition.y; _lastTouch = touch; // once we move too far unhighlight and stop tracking the touchable if (Mathf.Abs(_deltaTouch) > TOUCH_MAX_DELTA_FOR_ACTIVATION && _activeTouchable != null) { _activeTouchable.onTouchEnded(touch, touchPos, true); _activeTouchable = null; } var newTop = _scrollPosition - touch.deltaPosition.y; newTop = Mathf.Clamp(newTop, _minEdgeInset.y, _maxEdgeInset.y); _scrollPosition = newTop; layoutChildren(); // pop any extra velocities and push the current velocity onto the stack if (_velocities.Count == TOTAL_VELOCITY_SAMPLE_COUNT) { _velocities.Dequeue(); } _velocities.Enqueue(touch.deltaPosition.y / Time.deltaTime); }
/// <summary> /// mutates an item in the eviction condition store, and returns true if it's not flagged for eviction /// </summary> /// <param name="soId"></param> /// <returns></returns> protected bool TouchExpirable(StoredObjectId soId) { if (soId == null) { return(false); } bool isExpired = false; //get the item's condition from the condition store var record = this.ExpirableStore.Get <ContextualId <StoredObjectId, IExpirable> >(soId); //if the eviction condition is touchable, touch it if (record != null && record.Context != null) { isExpired = record.Context.IsExpired(); //if the expirable is touchable, touch it if (record.Context is ITouchable) { ITouchable touch = (ITouchable)record.Context; touch.Touch(); } else if (record.Context is IPolyfacing) //or if it's polyfacing with a touchable face { IPolyfacing poly = (IPolyfacing)record.Context; var touch = poly.RootFace.AsHasTouchable(); if (touch != null) { touch.Touch(); } } } return(!isExpired); }
private void HandleInputMobile() { if (Input.touchCount == 1) { Touch touch = Input.GetTouch(0); TouchPosition = (Vector2)Camera.main.ScreenToWorldPoint(touch.position); RaycastHit2D raycastHit = Physics2D.Raycast(TouchPosition, Vector3.forward, Mathf.Infinity); if (elementClicked != null) { switch (touch.phase) { case TouchPhase.Moved: elementClicked.TouchDrag(); break; case TouchPhase.Ended: elementClicked.TouchUp(); elementClicked = null; break; } } else if (touch.phase == TouchPhase.Began) { if (raycastHit) { elementClicked = raycastHit.collider.GetComponent <ITouchable>(); } } } else { ClearElementClicked(); } }
// Use this for initialization void Start() { touchOn = false; curSelect = null; curSelect_State = Select_State.NONE_SELECT; }
public ITouchable testTouchable(UIObject touchableObj, Vector2 touchPosition) { /* * foreach( Transform t in touchableObj.client.transform ) * { * UIElement uie = t.GetComponent<UIElement>(); * if( uie != null ) * { * UIObject o = t.GetComponent<UIElement>().UIObject; * if( o != null ) * { * var touched = testTouchable( o, touchPosition ); * if( touched != null ) * return touched; * } * } * }*/ ITouchable touchable = touchableObj as ITouchable; if (touchable != null) { Debug.Log("test" + " (" + Time.time + ")"); if (touchable.hitTest(touchPosition)) { Debug.Log("hittest" + " (" + Time.time + ")"); return(touchable as ITouchable); } } return(null); }
public static void Add(ITouchable listener) { if (!touchables.Contains(listener)) { touchables.Add(listener); } }
private void HandleInputDesktop() { lastPosition = TouchPosition; TouchPosition = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D raycastHit = Physics2D.Raycast(TouchPosition, Vector3.forward, Mathf.Infinity); if (elementClicked != null) { if (Input.GetMouseButton(0)) { if (lastPosition != TouchPosition) { elementClicked.TouchDrag(); } } else { elementClicked.TouchUp(); elementClicked = null; } } else if (Input.GetMouseButtonDown(0)) { if (raycastHit) { elementClicked = raycastHit.collider.GetComponent <ITouchable>(); } } }
public void CheckOnClick(Vector3 position, string layerName) { if (!GameController.instance.IsGameSceneEnabled) { return; } int layerTouchable = LayerMask.GetMask(layerName); RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(position); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerTouchable)) { if (hit.transform.GetComponent <ITouchable>() != null && GameController.instance.IsGameSceneEnabled) { ITouchable objectTouched = hit.transform.GetComponent <ITouchable>(); HelpPanel panel = GameObject.FindObjectOfType <HelpPanel>(); if (!panel.IsPointerOverPanel()) { panel.SetPanel(objectTouched); } } else if (hit.transform.GetComponent <IMultitouchable>() != null && GameController.instance.IsGameSceneEnabled) { IMultitouchable multitouchable = hit.transform.GetComponent <IMultitouchable>(); multitouchable.MultiTouch(); } else { return; } } }
public Fingered(ITouchable obj, Vector3 pos) { Obj = obj; Pos = pos; _startTime = Time.time; }
public override void Collide(ITouchable other) { if (!(other is Shape)) { // Damage to this Health -= other.Power * Screen.Elapsed.Ticks; if (Health <= 0) { Active = false; //Screen.MovableShapes.Remove(this); } } if (Active) { // Movement to opposite side var otherCenter = other.CollisionBounds.GetCenter(); var collisionAngle = otherCenter.GetAngle(Bounds.GetCenter()); if (Math.Abs(movementVector.Y) < 1) { movementVector.Y += (Single)(Math.Sin(collisionAngle) / Stability) * other.Impact; } if (Math.Abs(movementVector.X) < 1) { movementVector.X += (Single)(Math.Cos(collisionAngle) / Stability) * other.Impact; } } }
ITouchable testTouchable(UIObject touchableObj, Vector2 touchPosition) { foreach (Transform t in touchableObj.client.transform) { UIElement uie = t.GetComponent <UIElement>(); if (uie != null) { UIObject o = t.GetComponent <UIElement>().UIObject; if (o != null) { var touched = testTouchable(o, touchPosition); if (touched != null) { return(touched); } } } } ITouchable touchable = touchableObj as ITouchable; if (touchable != null) { if (touchable.hitTest(touchPosition)) { return(touchable as ITouchable); } } return(null); }
public void addTouchableSprite( ITouchable touchableSprite ) { if( touchableSprite is UISprite ) addSprite( touchableSprite as UISprite ); // Add the sprite to our touchables and sort them addToTouchables( touchableSprite ); }
public void testContainerReturnsSameInstaceEachCall() { picoContainer.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable)); ITouchable t1 = (ITouchable)picoContainer.GetComponentInstance(typeof(ITouchable)); ITouchable t2 = (ITouchable)picoContainer.GetComponentInstance(typeof(ITouchable)); Assert.AreSame(t1, t2); }
private void HandleTap(GameObject tappedObject) { ITouchable touched = tappedObject.GetComponent<ITouchable>(); if (touched != null) { touched.OnTouch(); } }
private void OnTriggerExit2D(Collider2D other) { ITouchable touchable = other.gameObject.GetComponent <ITouchable>(); if (touchable != null) { touchable.Untouch(); } }
void OnTriggerEnter(Collider other) { ITouchable collectable = other.gameObject.GetComponent <ITouchable>(); if (collectable != null) { collectable.OnTouch(); } }
private void OnCollisionEnter(Collision collision) { ITouchable obj = collision.gameObject.GetComponent <ITouchable>(); if (obj != null) { obj.TouchAction(this.gameObject); } }
public void addTouchableSprite(ITouchable touchableSprite) { if (touchableSprite is UISprite) { addSprite(touchableSprite as UISprite); } // Add the sprite to our touchables and sort them addToTouchables(touchableSprite); }
private void OnTriggerEnter2D(Collider2D other) { currentActionable = other.gameObject; ITouchable touchable = currentActionable.GetComponent <ITouchable>(); if (touchable != null) { touchable.Touch(); } }
public void UnambiguouSelfDependency() { IMutablePicoContainer pico = CreatePicoContainer(null); pico.RegisterComponentImplementation(typeof(SimpleTouchable)); pico.RegisterComponentImplementation(typeof(DecoratedTouchable)); ITouchable t = (ITouchable)pico.GetComponentInstance(typeof(DecoratedTouchable)); Assert.IsNotNull(t); }
public override bool VerifyCollision(ITouchable other) { var colliding = CollisionBounds.IntersectsWith(other.CollisionBounds); if (!(other is Shape) && colliding) { this.colliding = true; } return(colliding); }
void Update() { if(Input.touchCount > 0) { foreach(Touch touch in Input.touches) { currentTouchID = touch.fingerId; ray = Camera.main.ScreenPointToRay(touch.position); if(Physics.Raycast(ray, out rayHitInfo)) { touchObject = rayHitInfo.transform.GetComponent(typeof(ITouchable)) as ITouchable; if(touchObject != null) { switch(touch.phase) { case TouchPhase.Began: touchObject.OnTouchBegan(); touchID = currentTouchID; break; case TouchPhase.Ended: touchObject.OnTouchEnded(); break; case TouchPhase.Moved: touchObject.OnTouchMoved(); break; case TouchPhase.Stationary: touchObject.OnTouchStayed(); break; case TouchPhase.Canceled: touchObject.OnTouchCanceled(); break; } } } else if(touchObject != null && touchID == currentTouchID) { switch(touch.phase) { case TouchPhase.Ended: touchObject.OnTouchEndedGlobal(); break; case TouchPhase.Moved: touchObject.OnTouchMovedGlobal(); break; case TouchPhase.Stationary: touchObject.OnTouchStayedGlobal(); break; case TouchPhase.Canceled: touchObject.OnTouchCanceledGlobal(); break; } } } } }
public bool VerifyCollision(ITouchable other) { if (other is Shoot shoot) { if (shoot.Cannon.Support == this) { return(false); } } return(CollisionBounds.IntersectsWith(other.CollisionBounds)); }
public void ComponentParameterFetches() { DefaultPicoContainer pico = new DefaultPicoContainer(); pico.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable)); ComponentParameter parameter = new ComponentParameter(typeof(ITouchable)); Assert.IsNotNull(pico.GetComponentInstance(typeof(ITouchable))); ITouchable touchable = (ITouchable)parameter.ResolveInstance(pico, null, typeof(ITouchable)); Assert.IsNotNull(touchable); }
public void ComponentParameterExcludesSelf() { DefaultPicoContainer pico = new DefaultPicoContainer(); IComponentAdapter adapter = pico.RegisterComponentImplementation(typeof(ITouchable), typeof(SimpleTouchable)); Assert.IsNotNull(pico.GetComponentInstance(typeof(ITouchable))); ITouchable touchable = (ITouchable)ComponentParameter.DEFAULT.ResolveInstance(pico, adapter, typeof(ITouchable)); Assert.IsNull(touchable); }
public override bool VerifyCollision(ITouchable other) { var colliding = CollisionBounds.IntersectsWith(other.CollisionBounds); if (!(other is Block) && colliding) { return(this.colliding = true); } else { return(colliding); } }
public void addTouchableSprite(ITouchable touchableSprite) { if (touchableSprite is UISprite) { addSprite(touchableSprite as UISprite); } // Add the sprite to our touchables and sort them _touchableSprites.Add(touchableSprite as ITouchable); // Sort the sprites container _touchableSprites.Sort(); }
private bool IsTouchable(GameObject go, out ITouchable touchable) { foreach (MonoBehaviour mb in go.GetComponents <MonoBehaviour>()) { if (mb is ITouchable) { touchable = (ITouchable)mb; return(true); } } touchable = null; return(false); }
protected IEnumerator checkDelayedContentTouch() { yield return(new WaitForSeconds(CONTENT_TOUCH_DELAY)); if (_isDragging && Mathf.Abs(_deltaTouch) < TOUCH_MAX_DELTA_FOR_ACTIVATION) { var fixedTouchPosition = new Vector2(_lastTouch.position.x, Screen.height - _lastTouch.position.y); _activeTouchable = getButtonForScreenPosition(fixedTouchPosition); if (_activeTouchable != null) { _activeTouchable.onTouchBegan(_lastTouch, fixedTouchPosition); } } }
public TouchHandler(ITouchable touchable) { m_Touchable = touchable; m_Owner = (touchable as MonoBehaviour).gameObject; MouseTouchManager.Instance.AddHandler(this); }
public TouchableObserver(ITouchable[] touchables) { this.touchables = touchables; }
public NamedDependsOnTouchable(ITouchable t, String name) : base(t) { }
public NeedsTouchable(ITouchable touchable) { this.touchable = touchable; }
public void removeFromTouchables( ITouchable touchable ) { _touchableSprites.Remove( touchable ); }
// Touch handlers. Subclasses should override onTouchMoved public virtual void onTouchBegan( Touch touch, Vector2 touchPos ) { // sanity check in case we lost a touch (happens with Unity on occassion) if( _activeTouchable != null ) { // we dont pass onTouchEnded here because technically we are still over the ITouchable _activeTouchable.highlighted = false; _activeTouchable = null; } _deltaTouch = 0; _isDragging = true; _velocities.Clear(); // kick off a new check _manager.StartCoroutine( checkDelayedContentTouch() ); }
public void addToTouchables( ITouchable touchable ) { _touchableSprites.Add( touchable ); // Sort the sprites container _touchableSprites.Sort(); }
public DecoratedTouchable(ITouchable theDelegate) { this.theDelegate = theDelegate; }
public DependsOnTouchable(ITouchable touchable) { Assert.IsNotNull(touchable, "Touchable cannot be passed in as null"); touchable.Touch(); this.touchable = touchable; }
void Start() { pickableBackgroundTouchable = (ITouchable)PickableBackground.gameObject.GetComponent(typeof(ITouchable)); pickableBackgroundCollider = PickableBackground.gameObject.GetComponent<BoxCollider>(); }
public void addTouchableSprite( ITouchable touchableSprite ) { if( touchableSprite is UISprite ) addSprite( touchableSprite as UISprite ); // Add the sprite to our touchables and sort them _touchableSprites.Add( touchableSprite as ITouchable ); // TODO: why does this not work with UIAbstractTouchableContainer? //_touchableSprites.Sort(); }
public TouchableContactPair(ITouchable touchable, ContactData contact) { this.touchable = touchable; this.contact = contact; }
public virtual void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame ) { _isDragging = false; // pass on the touch if we still have an active touchable if( _activeTouchable != null ) { _activeTouchable.onTouchEnded( touch, touchPos, true ); _activeTouchable.highlighted = false; _activeTouchable = null; } else { _manager.StartCoroutine( decelerate() ); } }
public DependsOnTwoComponents(ITouchable Touchable, DependsOnTouchable fred) { // Assert.IsNotNull("Touchable cannot be passed in as null", Touchable); // Assert.IsNotNull("DependsOnTouchable cannot be passed in as null", fred); }
public InputFocus(int fingerID) { this.fingerID = fingerID; myTouchable = null; }
public void addTouchableSprite( ITouchable touchableSprite ) { if( touchableSprite is UISprite ) addSprite( touchableSprite as UISprite ); // Add the sprite to our touchables and sort them _touchableSprites.Add( touchableSprite as ITouchable ); // Sort the sprites container _touchableSprites.Sort(); }
public void SetFocus(ITouchable target) { myTouchable = target; }
public void addToTouchables( ITouchable touchable ) { _touchableSprites.Add( touchable ); }
protected IEnumerator checkDelayedContentTouch() { yield return new WaitForSeconds( CONTENT_TOUCH_DELAY ); if( _isDragging && Mathf.Abs( _deltaTouch ) < TOUCH_MAX_DELTA_FOR_ACTIVATION ) { var fixedTouchPosition = new Vector2( _lastTouch.position.x, Screen.height - _lastTouch.position.y ); _activeTouchable = getButtonForScreenPosition( fixedTouchPosition ); if( _activeTouchable != null ) _activeTouchable.onTouchBegan( _lastTouch, fixedTouchPosition ); } }