protected void RenderButtonMenu() { var menu = (LyumaAv3Menu)target; if (menu.Runtime == null) { return; } if (menu.RootMenu == null) { menu.RootMenu = (VRCExpressionsMenu)EditorGUILayout.ObjectField(new GUIContent("Expressions Menu"), null, typeof(VRCExpressionsMenu), false); return; } var isInRootMenu = menu.MenuStack.Count == 0; GUILayout.Label( (isInRootMenu ? "Expressions" : LabelizeMenu()) + (menu.IsMenuOpen ? "" : " [Menu is closed]"), EditorStyles.boldLabel); if (!menu.IsMenuOpen) { return; } _currentMenu = menu.MenuStack.Count == 0 ? menu.RootMenu : menu.MenuStack.Last().ExpressionsMenu; EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField(_currentMenu, typeof(VRCExpressionsMenu), false); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(isInRootMenu || menu.HasActiveControl()); if (GUILayout.Button("Back")) { menu.UserBack(); } EditorGUI.EndDisabledGroup(); if (_currentMenu == null) { EditorGUILayout.LabelField("(This submenu is null)"); return; } for (var controlIndex = 0; controlIndex < _currentMenu.controls.Count; controlIndex++) { var control = _currentMenu.controls[controlIndex]; switch (control.type) { case VRCExpressionsMenu.Control.ControlType.Button: FromToggle(control, "Button"); break; case VRCExpressionsMenu.Control.ControlType.Toggle: FromToggle(control, "Toggle"); break; case VRCExpressionsMenu.Control.ControlType.SubMenu: FromSubMenu(control); break; case VRCExpressionsMenu.Control.ControlType.TwoAxisPuppet: FromTwoAxis(control, controlIndex); break; case VRCExpressionsMenu.Control.ControlType.FourAxisPuppet: FromFourAxis(control, controlIndex); break; case VRCExpressionsMenu.Control.ControlType.RadialPuppet: FromRadial(control, controlIndex); break; default: throw new ArgumentOutOfRangeException(); } } if (_currentMenu.controls.Count == 0) { EditorGUILayout.LabelField("(This menu has no controls)"); } }
public void Generate() { // Unique directory setup, named after avatar Directory.CreateDirectory("Assets/VRLabs/Marker/Generated/"); // Folder name cannot contain these chars string cleanedName = string.Join("", descriptor.name.Split('/', '?', '<', '>', '\\', ':', '*', '|', '\"')); string guid = AssetDatabase.CreateFolder("Assets/VRLabs/Marker/Generated", cleanedName); string directory = AssetDatabase.GUIDToAssetPath(guid) + "/"; // Install layers, parameters, and menu before prefab setup // FX layer if (useIndexFinger) { AssetDatabase.CopyAsset("Assets/VRLabs/Marker/Resources/M_FX (Finger).controller", directory + "FXtemp.controller"); } else { AssetDatabase.CopyAsset("Assets/VRLabs/Marker/Resources/M_FX.controller", directory + "FXtemp.controller"); } AnimatorController FX = AssetDatabase.LoadAssetAtPath(directory + "FXtemp.controller", typeof(AnimatorController)) as AnimatorController; // remove controller layers before merging to avatar, corresponding to setup if (leftHanded) { RemoveLayer(FX, "M_Marker R"); } else { RemoveLayer(FX, "M_Marker L"); } if (!brushSize) { RemoveLayer(FX, "M_Size"); RemoveParameter(FX, "M_Size"); } if (!eraserSize) { RemoveLayer(FX, "M_EraserSize"); RemoveParameter(FX, "M_EraserSize"); } if (!localSpace) { RemoveLayer(FX, "M_Space"); RemoveParameter(FX, "M_Space"); RemoveLayer(FX, "M_Cull"); } else { RemoveLayer(FX, "M_SpaceSimple"); RemoveParameter(FX, "M_SpaceSimple"); RemoveLayer(FX, "M_CullSimple"); } if (writeDefaults) { AV3ManagerFunctions.SetWriteDefaults(FX); } if (gestureToDraw != 3) // uses fingerpoint by default { ChangeGestureCondition(FX, 0, gestureToDraw); } // Set parameter driver on 'Clear' state to reset local space AnimatorState state = FX.layers[0].stateMachine.states.FirstOrDefault(s => s.state.name.Equals("Clear")).state; VRCAvatarParameterDriver driver = (VRCAvatarParameterDriver)state.behaviours[0]; string driverParamName = localSpace ? "M_Space" : "M_SpaceSimple"; VRC.SDKBase.VRC_AvatarParameterDriver.Parameter param = new VRC.SDKBase.VRC_AvatarParameterDriver.Parameter() { name = driverParamName, type = VRC.SDKBase.VRC_AvatarParameterDriver.ChangeType.Set, value = 0f }; driver.parameters.Add(param); EditorUtility.SetDirty(FX); AV3ManagerFunctions.MergeToLayer(descriptor, FX, AV3ManagerFunctions.PlayableLayer.FX, directory); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(FX)); // delete temporary FX layer // Gesture layer AssetDatabase.CopyAsset("Assets/VRLabs/Marker/Resources/M_Gesture.controller", directory + "gestureTemp.controller"); // to modify AnimatorController gesture = AssetDatabase.LoadAssetAtPath(directory + "gestureTemp.controller", typeof(AnimatorController)) as AnimatorController; if (descriptor.baseAnimationLayers[2].isDefault == true || descriptor.baseAnimationLayers[2].animatorController == null) { AssetDatabase.CopyAsset(path_defaultGesture, directory + "Gesture.controller"); AnimatorController gestureOriginal = AssetDatabase.LoadAssetAtPath(directory + "Gesture.controller", typeof(AnimatorController)) as AnimatorController; descriptor.customExpressions = true; descriptor.baseAnimationLayers[2].isDefault = false; descriptor.baseAnimationLayers[2].animatorController = gestureOriginal; if (writeDefaults) { AV3ManagerFunctions.SetWriteDefaults(gestureOriginal); EditorUtility.SetDirty(gestureOriginal); } } gesture.RemoveLayer((leftHanded) ? 1 : 0); if (useIndexFinger) { // use different hand animations for (int i = 0; i < 3; i++) { if (gesture.layers[0].stateMachine.states[i].state.motion.name == "M_Gesture") { gesture.layers[0].stateMachine.states[i].state.motion = AssetDatabase.LoadAssetAtPath("Assets/VRLabs/Marker/Resources/Animations/Gesture/M_Gesture (Finger).anim", typeof(AnimationClip)) as AnimationClip; } else if (gesture.layers[0].stateMachine.states[i].state.motion.name == "M_Gesture Draw") { gesture.layers[0].stateMachine.states[i].state.motion = AssetDatabase.LoadAssetAtPath("Assets/VRLabs/Marker/Resources/Animations/Gesture/M_Gesture Draw (Finger).anim", typeof(AnimationClip)) as AnimationClip; } } } if (gestureToDraw != 3) { ChangeGestureCondition(gesture, 0, gestureToDraw); } if (writeDefaults) { AV3ManagerFunctions.SetWriteDefaults(gesture, true); } EditorUtility.SetDirty(gesture); AV3ManagerFunctions.MergeToLayer(descriptor, gesture, AV3ManagerFunctions.PlayableLayer.Gesture, directory); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(gesture)); // delete temporary gesture layer // layer weight control from merged layer may need index set correctly AnimatorController avatarGesture = (AnimatorController)descriptor.baseAnimationLayers[2].animatorController; for (int i = 0; i < avatarGesture.layers.Length; i++) { // the controls' layer is normally 3 (AllParts, LeftHand, RightHand, >>>M_Gesture<<<) if (avatarGesture.layers[i].name.Contains("M_Gesture") && (i != 3)) { for (int j = 0; j < 3; j++) { if (avatarGesture.layers[i].stateMachine.states[j].state.behaviours.Length != 0) { VRCAnimatorLayerControl ctrl = (VRCAnimatorLayerControl)avatarGesture.layers[i].stateMachine.states[j].state.behaviours[0]; ctrl.layer = i; } } } } EditorUtility.SetDirty(avatarGesture); // Parameters VRCExpressionParameters.Parameter p_marker = new VRCExpressionParameters.Parameter { name = "M_Marker", valueType = VRCExpressionParameters.ValueType.Bool, saved = false }, p_eraser = new VRCExpressionParameters.Parameter { name = "M_Eraser", valueType = VRCExpressionParameters.ValueType.Bool, saved = false }, p_clear = new VRCExpressionParameters.Parameter { name = "M_Clear", valueType = VRCExpressionParameters.ValueType.Bool, saved = false }, p_color = new VRCExpressionParameters.Parameter { name = "M_Color", valueType = VRCExpressionParameters.ValueType.Float, saved = true }; AV3ManagerFunctions.AddParameter(descriptor, p_marker, directory); AV3ManagerFunctions.AddParameter(descriptor, p_eraser, directory); AV3ManagerFunctions.AddParameter(descriptor, p_clear, directory); AV3ManagerFunctions.AddParameter(descriptor, p_color, directory); if (localSpace) { VRCExpressionParameters.Parameter p_space = new VRCExpressionParameters.Parameter { name = "M_Space", valueType = VRCExpressionParameters.ValueType.Int, saved = false }; AV3ManagerFunctions.AddParameter(descriptor, p_space, directory); } else { VRCExpressionParameters.Parameter p_spaceSimple = new VRCExpressionParameters.Parameter { name = "M_SpaceSimple", valueType = VRCExpressionParameters.ValueType.Bool, saved = false }; AV3ManagerFunctions.AddParameter(descriptor, p_spaceSimple, directory); } if (brushSize) { VRCExpressionParameters.Parameter p_size = new VRCExpressionParameters.Parameter { name = "M_Size", valueType = VRCExpressionParameters.ValueType.Float, saved = false }; AV3ManagerFunctions.AddParameter(descriptor, p_size, directory); } if (eraserSize) { VRCExpressionParameters.Parameter p_eraserSize = new VRCExpressionParameters.Parameter { name = "M_EraserSize", valueType = VRCExpressionParameters.ValueType.Float, saved = false }; AV3ManagerFunctions.AddParameter(descriptor, p_eraserSize, directory); } VRCExpressionParameters.Parameter p_menu = new VRCExpressionParameters.Parameter { name = "M_Menu", valueType = VRCExpressionParameters.ValueType.Bool, saved = false }; AV3ManagerFunctions.AddParameter(descriptor, p_menu, directory); // handle menu instancing AssetDatabase.CopyAsset("Assets/VRLabs/Marker/Resources/M_Menu.asset", directory + "Marker Menu.asset"); VRCExpressionsMenu markerMenu = AssetDatabase.LoadAssetAtPath(directory + "Marker Menu.asset", typeof(VRCExpressionsMenu)) as VRCExpressionsMenu; if (!localSpace) // change from submenu to 1 toggle { VRCExpressionsMenu.Control.Parameter pm_spaceSimple = new VRCExpressionsMenu.Control.Parameter { name = "M_SpaceSimple" }; markerMenu.controls[6].type = VRCExpressionsMenu.Control.ControlType.Toggle; markerMenu.controls[6].parameter = pm_spaceSimple; markerMenu.controls[6].subMenu = null; // or else the submenu is still there internally, SDK complains } else { AssetDatabase.CopyAsset("Assets/VRLabs/Marker/Resources/M_Menu Space.asset", directory + "Marker Space Submenu.asset"); VRCExpressionsMenu subMenu = AssetDatabase.LoadAssetAtPath(directory + "Marker Space Submenu.asset", typeof(VRCExpressionsMenu)) as VRCExpressionsMenu; if (localSpaceFullBody == 0) // remove left and right foot controls { subMenu.controls.RemoveAt(7); subMenu.controls.RemoveAt(6); } markerMenu.controls[6].subMenu = subMenu; EditorUtility.SetDirty(subMenu); } if (!brushSize) { RemoveMenuControl(markerMenu, "Brush Size"); } if (!eraserSize) { RemoveMenuControl(markerMenu, "Eraser Size"); } EditorUtility.SetDirty(markerMenu); VRCExpressionsMenu.Control.Parameter pm_menu = new VRCExpressionsMenu.Control.Parameter { name = "M_Menu" }; Texture2D markerIcon = AssetDatabase.LoadAssetAtPath("Assets/VRLabs/Marker/Resources/Icons/M_Icon_Menu.png", typeof(Texture2D)) as Texture2D; AV3ManagerFunctions.AddSubMenu(descriptor, markerMenu, "Marker", directory, pm_menu, markerIcon); // setup in scene GameObject marker = PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath("Assets/VRLabs/Marker/Resources/Marker.prefab", typeof(GameObject))) as GameObject; PrefabUtility.UnpackPrefabInstance(marker, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); marker.transform.SetParent(avatar.transform, false); Transform system = marker.transform.Find("System"); Transform targets = marker.transform.Find("Targets"); Transform markerTarget = targets.Find("MarkerTarget"); Transform markerModel = targets.Find("Model"); Transform eraser = system.Find("Eraser"); // constrain cull object to avatar Transform cull = marker.transform.Find("Cull"); cull.GetComponent <ParentConstraint>().SetSource(0, new ConstraintSource { sourceTransform = descriptor.transform, weight = 1f }); if (useIndexFinger) { DestroyImmediate(markerTarget.GetChild(0).gameObject); // destroy Flip Transform indexDistal = leftHanded ? avatar.GetBoneTransform(HumanBodyBones.LeftIndexDistal) : avatar.GetBoneTransform(HumanBodyBones.RightIndexDistal); // prefer the end bone of the index finger if it exists if (indexDistal.Find(indexDistal.gameObject.name + "_end") != null) { markerTarget.SetParent(indexDistal.Find(indexDistal.gameObject.name + "_end"), true); } else { markerTarget.SetParent(indexDistal, false); } } else // using model: scale Model to target freely, and until script is destroyed, scale System to target uniformly with X-axis { markerModel.SetParent(marker.transform); // move it out of Targets hierarchy if (leftHanded) { markerTarget.SetParent(avatar.GetBoneTransform(HumanBodyBones.LeftHand), true); } else { markerTarget.SetParent(avatar.GetBoneTransform(HumanBodyBones.RightHand), true); } ((Marker)target).markerModel = markerModel; // to turn its mesh renderer off when script is finished } markerTarget.localPosition = Vector3.zero; markerTarget.localRotation = Quaternion.Euler(0f, 0f, 0f); if (localSpace) { targets.Find("M_LocalSpace2").SetParent(avatar.GetBoneTransform(HumanBodyBones.Hips), false); targets.Find("M_LocalSpace3").SetParent(avatar.GetBoneTransform(HumanBodyBones.Chest), false); Transform headRef = targets.Find("HeadRef"); // special setup for head bone b/c local shrink headRef.SetParent(avatar.GetBoneTransform(HumanBodyBones.Head), false); // get head position, headRef.SetParent(avatar.GetBoneTransform(HumanBodyBones.Neck), true); // but parent to neck headRef.GetComponent <RotationConstraint>().SetSource(0, new ConstraintSource { sourceTransform = avatar.GetBoneTransform(HumanBodyBones.Head), weight = 1f }); targets.Find("M_LocalSpace5").SetParent(avatar.GetBoneTransform(HumanBodyBones.LeftHand), false); targets.Find("M_LocalSpace6").SetParent(avatar.GetBoneTransform(HumanBodyBones.RightHand), false); if (localSpaceFullBody == 1) { targets.Find("M_LocalSpace7").SetParent(avatar.GetBoneTransform(HumanBodyBones.LeftFoot), false); targets.Find("M_LocalSpace8").SetParent(avatar.GetBoneTransform(HumanBodyBones.RightFoot), false); } } targets.Find("M_LocalSpace1").SetParent(avatar.transform, false); DestroyImmediate(targets.gameObject); // remove the "Targets" container object when finished // set anything not adjustable to a medium-ish amount if (!eraserSize) { eraser.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); } if (!brushSize) { ParticleSystem.MinMaxCurve size = new ParticleSystem.MinMaxCurve(0.024f); Transform draw = system.transform.Find("Draw"); Transform preview = draw.GetChild(0); ParticleSystem.MainModule main = draw.GetComponent <ParticleSystem>().main; main.startSize = size; main = preview.GetComponent <ParticleSystem>().main; main.startSize = size; } ((Marker)target).system = system; ((Marker)target).markerTarget = markerTarget; ((Marker)target).finished = true; AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Debug.Log("Successfully generated Marker!"); }
public MenuConditional(VRCExpressionsMenu expressionsMenu, LyumaAv3Runtime.FloatParam mandatedParam) { ExpressionsMenu = expressionsMenu; MandatedParam = mandatedParam; }
private void ValidateExpressionsMenu(VRCAvatarDescriptor avatar, VRCExpressionsMenu menu) { foreach(VRCExpressionsMenu.Control control in menu.controls) { if(control.type == VRCExpressionsMenu.Control.ControlType.Button) { if(string.IsNullOrEmpty(control.parameter.name)) issues.ExpressionsMenu.Add(new Issue($"Button[{control.name}] has no parameter", menu)); else if(null == avatar.expressionParameters.FindParameter(control.parameter.name)) issues.ExpressionsMenu.Add(new Issue($"Button[{control.name}] parameter[{control.parameter.name}] not in ExpressionParameters", menu)); } if(control.type == VRCExpressionsMenu.Control.ControlType.Toggle) { if(string.IsNullOrEmpty(control.parameter.name)) issues.ExpressionsMenu.Add(new Issue($"Toggle[{control.name}] has no parameter", menu)); else if(null == avatar.expressionParameters.FindParameter(control.parameter.name)) issues.ExpressionsMenu.Add(new Issue($"Toggle[{control.name}] parameter[{control.parameter.name}] not in ExpressionParameters", menu)); } if(control.type == VRCExpressionsMenu.Control.ControlType.RadialPuppet) { if(1 > control.subParameters.Length) issues.ExpressionsMenu.Add(new Issue($"Radial Puppet[{control.name}] has no sub parameters", menu)); int count = 0; foreach(VRCExpressionsMenu.Control.Parameter param in control.subParameters) { if(!string.IsNullOrEmpty(param.name)) count++; if(null == avatar.expressionParameters.FindParameter(param.name)) issues.ExpressionsMenu.Add(new Issue($"Radial Puppet[{control.name}] parameter[{param.name}] not in ExpressionParameters", menu)); } if(count < 1) issues.ExpressionsMenu.Add(new Issue($"Radial Puppet[{control.name}] has no sub parameters", menu)); } if(control.type == VRCExpressionsMenu.Control.ControlType.FourAxisPuppet) { if(4 != control.subParameters.Length) issues.ExpressionsMenu.Add(new Issue($"Four Axis Puppet[{control.name}] less than 4 sub parameters", menu)); int count = 0; foreach(VRCExpressionsMenu.Control.Parameter param in control.subParameters) { if(!string.IsNullOrEmpty(param.name)) count++; else continue; if(null == avatar.expressionParameters.FindParameter(param.name)) issues.ExpressionsMenu.Add(new Issue($"Four Axis Puppet[{control.name}] parameter[{param.name}] not in ExpressionParameters", menu)); } if(count < 4) issues.ExpressionsMenu.Add(new Issue($"Four Axis Puppet[{control.name}] less than 4 sub parameters", menu)); } if(control.type == VRCExpressionsMenu.Control.ControlType.TwoAxisPuppet) { if(1 > control.subParameters.Length) issues.ExpressionsMenu.Add(new Issue($"Two Axis Puppet[{control.name}] has no sub parameters", menu)); int count = 0; foreach(VRCExpressionsMenu.Control.Parameter param in control.subParameters) { if(!string.IsNullOrEmpty(param.name)) count++; else continue; if(null == avatar.expressionParameters.FindParameter(param.name)) issues.ExpressionsMenu.Add(new Issue($"Two Axis Puppet[{control.name}] parameter[{param.name}] not in ExpressionParameters", menu)); } if(count < 1) issues.ExpressionsMenu.Add(new Issue($"Two Axis Puppet[{control.name}] has no sub parameters", menu)); } if(control.type == VRCExpressionsMenu.Control.ControlType.SubMenu) { if(null == control.subMenu) issues.ExpressionsMenu.Add(new Issue($"Sub Menu[{control.name}] is blank", menu)); else { EMenus.Add(menu); EMenusText.Add(new string('+', eMenuIndent) + menu.name); if(EMenus.Find(m => m == control.subMenu)) { string text = $"Loop detected in Menu[{menu.name}] Sub Menu[{control.name}][{control.subMenu.name}].\n" + "This will cause an infinite loop on play.\n\n"; foreach(string lMenu in EMenusText) { text += $"{lMenu}\n"; } EditorUtility.DisplayDialog($"Expressions Menu Loop in [{currentAvatar.gameObject.name}]", text, "Cancel"); throw new TEA_Exception("Infinite Expressions Menu Loop"); } else { eMenuIndent++; ValidateExpressionsMenu(avatar, control.subMenu); eMenuIndent--; } } } } }
public void UserSubMenu(VRCExpressionsMenu subMenu) { MenuStack.Add(new MenuConditional(subMenu)); }
public MenuConditional(VRCExpressionsMenu expressionsMenu) { ExpressionsMenu = expressionsMenu; }
/* * Menu */ internal void OpenMenu(VRCExpressionsMenu menu, Vrc3Param param, float value) { _menuPath.Add(new RadialPage(this, menu, param, value)); SetMenu(menu); }
private void ShowMenuFoldout(VRCExpressionsMenu menu, string title) { if (menu == null) { return; } bool b = expandedMenus.Contains(menu); // Remove before we go any further, prevents infinite recursion on cyclic menus. expandedMenus.Remove(menu); if (!EditorGUILayout.Foldout(b, title, true)) { return; } EditorGUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Space(EditorGUI.indentLevel * 17); int size = GetParameterSize(); if (menu.controls.Count < expressionParams.parameters.Length) { if (GUILayout.Button("Add Marker Here", GUILayout.Width(130))) { updatePaths(); InstallMarker(ref menu); } } else { if (size < VRCExpressionParameters.MAX_PARAMETER_COST) { if (GUILayout.Button("enlarge parameters", GUILayout.Width(130))) { updatePaths(); if (size < VRCExpressionParameters.MAX_PARAMETER_COST) { VRCExpressionParameters.Parameter[] newParams = new VRCExpressionParameters.Parameter[expressionParams.parameters.Length + 1]; for (int i = 0; i < expressionParams.parameters.Length; i++) { newParams[i] = expressionParams.parameters[i]; } newParams[expressionParams.parameters.Length] = new VRCExpressionParameters.Parameter(); expressionParams.parameters = newParams; EditorUtility.SetDirty(expressionParams); } } } else { GUILayout.Label("No room.", GUILayout.Width(130)); } } GUILayout.EndHorizontal(); EditorGUI.indentLevel++; foreach (var child in menu.controls) { if (child.type == ControlType.SubMenu) { ShowMenuFoldout(child.subMenu, child.name); } } EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); // Okay, it's safe to add the menu back. expandedMenus.Add(menu); }
public void Decompose(VRCExpressionsMenu visiting, Transform currentTransform) { _visited.Add(visiting, currentTransform); foreach (var control in visiting.controls) { var hierarchyName = control.name.Trim() != "" ? control.name : control.icon != null ? $"({control.icon.name})" : control.name; var gameObject = NewGameObject(hierarchyName, currentTransform); var m2h = gameObject.AddComponent <ExpressionsMenuHierarchyItem>(); m2h.nameSource = control.name.Trim() == "" && control.icon != null && control.icon.name != "" ? Emh.EmhNameSource.UseCustomName : Emh.EmhNameSource.UseHierarchyObjectName; m2h.customName = m2h.nameSource == Emh.EmhNameSource.UseCustomName ? control.name : ""; m2h.type = TypeOf(control); m2h.icon = control.icon; m2h.parameter = control.parameter.name; m2h.value = control.value; var subParamsLength = DefensiveArrayIfNullable(control.subParameters).Length; m2h.puppetParameter0 = subParamsLength > 0 ? control.subParameters[0]?.name : ""; m2h.puppetParameter1 = subParamsLength > 1 ? control.subParameters[1]?.name : ""; m2h.puppetParameter2 = subParamsLength > 2 ? control.subParameters[2]?.name : ""; m2h.puppetParameter3 = subParamsLength > 3 ? control.subParameters[3]?.name : ""; var labelLength = DefensiveArrayIfNullable(control.labels).Length; m2h.puppetLabelUp.icon = labelLength > 0 ? control.labels[0].icon : null; m2h.puppetLabelUp.name = labelLength > 0 ? control.labels[0].name : ""; m2h.puppetLabelRight.icon = labelLength > 1 ? control.labels[1].icon : null; m2h.puppetLabelRight.name = labelLength > 1 ? control.labels[1].name : ""; m2h.puppetLabelDown.icon = labelLength > 2 ? control.labels[2].icon : null; m2h.puppetLabelDown.name = labelLength > 2 ? control.labels[2].name : ""; m2h.puppetLabelLeft.icon = labelLength > 3 ? control.labels[3].icon : null; m2h.puppetLabelLeft.name = labelLength > 3 ? control.labels[3].name : ""; if (m2h.type == Emh.EmhType.SubMenu) { var subMenuAsset = control.subMenu; m2h.subMenuAsset = subMenuAsset; if (subMenuAsset == null) { m2h.subMenuSource = Emh.EmhSubMenuSource.HierarchyReference; } else { if (_visited.ContainsKey(subMenuAsset)) { m2h.subMenuSource = Emh.EmhSubMenuSource.HierarchyReference; m2h.subMenuHierarchyReference = _visited[subMenuAsset]; } else { m2h.subMenuSource = Emh.EmhSubMenuSource.HierarchyChildren; Decompose(subMenuAsset, gameObject.transform); } } } // m2h.subTitle = ""; // m2h.documentation = ""; } }
public override void ValidateFeatures(VRC_AvatarDescriptor avatar, Animator anim, AvatarPerformanceStats perfStats) { //Create avatar debug hashset VRCAvatarDescriptor avatarSDK3 = avatar as VRCAvatarDescriptor; if (avatarSDK3 != null) { avatarSDK3.animationHashSet.Clear(); foreach (VRCAvatarDescriptor.CustomAnimLayer animLayer in avatarSDK3.baseAnimationLayers) { AnimatorController controller = animLayer.animatorController as AnimatorController; if (controller != null) { foreach (AnimatorControllerLayer layer in controller.layers) { ProcessStateMachine(layer.stateMachine, ""); void ProcessStateMachine(AnimatorStateMachine stateMachine, string prefix) { //Update prefix prefix = prefix + stateMachine.name + "."; //States foreach (var state in stateMachine.states) { VRCAvatarDescriptor.DebugHash hash = new VRCAvatarDescriptor.DebugHash(); string fullName = prefix + state.state.name; hash.hash = Animator.StringToHash(fullName); hash.name = fullName.Remove(0, layer.stateMachine.name.Length + 1); avatarSDK3.animationHashSet.Add(hash); } //Sub State Machines foreach (var subMachine in stateMachine.stateMachines) { ProcessStateMachine(subMachine.stateMachine, prefix); } } } } } } //Validate Playable Layers if (avatarSDK3 != null && avatarSDK3.customizeAnimationLayers) { VRCAvatarDescriptor.CustomAnimLayer gestureLayer = avatarSDK3.baseAnimationLayers[2]; if (anim != null && anim.isHuman && gestureLayer.animatorController != null && gestureLayer.type == VRCAvatarDescriptor.AnimLayerType.Gesture && !gestureLayer.isDefault) { AnimatorController controller = gestureLayer.animatorController as AnimatorController; if (controller != null && controller.layers[0].avatarMask == null) { _builder.OnGUIError(avatar, "Gesture Layer needs valid mask on first animator layer", delegate { OpenAnimatorControllerWindow(controller); }, null); } } } //Expression menu images if (avatarSDK3 != null) { bool ValidateTexture(Texture2D texture) { string path = AssetDatabase.GetAssetPath(texture); TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter; if (importer == null) { return(true); } TextureImporterPlatformSettings settings = importer.GetDefaultPlatformTextureSettings(); //Max texture size if ((texture.width > MAX_ACTION_TEXTURE_SIZE || texture.height > MAX_ACTION_TEXTURE_SIZE) && settings.maxTextureSize > MAX_ACTION_TEXTURE_SIZE) { return(false); } //Compression if (settings.textureCompression == TextureImporterCompression.Uncompressed) { return(false); } //Success return(true); } void FixTexture(Texture2D texture) { string path = AssetDatabase.GetAssetPath(texture); TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter; if (importer == null) { return; } TextureImporterPlatformSettings settings = importer.GetDefaultPlatformTextureSettings(); //Max texture size if (texture.width > MAX_ACTION_TEXTURE_SIZE || texture.height > MAX_ACTION_TEXTURE_SIZE) { settings.maxTextureSize = Math.Min(settings.maxTextureSize, MAX_ACTION_TEXTURE_SIZE); } //Compression if (settings.textureCompression == TextureImporterCompression.Uncompressed) { settings.textureCompression = TextureImporterCompression.Compressed; } //Set & Reimport importer.SetPlatformTextureSettings(settings); AssetDatabase.ImportAsset(path); } //Find all textures List <Texture2D> textures = new List <Texture2D>(); List <VRCExpressionsMenu> menuStack = new List <VRCExpressionsMenu>(); FindTextures(avatarSDK3.expressionsMenu); void FindTextures(VRCExpressionsMenu menu) { if (menu == null || menuStack.Contains(menu)) //Prevent recursive menu searching { return; } menuStack.Add(menu); //Check controls foreach (VRCExpressionsMenu.Control control in menu.controls) { AddTexture(control.icon); if (control.labels != null) { foreach (VRCExpressionsMenu.Control.Label label in control.labels) { AddTexture(label.icon); } } if (control.subMenu != null) { FindTextures(control.subMenu); } } void AddTexture(Texture2D texture) { if (texture != null) { textures.Add(texture); } } } //Validate bool isValid = true; foreach (Texture2D texture in textures) { if (!ValidateTexture(texture)) { isValid = false; } } if (!isValid) { _builder.OnGUIError(avatar, "Images used for Actions & Moods are too large.", delegate { Selection.activeObject = avatar.gameObject; }, FixTextures); } //Fix void FixTextures() { foreach (Texture2D texture in textures) { FixTexture(texture); } } } //Expression menu parameters if (avatarSDK3 != null) { //Check for expression menu/parameters object if (avatarSDK3.expressionsMenu != null || avatarSDK3.expressionParameters != null) { //Menu if (avatarSDK3.expressionsMenu == null) { _builder.OnGUIError(avatar, "VRCExpressionsMenu object reference is missing.", delegate { Selection.activeObject = avatarSDK3; }, null); } //Parameters if (avatarSDK3.expressionParameters == null) { _builder.OnGUIError(avatar, "VRCExpressionParameters object reference is missing.", delegate { Selection.activeObject = avatarSDK3; }, null); } } //Check if parameters is valid if (avatarSDK3.expressionParameters != null && avatarSDK3.expressionParameters.CalcTotalCost() > VRCExpressionParameters.MAX_PARAMETER_COST) { _builder.OnGUIError(avatar, "VRCExpressionParameters has too many parameters defined.", delegate { Selection.activeObject = avatarSDK3.expressionParameters; }, null); } //Find all existing parameters if (avatarSDK3.expressionsMenu != null && avatarSDK3.expressionParameters != null) { List <VRCExpressionsMenu> menuStack = new List <VRCExpressionsMenu>(); List <string> parameters = new List <string>(); List <VRCExpressionsMenu> selects = new List <VRCExpressionsMenu>(); FindParameters(avatarSDK3.expressionsMenu); void FindParameters(VRCExpressionsMenu menu) { if (menu == null || menuStack.Contains(menu)) //Prevent recursive menu searching { return; } menuStack.Add(menu); //Check controls foreach (VRCExpressionsMenu.Control control in menu.controls) { AddParameter(control.parameter); if (control.subParameters != null) { foreach (VRCExpressionsMenu.Control.Parameter subParameter in control.subParameters) { AddParameter(subParameter); } } if (control.subMenu != null) { FindParameters(control.subMenu); } } void AddParameter(VRCExpressionsMenu.Control.Parameter parameter) { if (parameter != null) { parameters.Add(parameter.name); selects.Add(menu); } } } //Validate parameters for (int i = 0; i < parameters.Count; i++) { string parameter = parameters[i]; VRCExpressionsMenu select = selects[i]; //Find bool exists = string.IsNullOrEmpty(parameter) || avatarSDK3.expressionParameters.FindParameter(parameter) != null; if (!exists) { _builder.OnGUIError(avatar, "VRCExpressionsMenu uses a parameter that is not defined.\nParameter: " + parameter, delegate { Selection.activeObject = select; }, null); } } //Validate param choices foreach (var menu in menuStack) { foreach (var control in menu.controls) { bool isValid = true; if (control.type == VRCExpressionsMenu.Control.ControlType.FourAxisPuppet) { isValid &= ValidateNonBoolParam(control.subParameters[0].name); isValid &= ValidateNonBoolParam(control.subParameters[1].name); isValid &= ValidateNonBoolParam(control.subParameters[2].name); isValid &= ValidateNonBoolParam(control.subParameters[3].name); } else if (control.type == VRCExpressionsMenu.Control.ControlType.RadialPuppet) { isValid &= ValidateNonBoolParam(control.subParameters[0].name); } else if (control.type == VRCExpressionsMenu.Control.ControlType.TwoAxisPuppet) { isValid &= ValidateNonBoolParam(control.subParameters[0].name); isValid &= ValidateNonBoolParam(control.subParameters[1].name); } if (!isValid) { _builder.OnGUIError(avatar, "VRCExpressionsMenu uses an invalid parameter for a control.\nControl: " + control.name, delegate { Selection.activeObject = menu; }, null); } } bool ValidateNonBoolParam(string name) { VRCExpressionParameters.Parameter param = string.IsNullOrEmpty(name) ? null : avatarSDK3.expressionParameters.FindParameter(name); if (param != null && param.valueType == VRCExpressionParameters.ValueType.Bool) { return(false); } return(true); } } } } List <Component> componentsToRemove = AvatarValidation.FindIllegalComponents(avatar.gameObject).ToList(); // create a list of the PipelineSaver component(s) List <Component> toRemoveSilently = new List <Component>(); foreach (Component c in componentsToRemove) { if (c.GetType().Name == "PipelineSaver") { toRemoveSilently.Add(c); } } // delete PipelineSaver(s) from the list of the Components we will destroy now foreach (Component c in toRemoveSilently) { componentsToRemove.Remove(c); } HashSet <string> componentsToRemoveNames = new HashSet <string>(); List <Component> toRemove = componentsToRemove as List <Component> ?? componentsToRemove; foreach (Component c in toRemove) { if (componentsToRemoveNames.Contains(c.GetType().Name) == false) { componentsToRemoveNames.Add(c.GetType().Name); } } if (componentsToRemoveNames.Count > 0) { _builder.OnGUIError(avatar, "The following component types are found on the Avatar and will be removed by the client: " + string.Join(", ", componentsToRemoveNames.ToArray()), delegate { ShowRestrictedComponents(toRemove); }, delegate { FixRestrictedComponents(toRemove); }); } List <AudioSource> audioSources = avatar.gameObject.GetComponentsInChildren <AudioSource>(true).ToList(); if (audioSources.Count > 0) { _builder.OnGUIWarning(avatar, "Audio sources found on Avatar, they will be adjusted to safe limits, if necessary.", GetAvatarSubSelectAction(avatar, typeof(AudioSource)), null); } List <VRCStation> stations = avatar.gameObject.GetComponentsInChildren <VRCStation>(true).ToList(); if (stations.Count > 0) { _builder.OnGUIWarning(avatar, "Stations found on Avatar, they will be adjusted to safe limits, if necessary.", GetAvatarSubSelectAction(avatar, typeof(VRCStation)), null); } if (VRCSdkControlPanel.HasSubstances(avatar.gameObject)) { _builder.OnGUIWarning(avatar, "This avatar has one or more Substance materials, which is not supported and may break in-game. Please bake your Substances to regular materials.", () => { Selection.objects = VRCSdkControlPanel.GetSubstanceObjects(avatar.gameObject); }, null); } CheckAvatarMeshesForLegacyBlendShapesSetting(avatar); CheckAvatarMeshesForMeshReadWriteSetting(avatar); #if UNITY_ANDROID IEnumerable <Shader> illegalShaders = AvatarValidation.FindIllegalShaders(avatar.gameObject); foreach (Shader s in illegalShaders) { _builder.OnGUIError(avatar, "Avatar uses unsupported shader '" + s.name + "'. You can only use the shaders provided in 'VRChat/Mobile' for Quest avatars.", delegate() { Selection.activeObject = avatar.gameObject; }, null); } #endif foreach (AvatarPerformanceCategory perfCategory in Enum.GetValues(typeof(AvatarPerformanceCategory))) { if (perfCategory == AvatarPerformanceCategory.Overall || perfCategory == AvatarPerformanceCategory.PolyCount || perfCategory == AvatarPerformanceCategory.AABB || perfCategory == AvatarPerformanceCategory.AvatarPerformanceCategoryCount) { continue; } Action show = null; switch (perfCategory) { case AvatarPerformanceCategory.AnimatorCount: show = GetAvatarSubSelectAction(avatar, typeof(Animator)); break; case AvatarPerformanceCategory.AudioSourceCount: show = GetAvatarSubSelectAction(avatar, typeof(AudioSource)); break; case AvatarPerformanceCategory.BoneCount: show = GetAvatarSubSelectAction(avatar, typeof(SkinnedMeshRenderer)); break; case AvatarPerformanceCategory.ClothCount: show = GetAvatarSubSelectAction(avatar, typeof(Cloth)); break; case AvatarPerformanceCategory.ClothMaxVertices: show = GetAvatarSubSelectAction(avatar, typeof(Cloth)); break; case AvatarPerformanceCategory.LightCount: show = GetAvatarSubSelectAction(avatar, typeof(Light)); break; case AvatarPerformanceCategory.LineRendererCount: show = GetAvatarSubSelectAction(avatar, typeof(LineRenderer)); break; case AvatarPerformanceCategory.MaterialCount: show = GetAvatarSubSelectAction(avatar, new[] { typeof(MeshRenderer), typeof(SkinnedMeshRenderer) }); break; case AvatarPerformanceCategory.MeshCount: show = GetAvatarSubSelectAction(avatar, new[] { typeof(MeshRenderer), typeof(SkinnedMeshRenderer) }); break; case AvatarPerformanceCategory.ParticleCollisionEnabled: show = GetAvatarSubSelectAction(avatar, typeof(ParticleSystem)); break; case AvatarPerformanceCategory.ParticleMaxMeshPolyCount: show = GetAvatarSubSelectAction(avatar, typeof(ParticleSystem)); break; case AvatarPerformanceCategory.ParticleSystemCount: show = GetAvatarSubSelectAction(avatar, typeof(ParticleSystem)); break; case AvatarPerformanceCategory.ParticleTotalCount: show = GetAvatarSubSelectAction(avatar, typeof(ParticleSystem)); break; case AvatarPerformanceCategory.ParticleTrailsEnabled: show = GetAvatarSubSelectAction(avatar, typeof(ParticleSystem)); break; case AvatarPerformanceCategory.PhysicsColliderCount: show = GetAvatarSubSelectAction(avatar, typeof(Collider)); break; case AvatarPerformanceCategory.PhysicsRigidbodyCount: show = GetAvatarSubSelectAction(avatar, typeof(Rigidbody)); break; case AvatarPerformanceCategory.PolyCount: show = GetAvatarSubSelectAction(avatar, new[] { typeof(MeshRenderer), typeof(SkinnedMeshRenderer) }); break; case AvatarPerformanceCategory.SkinnedMeshCount: show = GetAvatarSubSelectAction(avatar, typeof(SkinnedMeshRenderer)); break; case AvatarPerformanceCategory.TrailRendererCount: show = GetAvatarSubSelectAction(avatar, typeof(TrailRenderer)); break; } // we can only show these buttons if DynamicBone is installed Type dynamicBoneType = typeof(AvatarValidation).Assembly.GetType("DynamicBone"); Type dynamicBoneColliderType = typeof(AvatarValidation).Assembly.GetType("DynamicBoneCollider"); if ((dynamicBoneType != null) && (dynamicBoneColliderType != null)) { switch (perfCategory) { case AvatarPerformanceCategory.DynamicBoneColliderCount: show = GetAvatarSubSelectAction(avatar, dynamicBoneColliderType); break; case AvatarPerformanceCategory.DynamicBoneCollisionCheckCount: show = GetAvatarSubSelectAction(avatar, dynamicBoneColliderType); break; case AvatarPerformanceCategory.DynamicBoneComponentCount: show = GetAvatarSubSelectAction(avatar, dynamicBoneType); break; case AvatarPerformanceCategory.DynamicBoneSimulatedBoneCount: show = GetAvatarSubSelectAction(avatar, dynamicBoneType); break; } } OnGUIPerformanceInfo(avatar, perfStats, perfCategory, show, null); } _builder.OnGUILink(avatar, "Avatar Optimization Tips", VRCSdkControlPanel.AVATAR_OPTIMIZATION_TIPS_URL); }
public static void SetExpressionsMenu(this VRCAvatarDescriptor avatarDescriptor, VRCExpressionsMenu menu) { var avatarDesctiptorSerializedObject = new SerializedObject(avatarDescriptor); avatarDesctiptorSerializedObject.Update(); avatarDescriptor.expressionsMenu = menu; avatarDescriptor.customExpressions = avatarDescriptor.expressionParameters != null || avatarDescriptor.expressionsMenu != null; avatarDesctiptorSerializedObject.ApplyModifiedProperties(); }