public void OnHover(RectTransform uiElement, ShowPriority showPriority = ShowPriority.Up) {
			
			this.uiElement = uiElement;

			if (this.tempHud != null) this.tempHud.enabled = false;

			if (this.animationRoot != null) this.animationRoot.SetInState();

			var canvas = uiElement.root.GetComponentsInChildren<Canvas>()[0];
			uiElement.root.GetComponentInChildren<Canvas>();
			this.uiElementCanvas = canvas;

			this.ApplyPosition();

			if (this.animationRoot != null) this.animationRoot.SetResetState();

			if (this.layoutRoot != null) {

				this.CheckPivot(uiElement.rect.size, canvas.transform as RectTransform, showPriority);

			} else {
				
				var anchor = this.root.anchoredPosition3D;
				anchor.z = 0f;
				this.root.anchoredPosition3D = anchor + Vector3.up * uiElement.rect.size.y * 0.5f;

			}

		}
Exemple #2
0
        public void OnHover(RectTransform uiElement, ShowPriority showPriority = ShowPriority.Up)
        {
            this.uiElement = uiElement;

            if (this.tempHud != null)
            {
                this.tempHud.enabled = false;
            }

            //if (this.animationRoot != null) this.animationRoot.SetInState();

            var canvas = uiElement.root.GetComponentsInChildren <Canvas>()[0];

            uiElement.root.GetComponentInChildren <Canvas>();
            this.uiElementCanvas = canvas;

            this.ApplyPosition();

            //if (this.animationRoot != null) this.animationRoot.SetResetState();

            if (this.layoutRoot != null)
            {
                this.CheckPivot(uiElement.rect.size, canvas.transform as RectTransform, showPriority);
            }
            else
            {
                var anchor = this.root.anchoredPosition3D;
                anchor.z = 0f;
                this.root.anchoredPosition3D = anchor + Vector3.up * uiElement.rect.size.y * 0.5f;
            }
        }
Exemple #3
0
    public void GivePriority(string color)
    {
        GameObject victim = getVictim();

        if (victim)
        {
            Parameters Parameters = victim.GetComponent <Parameters>();
            Parameters.SetPrioColor(color);
            ShowPriority ShowPriority = victim.transform.Find("PriorityCard").GetComponent <ShowPriority>();
            ShowPriority.UpdatePriority(color);
        }
    }
		public IEnumerator CheckPivot_YIELD(Vector2 size, RectTransform sourceTransform, ShowPriority showPriority) {

			// Get pivot point according on screen rect

			// Check points
			var checks = new Vector2[0];
			var offsetDirs = new Vector2[0];

			if (showPriority == ShowPriority.Down) {

				checks = new Vector2[] {
					new Vector2(0.5f, 1f), 	// top center
					new Vector2(0f, 1f), 	// top left
					new Vector2(1f, 1f), 	// top right
					new Vector2(0.5f, 0f), 	// bottom center
					new Vector2(0f, 0f), 	// bottom left
					new Vector2(1f, 0f), 	// bottom right
				};

				offsetDirs = new Vector2[] {
					Vector2.down,
					Vector2.down,
					Vector2.down,
					Vector2.up,
					Vector2.up,
					Vector2.up,
				};

			} else if (showPriority == ShowPriority.Up) {
				
				checks = new Vector2[] {
					new Vector2(0.5f, 0f), 	// bottom center
					new Vector2(0f, 0f), 	// bottom left
					new Vector2(1f, 0f), 	// bottom right
					new Vector2(0.5f, 1f), 	// top center
					new Vector2(0f, 1f), 	// top left
					new Vector2(1f, 1f), 	// top right
				};
				
				offsetDirs = new Vector2[] {
					Vector2.up,
					Vector2.up,
					Vector2.up,
					Vector2.down,
					Vector2.down,
					Vector2.down,
				};

			}

			CanvasUpdater.ForceUpdate(this.canvas, this.canvasScaler);
			yield return false;
			
			var scaleFactor = this.GetScaleFactor();
			size *= scaleFactor;

			this.ApplyPosition();

			var centerPoint = this.root.anchoredPosition;
			var sourceRect = (this.canvas.transform as RectTransform).rect;

			for (int i = 0; i < checks.Length; ++i) {

				var centerOffset = offsetDirs[i] * size.y * 0.5f;
				var pivot = checks[i];
				this.layoutRoot.pivot = pivot;

				this.root.anchoredPosition = centerPoint + centerOffset;

				Vector3[] points = new Vector3[4];
				this.layoutRoot.GetLocalCorners(points);

				var offset = this.root.anchoredPosition;
				var bottomLeft = offset + points[0].XY();
				var topLeft = offset + points[1].XY();
				var topRight = offset + points[2].XY();
				var bottomRight = offset + points[3].XY();

				if (sourceRect.Contains(bottomLeft) == false) {
					
					//Debug.Log("Failed bottom left: " + sourceRect + " << " + bottomLeft);
					continue;
					
				}
				
				if (sourceRect.Contains(topLeft) == false) {
					
					//Debug.Log("Failed top left: " + sourceRect + " << " + topLeft);
					continue;
					
				}
				
				if (sourceRect.Contains(topRight) == false) {
					
					//Debug.Log("Failed top right: " + sourceRect + " << " + topRight);
					continue;
					
				}
				
				if (sourceRect.Contains(bottomRight) == false) {
					
					//Debug.Log("Failed bottom right: " + sourceRect + " << " + bottomRight);
					continue;
					
				}

				break;

			}

		}
		public void CheckPivot(Vector2 size, RectTransform sourceRect, ShowPriority showPriority) {
			
			this.StartCoroutine(this.CheckPivot_YIELD(size, sourceRect, showPriority));

		}
