internal static bool IsOpenForEdit(string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            message = "";
            bool result;

            if (string.IsNullOrEmpty(assetPath))
            {
                result = true;
            }
            else
            {
                bool         flag  = AssetModificationHook.IsOpenForEdit(assetPath, out message, statusOptions);
                MethodInfo[] array = AssetModificationProcessorInternal.GetIsOpenForEditMethods();
                for (int i = 0; i < array.Length; i++)
                {
                    MethodInfo methodInfo = array[i];
                    object[]   array2     = new object[]
                    {
                        assetPath,
                        message
                    };
                    if (!(bool)methodInfo.Invoke(null, array2))
                    {
                        message = (array2[1] as string);
                        result  = false;
                        return(result);
                    }
                }
                result = flag;
            }
            return(result);
        }
示例#2
0
        static internal bool IsAppropriateFileOpenForEdit(UnityObject assetObject, out string message)
        {
            message = string.Empty;

            // Need to check for null early to avoid an exception being thrown in
            // AssetDatabase.IsNativeAsset(). One of these exceptions, unhandled,
            // caused case 930291 and case 930931. For both cases, the UI broke because
            // it was exiting early due to the exception.
            if (assetObject == null)
            {
                return(false);
            }

            StatusQueryOptions opts = EditorUserSettings.allowAsyncStatusUpdate ? StatusQueryOptions.UseCachedAsync : StatusQueryOptions.UseCachedIfPossible;

            if (AssetDatabase.IsNativeAsset(assetObject))
            {
                if (!AssetDatabase.IsOpenForEdit(assetObject, out message, opts))
                {
                    return(false);
                }
            }
            else if (AssetDatabase.IsForeignAsset(assetObject))
            {
                if (!AssetDatabase.IsMetaFileOpenForEdit(assetObject, out message, opts))
                {
                    return(false);
                }
            }

            return(true);
        }
        internal static bool IsOpenForEdit(string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            message = string.Empty;
            if (string.IsNullOrEmpty(assetPath))
            {
                return(true); // treat empty/null paths as editable (might be under Library folders etc.)
            }
            var editability = GetPathEditability(assetPath);

            if (editability == Editability.Always)
            {
                return(true);
            }
            if (editability == Editability.Never)
            {
                return(false);
            }
            if (!AssetModificationHook.IsOpenForEdit(assetPath, out message, statusOptions))
            {
                return(false);
            }
            if (!IsOpenForEditViaScriptCallbacks(assetPath, ref message))
            {
                return(false);
            }

            return(true);
        }
示例#4
0
        internal static bool IsAppropriateFileOpenForEdit(UnityEngine.Object assetObject, out string message)
        {
            message = string.Empty;
            bool result;

            if (assetObject == null)
            {
                result = false;
            }
            else
            {
                StatusQueryOptions statusOptions = (!EditorUserSettings.allowAsyncStatusUpdate) ? StatusQueryOptions.UseCachedIfPossible : StatusQueryOptions.UseCachedAsync;
                if (AssetDatabase.IsNativeAsset(assetObject))
                {
                    if (!AssetDatabase.IsOpenForEdit(assetObject, out message, statusOptions))
                    {
                        result = false;
                        return(result);
                    }
                }
                else if (AssetDatabase.IsForeignAsset(assetObject))
                {
                    if (!AssetDatabase.IsMetaFileOpenForEdit(assetObject, out message, statusOptions))
                    {
                        result = false;
                        return(result);
                    }
                }
                result = true;
            }
            return(result);
        }
