Esempio n. 1
0
        protected override void OnDrag()
        {
            base.OnDrag();

            Vector3 pointOnPlane;

            if (GetPointOnDragPlane(Window.Pointer, out pointOnPlane))
            {
                if (m_selectedPointIndex == m_referencePoints.Length - 1)
                {
                    Vector3 offset = pointOnPlane - m_beginDragPoint;

                    m_points.transform.position = m_position + offset;
                    m_lines.transform.position  = m_position + offset;

                    if (EffectiveGridUnitSize > 0.001)
                    {
                        Vector3 gridOffset = GetGridOffset(EffectiveGridUnitSize, m_points.transform.position);
                        m_points.transform.position += gridOffset;
                        m_lines.transform.position  += gridOffset;
                        offset += gridOffset;
                    }

                    for (int i = 0; i < ActiveTargets.Length; ++i)
                    {
                        ActiveTargets[i].position = m_referencePositions[i] + offset;
                    }
                    UpdateText();
                }
                else
                {
                    Vector3 sign = Vector3.one;
                    if (m_selectedPointIndex >= 0)
                    {
                        Vector3 refPoint;
                        pointOnPlane = m_points.transform.InverseTransformPoint(pointOnPlane);
                        Vector3 offset = GetOffset(m_selectedPointIndex, pointOnPlane, out refPoint);
                        if (EffectiveGridUnitSize > 0.001)
                        {
                            float gridSize = EffectiveGridUnitSize;
                            gridSize /= 2;

                            if (!Mathf.Approximately(m_localScale.x, 0))
                            {
                                float gridSizeX = gridSize / m_localScale.x;
                                offset.x = Mathf.RoundToInt(offset.x / gridSizeX) * gridSizeX;
                            }

                            if (!Mathf.Approximately(m_localScale.y, 0))
                            {
                                float gridSizeY = gridSize / m_localScale.y;
                                offset.y = Mathf.RoundToInt(offset.y / gridSizeY) * gridSizeY;
                            }

                            if (!Mathf.Approximately(m_localScale.z, 0))
                            {
                                float gridSizeZ = gridSize / m_localScale.z;

                                offset.z = Mathf.RoundToInt(offset.z / gridSizeZ) * gridSizeZ;
                            }
                        }

                        m_bounds.center = refPoint + offset;
                        Vector3 extents = m_bounds.extents;
                        if (m_currentAxis == RuntimeHandleAxis.XY)
                        {
                            offset.z = extents.z;
                            sign.x   = Mathf.Sign(offset.x / m_beginDragOffset.x);
                            sign.y   = Mathf.Sign(offset.y / m_beginDragOffset.y);
                        }
                        else if (m_currentAxis == RuntimeHandleAxis.XZ)
                        {
                            offset.y = extents.y;
                            sign.x   = Mathf.Sign(offset.x / m_beginDragOffset.x);
                            sign.z   = Mathf.Sign(offset.z / m_beginDragOffset.z);
                        }
                        else
                        {
                            offset.x = extents.x;
                            sign.y   = Mathf.Sign(offset.y / m_beginDragOffset.y);
                            sign.z   = Mathf.Sign(offset.z / m_beginDragOffset.z);
                        }
                        m_bounds.extents = new Vector3(Mathf.Abs(offset.x), Mathf.Abs(offset.y), Mathf.Abs(offset.z));

                        UpdatePointsMesh(m_points.sharedMesh, m_currentAxis, m_bounds);
                        UpdateLinesMesh(m_lines.sharedMesh, m_currentAxis, m_bounds);
                        UpdateText();
                    }
                    else if (m_selectedEdgeIndex >= 0)
                    {
                        pointOnPlane = m_lines.transform.InverseTransformPoint(pointOnPlane);

                        Vector3 p0;
                        Vector3 p1;
                        Vector3 offset = GetOffset(m_selectedEdgeIndex, pointOnPlane, out p0, out p1);
                        if (EffectiveGridUnitSize > 0.001)
                        {
                            float gridSize = EffectiveGridUnitSize;

                            if (!Mathf.Approximately(m_localScale.x, 0))
                            {
                                float gridSizeX = gridSize / m_localScale.x;
                                offset.x = Mathf.RoundToInt(offset.x / gridSizeX) * gridSizeX;
                            }

                            if (!Mathf.Approximately(m_localScale.y, 0))
                            {
                                float gridSizeY = gridSize / m_localScale.y;
                                offset.y = Mathf.RoundToInt(offset.y / gridSizeY) * gridSizeY;
                            }

                            if (!Mathf.Approximately(m_localScale.z, 0))
                            {
                                float gridSizeZ = gridSize / m_localScale.z;

                                offset.z = Mathf.RoundToInt(offset.z / gridSizeZ) * gridSizeZ;
                            }
                        }

                        Vector3 p2  = p1 + offset;
                        Vector3 ext = (p2 - p0) / 2;

                        m_bounds.center = ((p0 + p1) + offset) / 2;

                        Vector3 extents = m_bounds.extents;
                        if (m_currentAxis == RuntimeHandleAxis.XY)
                        {
                            ext.z = extents.z;
                            if (Mathf.Abs(offset.y) > Mathf.Abs(offset.x))
                            {
                                sign.y = Mathf.Sign(offset.y / m_beginDragOffset.y);
                            }
                            else
                            {
                                sign.x = Mathf.Sign(offset.x / m_beginDragOffset.x);
                            }
                        }
                        else if (m_currentAxis == RuntimeHandleAxis.XZ)
                        {
                            ext.y = extents.y;

                            if (Mathf.Abs(offset.z) > Mathf.Abs(offset.x))
                            {
                                sign.z = Mathf.Sign(offset.z / m_beginDragOffset.z);
                            }
                            else
                            {
                                sign.x = Mathf.Sign(offset.x / m_beginDragOffset.x);
                            }
                        }
                        else
                        {
                            ext.x = extents.x;
                            if (Mathf.Abs(offset.z) > Mathf.Abs(offset.y))
                            {
                                sign.z = Mathf.Sign(offset.z / m_beginDragOffset.z);
                            }
                            else
                            {
                                sign.y = Mathf.Sign(offset.y / m_beginDragOffset.y);
                            }
                        }
                        m_bounds.extents = new Vector3(Mathf.Abs(ext.x), Mathf.Abs(ext.y), Mathf.Abs(ext.z));

                        UpdatePointsMesh(m_points.sharedMesh, m_currentAxis, m_bounds);
                        UpdateLinesMesh(m_lines.sharedMesh, m_currentAxis, m_bounds);
                        UpdateText();
                    }

                    for (int i = 0; i < ActiveTargets.Length; ++i)
                    {
                        Transform target = ActiveTargets[i];

                        target.localScale = Vector3.Scale(m_referenceScale[i],
                                                          new Vector3(m_bounds.extents.x / m_referenceBounds.extents.x * sign.x,
                                                                      m_bounds.extents.y / m_referenceBounds.extents.y * sign.y,
                                                                      m_bounds.extents.z / m_referenceBounds.extents.z * sign.z));


                        Vector3 pivotOffset = Vector3.zero;

                        ExposeToEditor exposeToEditor = target.GetComponent <ExposeToEditor>();
                        if (exposeToEditor != null)
                        {
                            pivotOffset = target.TransformVector(-exposeToEditor.Bounds.center);
                        }

                        target.position = m_referencePositions[i] + (m_points.transform.TransformPoint(m_bounds.center) - m_referencePositions[i]) + pivotOffset;
                    }
                }

                UpdateConnectedTools();
            }
        }
