static ProjectAssetsWatcher() { QuickAssetWatcher watcher = QuickAssetWatcher.Observe(); watcher.OnAssetCreated.AddListener(asset => { Debug.Log("<color=cyan>Created</color> asset {0} of type {1}", asset.Name, asset.Type); }); watcher.OnAssetDeleted.AddListener(asset => { Debug.Log("<color=red>Deleted</color> asset {0} of type {1}", asset.Name, asset.Type); }); watcher.OnAssetModified.AddListener(asset => { Debug.Log("<color=orange>Modified</color> asset {0} of type {1}", asset.Name, asset.Type); }); watcher.OnAssetMoved.AddListener((before, after) => { Debug.Log("<color=blue>Moved</color> asset {0} from {1} to {2}", before.Name, before.DirectoryName, after.DirectoryName); }); watcher.OnAssetRenamed.AddListener((before, after) => { Debug.Log("<color=magenta>Renamed</color> asset from {0} to {1}", before.Name, after.Name); }); }
/// <summary> /// Watch for changes to the given asset type flags in the given path, and optionally recursing subdirectories. /// If no path is specified, the entire Assets folder will be used. /// If no asset type is specified, all asset types will be observed. /// </summary> public static QuickAssetWatcher Observe(string path = "", UnityAssetType assetType = UnityAssetType.None, bool recurseSubdirectories = true) { QuickAssetWatcher w = new QuickAssetWatcher(path, assetType, recurseSubdirectories); allWatchers.Add(w); return(w); }
static UnityScripsCompileWatcher() { QuickUnityEditorEventWatcher projectEditorEventWatcher = QuickUnityEditorEventWatcher.Observe(); projectEditorEventWatcher.onUpdate.AddListener(onUpdate); QuickAssetWatcher watcher = QuickAssetWatcher.Observe(); watcher.onAssetCreated.AddListener(onAssetHandle); watcher.onAssetModified.AddListener(onAssetHandle); }
static ProjectAssetsWatcher() { QuickUnityEditorEventWatcher editorEventWatcher = QuickUnityEditorEventWatcher.Observe(); editorEventWatcher.BuildTarget.onActiveBuildTargetChanged.AddListener(target => { UnityEngine.Debug.Log("当前平台为: " + target); }); // Observe the entire assets folder for changes var watcher = QuickAssetWatcher.Observe(); watcher.onAssetCreated.AddListener(asset => { Debug.Log(string.Format(LOG_FORMAT, LOG_TAG, " <color=cyan>Created</color> asset '" + asset.Name + "' of type " + asset.Type)); }); watcher.onAssetDeleted.AddListener(asset => { Debug.Log(string.Format(LOG_FORMAT, LOG_TAG, " <color=red>Deleted</color> asset '" + asset.Name + "' of type " + asset.Type)); }); watcher.onAssetModified.AddListener(asset => { Debug.Log(string.Format(LOG_FORMAT, LOG_TAG, " <color=orange>Modified</color> asset '" + asset.Name + "' of type " + asset.Type)); }); watcher.onAssetMoved.AddListener((before, after) => { Debug.Log(string.Format(LOG_FORMAT, LOG_TAG, " <color=blue>Moved</color> asset '" + before.Name + "' from '" + before.DirectoryName + "' to '" + after.DirectoryName + "'")); }); watcher.onAssetRenamed.AddListener((before, after) => { Debug.Log(string.Format(LOG_FORMAT, LOG_TAG, " <color=magenta>Renamed</color> asset from '" + before.Name + "' to '" + after.Name + "'")); }); }
/// <summary> /// Disable the specified watcher. /// </summary> private static void RemoveWatcher(QuickAssetWatcher watcher) { allWatchers.Remove(watcher); }