Exemple #6
0
        public IEnumerator CheckPivot_YIELD(Vector2 size, RectTransform sourceTransform, ShowPriority showPriority)
        {
            // Get pivot point according on screen rect

            // Check points
            var checks     = new Vector2[0];
            var offsetDirs = new Vector2[0];

            if (showPriority == ShowPriority.Down)
            {
                checks = new Vector2[] {
                    new Vector2(0.5f, 1f),                      // top center
                    new Vector2(0f, 1f),                        // top left
                    new Vector2(1f, 1f),                        // top right
                    new Vector2(0.5f, 0f),                      // bottom center
                    new Vector2(0f, 0f),                        // bottom left
                    new Vector2(1f, 0f),                        // bottom right
                };

                offsetDirs = new Vector2[] {
                    Vector2.down,
                    Vector2.down,
                    Vector2.down,
                    Vector2.up,
                    Vector2.up,
                    Vector2.up,
                };
            }
            else if (showPriority == ShowPriority.Up)
            {
                checks = new Vector2[] {
                    new Vector2(0.5f, 0f),                      // bottom center
                    new Vector2(0f, 0f),                        // bottom left
                    new Vector2(1f, 0f),                        // bottom right
                    new Vector2(0.5f, 1f),                      // top center
                    new Vector2(0f, 1f),                        // top left
                    new Vector2(1f, 1f),                        // top right
                };

                offsetDirs = new Vector2[] {
                    Vector2.up,
                    Vector2.up,
                    Vector2.up,
                    Vector2.down,
                    Vector2.down,
                    Vector2.down,
                };
            }

            CanvasUpdater.ForceUpdate(this.canvas, this.canvasScaler);
            yield return(false);

            var scaleFactor = this.GetScaleFactor();

            size *= scaleFactor;

            this.ApplyPosition();

            var centerPoint = this.root.anchoredPosition;
            var sourceRect  = (this.canvas.transform as RectTransform).rect;

            for (int i = 0; i < checks.Length; ++i)
            {
                var centerOffset = offsetDirs[i] * size.y * 0.5f;
                var pivot        = checks[i];
                this.layoutRoot.pivot = pivot;

                this.root.anchoredPosition = centerPoint + centerOffset;

                Vector3[] points = new Vector3[4];
                this.layoutRoot.GetLocalCorners(points);

                var offset      = this.root.anchoredPosition;
                var bottomLeft  = offset + points[0].XY();
                var topLeft     = offset + points[1].XY();
                var topRight    = offset + points[2].XY();
                var bottomRight = offset + points[3].XY();

                if (sourceRect.Contains(bottomLeft) == false)
                {
                    //Debug.Log("Failed bottom left: " + sourceRect + " << " + bottomLeft);
                    continue;
                }

                if (sourceRect.Contains(topLeft) == false)
                {
                    //Debug.Log("Failed top left: " + sourceRect + " << " + topLeft);
                    continue;
                }

                if (sourceRect.Contains(topRight) == false)
                {
                    //Debug.Log("Failed top right: " + sourceRect + " << " + topRight);
                    continue;
                }

                if (sourceRect.Contains(bottomRight) == false)
                {
                    //Debug.Log("Failed bottom right: " + sourceRect + " << " + bottomRight);
                    continue;
                }

                break;
            }
        }
Exemple #7
0
 public void CheckPivot(Vector2 size, RectTransform sourceRect, ShowPriority showPriority)
 {
     this.StartCoroutine(this.CheckPivot_YIELD(size, sourceRect, showPriority));
 }