private void SetTargetPosition() { float _x = 0; float _y = 0; float _z = 0; if (m_customMovement) { _x = (m_defaultLocalPosition.x - m_borderLeft) + Random.Range(m_borderLeft, m_borderRight); _y = (m_defaultLocalPosition.y + m_borderTop) + Random.Range(m_borderTop, m_borderBottom); _z = 1; } else { BubbleArea _bubbleArea = BubbleCreator.instance.bubbleArea; _x = Random.Range(_bubbleArea.left, _bubbleArea.right); _y = Random.Range(_bubbleArea.top, _bubbleArea.bottom); _z = this.transform.position.z; } targetLocalPosition = new Vector3(_x, _y, _z); }
public BubbleLabelInfo(GameObject ui, GameObject rootArea) { var rootRect = rootArea.GetComponent <RectTransform>(); var localPos = rootArea.transform.InverseTransformPoint(ui.transform.position); if (localPos.x < 0 && localPos.y > 0) { this.BubbleArea = BubbleArea.LeftTop; this.CornerPos = new Vector3(-rootRect.rect.width / 2, rootRect.rect.height / 2, 0); } else if (localPos.x > 0 && localPos.y > 0) { this.BubbleArea = BubbleArea.RightTop; this.CornerPos = new Vector3(rootRect.rect.width / 2, rootRect.rect.height / 2, 0); } else if (localPos.x < 0 && localPos.y < 0) { this.BubbleArea = BubbleArea.LeftBottom; this.CornerPos = new Vector3(-rootRect.rect.width / 2, -rootRect.rect.height / 2, 0); } else { this.BubbleArea = BubbleArea.RightBottom; this.CornerPos = new Vector3(rootRect.rect.width / 2, -rootRect.rect.height / 2, 0); } float distance = Vector3.Distance(localPos, this.CornerPos); float bet = distance / (distance + L); float distanceX = rootRect.rect.width / 2 - Mathf.Abs(localPos.x); float deltaX = distanceX / bet - distanceX; float distanceY = rootRect.rect.height / 2 - Mathf.Abs(localPos.y); float deltaY = distanceY / bet - distanceY; Vector3 d2 = localPos - this.CornerPos; switch (this.BubbleArea) { case BubbleArea.LeftTop: { Vector3 d1 = new Vector3(0, -1, 0); float dot = Vector3.Dot(d1, d2.normalized); this.Angle = Mathf.Acos(dot) * Mathf.Rad2Deg; this.LabelPos = new Vector3(deltaX, -deltaY, 0); } break; case BubbleArea.RightTop: { Vector3 d1 = new Vector3(0, -1, 0); float dot = Vector3.Dot(d1, d2.normalized); this.Angle = 360 - Mathf.Acos(dot) * Mathf.Rad2Deg; this.LabelPos = new Vector3(-deltaX, -deltaY, 0); } break; case BubbleArea.LeftBottom: { Vector3 d1 = new Vector3(0, 1, 0); float dot = Vector3.Dot(d1, d2.normalized); this.Angle = 180 - Mathf.Acos(dot) * Mathf.Rad2Deg; this.LabelPos = new Vector3(deltaX, deltaY, 0); } break; case BubbleArea.RightBottom: { Vector3 d1 = new Vector3(0, 1, 0); float dot = Vector3.Dot(d1, d2.normalized); this.Angle = 180 + Mathf.Acos(dot) * Mathf.Rad2Deg; this.LabelPos = new Vector3(-deltaX, deltaY, 0); } break; } }