Inheritance: BaseActions
Esempio n. 1
0
        public override void Inspector_Body()
        {
            menuScript = target as MenuActions;

            int actionCount = 0;
            foreach(var action in menuScript.actions)
            {
                if (action.ShouldBuild())
                    actionCount += 1;
            }
            if(actionCount > ExpressionsMenu.MAX_CONTROLS)
            {
                EditorGUILayout.HelpBox($"Too many actions are defined, disable or delete until there are only {ExpressionsMenu.MAX_CONTROLS}", MessageType.Error);
            }

            base.Inspector_Body();
        }
Esempio n. 2
0
        static void BuildExpressionsMenu(MenuActions rootMenu)
        {
            List<MenuActions> menuList = new List<MenuActions>();

            //Create root menu if needed
            if (AvatarDescriptor.expressionsMenu == null)
            {
                AvatarDescriptor.expressionsMenu = ScriptableObject.CreateInstance<ExpressionsMenu>();
                AvatarDescriptor.expressionsMenu.name = "ExpressionsMenu_Root";
                SaveAsset(AvatarDescriptor.expressionsMenu, rootMenu, "Generated");
            }

            //Expressions
            CreateMenu(rootMenu, AvatarDescriptor.expressionsMenu);
            void CreateMenu(MenuActions ourMenu, ExpressionsMenu expressionsMenu)
            {
                //Clear old controls
                List<ExpressionsMenu.Control> oldControls = new List<ExpressionsMenu.Control>();
                oldControls.AddRange(expressionsMenu.controls);
                expressionsMenu.controls.Clear();

                //Create controls from actions
                foreach (var action in ourMenu.actions)
                {
                    if (!action.ShouldBuild())
                        continue;

                    if (action.menuType == MenuAction.MenuType.Button)
                    {
                        //Create control
                        var control = new ExpressionsMenu.Control();
                        control.name = action.name;
                        control.icon = action.icon;
                        control.type = ExpressionsMenu.Control.ControlType.Button;
                        control.parameter = new ExpressionsMenu.Control.Parameter();
                        control.parameter.name = action.parameter;
                        control.value = action.controlValue;
                        expressionsMenu.controls.Add(control);
                    }
                    else if (action.menuType == MenuAction.MenuType.Toggle)
                    {
                        //Create control
                        var control = new ExpressionsMenu.Control();
                        control.name = action.name;
                        control.icon = action.icon;
                        control.type = ExpressionsMenu.Control.ControlType.Toggle;
                        control.parameter = new ExpressionsMenu.Control.Parameter();
                        control.parameter.name = action.parameter;
                        control.value = action.controlValue;
                        expressionsMenu.controls.Add(control);
                    }
                    else if (action.menuType == MenuAction.MenuType.Slider)
                    {
                        //Create control
                        var control = new ExpressionsMenu.Control();
                        control.name = action.name;
                        control.icon = action.icon;
                        control.type = ExpressionsMenu.Control.ControlType.RadialPuppet;
                        control.subParameters = new ExpressionsMenu.Control.Parameter[1];
                        control.subParameters[0] = new ExpressionsMenu.Control.Parameter();
                        control.subParameters[0].name = action.parameter;
                        control.value = action.controlValue;
                        expressionsMenu.controls.Add(control);
                    }
                    else if (action.menuType == MenuAction.MenuType.SubMenu)
                    {
                        //Recover old sub-menu
                        ExpressionsMenu expressionsSubMenu = null;
                        foreach (var controlIter in oldControls)
                        {
                            if (controlIter.name == action.name)
                            {
                                expressionsSubMenu = controlIter.subMenu;
                                break;
                            }
                        }

                        //Create if needed
                        if (expressionsSubMenu == null)
                        {
                            expressionsSubMenu = ScriptableObject.CreateInstance<ExpressionsMenu>();
                            expressionsSubMenu.name = "ExpressionsMenu_" + action.name;
                            SaveAsset(expressionsSubMenu, rootMenu, "Generated");
                        }

                        //Create control
                        var control = new ExpressionsMenu.Control();
                        control.name = action.name;
                        control.icon = action.icon;
                        control.type = ExpressionsMenu.Control.ControlType.SubMenu;
                        control.subMenu = expressionsSubMenu;
                        expressionsMenu.controls.Add(control);

                        //Populate sub-menu
                        CreateMenu(action.subMenu, expressionsSubMenu);
                    }
                    else if (action.menuType == MenuAction.MenuType.PreExisting)
                    {
                        //Recover old control
                        foreach (var controlIter in oldControls)
                        {
                            if (controlIter.name == action.name)
                            {
                                oldControls.Remove(controlIter);
                                expressionsMenu.controls.Add(controlIter);
                                break;
                            }
                        }
                    }
                }

                //Save prefab
                EditorUtility.SetDirty(expressionsMenu);
            }

            //Save all assets
            AssetDatabase.SaveAssets();
        }