private void AddComputeMenuItems(GenericMenu menu, string menuItemPrefix, BlendTreeInspector.ChildPropertyToCompute prop) { menu.AddItem(new GUIContent(menuItemPrefix + "Speed"), false, new GenericMenu.MenuFunction2(this.ComputeFromSpeed), (object) prop); menu.AddItem(new GUIContent(menuItemPrefix + "Velocity X"), false, new GenericMenu.MenuFunction2(this.ComputeFromVelocityX), (object) prop); menu.AddItem(new GUIContent(menuItemPrefix + "Velocity Y"), false, new GenericMenu.MenuFunction2(this.ComputeFromVelocityY), (object) prop); menu.AddItem(new GUIContent(menuItemPrefix + "Velocity Z"), false, new GenericMenu.MenuFunction2(this.ComputeFromVelocityZ), (object) prop); menu.AddItem(new GUIContent(menuItemPrefix + "Angular Speed (Rad)"), false, new GenericMenu.MenuFunction2(this.ComputeFromAngularSpeedRadians), (object) prop); menu.AddItem(new GUIContent(menuItemPrefix + "Angular Speed (Deg)"), false, new GenericMenu.MenuFunction2(this.ComputeFromAngularSpeedDegrees), (object) prop); }
private void ComputeProperty(BlendTreeInspector.GetFloatFromMotion func, BlendTreeInspector.ChildPropertyToCompute prop) { float num1 = 0.0f; float[] numArray = new float[this.m_Childs.arraySize]; this.m_UseAutomaticThresholds.boolValue = false; for (int index = 0; index < this.m_Childs.arraySize; ++index) { SerializedProperty propertyRelative1 = this.m_Childs.GetArrayElementAtIndex(index).FindPropertyRelative("m_Motion"); SerializedProperty propertyRelative2 = this.m_Childs.GetArrayElementAtIndex(index).FindPropertyRelative("m_Mirror"); Motion objectReferenceValue = propertyRelative1.objectReferenceValue as Motion; if ((UnityEngine.Object) objectReferenceValue != (UnityEngine.Object) null) { float num2 = func(objectReferenceValue, !propertyRelative2.boolValue ? 1f : -1f); numArray[index] = num2; num1 += num2; if (prop == BlendTreeInspector.ChildPropertyToCompute.Threshold) { this.m_Childs.GetArrayElementAtIndex(index).FindPropertyRelative("m_Threshold").floatValue = num2; } else { SerializedProperty propertyRelative3 = this.m_Childs.GetArrayElementAtIndex(index).FindPropertyRelative("m_Position"); Vector2 vector2Value = propertyRelative3.vector2Value; if (prop == BlendTreeInspector.ChildPropertyToCompute.PositionX) vector2Value.x = num2; else vector2Value.y = num2; propertyRelative3.vector2Value = vector2Value; } } } float num3 = num1 / (float) this.m_Childs.arraySize; float num4 = 0.0f; for (int index = 0; index < numArray.Length; ++index) num4 += Mathf.Pow(numArray[index] - num3, 2f); if ((double) (num4 / (float) numArray.Length) < (double) Mathf.Epsilon) { UnityEngine.Debug.LogWarning((object) ("Could not compute threshold for '" + this.m_BlendTree.name + "' there is not enough data")); this.m_SerializedObject.Update(); } else { this.m_SerializedObject.ApplyModifiedProperties(); if (prop != BlendTreeInspector.ChildPropertyToCompute.Threshold) return; this.SortByThreshold(); this.SetMinMaxThreshold(); } }
private void ComputeProperty(BlendTreeInspector.GetFloatFromMotion func, BlendTreeInspector.ChildPropertyToCompute prop) { float num = 0f; float[] array = new float[this.m_Childs.arraySize]; this.m_UseAutomaticThresholds.boolValue = false; for (int i = 0; i < this.m_Childs.arraySize; i++) { SerializedProperty serializedProperty = this.m_Childs.GetArrayElementAtIndex(i).FindPropertyRelative("m_Motion"); SerializedProperty serializedProperty2 = this.m_Childs.GetArrayElementAtIndex(i).FindPropertyRelative("m_Mirror"); Motion motion = serializedProperty.objectReferenceValue as Motion; if (motion != null) { float num2 = func(motion, (float)((!serializedProperty2.boolValue) ? 1 : -1)); array[i] = num2; num += num2; if (prop == BlendTreeInspector.ChildPropertyToCompute.Threshold) { SerializedProperty serializedProperty3 = this.m_Childs.GetArrayElementAtIndex(i).FindPropertyRelative("m_Threshold"); serializedProperty3.floatValue = num2; } else { SerializedProperty serializedProperty4 = this.m_Childs.GetArrayElementAtIndex(i).FindPropertyRelative("m_Position"); Vector2 vector2Value = serializedProperty4.vector2Value; if (prop == BlendTreeInspector.ChildPropertyToCompute.PositionX) { vector2Value.x = num2; } else { vector2Value.y = num2; } serializedProperty4.vector2Value = vector2Value; } } } num /= (float)this.m_Childs.arraySize; float num3 = 0f; for (int j = 0; j < array.Length; j++) { num3 += Mathf.Pow(array[j] - num, 2f); } num3 /= (float)array.Length; if (num3 < Mathf.Epsilon) { UnityEngine.Debug.LogWarning("Could not compute threshold for '" + this.m_BlendTree.name + "' there is not enough data"); this.m_SerializedObject.Update(); } else { this.m_SerializedObject.ApplyModifiedProperties(); if (prop == BlendTreeInspector.ChildPropertyToCompute.Threshold) { this.SortByThreshold(); this.SetMinMaxThreshold(); } } }