private void SearchNullRefs() { nullRefs = new List <NullRefData>(); if (root != null) { if (root is GameObject) { foreach (Transform t in (root as GameObject).GetComponentsInChildren <Transform>(true)) { Component[] comps = t.GetComponents(typeof(Component)); for (int i = 0; i < comps.Length; ++i) { Component c = comps[i]; SearchNullRef(c); } } } else if (root is Component) { SearchNullRef(root as Component); } else if (AssetDatabase.IsMainAsset(root)) { Object[] assets = EditorAssetUtil.ListAssets <Object>(AssetDatabase.GetAssetPath(root), FileType.All); foreach (Object a in assets) { SearchNullRef(a); } } } }
public override void OnSelected(bool sel) { if (sel) { atlasRefs = EditorAssetUtil.LoadReferencesFromFile <UIAtlas>(ATLAS_PATH); CreateAtlasMap(); } }
// check if applied by prefab and instance has different texture private bool IsTextureMismatch(UITexture tex) { TexSetter s = tex.GetComponent <TexSetter>(); if (s == null || s.textures.Count == 0) { return(false); } return(s.textures.Count == 1 && s.textures[0].path != EditorAssetUtil.GetAssetRelativePath(tex.mainTexture)); }
public override T LoadImpl() { #if UNITY_EDITOR if (!EditorApplication.isPlayingOrWillChangePlaymode) { return(EditorAssetUtil.LoadBundledAsset <T>(BundleName, AssetName)); } #endif throw new InvalidOperationException($"Cannot synchronously load assets from AssetBundles. Path: {Path}"); }
// check if applied by prefab and instance has different texture private bool IsTextureMismatch(Renderer r) { MeshTexSetter s = r.GetComponent <MeshTexSetter>(); if (s == null || s.textures.Count == 0) { return(false); } return(s.textures.Count == 1 && s.textures[0].path != EditorAssetUtil.GetAssetRelativePath(r.sharedMaterial.mainTexture)); }
public BackupRef(Object o) { if (o != null) { this.objId = EditorAssetUtil.GetObjectId(o, out asset); if (o is Component) { comp = o.GetType().FullName; } } }
private Dictionary <string, string> FindTexturePaths(Object folder) { Dictionary <string, string> map = new Dictionary <string, string>(); foreach (string p in EditorAssetUtil.ListAssetPaths(AssetDatabase.GetAssetPath(folder), FileType.All)) { if (FileTypeEx.GetFileType(p) == FileType.Image) { map[Path.GetFileNameWithoutExtension(p)] = p; } } return(map); }
public override void OnInspectorGUI() { DrawDefaultInspector(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Set")) { SetMatTexture(loader); } if (GUILayout.Button("Clear")) { ClearMatTexture(loader); } if (GUILayout.Button("Scan")) { EditorAssetUtil.ScanFolder("MaterialTexLoader_ScanFolder_" + loader.name, FileType.Material, files => { if (loader.materials == null) { loader.materials = new MaterialTexData[0]; } foreach (FileInfo f in files) { string path = EditorAssetUtil.GetProjectRelativePath(f.FullName); MaterialTexData data = new MaterialTexData(); data.material = AssetDatabase.LoadAssetAtPath <Material>(path); if (data.material != null) { if (data.material.HasProperty(MaterialTexLoader.TEX1)) { Texture tex1 = data.material.GetTexture(MaterialTexLoader.TEX1); if (tex1 != null) { data.tex1.SetPath(tex1); } } if (data.material.HasProperty(MaterialTexLoader.TEX2)) { Texture tex2 = data.material.GetTexture(MaterialTexLoader.TEX2); if (tex2 != null) { data.tex2.SetPath(tex2); } } ArrayUtil.Add(ref loader.materials, data); } } EditorUtil.SetDirty(loader); }); } EditorGUILayout.EndHorizontal(); }
private void AddObjects(List <Object> list, params Object[] objs) { foreach (Object o in objs) { if (o == null) { continue; } if (EditorAssetUtil.IsFolder(o) && !list.Contains(o)) { list.Add(o); } } }
public static void AssignAssetBundleNames() { // Clear All AssetBundles var dep = new AssetBundler(); var assets = EditorAssetUtil.ListAssets(Selection.objects); var paths = new List <string>(); foreach (var a in assets) { paths.Add(AssetDatabase.GetAssetPath(a)); } //dep.SetPathFilter(true, @"\.jpg$", @"\.png$", @"\.tga$"); dep.SetCommonAssetAsBundles(paths); }
protected override void Preprocess(string path, UnityEngine.Object obj) { LexiconRegistry reg = obj as LexiconRegistry; if (reg.assetDir.isValid) { string dir = AssetDatabase.GUIDToAssetPath(reg.assetDir); if (!dir.IsEmpty()) { dir = EditorAssetUtil.GetAssetRelativePath(dir); TextAsset[] assets = EditorAssetUtil.ListAssets <TextAsset>(dir, FileType.Text); AddAssets(reg, assets); } } }
public Data(SerializedProperty property, GUIContent content) { _path = property.stringValue; if (Bundles.IsBundlePath(_path)) { var bundlePath = Bundles.SplitBundlePath(_path); _object = EditorAssetUtil.LoadBundledAsset <Object>(bundlePath.Item1, bundlePath.Item2); } else { _object = Resources.Load <Object>(_path); } Content = new GUIContent(content); UpdateContent(content); }
private DirectoryInfo GetDir() { string currentSceneName = EditorAssetUtil.GetCurrentScene(); if (sceneName != currentSceneName) { dir = new DirectoryInfo(Application.dataPath + "/../Library/backup/" + EditorAssetUtil.GetCurrentScene()); if (!dir.Exists) { dir.Create(); } sceneName = currentSceneName; } return(dir); }
private static void Rename() { foreach (var guid in Selection.assetGUIDs) { var path = AssetDatabase.GUIDToAssetPath(guid); var assets = EditorAssetUtil.ListAssets <GameObject>(path, FileType.Prefab); foreach (GameObject a in assets) { Rename(a); } } foreach (var o in Selection.gameObjects) { Rename(o); } }
private void CheckAnimation() { List <Animation> anims = new List <Animation>(); foreach (Animation anim in EditorAssetUtil.FindSceneComponents <Animation>()) { if (anim.cullingType == AnimationCullingType.AlwaysAnimate) { anims.Add(anim); } } if (anims.Count > 0) { GUILayout.Label("AnimationCullingType.AlwaysAnimate", EditorStyles.boldLabel); var drawer = new ListDrawer <Animation>(anims, new ObjListItemDrawer <Animation>()); drawer.Draw(); } }
void Update(Object obj) { _object = obj; var bundleName = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(_object)).assetBundleName; if (EditorAssetUtil.IsResource(_object)) { _path = EditorAssetUtil.GetResourcePath(_object); } else if (!string.IsNullOrEmpty(bundleName)) { _path = Bundles.CreateBundlePath(bundleName, _object.name); } else { _path = string.Empty; } }
private List <string> GetRawAssetMods(AssetSnapshot snapshot, string srcDir) { List <string> mod = new List <string>(); foreach (string assetPath in EditorAssetUtil.ListAssetPaths(srcDir, FileType.All, true)) { if (assetPath.EndsWithIgnoreCase(".meta") || Path.GetFileName(assetPath).StartsWith(".", StringComparison.Ordinal)) { continue; } AssetDigest digest = snapshot.GetAssetDigest(assetPath); if (digest.IsModified()) { mod.Add(assetPath); } } return(mod); }
public static void Convert(this TexFormatGroup format, string folder) { log.Debug("Converting texture format to '{0}'", format); Regex ignore = new Regex("/Editor/|Assets/Plugins/"); foreach (string p in EditorAssetUtil.ListAssetPaths(folder, FileType.Image)) { if (ignore.IsMatch(p)) { continue; } log.Debug(p); Texture2D t = AssetDatabase.LoadAssetAtPath <Texture2D>(p); if (t != null) { format.Convert(t); } } }
public bool OnInspectorGUI <T>(ref string srcPath) where T : Object { Object oldAsset = GetCache(srcPath); Object newAsset = EditorGUILayout.ObjectField(oldAsset, typeof(T), false); if (oldAsset != newAsset) { if (newAsset == null) { srcPath = null; } else { srcPath = EditorAssetUtil.GetAssetRelativePath(newAsset); } return(true); } return(false); }
protected override void OnGUI(SerializedProperty p, Rect bound) { SerializedProperty mat = p.FindPropertyRelative("material"); SerializedProperty tex1 = p.FindPropertyRelative("tex1"); SerializedProperty tex2 = p.FindPropertyRelative("tex2"); Material m = mat.objectReferenceValue as Material; if (DrawObjectField <Material>(bound, new GUIContent(p.name), ref m, false)) { mat.objectReferenceValue = m; if (m != null) { tex1.stringValue = EditorAssetUtil.GetAssetRelativePath(m.mainTexture); } else { tex1.stringValue = null; } } }
static bool IsDepModified(AssetSnapshot snapshot, AssetDigest digest) { string[] dependPaths = AssetDatabase.GetDependencies(new string[] { "Assets/" + digest.path }); bool modified = digest.IsModified(); // check dependencies midified for (int i = 0; i < dependPaths.Length; ++i) { dependPaths[i] = EditorAssetUtil.GetAssetRelativePath(dependPaths[i]); if (digest.path == dependPaths[i]) { continue; } AssetDigest depDigest = snapshot.GetDependDigest(dependPaths[i]); modified |= depDigest.IsModified(); if (depDigest.path.Is(FileType.Asset, FileType.Prefab)) { modified |= IsDepModified(snapshot, depDigest); } } return(modified); }
public Object GetObject() { if (objId == null) { return(null); } Object o = EditorAssetUtil.GetObject(objId); if (o == null) { return(null); } if (!string.IsNullOrEmpty(comp) && o is GameObject) { Type type = TypeEx.GetType(comp); if (type != null) { Component c = (o as GameObject).GetComponent(type); return(c); } } return(o); }
static void ClearCharacterMaterials() { Debug.Log("Clearing character materials."); var characters = EditorAssetUtil.LoadAll <CharacterData>().Select(c => c.Prefab).Distinct(); foreach (var character in characters) { var prefab = character.Load(); if (prefab == null) { continue; } var colorStates = prefab.GetComponentsInChildren <CharacterColor>(); foreach (var color in colorStates) { color.Clear(); } EditorUtility.SetDirty(prefab); Debug.Log($"Cleared materials for {prefab.name}"); } AssetDatabase.SaveAssets(); Debug.Log("Finished clearing "); }
// TODOM use IEnumerator to save memory protected IEnumerable <Object> SearchAssets(Type type, params FileType[] fileTypes) { List <Object> roots = new List <Object>(); if (root != null) { roots.Add(root); } else { roots.AddRange(Selection.objects); } foreach (Object rootObj in roots) { foreach (FileType t in fileTypes) { foreach (var o in EditorAssetUtil.SearchAssetObjects(rootObj, type, t)) { yield return(o); } } } }
private List <string> GetAssetMods(AssetSnapshot snapshot, string srcDir) { List <string> mods = new List <string>(); string[] assetPaths = EditorAssetUtil.ListAssetPaths(srcDir, FileType.All, true); foreach (string assetPath in assetPaths) { if (assetPath.EndsWithIgnoreCase(".meta") || Path.GetFileName(assetPath).StartsWith(".", StringComparison.Ordinal) || assetPath.EndsWithIgnoreCase(".unity")) { continue; } AssetDigest digest = snapshot.GetAssetDigest(assetPath); bool modified = IsDepModified(snapshot, digest); if (modified) { mods.Add(assetPath); } } return(mods); }
public override void OnInspectorGUI() { if (nestedPrefab.GetPrefab() != null) { EditorGUILayout.ObjectField(nestedPrefab.GetPrefab(), typeof(GameObject), false); } if (AssetDatabase.IsMainAsset(nestedPrefab.gameObject) || AssetDatabase.IsSubAsset(nestedPrefab.gameObject)) { return; } if (nestedPrefab.IsLinked()) { if (GUILayout.Button("Unlink Prefabs")) { PrefabRestore restore = new PrefabRestore(); nestedPrefab.transform.DepthFirstTraversal(restore.Apply); restore.Destroy(); } } else { if (GUILayout.Button("Link Prefabs")) { Build(); } } GameObject rootPrefab = PrefabUtility.GetPrefabParent(nestedPrefab.gameObject) as GameObject; EditorGUILayout.BeginHorizontal(); EditorGUIEx.ObjectField <Object>("Folder", ref folder, false); GUI.enabled = folder != null; if (GUILayout.Button("Create Prefab")) { if (!nestedPrefab.IsLinked()) { Build(); } string dir = EditorAssetUtil.GetAssetFileFullPath(AssetDatabase.GetAssetPath(folder)); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); AssetDatabase.Refresh(ImportAssetOptions.Default); } string path = AssetDatabase.GenerateUniqueAssetPath(PathUtil.Combine(AssetDatabase.GetAssetPath(folder), nestedPrefab.name + ".prefab")); rootPrefab = PrefabUtility.CreatePrefab(path, nestedPrefab.gameObject); Selection.activeGameObject = rootPrefab; } EditorGUILayout.EndHorizontal(); GUI.enabled = true; if (rootPrefab != null) { if (GUILayout.Button("Disconnect Prefab")) { PrefabUtility.DisconnectPrefabInstance(nestedPrefab.gameObject); } } if (EditorGUIEx.Toggle("Instantiate On Start", ref nestedPrefab.instantiateOnStart)) { EditorUtil.SetDirty(nestedPrefab); } if (EditorGUIEx.Toggle("Destroy On Instantiation", ref nestedPrefab.destroyOnInstantiation)) { EditorUtil.SetDirty(nestedPrefab); } }
private void SaveAtlasRefs() { EditorAssetUtil.SaveReferences(ATLAS_PATH, atlasRefs); }
protected override void OnGUI(SerializedProperty p, Rect bound) { int lineCount = GetLineCount(p); var bounds = bound.SplitByHeights(lineHeight); int lineNo = 0; SerializedProperty cdn = GetProperty("cdn"); SerializedProperty path = GetProperty("path"); SerializedProperty exclusiveId = GetProperty("exclusiveAssetId"); SerializedProperty reference = GetProperty("reference"); SerializedProperty md5 = GetProperty("md5"); SerializedProperty guid = GetProperty("guid"); if (reference == null) { return; } string editorPath = AssetDatabase.GUIDToAssetPath(guid.stringValue); if (editorPath.IsEmpty()) { editorPath = path.stringValue; } Object obj = AssetDatabase.LoadAssetAtPath(editorPath, typeof(Object)); if (obj == null) { obj = reference.objectReferenceValue; if (obj != null) { editorPath = AssetDatabase.GetAssetPath(obj); } } string assetPath = string.Empty; if (!editorPath.IsEmpty()) { assetPath = EditorAssetUtil.GetAssetRelativePath(editorPath); } EditorGUI.indentLevel = p.depth; string refType = null; if (assetPath.IsResourcesPath()) { refType = "R"; } else { refType = reference.objectReferenceValue != null? "O" : "X"; } string title = string.Format("{0} ({1})", p.name, refType); Color oldColor = GUI.backgroundColor; if (DIGEST && EditorAssetUtil.IsModified(path.stringValue, md5.stringValue)) { GUI.backgroundColor = Color.red; } Object newRef = EditorGUI.ObjectField(bounds[lineNo], title, obj, typeof(Object), true); if (newRef != obj || path.stringValue != assetPath || (cdn.boolValue ^ reference.objectReferenceValue == null)) { Set(cdn, path, reference, guid, newRef); } lineNo++; EditorGUI.indentLevel++; if (lineNo < lineCount) { if (newRef != null) { Rect pathRect = bounds[lineNo]; EditorGUI.SelectableLabel(pathRect, path.stringValue); lineNo++; } } GUI.backgroundColor = oldColor; if (lineNo < lineCount && cdn.boolValue == true) { // draw alias Rect aliasRect = bounds[lineNo]; string newAlias = EditorGUI.TextField(aliasRect, exclusiveId.name, exclusiveId.stringValue); if (newAlias != exclusiveId.stringValue) { exclusiveId.stringValue = newAlias; } lineNo++; } EditorGUI.indentLevel--; }
/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> #if UNITY_EDITOR void Awake() { foreach (var type in ValidImportTypes) { RegisterAll(EditorAssetUtil.LoadAll(type)); } #else async void Awake() { LoadingScreen.Await(LoadTask.Task); RegisterAll(GameModes); var paths = await GetAllValidPaths(BundleSearch); var bundles = paths.Select(async path => { var bundle = await AssetBundleManager.LoadAssetBundleAsync(path); var asset = await LoadMainAsset(bundle); ProcessLoadedAsset(asset, path); }); await Task.WhenAll(bundles); #endif LoadTask.TrySetResult(new object()); Debug.Log("Finished loading data"); } void RegisterAll(IEnumerable <Object> data) { foreach (var datum in data) { Register(datum); } } bool Register(Object data) { foreach (var type in ValidImportTypes) { var dataObj = data as IEntity; if (dataObj != null && type.IsInstanceOfType(data)) { Registry.Register(type, dataObj); Debug.Log($"Registered {type.Name}: {data.name} ({dataObj.Id})"); return(true); } } return(false); } async Task <IEnumerable <string> > GetAllValidPaths(string[] searchPatterns) { var allSets = await Task.WhenAll(searchPatterns.Select(pattern => AssetBundleManager.GetValidBundlePaths(pattern))); return(allSets.SelectMany(s => s).Distinct()); } async Task <Object> LoadMainAsset(LoadedAssetBundle bundle) { var assetBundle = bundle.AssetBundle; if (assetBundle.mainAsset != null) { return(assetBundle.mainAsset); } else { var mainPath = assetBundle.GetAllAssetNames()[0]; var request = await assetBundle.LoadAssetAsync <Object>(mainPath).ToTask(); return(request.asset); } } void ProcessLoadedAsset(Object asset, string path) { var identifiable = asset as IEntity; if (identifiable == null || !Register(asset)) { Resources.UnloadAsset(asset); AssetBundleManager.UnloadAssetBundle(path); } } }
private static string GetStorePath() { return(EditorAssetUtil.GetProjectFileFullPath(STORE_PATH)); }