예제 #1
0
        private static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions options)
        {
            AssetDeleteResult assetDeleteResult = AssetDeleteResult.DidNotDelete;

            if (!InternalEditorUtility.HasTeamLicense())
            {
                return(assetDeleteResult);
            }
            foreach (Type current in AssetModificationProcessorInternal.AssetModificationProcessors)
            {
                MethodInfo method = current.GetMethod("OnWillDeleteAsset", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                if (method != null)
                {
                    AssetModificationProcessorInternal.RequireTeamLicense();
                    object[] array = new object[]
                    {
                        assetPath,
                        options
                    };
                    if (AssetModificationProcessorInternal.CheckArgumentsAndReturnType(array, method, assetDeleteResult.GetType()))
                    {
                        assetDeleteResult |= (AssetDeleteResult)((int)method.Invoke(null, array));
                    }
                }
            }
            if (assetDeleteResult != AssetDeleteResult.DidNotDelete)
            {
                return(assetDeleteResult);
            }
            assetDeleteResult = AssetModificationHook.OnWillDeleteAsset(assetPath, options);
            return(assetDeleteResult);
        }
        static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions options)
        {
            AssetDeleteResult finalResult = AssetDeleteResult.DidNotDelete;

            foreach (var assetModificationProcessorClass in AssetModificationProcessors)
            {
                MethodInfo method = assetModificationProcessorClass.GetMethod("OnWillDeleteAsset", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                if (method != null)
                {
                    object[] args = { assetPath, options };
                    if (!CheckArgumentsAndReturnType(args, method, finalResult.GetType()))
                    {
                        continue;
                    }

                    finalResult |= (AssetDeleteResult)method.Invoke(null, args);
                }
            }

            if (finalResult != AssetDeleteResult.DidNotDelete)
            {
                return(finalResult);
            }

            finalResult = AssetModificationHook.OnWillDeleteAsset(assetPath, options);

            return(finalResult);
        }
        /// <summary>
        /// Before a DataSetAsset is deleted, unload its Entities to clean up any scene proxies.
        /// </summary>
        /// <param name="assetPath"></param>
        /// <param name="rao"></param>
        /// <returns></returns>
        public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions rao)
        {
            const AssetDeleteResult Result = AssetDeleteResult.DidNotDelete;

            var dataSet = AssetDatabase.LoadAssetAtPath <DataSetAsset>(assetPath);

            if (dataSet == null)
            {
                return(Result);
            }

            // TODO: Refactor and fix this monstrosity

            var wasDataListWindowOpen = DataListWindow.IsOpen;
            var window = DataListWindow.GetInstance();
            var guid   = AssetDatabase.AssetPathToGUID(assetPath);

            if (!window.IsDataSetOpen(guid))
            {
                return(Result);
            }

            window.RemoveDataSet(guid);

            if (!wasDataListWindowOpen)
            {
                window.Close();
            }

            return(Result);
        }
        private static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions options)
        {
            AssetDeleteResult didNotDelete = AssetDeleteResult.DidNotDelete;

            if (!InternalEditorUtility.HasTeamLicense())
            {
                return(didNotDelete);
            }
            foreach (System.Type type in AssetModificationProcessors)
            {
                MethodInfo method = type.GetMethod("OnWillDeleteAsset", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
                if (method != null)
                {
                    RequireTeamLicense();
                    object[] args = new object[] { assetPath, options };
                    if (CheckArgumentsAndReturnType(args, method, didNotDelete.GetType()))
                    {
                        didNotDelete |= (AssetDeleteResult)method.Invoke(null, args);
                    }
                }
            }
            if (didNotDelete != AssetDeleteResult.DidNotDelete)
            {
                return(didNotDelete);
            }
            return(AssetModificationHook.OnWillDeleteAsset(assetPath, options));
        }
    private static void OnDeleteAssetCallBack(AssetDeleteResult t, string t1, RemoveAssetOptions t2)
    {
        List <string> paths = new List <string>();

        paths.Add(t1);
        UpdateAsset(paths);
        //Debug.Log("OnDeleteAssetCallBack");
    }
    static AssetDeleteResult OnWillDeleteAsset(string name, RemoveAssetOptions options)
    {
        Debug.Log($"Will destroy asset with name {name} and options {options}");

        AssetDeleteResult delRes = AssetDeleteResult.DidNotDelete;

        return(delRes);
    }
예제 #7
0
    private static void OnDeleteAssetCallBack(AssetDeleteResult t, string t1, RemoveAssetOptions t2)
    {
        List <string> paths = new List <string>();

        paths.Add(t1);
        UpdateAsset(paths);
        GlobalEvent.DispatchEvent(EditorGlobalEventEnum.OnDeleteAsset, t, t1, t2);
    }
    /// <summary>
    /// Unity method called whenever an asset deletion is attempted.
    /// </summary>
    /// <param name="path">Path.</param>
    /// <param name="option">RemoveAssetOptions.</param>
    private static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions option)
    {
        AssetDeleteResult assetDeleteResult = AssetDeleteResult.DidNotDelete;

        if (FolderLockSettings.Instance != null && FolderLockSettings.Instance.IsLockedFolder(path))
        {
            assetDeleteResult = AssetDeleteResult.FailedDelete;
        }
        return(assetDeleteResult);
    }
    private static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions option)
    {
        if (OnWillDeleteAssetCallBack != null)
        {
            OnWillDeleteAssetCallBack(assetPath, option);
        }

        AssetDeleteResult res = AssetDeleteResult.DidDelete;

        if (IsLocked(assetPath))
        {
            Debug.LogError(string.Format("Could not delete {0} because it is locked!", assetPath));
            res = AssetDeleteResult.FailedDelete;
        }
        OnDeleteAssetP = new object[] { res, assetPath, option };
        //Debug.Log("OnWillDeleteAsset:" + assetPath + " :" + EditorApplication.timeSinceStartup);

        return(AssetDeleteResult.DidNotDelete);
    }
        private static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions options)
        {
            AssetMode.Rebuild();
            AssetDeleteResult r = AssetDeleteResult.DidNotDelete;
            var isFolder        = Directory.Exists(assetPath);
            var isres           = CheckIsResPath(assetPath);

            if (isres)
            {
                if (UnityEditor.EditorUtility.DisplayDialog("tips", "此资源已经被添加至了资源编辑器,删除后将会从管理器中移除\n 确定要删除吗?", "确定"))
                {
                    DelAssset(assetPath);
                }
                else
                {
                    r = AssetDeleteResult.FailedDelete;
                }
            }

            return(r);
        }
        private static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions options)
        {
            AssetDeleteResult didNotDelete = AssetDeleteResult.DidNotDelete;

            if (!InternalEditorUtility.HasTeamLicense())
            {
                return(didNotDelete);
            }
            IEnumerator <Type> enumerator = AssetModificationProcessors.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    MethodInfo method = enumerator.Current.GetMethod("OnWillDeleteAsset", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
                    if (method != null)
                    {
                        RequireTeamLicense();
                        object[] args = new object[] { assetPath, options };
                        if (CheckArgumentsAndReturnType(args, method, didNotDelete.GetType()))
                        {
                            didNotDelete |= (int)method.Invoke(null, args);
                        }
                    }
                }
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
            if (didNotDelete != AssetDeleteResult.DidNotDelete)
            {
                return(didNotDelete);
            }
            return(AssetModificationHook.OnWillDeleteAsset(assetPath, options));
        }
        static void OnWillDeleteAssets(string[] assetPaths, AssetDeleteResult[] outPathDeletionResults, RemoveAssetOptions options)
        {
            for (int i = 0; i < outPathDeletionResults.Length; i++)
            {
                outPathDeletionResults[i] = (int)AssetDeleteResult.DidNotDelete;
            }

            List <string> nonDeletedPaths       = new List <string>();
            List <int>    nonDeletedPathIndices = new List <int>();

            foreach (var assetModificationProcessorClass in AssetModificationProcessors)
            {
                MethodInfo method = assetModificationProcessorClass.GetMethod("OnWillDeleteAsset", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                if (method == null)
                {
                    continue;
                }

                for (int i = 0; i < assetPaths.Length; i++)
                {
                    object[] args = { assetPaths[i], options };
                    if (!CheckArgumentsAndReturnType(args, method, typeof(AssetDeleteResult)))
                    {
                        continue;
                    }

                    AssetDeleteResult callbackResult = (AssetDeleteResult)method.Invoke(null, args);
                    outPathDeletionResults[i] |= callbackResult;
                }
            }

            for (int i = 0; i < assetPaths.Length; i++)
            {
                if (outPathDeletionResults[i] == (int)AssetDeleteResult.DidNotDelete)
                {
                    nonDeletedPaths.Add(assetPaths[i]);
                    nonDeletedPathIndices.Add(i);
                }
            }

            if (nonDeletedPaths.Count > 0)
            {
                if (!Provider.enabled || EditorUserSettings.WorkOffline)
                {
                    return;
                }

                for (int i = 0; i < nonDeletedPaths.Count; i++)
                {
                    if (!Provider.PathIsVersioned(nonDeletedPaths[i]))
                    {
                        nonDeletedPaths.RemoveAt(i);
                        nonDeletedPathIndices.RemoveAt(i);
                        i--;
                    }
                }

                var nonDeletedPathDeletionResults = new AssetDeleteResult[nonDeletedPaths.Count];

                AssetModificationHook.OnWillDeleteAssets(nonDeletedPaths.ToArray(), nonDeletedPathDeletionResults, options);

                for (int i = 0; i < nonDeletedPathIndices.Count; i++)
                {
                    outPathDeletionResults[nonDeletedPathIndices[i]] = nonDeletedPathDeletionResults[i];
                }
            }
        }