private void ONAddCallback(ReorderableList reorderableList) { var menu = serializedObject.targetObject as ExpressionsMenu; var control = new ExpressionControl(); control.name = "New Control"; menu.controls.Add(control); if (controls.arraySize >= ExpressionsMenu.MAX_CONTROLS - 1) { list.displayAdd = false; } }
public override void OnInspectorGUI() { serializedObject.Update(); SelectAvatarDescriptor(); if (activeDescriptor == null) { EditorGUILayout.HelpBox("No active avatar descriptor found in scene.", MessageType.Error); } EditorGUILayout.Space(); //Controls EditorGUI.BeginDisabledGroup(activeDescriptor == null); EditorGUILayout.LabelField("Controls"); EditorGUI.indentLevel += 1; { var controls = serializedObject.FindProperty("controls"); for (int i = 0; i < controls.arraySize; i++) { var control = controls.GetArrayElementAtIndex(i); DrawControl(controls, control as SerializedProperty, i); } //Add EditorGUI.BeginDisabledGroup(controls.arraySize >= ExpressionsMenu.MAX_CONTROLS); if (GUILayout.Button("Add Control")) { var menu = serializedObject.targetObject as ExpressionsMenu; var control = new ExpressionControl(); control.name = "New Control"; menu.controls.Add(control); } EditorGUI.EndDisabledGroup(); } EditorGUI.indentLevel -= 1; EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); }
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(); }