void OnDestroy() { if (primitiveIndex >= 0) { if (!EditorUtility.DisplayDialog("Keep changes?", "Do you want to apply the primitive to the spline ?", "Apply", "Revert")) { primitives[primitiveIndex].Close(); } } if (presetIndex >= 0) { if (!EditorUtility.DisplayDialog("Keep changes?", "Do you want to apply the preset to the spline ?", "Apply", "Revert")) { presets[presetIndex].Cancel(); } } presetIndex = -1; primitiveIndex = -1; SplineUser[] users = computer.GetComponents <SplineUser>(); foreach (SplineUser user in users) { user.Rebuild(true); } computer.Rebuild(); ((SplineEditor)editor).Refresh(); SceneView.RepaintAll(); primitives = null; presets = null; newPreset = null; }
protected void UpdateUsers() { if (computer == null) { return; } SplineUser[] users = computer.GetComponents <SplineUser>(); foreach (SplineUser user in users) { user.Rebuild(true); } computer.Rebuild(); }
protected virtual void Update() { if (computer == null) { return; } SplineUser[] users = computer.GetComponents <SplineUser>(); foreach (SplineUser user in users) { user.Rebuild(true); } computer.Rebuild(); SceneView.RepaintAll(); }
void Bake() { meshGen.Bake(isStatic, true); if (permanent && !copy) { SplineComputer meshGenComputer = meshGen.computer; if (permanent) { meshGenComputer.Unsubscribe(meshGen); DestroyImmediate(meshGen); } if (removeComputer) { if (meshGenComputer.GetComponents <Component>().Length == 2) { DestroyImmediate(meshGenComputer.gameObject); } else { DestroyImmediate(meshGenComputer); } } } }
private void Bake(MeshGenerator gen) { MeshFilter filter = gen.GetComponent <MeshFilter>(); if (filter == null) { EditorUtility.DisplayDialog("Save error", "No mesh present in " + gen.name, "OK"); return; } if (copy) { UnityEditor.MeshUtility.Optimize(filter.sharedMesh); Unwrapping.GenerateSecondaryUVSet(filter.sharedMesh); } else { gen.Bake(isStatic, true); } if (format == BakeMeshWindow.SaveFormat.OBJ) { MeshRenderer renderer = gen.GetComponent <MeshRenderer>(); dirInfo = new DirectoryInfo(savePath); FileInfo[] files = dirInfo.GetFiles(filter.sharedMesh.name + "*.obj"); string meshName = filter.sharedMesh.name; if (files.Length > 0) { meshName += "_" + files.Length; } string path = savePath + "/" + meshName + ".obj"; string objString = MeshUtility.ToOBJString(filter.sharedMesh, renderer.sharedMaterials); File.WriteAllText(path, objString); if (copy) { string relativepath = "Assets" + path.Substring(Application.dataPath.Length); AssetDatabase.ImportAsset(relativepath, ImportAssetOptions.ForceSynchronousImport); filter.sharedMesh = AssetDatabase.LoadAssetAtPath <Mesh>(relativepath); } } if (format == BakeMeshWindow.SaveFormat.MeshAsset) { dirInfo = new DirectoryInfo(savePath); FileInfo[] files = dirInfo.GetFiles(filter.sharedMesh.name + "*.asset"); string meshName = filter.sharedMesh.name; if (files.Length > 0) { meshName += "_" + files.Length; } string path = savePath + "/" + meshName + ".asset"; string relativepath = "Assets" + path.Substring(Application.dataPath.Length); if (copy) { Mesh assetMesh = MeshUtility.Copy(filter.sharedMesh); AssetDatabase.CreateAsset(assetMesh, relativepath); } else { AssetDatabase.CreateAsset(filter.sharedMesh, relativepath); } } if (permanent && !copy) { SplineComputer meshGenComputer = gen.computer; if (permanent) { meshGenComputer.Unsubscribe(gen); Object.DestroyImmediate(gen); } if (removeComputer) { if (meshGenComputer.GetComponents <Component>().Length == 2) { Object.DestroyImmediate(meshGenComputer.gameObject); } else { Object.DestroyImmediate(meshGenComputer); } } } }