示例#5
0
        static internal bool IsAppropriateFileOpenForEdit(UnityObject assetObject)
        {
            // The native object for a ScriptableObject with an invalid script will be considered not alive.
            // In order to allow editing of the m_Script property of a ScriptableObject with an invalid script
            // we use the instance ID instead of the UnityEngine.Object reference to check if the asset is open for edit.

            if ((object)assetObject == null)
                return false;

            var instanceID = assetObject.GetInstanceID();
            if (instanceID == 0)
                return false;

            StatusQueryOptions opts = EditorUserSettings.allowAsyncStatusUpdate ? StatusQueryOptions.UseCachedAsync : StatusQueryOptions.UseCachedIfPossible;
            if (AssetDatabase.IsNativeAsset(instanceID))
            {
                var assetPath = AssetDatabase.GetAssetPath(instanceID);
                if (!AssetDatabase.IsOpenForEdit(assetPath, opts))
                    return false;
            }
            else if (AssetDatabase.IsForeignAsset(instanceID))
            {
                if (!AssetDatabase.IsMetaFileOpenForEdit(assetObject, opts))
                    return false;
            }

            return true;
        }
        internal static bool IsOpenForEdit(string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            message = "";
            if (String.IsNullOrEmpty(assetPath))
            {
                return(true); // assetPath can be empty in some cases where Unity is checking for stuff in Library folder
            }
            bool rootFolder, readOnly;
            bool validPath = AssetDatabase.GetAssetFolderInfo(assetPath, out rootFolder, out readOnly);

            if (validPath && readOnly)
            {
                return(false);
            }

            bool finalResult = AssetModificationHook.IsOpenForEdit(assetPath, out message, statusOptions);

            foreach (var method in GetIsOpenForEditMethods())
            {
                object[] args = { assetPath, message };
                if (!((bool)method.Invoke(null, args)))
                {
                    message = args[1] as string;
                    return(false);
                }
            }

            return(finalResult);
        }
        public static bool IsOpenForEdit(string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            message = "";
            bool result;

            if (!Provider.enabled)
            {
                result = true;
            }
            else if (string.IsNullOrEmpty(assetPath))
            {
                result = true;
            }
            else
            {
                Asset asset = (statusOptions != StatusQueryOptions.UseCachedIfPossible) ? AssetModificationHook.GetStatusForceUpdate(assetPath) : AssetModificationHook.GetStatusCachedIfPossible(assetPath);
                if (asset == null)
                {
                    if (Provider.onlineState == OnlineState.Offline && Provider.offlineReason != string.Empty)
                    {
                        message = Provider.offlineReason;
                    }
                    result = false;
                }
                else
                {
                    result = Provider.IsOpenForEdit(asset);
                }
            }
            return(result);
        }
示例#8
0
        void AutoSaveButtons()
        {
            StageNavigationItem item = StageNavigationManager.instance.currentItem;

            if (item.isPrefabStage)
            {
                if (m_IsPrefabInValidAssetFolder && !m_IsPrefabInImmutableFolder)
                {
                    StatusQueryOptions opts = EditorUserSettings.allowAsyncStatusUpdate ? StatusQueryOptions.UseCachedAsync : StatusQueryOptions.UseCachedIfPossible;
                    bool openForEdit        = AssetDatabase.IsOpenForEdit(item.prefabAssetPath, opts);

                    PrefabStage stage = item.prefabStage;
                    if (stage.showingSavingLabel)
                    {
                        GUILayout.Label(Styles.autoSavingBadgeContent, Styles.savingBadge);
                        GUILayout.Space(4);
                    }

                    if (!stage.autoSave)
                    {
                        using (new EditorGUI.DisabledScope(!openForEdit || !PrefabStageUtility.GetCurrentPrefabStage().HasSceneBeenModified()))
                        {
                            if (GUILayout.Button(Styles.saveButtonContent, Styles.button))
                            {
                                PrefabStageUtility.GetCurrentPrefabStage().SavePrefabWithVersionControlDialogAndRenameDialog();
                            }
                        }
                    }

                    using (new EditorGUI.DisabledScope(stage.temporarilyDisableAutoSave))
                    {
                        bool autoSaveForScene = stage.autoSave;
                        EditorGUI.BeginChangeCheck();
                        autoSaveForScene = GUILayout.Toggle(autoSaveForScene, Styles.autoSaveGUIContent, Styles.saveToggle);
                        if (EditorGUI.EndChangeCheck())
                        {
                            stage.autoSave = autoSaveForScene;
                        }
                    }

                    if (!openForEdit)
                    {
                        if (GUILayout.Button(Styles.checkoutButtonContent, Styles.button))
                        {
                            Task task = Provider.Checkout(AssetDatabase.LoadAssetAtPath <GameObject>(item.prefabAssetPath), CheckoutMode.Both);
                            task.Wait();
                        }
                    }
                }
                else
                {
                    GUILayout.Label(Styles.immutablePrefabContent, EditorStyles.boldLabel);
                }
            }
        }
