void OnComputeMesh() { for (int i = 0; i < computeMeshGoList.Count; i++) { //1.清除原来的数据 GameObject go = computeMeshGoList[i]; MeshSimplify simplify = go.GetComponent <MeshSimplify>(); if (go == null || simplify == null) { continue; } simplify.RestoreOriginalMesh(true, simplify.m_meshSimplifyRoot == null); RemoveChildMeshSimplifyComponents(simplify); //2.开始计算 try { if (simplify.DataDirty || simplify.HasData() == false || simplify.HasNonMeshSimplifyGameObjectsInTree()) { simplify.RestoreOriginalMesh(true, simplify.m_meshSimplifyRoot == null); bool mMeshSimplefyRoot = simplify.m_meshSimplifyRoot == null; simplify.ComputeData(mMeshSimplefyRoot, null); } } catch (System.Exception e) { Debug.LogError("Error generating mesh: " + e.Message + " Stack: " + e.StackTrace); EditorUtility.ClearProgressBar(); Simplifier.Cancelled = false; } //3.最后应用Prefab } isClickButton = true; }
void OnSceneGUI() { MeshSimplify meshSimplify = target as MeshSimplify; bool bDrawSpheres = true; if (meshSimplify.MeshSimplifyRoot != null) { if (meshSimplify.MeshSimplifyRoot.ExpandRelevanceSpheres == false) { bDrawSpheres = false; } } else { if (meshSimplify.ExpandRelevanceSpheres == false) { bDrawSpheres = false; } } if (meshSimplify.RelevanceSpheres != null && bDrawSpheres) { for (int nSphere = 0; nSphere < meshSimplify.RelevanceSpheres.Length; nSphere++) { if (meshSimplify.RelevanceSpheres[nSphere].Expanded == false) { continue; } RelevanceSphere relevanceSphere = meshSimplify.RelevanceSpheres[nSphere]; if (Tools.current == Tool.Move) { EditorGUI.BeginChangeCheck(); Vector3 v3Position = Handles.PositionHandle(relevanceSphere.Position, relevanceSphere.Rotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(meshSimplify, "Move Relevance Sphere"); relevanceSphere.Position = v3Position; meshSimplify.RestoreOriginalMesh(false, true); meshSimplify.DataDirty = true; EditorUtility.SetDirty(target); } } else if (Tools.current == Tool.Rotate) { EditorGUI.BeginChangeCheck(); Quaternion qRotation = Handles.RotationHandle(relevanceSphere.Rotation, relevanceSphere.Position); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(meshSimplify, "Rotate Relevance Sphere"); relevanceSphere.Rotation = qRotation; meshSimplify.RestoreOriginalMesh(false, true); meshSimplify.DataDirty = true; EditorUtility.SetDirty(target); } } else if (Tools.current == Tool.Scale) { EditorGUI.BeginChangeCheck(); Vector3 v3Scale = Handles.ScaleHandle(relevanceSphere.Scale, relevanceSphere.Position, relevanceSphere.Rotation, HandleUtility.GetHandleSize(relevanceSphere.Position) * 1.0f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(meshSimplify, "Scale Relevance Sphere"); relevanceSphere.Scale = v3Scale; meshSimplify.RestoreOriginalMesh(false, true); meshSimplify.DataDirty = true; EditorUtility.SetDirty(target); } } if (Event.current.type == EventType.Repaint) { Matrix4x4 mtxHandles = Handles.matrix; Handles.matrix = Matrix4x4.TRS(relevanceSphere.Position, relevanceSphere.Rotation, relevanceSphere.Scale); Handles.color = new Color(0.0f, 0.0f, 1.0f, 0.5f); Handles.SphereHandleCap(0, Vector3.zero, Quaternion.identity, 1.0f, EventType.Repaint); Handles.matrix = mtxHandles; } } } }