private void OnRendered(BoundedUIObjectEventArgs e) { ResizeBoundaryScale(e); RelocatePosition(e); ResetMeshObj(); if (m_boundaryScaleMode == BoundaryScaleMode.ScaleWithParent) { var count = transform.childCount; for (int i = 0; i < count; i++) { var obj = transform.GetChild(i).GetComponent <KaiTool_BoundedUIObject>(); if (obj != null) { obj.OnRendered(e); } } } m_lastBoundary = (KaiTool_Boundary)m_boudary.Clone(); }
private void ResizeBoundaryScale(BoundedUIObjectEventArgs e) { if (m_boundaryScaleMode == BoundaryScaleMode.ScaleWithParent) { if (m_lastBoundary != null) { var dic = e.m_resizeArgsDic; if (dic != null) { if (dic.ContainsKey(BoundaryDirection.Forward)) { m_boudary.Forward *= dic[BoundaryDirection.Forward]; } if (dic.ContainsKey(BoundaryDirection.Backward)) { m_boudary.Backward *= dic[BoundaryDirection.Backward]; } if (dic.ContainsKey(BoundaryDirection.Leftward)) { m_boudary.Leftward *= dic[BoundaryDirection.Leftward]; } if (dic.ContainsKey(BoundaryDirection.Rightward)) { m_boudary.Rightward *= dic[BoundaryDirection.Rightward]; } if (dic.ContainsKey(BoundaryDirection.Upward)) { m_boudary.Upward *= dic[BoundaryDirection.Upward]; } if (dic.ContainsKey(BoundaryDirection.Downward)) { m_boudary.Downward *= dic[BoundaryDirection.Downward]; } } } if (m_boundaryResized != null) { m_boundaryResized(this, e); } } }
private BoundedUIObjectEventArgs GetEventArgsByHandles(BoundaryDirection direction) { var dic = new Dictionary <BoundaryDirection, float>(); float temp = 0f; switch (direction) { case BoundaryDirection.Forward: temp = Vector3.Dot((m_forwardHandle.Position - m_boudary.Center.position), transform.forward); dic.Add(BoundaryDirection.Forward, temp / m_boudary.Forward); break; case BoundaryDirection.Backward: temp = Vector3.Dot((m_backwardHandle.Position - m_boudary.Center.position), -transform.forward); dic.Add(BoundaryDirection.Backward, temp / m_boudary.Backward); break; case BoundaryDirection.Leftward: temp = Vector3.Dot((m_leftwardHandle.Position - m_boudary.Center.position), -transform.right); dic.Add(BoundaryDirection.Leftward, temp / m_boudary.Leftward); break; case BoundaryDirection.Rightward: temp = Vector3.Dot((m_rightwardHandle.Position - m_boudary.Center.position), transform.right); dic.Add(BoundaryDirection.Rightward, temp / m_boudary.Rightward); break; case BoundaryDirection.Upward: temp = Vector3.Dot((m_upwardHandle.Position - m_boudary.Center.position), transform.up); dic.Add(BoundaryDirection.Upward, temp / m_boudary.Upward); break; case BoundaryDirection.Downward: temp = Vector3.Dot((m_downwardHandle.Position - m_boudary.Center.position), -transform.up); dic.Add(BoundaryDirection.Downward, temp / m_boudary.Downward); break; } var args = new BoundedUIObjectEventArgs(dic); return(args); }
private void ResetRelativePosition(BoundedUIObjectEventArgs e) { if (m_anchor.AnchorMode == AnchorMode.ConstantPosition) { //Do nothing } if (m_anchor.AnchorMode == AnchorMode.RelocateWithParent) { var dic = e.m_resizeArgsDic; var anchorDirection = m_anchor.AnchorDirection; if (dic != null) { if (dic.ContainsKey(BoundaryDirection.Forward)) { if ((anchorDirection & (AnchorDirection.Center | AnchorDirection.NegativeXNegativeYZ | AnchorDirection.XNegativeYZ | AnchorDirection.NegativeXYZ | AnchorDirection.XYZ | AnchorDirection.Z)) != 0) { m_anchor.Z = dic[BoundaryDirection.Forward] * m_anchor.Z; } } if (dic.ContainsKey(BoundaryDirection.Backward)) { if ((anchorDirection & (AnchorDirection.NegativeXNegativeYNegativeZ | AnchorDirection.XNegativeYNegativeZ | AnchorDirection.NegativeXYNegativeZ | AnchorDirection.XYNegativeZ | AnchorDirection.NegativeZ)) != 0) { m_anchor.Z = dic[BoundaryDirection.Backward] * m_anchor.Z; } } if (dic.ContainsKey(BoundaryDirection.Leftward)) { if ((anchorDirection & (AnchorDirection.Center | AnchorDirection.NegativeXNegativeYNegativeZ | AnchorDirection.NegativeXYNegativeZ | AnchorDirection.NegativeXNegativeYZ | AnchorDirection.NegativeXYZ | AnchorDirection.NegativeX)) != 0) { m_anchor.X = dic[BoundaryDirection.Leftward] * m_anchor.X; } } if (dic.ContainsKey(BoundaryDirection.Rightward)) { if ((anchorDirection & (AnchorDirection.XNegativeYNegativeZ | AnchorDirection.XYNegativeZ | AnchorDirection.XNegativeYZ | AnchorDirection.XYZ | AnchorDirection.X)) != 0) { m_anchor.X = dic[BoundaryDirection.Rightward] * m_anchor.X; } } if (dic.ContainsKey(BoundaryDirection.Upward)) { if ((anchorDirection & (AnchorDirection.Center | AnchorDirection.NegativeXYNegativeZ | AnchorDirection.NegativeXYZ | AnchorDirection.XYNegativeZ | AnchorDirection.XYZ | AnchorDirection.Y)) != 0) { m_anchor.Y = dic[BoundaryDirection.Upward] * m_anchor.Y; } } if (dic.ContainsKey(BoundaryDirection.Downward)) { if ((anchorDirection & (AnchorDirection.NegativeXNegativeYNegativeZ | AnchorDirection.NegativeXNegativeYZ | AnchorDirection.XNegativeYNegativeZ | AnchorDirection.XNegativeYZ | AnchorDirection.NegativeY)) != 0) { m_anchor.Y = dic[BoundaryDirection.Downward] * m_anchor.Y; } } } } }
private void RelocatePosition(BoundedUIObjectEventArgs e) { if (m_UIParent != null) { // var vec = m_anchor.RelativePostion; ResetRelativePosition(e); Vector3 pos; switch (m_anchor.AnchorDirection) { case AnchorDirection.Center: pos = m_UIParent.transform.position + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; case AnchorDirection.NegativeXNegativeYNegativeZ: pos = m_UIParent.m_boudary.GetVertex(0) + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; case AnchorDirection.NegativeXNegativeYZ: pos = m_UIParent.m_boudary.GetVertex(1) + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; case AnchorDirection.XNegativeYZ: pos = m_UIParent.m_boudary.GetVertex(2) + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; case AnchorDirection.XNegativeYNegativeZ: pos = m_UIParent.m_boudary.GetVertex(3) + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; case AnchorDirection.NegativeXYNegativeZ: pos = m_UIParent.m_boudary.GetVertex(4) + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; case AnchorDirection.NegativeXYZ: pos = m_UIParent.m_boudary.GetVertex(5) + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; case AnchorDirection.XYZ: pos = m_UIParent.m_boudary.GetVertex(6) + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; case AnchorDirection.XYNegativeZ: pos = m_UIParent.m_boudary.GetVertex(7) + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; default: pos = m_UIParent.transform.position + m_UIParent.transform.rotation * m_anchor.RelativePostion; transform.position = pos; break; } } if (e.m_resizeArgsDic != null) { if (e.m_resizeArgsDic.Count != 0) { if (m_boundaryRelocated != null) { m_boundaryRelocated(this, e); } } } }