示例#9
0
        internal static bool CanOpenForEdit(string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            if (IsOpenForEdit(assetPath, out message, statusOptions))
            {
                return(true);
            }

            // Status has just been updated so there's no need to force update again.
            if (statusOptions == StatusQueryOptions.ForceUpdate)
            {
                statusOptions = StatusQueryOptions.UseCachedIfPossible;
            }

            return(GetOpenForEdit(true, assetPath, out message, statusOptions));
        }
        public static bool IsEditable(this SerializedObject obj, StatusQueryOptions queryOptions)
        {
            if (obj == null)
            {
                return(false);
            }

            foreach (var target in obj.targetObjects)
            {
                if (!target || (target.hideFlags & HideFlags.NotEditable) != 0 ||
                    (EditorUtility.IsPersistent(target) && !AssetDatabase.IsOpenForEdit(target, queryOptions)))
                {
                    return(false);
                }
            }

            return(true);
        }
        public static bool IsOpenForEdit(string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            message = "";
            if (!Provider.enabled)
            {
                return(true);
            }
            if (string.IsNullOrEmpty(assetPath))
            {
                return(true);
            }
            Asset asset = (statusOptions != StatusQueryOptions.UseCachedIfPossible) ? GetStatusForceUpdate(assetPath) : GetStatusCachedIfPossible(assetPath);

            if (asset == null)
            {
                return(false);
            }
            return(Provider.IsOpenForEdit(asset));
        }
示例#12
0
        public static bool IsOpenForEdit(string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            message = "";
            bool result;

            if (!Provider.enabled)
            {
                result = true;
            }
            else if (string.IsNullOrEmpty(assetPath))
            {
                result = true;
            }
            else
            {
                Asset asset = (statusOptions != StatusQueryOptions.UseCachedIfPossible) ? AssetModificationHook.GetStatusForceUpdate(assetPath) : AssetModificationHook.GetStatusCachedIfPossible(assetPath);
                result = (asset != null && Provider.IsOpenForEdit(asset));
            }
            return(result);
        }
        internal static bool IsOpenForEdit(string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            message = "";
            if (string.IsNullOrEmpty(assetPath))
            {
                return(true);
            }
            bool flag2 = AssetModificationHook.IsOpenForEdit(assetPath, out message, statusOptions);

            foreach (MethodInfo info in GetIsOpenForEditMethods())
            {
                object[] parameters = new object[] { assetPath, message };
                if (!((bool)info.Invoke(null, parameters)))
                {
                    message = parameters[1] as string;
                    return(false);
                }
            }
            return(flag2);
        }
示例#14
0
        public static bool IsOpenForEdit(string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            message = "";

            if (!Provider.enabled)
            {
                return(true);
            }

            if (string.IsNullOrEmpty(assetPath))
            {
                return(true);
            }

            Asset asset = null;

            if (statusOptions == StatusQueryOptions.UseCachedIfPossible || statusOptions == StatusQueryOptions.UseCachedAsync)
            {
                CachedStatusMode mode = statusOptions == StatusQueryOptions.UseCachedAsync ? CachedStatusMode.Async : CachedStatusMode.Sync;
                asset = GetStatusCachedIfPossible(assetPath, mode);
            }
            else
            {
                asset = GetStatusForceUpdate(assetPath);
            }

            if (asset == null)
            {
                if (Provider.onlineState == OnlineState.Offline && Provider.offlineReason != string.Empty)
                {
                    message = Provider.offlineReason;
                }
                return(false);
            }

            return(Provider.IsOpenForEdit(asset));
        }
        public static bool IsMetaFileOpenForEdit(UnityEngine.Object assetObject, StatusQueryOptions statusOptions)
        {
            string message;

            return(IsMetaFileOpenForEdit(assetObject, out message, statusOptions));
        }
 public static bool IsOpenForEdit(string assetOrMetaFilePath, out string message, StatusQueryOptions statusOptions)
 {
     return(AssetModificationProcessorInternal.IsOpenForEdit(assetOrMetaFilePath, out message, statusOptions));
 }
        public static bool IsOpenForEdit(UnityEngine.Object assetObject, out string message, StatusQueryOptions statusOptions)
        {
            string assetPath = GetAssetOrScenePath(assetObject);

            return(IsOpenForEdit(assetPath, out message, statusOptions));
        }
        public static bool IsOpenForEdit(string assetOrMetaFilePath, StatusQueryOptions StatusQueryOptions)
        {
            string message;

            return(IsOpenForEdit(assetOrMetaFilePath, out message, StatusQueryOptions));
        }
