void LateUpdate()
    {
        if (!m_active)
        {
            return;
        }

        if (m_selectedPoint == null)
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 1000f, m_dragPointMask))
                {
                    DraggableMeshPoint point = hit.collider.GetComponent <DraggableMeshPoint>();
                    if (point != null)
                    {
                        point.Highlight();
                        if (Input.GetButtonDown(m_buttonPrimary))
                        {
                            m_selectedPoint = point;
                            m_zDistance     = m_selectedPoint.transform.position.z;
                        }
                    }
                }
            }
        }
        else
        {
            if (Input.GetButtonUp(m_buttonPrimary))
            {
                m_selectedPoint = null;
            }
            else
            {
                m_selectedPoint.Select();
                if (Input.GetButton(m_buttonPrimary))
                {
                    var vector = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, m_zDistance));
                    vector.z = m_zDistance;
                    m_selectedPoint.transform.position = vector;
                    foreach (var triangle in m_dict[m_selectedPoint])
                    {
                        triangle.m_triangle.m_uvs[triangle.m_index] = WorldToUv(vector);
                    }
                }
            }
        }

        for (int i = 0; i < m_edges.Count; i++)
        {
            var edge = m_edges[i];

            edge.m_renderer.SetPosition(0, edge.m_pointA.transform.position);
            edge.m_renderer.SetPosition(1, edge.m_pointB.transform.position);
        }
    }
Exemple #2
0
    void LateUpdate()
    {
        if (!m_active)
        {
            return;
        }

        if (m_selectedPoint == null)
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                Ray        ray = m_camera.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 1000f, m_dragPointMask))
                {
                    DraggableMeshPoint point = hit.collider.GetComponent <DraggableMeshPoint>();
                    if (point != null)
                    {
                        point.Highlight();
                        if (Input.GetButtonDown(m_buttonPrimary))
                        {
                            m_selectedPoint = point;
                            m_zDistance     = m_camera.transform.worldToLocalMatrix.MultiplyPoint(m_selectedPoint.transform.position).z;
                        }
                    }
                }
            }
        }
        else
        {
            if (Input.GetButtonUp(m_buttonPrimary))
            {
                m_selectedPoint = null;
            }
            else
            {
                m_selectedPoint.Select();
                if (Input.GetButton(m_buttonPrimary))
                {
                    m_selectedPoint.transform.position = m_camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, m_zDistance));
                }
                if (Input.GetKeyDown(KeyCode.Delete))
                {
                    RemoveConnected(m_selectedPoint);
                }
            }
        }

        for (int i = 0; i < m_edges.Count; i++)
        {
            var edge = m_edges[i];
            if (edge.m_renderer == null)
            {
                var go = new GameObject("Edge Renderer (copy)");
                go.transform.SetParent(transform);
                go.layer                       = edge.m_pointA.gameObject.layer;
                edge.m_renderer                = go.AddComponent <LineRenderer>();
                edge.m_renderer.startWidth     = 0.04f;
                edge.m_renderer.endWidth       = 0.04f;
                edge.m_renderer.sharedMaterial = m_edgeMaterial;
                m_edges[i]                     = edge;
            }
            edge.m_renderer.SetPosition(0, edge.m_pointA.transform.position);
            edge.m_renderer.SetPosition(1, edge.m_pointB.transform.position);
        }
    }