using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; namespace Phantom.XRMOD.XRMODPackageTools.Editor { public class PrefabChangeMonitor : AssetModificationProcessor { private const string _CONST_TEMP_FOLDER = "AutomaticGenerated/TempAssets"; private static readonly List _PENDING_PREFABS = new(); public static string[] OnWillSaveAssets(string[] _paths) { _PENDING_PREFABS.Clear(); foreach (var tmp_Path in _paths) { if (!tmp_Path.EndsWith(".prefab")) continue; if (tmp_Path.Contains(_CONST_TEMP_FOLDER)) continue; _PENDING_PREFABS.Add(tmp_Path); } EditorApplication.delayCall += CopyModifyPrefabs; return _paths; } private static void CopyModifyPrefabs() { for (int tmp_Idx = 0; tmp_Idx < _PENDING_PREFABS.Count; tmp_Idx++) { var tmp_Path = _PENDING_PREFABS[tmp_Idx]; var tmp_EditingProject = PackageToolsEditor.ALL_PROJECT_CACHE.GetEditingProjectData(); if (tmp_EditingProject == null) return; var tmp_CurrentProjectPath = tmp_EditingProject.DetailCacheData.GetProjectPath(); var tmp_FileName = Path.GetFileName(tmp_Path); var tmp_DestPath = Path.Combine(tmp_CurrentProjectPath, _CONST_TEMP_FOLDER, tmp_FileName); AssetDatabase.CopyAsset(tmp_Path, tmp_DestPath); } _PENDING_PREFABS.Clear(); } } }