예제 #1
0
        UnityEngine.Mesh GetPreviewMesh(PhysicsShape shape)
        {
            if (shape.ShapeType != ShapeType.ConvexHull && shape.ShapeType != ShapeType.Mesh)
            {
                return(null);
            }

            if (!m_PreviewMeshes.TryGetValue(shape, out var preview))
            {
                preview = m_PreviewMeshes[shape] = new PreviewMeshData();
            }

            if (preview.Type != shape.ShapeType || preview.SourceMesh != shape.GetMesh())
            {
                if (preview.Mesh == null)
                {
                    preview.Mesh = new UnityEngine.Mesh {
                        hideFlags = HideFlags.HideAndDontSave
                    }
                }
                ;
                preview.SourceMesh = shape.GetMesh();
                preview.Type       = shape.ShapeType;
                preview.Mesh.Clear();
                if (shape.ShapeType == ShapeType.ConvexHull)
                {
                    // TODO: populate with the actual collision data
                }
                else
                {
                    // TODO: populate with the actual collision data
                    if (preview.SourceMesh != null)
                    {
                        preview.Mesh.vertices  = preview.SourceMesh.vertices;
                        preview.Mesh.normals   = preview.SourceMesh.normals;
                        preview.Mesh.triangles = preview.SourceMesh.triangles;
                    }
                }
                preview.Mesh.RecalculateBounds();
            }
            return(preview.Mesh);
        }
예제 #2
0
        PreviewMeshData GetPreviewData(PhysicsShapeAuthoring shape)
        {
            if (shape.ShapeType != ShapeType.ConvexHull && shape.ShapeType != ShapeType.Mesh)
            {
                return(null);
            }

            if (!m_PreviewData.TryGetValue(shape, out var preview))
            {
                preview = m_PreviewData[shape] = new PreviewMeshData();
                preview.SchedulePreviewIfChanged(shape);
            }

            // do not generate a new preview until the user has finished dragging a control handle (e.g., scale)
            if (m_DraggingControlID == 0 && !EditorGUIUtility.editingTextField)
            {
                preview.SchedulePreviewIfChanged(shape);
            }

            return(preview);
        }