public static void Do() { GameObject obj = Selection.activeGameObject; if (obj != null) { string directory = EditorUtility.OpenFolderPanel("Save", "Assets/KGame", ""); if (!directory.Contains(VIO.WorkSpace())) { return; } VIO.MeshUtil.CopyMeshToDst(obj.GetComponent <MeshFilter>(), directory, false); AssetDatabase.Refresh(); } }
public static Texture CopyTextureToDest(string path, string dstDirectory) { string sourceD = VIO.UnitySlash(path); Texture sourceDTex = AssetDatabase.LoadAssetAtPath <Texture>(sourceD); if (sourceDTex != null) { string dstD = dstDirectory + "/" + System.IO.Path.GetFileName(sourceD); VIO.CopyBinaryFile(sourceD, dstD); AssetDatabase.Refresh(); Texture dstTex = VIO.TextureUtil.GetTexture(dstD); return(dstTex); } return(null); }
public static Mesh CopyMeshToDst(MeshFilter mf, string directory, bool auto2UV) { if (mf != null) { Mesh mesh = mf.sharedMesh; if (mesh != null) { if (!directory.Contains(VIO.WorkSpace())) { return(null); } Mesh newMesh = new Mesh(); newMesh.vertices = mesh.vertices; newMesh.uv = mesh.uv; newMesh.normals = mesh.normals; newMesh.triangles = mesh.triangles; newMesh.bounds = mesh.bounds; newMesh.subMeshCount = mesh.subMeshCount; for (int i = 0; i < newMesh.subMeshCount; i++) { newMesh.SetTriangles(mesh.GetTriangles(i), i); } if (auto2UV) { Unwrapping.GenerateSecondaryUVSet(newMesh); } string unityPath = ToUnity(directory + "/" + mesh.name); AssetDatabase.CreateAsset(newMesh, unityPath + ".asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } return(mesh); } else { return(null); } }
void CreateCatmullRomSpline() { string riverFile = VIO.UnitySaveFolder(); if (riverFile == null) { return; } GameObject gameObject = new GameObject("River"); Camera camera = null; for (int i = 0; i < 10; i++) { if (SceneView.lastActiveSceneView == null || SceneView.lastActiveSceneView.camera == null) { continue; } camera = SceneView.lastActiveSceneView.camera; } if (camera != null) { gameObject.transform.position = camera.transform.position + camera.transform.forward * 10.0f; } gameObject.AddComponent <CatmullRomSpline>(); MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer>(); meshRenderer.receiveShadows = true; meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; if (meshRenderer.sharedMaterial == null) { meshRenderer.sharedMaterial = AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat"); } Selection.activeGameObject = gameObject; }
public static void SaveOBJFile(string path) { MeshToObjString.Start(); StringBuilder meshString = new StringBuilder(); Transform t = Selection.gameObjects[0].transform; Vector3 originalPosition = t.position; t.position = Vector3.zero; if (!makeSubmeshes) { meshString.Append("g ").Append(t.name).Append("\n"); } meshString.Append(processTransform(t, makeSubmeshes)); VIO.WriteToFile(meshString.ToString(), path); t.position = originalPosition; MeshToObjString.End(); }
public static Material[] CopyMaterialsToDst(MeshRenderer mr, string dstDirectory, System.Func <MaterialInfo, Material> func) { if (mr) { MaterialInfo[] materialInfos = GraphicsUtili.Get_MaterialInfo(mr, "_PBRTexture"); if (materialInfos != null) { Material[] materials = new Material[materialInfos.Length]; for (int i = 0; i < materials.Length; i++) { MaterialInfo info = materialInfos[i]; bool spbr = false; if (info.path_P == null) { spbr = true; } else { if (info.path_P.Length <= 0) { spbr = true; } } string materialPath = ToUnity(dstDirectory + "/" + info.matName + ".mat"); Material material = AssetDatabase.LoadAssetAtPath <Material>(materialPath); if (material == null) { if (func == null) { if (spbr) { material = new Material(Shader.Find("MSO/Standard/SPBR")); } else { material = new Material(Shader.Find("MSO/Standard/PBR")); } } else { material = func(info); } string sourceD = VIO.UnitySlash(info.path_D); Texture diffuseTex = AssetDatabase.LoadAssetAtPath <Texture>(sourceD); material.SetTexture("_MainTex", diffuseTex); string sourceN = VIO.UnitySlash(info.path_N); Texture normalTex = AssetDatabase.LoadAssetAtPath <Texture>(sourceN); material.SetTexture("_BumpMap", normalTex); string sourceP = VIO.UnitySlash(info.path_P); Texture pbrTex = AssetDatabase.LoadAssetAtPath <Texture>(sourceP); material.SetTexture("_MetallicGlossMap", pbrTex); AssetDatabase.CreateAsset(material, materialPath); AssetDatabase.Refresh(); } materials[i] = material; } return(materials); } } return(null); }