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();
        }