// Check for possible warnings with the biped references setup private void CheckWarning(BipedReferences references, IKSolverFullBodyBiped solver, Transform context, bool log) { // Check for all the warnings common to all bipeds BipedReferences.CheckSetupWarning(script.references, log); // Check for warnings specific to FBBIK Vector3 toRightShoulder = references.rightUpperArm.position - references.leftUpperArm.position; Vector3 shoulderToRootNode = solver.rootNode.position - references.leftUpperArm.position; float dot = Vector3.Dot(toRightShoulder.normalized, shoulderToRootNode.normalized); if (dot > 0.95f) { if (log) { Warning.Log("The root node, the left upper arm and the right upper arm bones should ideally form a triangle that is as close to equilateral as possible. " + "Currently the root node bone seems to be very close to the line between the left upper arm and the right upper arm bones. This might cause unwanted behaviour like the spine turning upside down when pulled by a hand effector." + "Please set the root node bone to be one of the lower bones in the spine.", context, true); } } Vector3 toRightThigh = references.rightThigh.position - references.leftThigh.position; Vector3 thighToRootNode = solver.rootNode.position - references.leftThigh.position; dot = Vector3.Dot(toRightThigh.normalized, thighToRootNode.normalized); if (dot > 0.95f && log) { Warning.Log("The root node, the left thigh and the right thigh bones should ideally form a triangle that is as close to equilateral as possible. " + "Currently the root node bone seems to be very close to the line between the left thigh and the right thigh bones. This might cause unwanted behaviour like the hip turning upside down when pulled by an effector." + "Please set the root node bone to be one of the higher bones in the spine.", context, true); } }
public void OnEnable() { if (serializedObject == null) { return; } // Store the MonoScript for changing script execution order if (!Application.isPlaying) { MonoScript monoScript = MonoScript.FromMonoBehaviour(script); // Changing the script execution order to make sure BipedIK always executes after any other script except FullBodyBipedIK int executionOrder = MonoImporter.GetExecutionOrder(monoScript); if (executionOrder != 9998) { MonoImporter.SetExecutionOrder(monoScript, 9998); } } references = serializedObject.FindProperty("references"); solvers = serializedObject.FindProperty("solvers"); solversProps = BipedIKSolversInspector.FindProperties(solvers); fixTransforms = new SerializedContent(serializedObject.FindProperty("fixTransforms"), new GUIContent("Fix Transforms", "If true, will fix all the Transforms used by the solver to their initial state in each Update. This prevents potential problems with unanimated bones and animator culling with a small cost of performance.")); // Automatically detecting references if (!Application.isPlaying) { if (script.references.isEmpty) { BipedReferences.AutoDetectReferences(ref script.references, script.transform, new BipedReferences.AutoDetectParams(false, true)); references.isExpanded = true; solvers.isExpanded = false; for (int i = 0; i < solversProps.Length; i++) { solversProps[i].isExpanded = false; } // Setting default values and initiating script.InitiateBipedIK(); script.SetToDefaults(); EditorUtility.SetDirty(script); } else { script.InitiateBipedIK(); } Warning.logged = false; if (Application.isPlaying) { if (ReferencesValid(true)) { BipedReferences.CheckSetupWarning(script.references, true); } } } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.Space(); Inspector.AddContent(fixTransforms); // Editing References if (BipedReferencesInspector.AddModifiedInspector(references)) { if (!Application.isPlaying) { Warning.logged = false; BipedReferences.CheckSetupError(script.references); BipedReferences.CheckSetupWarning(script.references); script.InitiateBipedIK(); } } // Editing Solvers BipedIKSolversInspector.AddInspector(solvers, solversProps, solverContents); EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }
private void WarningBox() { // Warning box EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal("Box"); EditorGUILayout.LabelField("Invalid/incomplete setup, can't initiate solver."); if (GUILayout.Button("What's wrong?")) { Warning.logged = false; if (ReferencesValid(true)) { BipedReferences.CheckSetupWarning(script.references, true); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.Space(); Inspector.AddContent(fixTransforms); // Editing References if (BipedReferencesInspector.AddModifiedInspector(references)) { if (!Application.isPlaying) { Warning.logged = false; if (ReferencesValid(false)) { BipedReferences.CheckSetupWarning(script.references, true); // Initiate only when inspector changed script.InitiateBipedIK(); } } } if (ReferencesValid(Application.isPlaying)) { // Editing Solvers BipedIKSolversInspector.AddInspector(solvers, solversProps); } else { // Warning box WarningBox(); } EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); }