示例#19
0
 public static void IsOpenForEdit(string[] assetOrMetaFilePaths, List <string> outNotEditablePaths, [uei.DefaultValue("StatusQueryOptions.UseCachedIfPossible")] StatusQueryOptions statusQueryOptions = StatusQueryOptions.UseCachedIfPossible)
 {
     if (assetOrMetaFilePaths == null)
     {
         throw new ArgumentNullException(nameof(assetOrMetaFilePaths));
     }
     if (outNotEditablePaths == null)
     {
         throw new ArgumentNullException(nameof(outNotEditablePaths));
     }
     UnityEngine.Profiling.Profiler.BeginSample("AssetDatabase.IsOpenForEdit");
     AssetModificationProcessorInternal.IsOpenForEdit(assetOrMetaFilePaths, outNotEditablePaths, statusQueryOptions);
     UnityEngine.Profiling.Profiler.EndSample();
 }
示例#20
0
        internal static bool CanOpenForEdit(string[] assetOrMetaFilePaths, List <string> outNotEditablePaths, StatusQueryOptions statusQueryOptions)
        {
            outNotEditablePaths.Clear();
            if (assetOrMetaFilePaths == null || assetOrMetaFilePaths.Length == 0)
            {
                return(true);
            }

            var queryList = GetQueryList(assetOrMetaFilePaths, outNotEditablePaths);

            if (queryList.Count == 0)
            {
                return(outNotEditablePaths.Count == 0);
            }

            // Get a list of paths that are not open for edit.
            var notOpenForEditPaths = new List <string>();

            AssetModificationHook.GetOpenForEdit(false, queryList, notOpenForEditPaths, statusQueryOptions);
            GetOpenForEditViaScriptCallbacks(false, queryList.ToArray(), notOpenForEditPaths, out var message, statusQueryOptions);

            if (notOpenForEditPaths.Count == 0)
            {
                return(outNotEditablePaths.Count == 0);
            }

            // Status has just been updated so there's no need to force update again.
            if (statusQueryOptions == StatusQueryOptions.ForceUpdate)
            {
                statusQueryOptions = StatusQueryOptions.UseCachedIfPossible;
            }

            // Check paths that are not open for edit.
            if (!AssetModificationHook.GetOpenForEdit(true, notOpenForEditPaths, outNotEditablePaths, statusQueryOptions))
            {
                return(false);
            }

            return(GetOpenForEditViaScriptCallbacks(true, notOpenForEditPaths.ToArray(), outNotEditablePaths, out message, statusQueryOptions));
        }
示例#21
0
        static bool GetOpenForEdit(bool canOpenForEditVariant, string assetPath, out string message, StatusQueryOptions statusOptions)
        {
            message = string.Empty;
            if (string.IsNullOrEmpty(assetPath))
            {
                return(true); // treat empty/null paths as editable (might be under Library folders etc.)
            }
            var editability = GetPathEditability(assetPath);

            if (editability == Editability.Always)
            {
                return(true);
            }
            if (editability == Editability.Never)
            {
                return(false);
            }

            if (!AssetModificationHook.GetOpenForEdit(canOpenForEditVariant, assetPath, out message, statusOptions))
            {
                return(false);
            }

            return(GetOpenForEditViaScriptCallbacks(canOpenForEditVariant, new[] { assetPath }, new List <string>(), out message, statusOptions));
        }
        public static bool IsMetaFileOpenForEdit(UnityEngine.Object assetObject, out string message, [uei.DefaultValue("StatusQueryOptions.UseCachedIfPossible")] StatusQueryOptions statusOptions)
        {
            string assetPath = GetAssetOrScenePath(assetObject);
            string metaPath  = AssetDatabase.GetTextMetaFilePathFromAssetPath(assetPath);

            return(IsOpenForEdit(metaPath, out message, statusOptions));
        }
