Exemplo n.º 1
0
    /// <summary>
    /// Called when the Themes window is enabled.
    /// </summary>
    public void OnEnable()
    {
        LoadLUTs();


#if UNITY_5 || UNITY_2017_1_OR_NEWER
        foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
        {
            Type type = a.GetType("UnityStandardAssets.ImageEffects.ColorCorrectionLookup");
            if (type != null)
            {
                colorCorrectionScriptType  = type;
                colorCorrectionScriptFound = true;
            }
        }
#elif !UNITY_5
        // Attempt to find the Color Correction script. (This is a wacky workaround since it's a .js file)
        string[] strings = Unsupported.GetSubmenus("Component");
        foreach (string s in strings)
        {
            if (s.Contains("Color Correction (3D Lookup Texture)"))
            {
                colorCorrectionScriptFound = true;
            }
        }
#endif

        picker = EditorGUIUtility.Load("Cinema Suite/Cinema Themes/Director_PickerIcon.png") as Texture2D;
    }
        public static IEnumerable <string> GetSubmenus(string path)
        {
            path = path.TrimEnd(Separator) + Separator;

            if (useUnsupported)
            {
                return(Unsupported.GetSubmenus(path));
            }
            else
            {
                return(Parse().Where(item => item.StartsWith(path)));
            }
        }
        private static List <KeyValuePair <string, string> > GetMenuDictionary()
        {
            var menus    = Unsupported.GetSubmenus("Component");
            var commands = Unsupported.GetSubmenusCommands("Component");

            var menuDictionary = new Dictionary <string, string>(menus.Length);

            for (var i = 0; i < menus.Length; i++)
            {
                menuDictionary.Add(menus[i], commands[i]);
            }
            return(menuDictionary.ToList());
        }
        private GenericMenu GetCMDMenu(GraphNode node)
        {
            string[] options = Unsupported.GetSubmenus("Assets");
            var      m       = new GenericMenu();

            foreach (var o in options)
            {
                m.AddItem(new GUIContent(o), false, () => {
                    node.command = o;
                });
            }
            return(m);
        }
        private GenericMenu GetCMDMenu(SerializedProperty cmdProp)
        {
            string[] options = Unsupported.GetSubmenus("Assets");
            var      m       = new GenericMenu();

            foreach (var o in options)
            {
                m.AddItem(new GUIContent(o), false, () => {
                    cmdProp.stringValue = o;
                    cmdProp.serializedObject.ApplyModifiedProperties();
                });
            }
            return(m);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 指定したメニューの文字列が存在するかチェックします
        /// </summary>
        /// <param name="menuName"></param>
        /// <returns></returns>
        public static bool HasMenuItem(string menuName)
        {
            var menuTop = menuName.Split('/')[0];
            var ss      = Unsupported.GetSubmenus(menuTop);

            foreach (var s in ss)
            {
                if (s == menuName)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 7
0
        static List <MenuItemData> GetSortedMenuItems(UnityEngine.GameObject[] targets)
        {
            var menus    = Unsupported.GetSubmenus("Component");
            var commands = Unsupported.GetSubmenusCommands("Component");

            var          menuItems       = new List <MenuItemData>(menus.Length);
            var          legacyMenuItems = new List <MenuItemData>(menus.Length);
            const string kLegacyString   = "legacy";

            var hasFilterOverride = ModeService.HasExecuteHandler("inspector_filter_component");

            for (var i = 0; i < menus.Length; i++)
            {
                var  menuPath = menus[i];
                bool isLegacy = menuPath.ToLower().Contains(kLegacyString);
                var  item     = new MenuItemData
                {
                    path     = menuPath,
                    command  = commands[i],
                    isLegacy = isLegacy
                };

                if (!hasFilterOverride || ModeService.Execute("inspector_filter_component", targets, menuPath))
                {
                    if (isLegacy)
                    {
                        legacyMenuItems.Add(item);
                    }
                    else
                    {
                        menuItems.Add(item);
                    }
                }
            }

            int comparison(MenuItemData x, MenuItemData y) => string.CompareOrdinal(x.path, y.path);

            menuItems.Sort(comparison);
            legacyMenuItems.Sort(comparison);

            menuItems.AddRange(legacyMenuItems);

            return(menuItems);
        }
Exemplo n.º 8
0
        static List <MenuItemData> GetSortedMenuItems()
        {
            var menus    = Unsupported.GetSubmenus("Component");
            var commands = Unsupported.GetSubmenusCommands("Component");

            var          menuItems       = new List <MenuItemData>(menus.Length);
            var          legacyMenuItems = new List <MenuItemData>(menus.Length);
            const string kLegacyString   = "legacy";

            for (var i = 0; i < menus.Length; i++)
            {
                var  menuPath = menus[i];
                bool isLegacy = menuPath.ToLower().Contains(kLegacyString);
                var  item     = new MenuItemData
                {
                    path     = menuPath,
                    command  = commands[i],
                    isLegacy = isLegacy
                };

                if (isLegacy)
                {
                    legacyMenuItems.Add(item);
                }
                else
                {
                    menuItems.Add(item);
                }
            }

            int comparison(MenuItemData x, MenuItemData y) => string.CompareOrdinal(x.path, y.path);

            menuItems.Sort(comparison);
            legacyMenuItems.Sort(comparison);

            menuItems.AddRange(legacyMenuItems);

            return(menuItems);
        }
Exemplo n.º 9
0
        public void ShowContextMenu(GameObject[] selection, bool openedViaCreateButton)
        {
            bool hasSelection = !openedViaCreateButton && selection != null && selection.Length > 0;

            if (selection == null || selection.Length == 0)
            {
                selection = new GameObject[1] {
                    RootGameObject
                }
            }
            ;

            GenericMenu menu = new GenericMenu();

            if (!openedViaCreateButton)
            {
                if (hasSelection)
                {
                    menu.AddItem(new GUIContent("Copy"), false, () => CopySelection(selection));
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Copy"));
                }

                menu.AddItem(new GUIContent("Paste"), false, () => PasteToSelection(selection));

                menu.AddSeparator("");

                if (hasSelection)
                {
                    TreeViewItem selectedItem = FindItem(selection[0].GetInstanceID(), rootItem);
                    if (selectedItem != null)
                    {
                        menu.AddItem(new GUIContent("Rename"), false, () => BeginRename(selectedItem));
                        menu.AddItem(new GUIContent("Duplicate"), false, () => DuplicateSelection(selection));
                        menu.AddItem(new GUIContent("Delete"), false, () => DeleteSelection(selection));

                        menu.AddSeparator("");

#if UNITY_2018_3_OR_NEWER
                        Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(EditorUtility.InstanceIDToObject(selectedItem.id));
#else
                        Object prefab = PrefabUtility.GetPrefabParent(EditorUtility.InstanceIDToObject(selectedItem.id));
#endif
                        if (prefab)
                        {
                            menu.AddItem(new GUIContent("Select Prefab"), false, () =>
                            {
                                Selection.activeObject = prefab;
                                EditorGUIUtility.PingObject(prefab.GetInstanceID());
                            });

#if UNITY_2018_3_OR_NEWER
                            for (int i = 0; i < selection.Length; i++)
                            {
                                if (selection[i] && PrefabUtility.IsPartOfNonAssetPrefabInstance(selection[i]) && PrefabUtility.IsOutermostPrefabInstanceRoot(selection[i]))
                                {
                                    int _i = i;

                                    menu.AddItem(new GUIContent("Prefab/Unpack"), false, () =>
                                    {
                                        for (int j = _i; j < selection.Length; j++)
                                        {
                                            GameObject go = selection[j];
                                            if (go && PrefabUtility.IsPartOfNonAssetPrefabInstance(go) && PrefabUtility.IsOutermostPrefabInstanceRoot(go))
                                            {
                                                PrefabUtility.UnpackPrefabInstance(go, PrefabUnpackMode.OutermostRoot, InteractionMode.UserAction);
                                            }
                                        }
                                    });

                                    menu.AddItem(new GUIContent("Prefab/Unpack Completely"), false, () =>
                                    {
                                        for (int j = _i; j < selection.Length; j++)
                                        {
                                            GameObject go = selection[j];
                                            if (go && PrefabUtility.IsPartOfNonAssetPrefabInstance(go) && PrefabUtility.IsOutermostPrefabInstanceRoot(go))
                                            {
                                                PrefabUtility.UnpackPrefabInstance(go, PrefabUnpackMode.Completely, InteractionMode.UserAction);
                                            }
                                        }
                                    });

                                    break;
                                }
                            }
#endif

                            menu.AddSeparator("");
                        }
                    }
                }
            }

#if UNITY_2020_2_OR_NEWER
            string menusLastItem = (string)typeof(GameObjectUtility).GetMethod("GetFirstItemPathAfterGameObjectCreationMenuItems", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, null);
#else
            string menusLastItem = "GameObject/Center On Children";
#endif
            foreach (string path in Unsupported.GetSubmenus("GameObject"))
            {
                if (path.Equals(menusLastItem, StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
                else if (path.Equals("GameObject/Create Empty Child", StringComparison.OrdinalIgnoreCase))                    // "Create Empty" does the same thing
                {
                    continue;
                }
                else if (path.Equals("GameObject/Create Empty Parent", StringComparison.OrdinalIgnoreCase))                    // Doesn't take context into account, it uses Unity's Selection
                {
                    continue;
                }
                else if (path.IndexOf("Collapse All", StringComparison.OrdinalIgnoreCase) >= 0)                    // Collapse functions don't work in this window
                {
                    continue;
                }

                // Don't include context for Wizards (...) to avoid opening multiple wizards at once
                Object[] tempContext = selection;
                if (path.EndsWith("..."))
                {
                    tempContext = null;
                }

                menu.AddItem(new GUIContent(path.Substring(11)), false, () =>                      // Substring: remove "GameObject/" prefix
                {
                    using (new SelectionChangeApplier(this))
                    {
                        if (tempContext != null)
                        {
                            typeof(EditorApplication).GetMethod("ExecuteMenuItemWithTemporaryContext", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { path, tempContext });
                        }
                        else
                        {
                            EditorApplication.ExecuteMenuItem(path);
                        }
                    }
                });
            }

            menu.ShowAsContext();
            Event.current.Use();
        }