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));
        }
Esempio n. 2
0
        public static bool IsMetaFileOpenForEdit(UnityEngine.Object assetObject, out string message)
        {
            string assetOrScenePath = AssetDatabase.GetAssetOrScenePath(assetObject);
            string textMetaFilePathFromAssetPath = AssetDatabase.GetTextMetaFilePathFromAssetPath(assetOrScenePath);

            return(AssetDatabase.IsOpenForEdit(textMetaFilePathFromAssetPath, out message));
        }
        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));
        }
        private void ShowScriptPopup(Rect r)
        {
            var length            = m_DefaultTimeScripts.Count;
            var names             = new List <string>(length);
            var selectableScripts = new List <MonoScript>(length);

            for (var i = 0; i < length; ++i)
            {
                var assetPath = AssetDatabase.GetAssetPath(m_DefaultTimeScripts[i]);
                if (string.IsNullOrEmpty(assetPath))
                {
                    continue;
                }

                var metaPath = AssetDatabase.GetTextMetaFilePathFromAssetPath(assetPath);
                if (!AssetDatabase.CanOpenForEdit(metaPath))
                {
                    continue;
                }

                names.Add(m_DefaultTimeScripts[i].GetClass().FullName); // todo: Localization with a proper database.
                selectableScripts.Add(m_DefaultTimeScripts[i]);
            }

            if (names.Count == 0)
            {
                EditorUtility.DisplayCustomMenu(r, Content.emptyMenuOptions, i => false, -1, null, null);
                return;
            }

            var options = names.ToArray();
            var enabled = Enumerable.Repeat(true, options.Length).ToArray();

            EditorUtility.DisplayCustomMenu(r, options, enabled, null, MenuSelection, selectableScripts);
        }
        private void Apply()
        {
            var changedIndices = new List <int>();
            var changedPaths   = new List <string>();

            for (var i = 0; i < m_AllScripts.Length; i++)
            {
                var script = m_AllScripts[i];
                if (MonoImporter.GetExecutionOrder(script) == m_AllOrders[i])
                {
                    continue;
                }

                var assetPath = AssetDatabase.GetAssetPath(script);
                if (string.IsNullOrEmpty(assetPath)) // Script might be outside of the project (e.g. in a package).
                {
                    continue;
                }

                var metaPath = AssetDatabase.GetTextMetaFilePathFromAssetPath(assetPath);
                if (!AssetDatabase.CanOpenForEdit(metaPath))
                {
                    continue;
                }

                changedIndices.Add(i);
                if (!AssetDatabase.IsOpenForEdit(metaPath)) // No VCS enabled, not connected, already checked out, etc.
                {
                    changedPaths.Add(metaPath);
                }
            }

            if (!AssetDatabase.MakeEditable(changedPaths.ToArray()))
            {
                Debug.LogError("Could not make scrips editable for changing script execution order.");
                return;
            }

            foreach (var index in changedIndices)
            {
                MonoImporter.SetExecutionOrder(m_AllScripts[index], m_AllOrders[index]);
            }

            PopulateScriptArray();
        }
Esempio n. 6
0
        private void ShowScriptPopup(Rect r)
        {
            int length = m_DefaultTimeScripts.Count;

            string[] names         = new string[length];
            bool[]   enabled       = new bool[length];
            var      lockedScripts = new HashSet <MonoScript>();

            if (Provider.enabled)
            {
                var assetList    = new AssetList();
                var pathToScript = new Dictionary <string, MonoScript>();

                for (int i = 0; i < length; i++)
                {
                    var metaPath = AssetDatabase.GetTextMetaFilePathFromAssetPath(AssetDatabase.GetAssetPath(m_DefaultTimeScripts[i]));

                    if (Provider.GetAssetByPath(metaPath) != null)
                    {
                        assetList.Add(Provider.GetAssetByPath(metaPath));
                        pathToScript.Add(metaPath, m_DefaultTimeScripts[i]);
                    }
                }

                Provider.Status(assetList).Wait();

                const Asset.States kExclusiveLockedRemote = Asset.States.Exclusive | Asset.States.LockedRemote;
                foreach (var asset in assetList)
                {
                    if ((asset.state & kExclusiveLockedRemote) == kExclusiveLockedRemote)
                    {
                        lockedScripts.Add(pathToScript[asset.metaPath]);
                    }
                }
            }

            for (int c = 0; c < length; c++)
            {
                names[c]   = m_DefaultTimeScripts[c].GetClass().FullName;      // TODO: localization with a proper database.
                enabled[c] = !lockedScripts.Contains(m_DefaultTimeScripts[c]); //List item is disabled when asset is locked
            }
            EditorUtility.DisplayCustomMenu(r, names, enabled, null, MenuSelection, null);
        }