示例#23
0
        internal static bool IsOpenForEdit(string[] assetOrMetaFilePaths, List <string> outNotEditablePaths, StatusQueryOptions statusQueryOptions)
        {
            outNotEditablePaths.Clear();
            if (assetOrMetaFilePaths == null || assetOrMetaFilePaths.Length == 0)
            {
                return(true);
            }

            var queryList = GetQueryList(assetOrMetaFilePaths, outNotEditablePaths);

            if (queryList.Count == 0)
            {
                return(outNotEditablePaths.Count == 0);
            }

            // check with VCS
            if (!AssetModificationHook.GetOpenForEdit(false, queryList, outNotEditablePaths, statusQueryOptions))
            {
                return(false);
            }

            // check with possible script callbacks
            return(GetOpenForEditViaScriptCallbacks(false, queryList.ToArray(), outNotEditablePaths, out var message, statusQueryOptions));
        }
        public static bool IsMetaFileOpenForEdit(UnityEngine.Object assetObject, out string message, StatusQueryOptions statusOptions)
        {
            string assetPath = GetAssetOrScenePath(assetObject);
            string metaPath  = AssetDatabase.GetTextMetaFilePathFromAssetPath(assetPath);

            return(IsOpenForEdit(metaPath, out message, statusOptions));
        }
        internal static void IsOpenForEdit(string[] assetOrMetaFilePaths, List <string> outNotEditablePaths, StatusQueryOptions statusQueryOptions = StatusQueryOptions.UseCachedIfPossible)
        {
            outNotEditablePaths.Clear();
            if (assetOrMetaFilePaths == null || assetOrMetaFilePaths.Length == 0)
            {
                return;
            }

            var queryList = new List <string>();

            foreach (var path in assetOrMetaFilePaths)
            {
                if (string.IsNullOrEmpty(path))
                {
                    continue; // treat empty/null paths as editable (might be under Library folders etc.)
                }
                var editability = GetPathEditability(path);
                if (editability == Editability.Always)
                {
                    continue;
                }
                if (editability == Editability.Never)
                {
                    outNotEditablePaths.Add(path);
                    continue;
                }
                queryList.Add(path);
            }

            // check with VCS
            AssetModificationHook.IsOpenForEdit(queryList, outNotEditablePaths, statusQueryOptions);

            // check with possible script callbacks
            var scriptCallbacks = GetIsOpenForEditMethods();

            if (scriptCallbacks != null && scriptCallbacks.Length > 0)
            {
                var stillEditable = assetOrMetaFilePaths.Except(outNotEditablePaths).Where(f => !string.IsNullOrEmpty(f));
                var message       = string.Empty;
                foreach (var path in stillEditable)
                {
                    if (!IsOpenForEditViaScriptCallbacks(path, ref message))
                    {
                        outNotEditablePaths.Add(path);
                    }
                }
            }
        }
        public static bool IsOpenForEdit(string assetOrMetaFilePath, [uei.DefaultValue("StatusQueryOptions.UseCachedIfPossible")] StatusQueryOptions statusOptions)
        {
            string message;

            return(IsOpenForEdit(assetOrMetaFilePath, out message, statusOptions));
        }
        public static bool IsOpenForEdit(UnityEngine.Object assetObject, out string message, [uei.DefaultValue("StatusQueryOptions.UseCachedIfPossible")] StatusQueryOptions statusOptions)
        {
            string assetPath = GetAssetOrScenePath(assetObject);

            return(IsOpenForEdit(assetPath, out message, statusOptions));
        }
        public static bool IsMetaFileOpenForEdit(UnityEngine.Object assetObject, [uei.DefaultValue("StatusQueryOptions.UseCachedIfPossible")] StatusQueryOptions statusOptions)
        {
            string message;

            return(IsMetaFileOpenForEdit(assetObject, out message, statusOptions));
        }
        internal static void IsOpenForEdit(List <string> assetPaths, List <string> outNotOpenPaths, StatusQueryOptions statusOptions)
        {
            if (!Provider.enabled || EditorUserSettings.WorkOffline || assetPaths == null || assetPaths.Count == 0)
            {
                return; // everything is editable
            }
            // paths that are empty/null are considered to be editable, so remove them from consideration
            assetPaths = assetPaths.Where(p => !string.IsNullOrEmpty(p)).ToList();

            AssetList assets;

            if (statusOptions == StatusQueryOptions.UseCachedIfPossible || statusOptions == StatusQueryOptions.UseCachedAsync)
            {
                assets = GetStatusCachedIfPossible(assetPaths, statusOptions == StatusQueryOptions.UseCachedIfPossible);
            }
            else
            {
                assets = GetStatusForceUpdate(assetPaths);
            }

            if (assets == null)
            {
                // nothing is editable (we might be disconnected)
                outNotOpenPaths.AddRange(assetPaths);
                return;
            }

            for (var i = 0; i < assetPaths.Count; ++i)
            {
                var asset = assets[i];
                if (asset == null || !Provider.IsOpenForEdit(asset))
                {
                    outNotOpenPaths.Add(assetPaths[i]);
                }
            }
        }
 public static bool IsOpenForEdit(string assetOrMetaFilePath, out string message, [uei.DefaultValue("StatusQueryOptions.UseCachedIfPossible")] StatusQueryOptions statusOptions)
 {
     return(AssetModificationProcessorInternal.IsOpenForEdit(assetOrMetaFilePath, out message, statusOptions));
 }