Esempio n. 2
0
        private void LateUpdate()
        {
            if (m_rte.ActiveWindow == null)
            {
                return;
            }

            if (m_rte.ActiveWindow.WindowType != RuntimeWindowType.Scene)
            {
                return;
            }

            if (!m_rte.ActiveWindow.Camera)
            {
                return;
            }

            if (m_exposeToEditor != null && m_exposeToEditor.MarkAsDestroyed)
            {
                EndEditing(true);
                m_exposeToEditor = null;
                return;
            }

            if (PolyShape != null && PolyShape.IsEditing)
            {
                BaseHandle baseHandle = m_rte.Tools.ActiveTool as BaseHandle;
                if (baseHandle != null && baseHandle.IsDragging && m_rte.Selection.activeGameObject == m_pivot.gameObject)
                {
                    if (baseHandle is PositionHandle)
                    {
                        PolyShape.SelectedPosition = PolyShape.transform.InverseTransformPoint(m_pivot.position);
                        m_endEditOnPointerUp       = false;
                    }
                }
                else
                {
                    if (m_rte.Input.GetPointerDown(0))
                    {
                        m_endEditOnPointerUp = true;
                        if (m_rte.Tools.ActiveTool is BaseHandle)
                        {
                            BaseHandle handle = (BaseHandle)m_rte.Tools.ActiveTool;
                            if (handle.IsDragging)
                            {
                                m_endEditOnPointerUp = false;
                            }
                        }
                    }
                    else if (m_rte.Input.GetKeyDown(KeyCode.Return))
                    {
                        EndEditing(true);
                    }
                    else if (m_rte.Input.GetPointerUp(0))
                    {
                        if (!m_rte.ActiveWindow.IsPointerOver || m_rte.Tools.ActiveTool != null && !(m_rte.Tools.ActiveTool is BoxSelection))
                        {
                            return;
                        }

                        if (m_endEditOnPointerUp)
                        {
                            RuntimeWindow window = m_rte.ActiveWindow;
                            if (PolyShape.Click(window.Camera, m_rte.Input.GetPointerXY(0)))
                            {
                                EndEditing(false);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void RecalculateBoundsAndRebuild()
        {
            m_rotation   = Quaternion.identity;
            m_position   = Vector3.zero;
            m_localScale = Vector3.one;
            m_bounds     = new Bounds();

            if (m_txtSize1 != null)
            {
                m_txtSize1.text = string.Empty;
            }

            if (m_txtSize2 != null)
            {
                m_txtSize2.text = string.Empty;
            }


            if (RealTargets == null || RealTargets.Length == 0)
            {
                return;
            }

            if (ActiveRealTargets.Length == 1 && ActiveRealTargets[0].GetComponent <ExposeToEditor>())
            {
                ExposeToEditor exposeToEditor = ActiveRealTargets[0].GetComponent <ExposeToEditor>();

                m_bounds     = exposeToEditor.Bounds;
                m_position   = exposeToEditor.transform.position;
                m_rotation   = exposeToEditor.transform.rotation;
                m_localScale = exposeToEditor.transform.lossyScale;

                if (m_bounds.extents == Vector3.zero)
                {
                    if (m_lines != null)
                    {
                        m_lines.sharedMesh.Clear();
                    }

                    if (m_points != null)
                    {
                        m_points.sharedMesh.Clear();
                    }
                    return;
                }
            }
            else
            {
                Renderer[] renderers = ActiveRealTargets.Where(t => t != null).SelectMany(t => t.GetComponentsInChildren <Renderer>()).ToArray();
                if (renderers.Length == 0)
                {
                    if (m_lines != null)
                    {
                        m_lines.sharedMesh.Clear();
                    }

                    if (m_points != null)
                    {
                        m_points.sharedMesh.Clear();
                    }

                    return;
                }
                else
                {
                    m_bounds = renderers[0].bounds;
                    for (int i = 1; i < renderers.Length; ++i)
                    {
                        Renderer renderer = renderers[i];
                        m_bounds.Encapsulate(renderer.bounds);
                    }
                }
            }

            if (m_lines == null && m_points == null)
            {
                return;
            }

            m_lines.transform.position    = m_position;
            m_lines.transform.rotation    = m_rotation;
            m_lines.transform.localScale  = m_localScale;
            m_points.transform.position   = m_position;
            m_points.transform.rotation   = m_rotation;
            m_points.transform.localScale = m_localScale;

            m_currentAxis = GetAxis(out m_currentDot);
            BuildPointsMesh(m_points.sharedMesh, m_currentAxis, m_bounds);
            BuildLineMesh(m_lines.sharedMesh, m_currentAxis, m_bounds);

            if (m_txtSize1 != null)
            {
                m_txtSize1.gameObject.layer = Editor.CameraLayerSettings.RuntimeGraphicsLayer + Window.Index;
            }
            if (m_txtSize2 != null)
            {
                m_txtSize2.gameObject.layer = Editor.CameraLayerSettings.RuntimeGraphicsLayer + Window.Index;
            }

            UpdateText();
            UpdateFontSize();
        }
Esempio n. 4
0
 private void Awake()
 {
     m_editor         = IOC.Resolve <IRTE>();
     m_exposeToEditor = GetComponent <ExposeToEditor>();
     RuntimeHandlesComponent.InitializeIfRequired(ref Appearance);
 }