private void Clip2AnimationClip(AssetFile assetFile, ref List <AssetFile> output) { if (assetFile.m_MainAsset != null) { AnimationClip clip = assetFile.m_MainAsset as AnimationClip; if (clip != null) { AnimationClip outClip = new AnimationClip(); outClip.name = name; EditorUtility.CopySerialized(clip, outClip); string clipPath = CRUtlity.DeleteExtension(assetFile.m_FilePath) + ".anim"; AssetDatabase.CreateAsset(outClip, clipPath); Resources.UnloadAsset(clip); Resources.UnloadAsset(outClip); AssetFile newFile = new AssetFile() { m_FilePath = clipPath, m_FileLowrPath = clipPath.ToLower() }; output.Add(newFile); } } }
private void Fbx2AnimatonClip(AssetFile assetFile, ref List <AssetFile> output) { AnimationClip clip = AssetDatabase.LoadAssetAtPath <AnimationClip>(assetFile.m_FilePath); if (clip != null) { ModelImporter modelImporter = AssetImporter.GetAtPath(assetFile.m_FilePath) as ModelImporter; if (modelImporter != null) { if (modelImporter.animationType != m_AnimationType) { Resources.UnloadAsset(clip); modelImporter.animationType = m_AnimationType; modelImporter.SaveAndReimport(); clip = AssetDatabase.LoadAssetAtPath <AnimationClip>(assetFile.m_FilePath); } AnimationClip outClip = new AnimationClip(); outClip.name = name; EditorUtility.CopySerialized(clip, outClip); string clipPath = CRUtlity.DeleteExtension(assetFile.m_FilePath) + ".anim"; AssetDatabase.CreateAsset(outClip, clipPath); Resources.UnloadAsset(clip); Resources.UnloadAsset(outClip); AssetFile newFile = new AssetFile() { m_FilePath = clipPath, m_FileLowrPath = clipPath.ToLower() }; output.Add(newFile); } } }
void IAssetCollector.Hanlde(out List <AssetFile> output) { LogUtility.m_LogTag = LogUtility.LogTag.AssetCollector; output = new List <AssetFile>(); if (!string.IsNullOrEmpty(m_UnityFilterText)) { string[] assetGuids = AssetDatabase.FindAssets(m_UnityFilterText, new string[] { m_AssetsPath }); foreach (var guid in assetGuids) { string filePath = AssetDatabase.GUIDToAssetPath(guid); AssetFile assetFile = new AssetFile() { m_AssetDatabaseId = guid, m_FilePath = filePath, m_FileLowrPath = filePath.ToLower() }; output.Add(assetFile); } } else { IEnumerable <string> paths = Directory.GetFiles(m_AssetsPath, "*.*", SearchOption.AllDirectories).Where( p => p.EndsWith(".meta") == false && p.EndsWith(".cs") == false ); foreach (var wholeFilePath in paths) { string filePath = CRUtlity.UnifyPathSeparator(wholeFilePath).Replace(Application.dataPath, ""); string guid = AssetDatabase.AssetPathToGUID(filePath); AssetFile assetFile = new AssetFile() { m_AssetDatabaseId = guid, m_FilePath = filePath, m_FileLowrPath = filePath.ToLower() }; output.Add(assetFile); } } if (!string.IsNullOrEmpty(m_RegularExpression)) { Regex regex = new Regex(m_RegularExpression); for (int i = output.Count - 1; i >= 0; i--) { AssetFile assetFile = output[i]; bool isMatched = (regex.IsMatch(assetFile.m_FilePath) || regex.IsMatch(assetFile.m_FileLowrPath)); if (m_RegularMatchedInculde != isMatched) { output.RemoveAt(i); } } } Statistics(0, output.Count); }
private static void CreateTemplateAsset <T>(string name) where T : Object { if (Selection.assetGUIDs.Length > 0) { string path = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]); if (!AssetDatabase.IsValidFolder(path)) { path = System.IO.Path.GetDirectoryName(path); } string createPath = CRUtlity.GetAddedName(path + "/" + name); FileUtil.CopyFileOrDirectory("Assets/H3D.CResources/SettingTemplate/" + name, createPath); AssetDatabase.ImportAsset(createPath); Object obj = AssetDatabase.LoadAssetAtPath <T>(createPath); Selection.activeObject = obj; EditorGUIUtility.PingObject(obj); } }
void IAssetGanerater.Hanlde(List <AssetFile> input, out List <AssetFile> output) { output = new List <AssetFile>(); foreach (var assetFile in input) { if (assetFile.m_MainAssetType == typeof(Texture2D) || AssetImporter.GetAtPath(assetFile.m_FilePath) is TextureImporter) { Material material = new Material(m_SoruceMaterial); Texture2D tex = AssetDatabase.LoadAssetAtPath <Texture2D>(assetFile.m_FilePath); material.mainTexture = tex; string matPath = CRUtlity.ReplaceExtension(assetFile.m_FilePath, ".mat"); AssetDatabase.CreateAsset(material, matPath); Resources.UnloadAsset(tex); output.Add(new AssetFile() { m_FilePath = matPath, m_FileLowrPath = matPath.ToLower() } ); } } }
void IBundleNameBuilder.Hanlde(List <AssetFile> input, out List <AssetFileGroup> output) { Dictionary <string, AssetFileGroup> groups = new Dictionary <string, AssetFileGroup>(); foreach (var assetFile in input) { string bundleName = CRUtlity.DeleteExtension(assetFile.m_FileLowrPath).Replace("assets/cresources/", ""); AssetFileGroup aGroup = null; if (groups.ContainsKey(bundleName) == false) { aGroup = groups[bundleName] = new AssetFileGroup(); aGroup.m_AssetFiles = new List <AssetFile>(); } else { aGroup = groups[bundleName]; } aGroup.m_BundleName = bundleName; aGroup.m_AssetFiles.Add(assetFile); } output = groups.Values.ToList <AssetFileGroup>(); }
private void MaterialSplit(List <string> matPaths) { HashSet <string> texCache = new HashSet <string>(); foreach (var matPath in matPaths) { Material mat = AssetDatabase.LoadAssetAtPath <Material>(matPath); Shader shader = mat.shader; if (shader == null) { LogUtility.Log("[{0}]{1} Shader is Null ", "MaterialSplitAlphaModifier", matPath); continue; } string shaderPath = AssetDatabase.GetAssetPath(shader); if (shaderPath == "Resources/unity_builtin_extra") { LogUtility.LogError("[{0}]{1} Have No Alpha ETC1 Shader ", "MaterialSplitAlphaModifier", matPath); continue; } if (!shaderPath.EndsWith(m_AddedSuffix + ".shader", System.StringComparison.Ordinal)) { shaderPath = CRUtlity.DeleteExtension(shaderPath) + m_AddedSuffix + ".shader"; if (System.IO.File.Exists(shaderPath)) { shader = mat.shader = AssetDatabase.LoadAssetAtPath <Shader>(shaderPath); } else { LogUtility.LogError("[{0}]{1} Have No Alpha ETC1 Shader ", "MaterialSplitAlphaModifier", matPath); continue; } } for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); ++i) { if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { string propertyName = ShaderUtil.GetPropertyName(shader, i); if (propertyName.EndsWith(m_ShaderPropertyAlphaAddedSuffix, System.StringComparison.Ordinal)) { string mainPropertyName = propertyName.Replace(m_ShaderPropertyAlphaAddedSuffix, ""); Texture2D tex = (UnityEngine.Texture2D)mat.GetTexture(mainPropertyName); if (tex == null) { LogUtility.LogError("{0} {1} Texture is Null", matPath, mainPropertyName); continue; } string texPath = AssetDatabase.GetAssetPath(tex); string alphaTexPath = CRUtlity.DeleteExtension(texPath) + m_AddedSuffix + ".png"; if (!texCache.Contains(texPath)) { SplitAlphaTexture(texPath, alphaTexPath); texCache.Add(texPath); } Texture2D alpahTex = AssetDatabase.LoadAssetAtPath <Texture2D>(alphaTexPath); mat.SetTexture(propertyName, alpahTex); Resources.UnloadAsset(alpahTex); Resources.UnloadAsset(tex); } } } } }