void ModeAndThresholdPopUp(ref AnimatorConditionMode mode, ref float threshold, AnimatorControllerParameterType parameterType) { string[] displayedOptions = null; int[] optionValues = null; switch (parameterType) { case AnimatorControllerParameterType.Bool: displayedOptions = new string[] { "true", "false" }; optionValues = new int[] { (int)AnimatorConditionMode.If, (int)AnimatorConditionMode.IfNot }; bool boolMode = EditorGUILayout.Toggle(mode == AnimatorConditionMode.If? true : false, GUILayout.MaxWidth(10f)); mode = boolMode ? AnimatorConditionMode.If : AnimatorConditionMode.IfNot; break; case AnimatorControllerParameterType.Int: displayedOptions = new string[] { "<", "==", ">", "!=" }; optionValues = new int[] { (int)AnimatorConditionMode.Less, (int)AnimatorConditionMode.Equals, (int)AnimatorConditionMode.Greater, (int)AnimatorConditionMode.NotEqual }; int intMode = EditorGUILayout.IntPopup((int)mode, displayedOptions, optionValues); int intThreshold = EditorGUILayout.IntField((int)threshold); mode = (AnimatorConditionMode)intMode; threshold = (int)intThreshold; break; case AnimatorControllerParameterType.Float: displayedOptions = new string[] { "<", ">" }; optionValues = new int[] { (int)AnimatorConditionMode.Less, (int)AnimatorConditionMode.Greater }; int floatMode = EditorGUILayout.IntPopup((int)mode, displayedOptions, optionValues); mode = (AnimatorConditionMode)floatMode; threshold = EditorGUILayout.FloatField(threshold); break; case AnimatorControllerParameterType.Trigger: break; } }
public void AddTransition(EditorAnimationItem Anim, AnimatorConditionMode mode, float v, string parameter, bool hasExitTime = true) { AnimatorStateTransition st = state.AddTransition(Anim.state); st.AddCondition(mode, v, parameter); st.hasExitTime = hasExitTime; }
public ConditionDefinition(IAnimationDefinition parent, AnimatorConditionMode mode, float threshold, string name = null) { Mode = mode; Threshold = threshold; Name = name ?? parent.Name; Parent = parent; AddParameter(false, Name); }
public void AddCondition(AnimatorConditionMode mode, float threshold, string parameter) { this.undoHandler.DoUndo(this, "Condition added"); AnimatorCondition[] conditions = this.conditions; ArrayUtility.Add <AnimatorCondition>(ref conditions, new AnimatorCondition { mode = mode, parameter = parameter, threshold = threshold }); this.conditions = conditions; }
public void AddCondition(AnimatorConditionMode mode, float threshold, string parameter) { this.undoHandler.DoUndo(this, "Condition added"); AnimatorCondition[] conditions = this.conditions; ArrayUtility.Add<AnimatorCondition>(ref conditions, new AnimatorCondition { mode = mode, parameter = parameter, threshold = threshold }); this.conditions = conditions; }
public void AddCondition(AnimatorConditionMode mode, float threshold, string parameter) { undoHandler.DoUndo(this, "Condition added"); AnimatorCondition[] conditionVector = conditions; AnimatorCondition newCondition = new AnimatorCondition(); newCondition.mode = mode; newCondition.parameter = parameter; newCondition.threshold = threshold; ArrayUtility.Add(ref conditionVector, newCondition); conditions = conditionVector; }
private void AddConditionInList(ReorderableList list) { AnimatorTransitionBase targetObject = this.m_SerializedTransition.targetObject as AnimatorTransitionBase; string parameter = ""; AnimatorConditionMode greater = AnimatorConditionMode.Greater; if (this.m_Controller != null) { UnityEngine.AnimatorControllerParameter[] parameters = this.m_Controller.parameters; if (parameters.Length > 0) { parameter = parameters[0].name; greater = ((parameters[0].type != UnityEngine.AnimatorControllerParameterType.Float) && (parameters[0].type != UnityEngine.AnimatorControllerParameterType.Int)) ? AnimatorConditionMode.If : AnimatorConditionMode.Greater; } } targetObject.AddCondition(greater, 0f, parameter); }
private void AddConditionInList(ReorderableList list) { AnimatorTransitionBase animatorTransitionBase = this.m_SerializedTransition.targetObject as AnimatorTransitionBase; string parameter = string.Empty; AnimatorConditionMode mode = AnimatorConditionMode.Greater; if (this.m_Controller) { UnityEngine.AnimatorControllerParameter[] parameters = this.m_Controller.parameters; if (parameters.Length > 0) { parameter = parameters[0].name; mode = ((parameters[0].type != UnityEngine.AnimatorControllerParameterType.Float && parameters[0].type != UnityEngine.AnimatorControllerParameterType.Int) ? AnimatorConditionMode.If : AnimatorConditionMode.Greater); } } animatorTransitionBase.AddCondition(mode, 0f, parameter); }
public void parseXml(XmlElement elem) { m_name = ExportUtil.getXmlAttrStr(elem.Attributes["name"]); m_value = ExportUtil.getXmlAttrStr(elem.Attributes["value"]); string _opMode = ExportUtil.getXmlAttrStr(elem.Attributes["OpMode"]); if (XmlCondition.GREATER == _opMode) { m_opMode = AnimatorConditionMode.Greater; } else if (XmlCondition.LESS == _opMode) { m_opMode = AnimatorConditionMode.Less; } else if (XmlCondition.EQUALS == _opMode) { m_opMode = AnimatorConditionMode.Equals; } else if (XmlCondition.NOTEQUAL == _opMode) { m_opMode = AnimatorConditionMode.NotEqual; } }
public static AnimatorStateTransition AddAnyTransitionDefaultParam(this AnimatorStateMachine stateMachine, AnimatorState destinationState, AnimatorConditionMode mode, float threshold, string parameter) { var transition = stateMachine.AddAnyStateTransition(destinationState); SetDefaultTransitionParam(transition); transition.AddCondition(mode, threshold, parameter); return(transition); }
private void DrawConditionsElement(Rect rect, int index, bool selected, bool focused) { SerializedProperty arrayElementAtIndex = this.m_Conditions.GetArrayElementAtIndex(index); AnimatorConditionMode intValue = (AnimatorConditionMode)arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue; int num = 3; Rect rect2 = new Rect(rect.x, rect.y + 2f, rect.width, rect.height - 5f); Rect position = rect2; position.xMax -= (rect2.width / 2f) + num; Rect rect4 = rect2; rect4.xMin += (rect2.width / 2f) + num; Rect rect5 = rect4; rect5.xMax -= (rect4.width / 2f) + num; Rect rect6 = rect4; rect6.xMin += (rect4.width / 2f) + num; string stringValue = arrayElementAtIndex.FindPropertyRelative("m_ConditionEvent").stringValue; int num2 = (this.m_Controller == null) ? -1 : this.m_Controller.IndexOfParameter(stringValue); bool flag = false; List <string> list = new List <string>(); UnityEngine.AnimatorControllerParameter[] parameters = null; if (this.m_Controller != null) { parameters = this.m_Controller.parameters; for (int i = 0; i < parameters.Length; i++) { list.Add(parameters[i].name); } } string name = EditorGUI.DelayedTextFieldDropDown(position, stringValue, list.ToArray()); if (stringValue != name) { num2 = this.m_Controller.IndexOfParameter(name); arrayElementAtIndex.FindPropertyRelative("m_ConditionEvent").stringValue = name; intValue = AnimatorConditionMode.Greater; arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue = (int)intValue; flag = true; } UnityEngine.AnimatorControllerParameterType type = (num2 == -1) ? ((UnityEngine.AnimatorControllerParameterType)(-1)) : parameters[num2].type; if ((num2 != -1) && ((type == UnityEngine.AnimatorControllerParameterType.Float) || (type == UnityEngine.AnimatorControllerParameterType.Int))) { List <AnimatorConditionMode> list2 = (type != UnityEngine.AnimatorControllerParameterType.Float) ? m_intModes : m_floatModes; string[] displayedOptions = new string[list2.Count]; for (int j = 0; j < displayedOptions.Length; j++) { displayedOptions[j] = list2[j].ToString(); } int selectedIndex = -1; for (int k = 0; k < displayedOptions.Length; k++) { if (intValue.ToString() == displayedOptions[k]) { selectedIndex = k; } } if (selectedIndex == -1) { Vector2 vector = GUI.skin.label.CalcSize(s_Styles.errorIcon); Rect rect7 = rect5; rect7.xMax = rect7.xMin + vector.x; rect5.xMin += vector.x; GUI.Label(rect7, s_Styles.errorIcon); } EditorGUI.BeginChangeCheck(); selectedIndex = EditorGUI.Popup(rect5, selectedIndex, displayedOptions); if (EditorGUI.EndChangeCheck() || flag) { arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue = list2[selectedIndex]; } EditorGUI.BeginChangeCheck(); float floatValue = arrayElementAtIndex.FindPropertyRelative("m_EventTreshold").floatValue; if (type == UnityEngine.AnimatorControllerParameterType.Float) { floatValue = EditorGUI.FloatField(rect6, floatValue); } else { floatValue = EditorGUI.IntField(rect6, Mathf.FloorToInt(floatValue)); } if (EditorGUI.EndChangeCheck() || flag) { arrayElementAtIndex.FindPropertyRelative("m_EventTreshold").floatValue = floatValue; } } else if ((num2 != -1) && (type == UnityEngine.AnimatorControllerParameterType.Bool)) { string[] strArray2 = new string[] { "true", "false" }; int num8 = (intValue != AnimatorConditionMode.IfNot) ? 0 : 1; EditorGUI.BeginChangeCheck(); num8 = EditorGUI.Popup(rect4, num8, strArray2); if (EditorGUI.EndChangeCheck() || flag) { arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue = (num8 != 0) ? 2 : 1; } } else if (type == UnityEngine.AnimatorControllerParameterType.Trigger) { if (flag) { arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue = 1; } } else { EditorGUI.LabelField(rect4, "Parameter does not exist in Controller"); } }
private void DrawConditionsElement(Rect rect, int index, bool selected, bool focused) { SerializedProperty arrayElementAtIndex = this.m_Conditions.GetArrayElementAtIndex(index); AnimatorConditionMode animatorConditionMode = (AnimatorConditionMode)arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue; int num = 3; Rect rect2 = new Rect(rect.x, rect.y + 2f, rect.width, rect.height - 5f); Rect position = rect2; position.xMax -= rect2.width / 2f + (float)num; Rect rect3 = rect2; rect3.xMin += rect2.width / 2f + (float)num; Rect rect4 = rect3; rect4.xMax -= rect3.width / 2f + (float)num; Rect position2 = rect3; position2.xMin += rect3.width / 2f + (float)num; string stringValue = arrayElementAtIndex.FindPropertyRelative("m_ConditionEvent").stringValue; int num2 = (!this.m_Controller) ? -1 : this.m_Controller.IndexOfParameter(stringValue); bool flag = false; List <string> list = new List <string>(); UnityEngine.AnimatorControllerParameter[] array = null; if (this.m_Controller) { array = this.m_Controller.parameters; for (int i = 0; i < array.Length; i++) { list.Add(array[i].name); } } string text = EditorGUI.DelayedTextFieldDropDown(position, stringValue, list.ToArray()); if (stringValue != text) { num2 = this.m_Controller.IndexOfParameter(text); arrayElementAtIndex.FindPropertyRelative("m_ConditionEvent").stringValue = text; animatorConditionMode = AnimatorConditionMode.Greater; arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue = (int)animatorConditionMode; flag = true; } UnityEngine.AnimatorControllerParameterType animatorControllerParameterType = (num2 == -1) ? ((UnityEngine.AnimatorControllerParameterType)(-1)) : array[num2].type; if (num2 != -1 && (animatorControllerParameterType == UnityEngine.AnimatorControllerParameterType.Float || animatorControllerParameterType == UnityEngine.AnimatorControllerParameterType.Int)) { List <AnimatorConditionMode> list2 = (animatorControllerParameterType != UnityEngine.AnimatorControllerParameterType.Float) ? AnimatorTransitionInspectorBase.m_intModes : AnimatorTransitionInspectorBase.m_floatModes; string[] array2 = new string[list2.Count]; for (int j = 0; j < array2.Length; j++) { array2[j] = list2[j].ToString(); } int num3 = -1; for (int k = 0; k < array2.Length; k++) { if (animatorConditionMode.ToString() == array2[k]) { num3 = k; } } if (num3 == -1) { Vector2 vector = GUI.skin.label.CalcSize(AnimatorTransitionInspectorBase.s_Styles.errorIcon); Rect position3 = rect4; position3.xMax = position3.xMin + vector.x; rect4.xMin += vector.x; GUI.Label(position3, AnimatorTransitionInspectorBase.s_Styles.errorIcon); } EditorGUI.BeginChangeCheck(); num3 = EditorGUI.Popup(rect4, num3, array2); if (EditorGUI.EndChangeCheck() || flag) { arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue = (int)list2[num3]; } EditorGUI.BeginChangeCheck(); float num4 = arrayElementAtIndex.FindPropertyRelative("m_EventTreshold").floatValue; if (animatorControllerParameterType == UnityEngine.AnimatorControllerParameterType.Float) { num4 = EditorGUI.FloatField(position2, num4); } else { num4 = (float)EditorGUI.IntField(position2, Mathf.FloorToInt(num4)); } if (EditorGUI.EndChangeCheck() || flag) { arrayElementAtIndex.FindPropertyRelative("m_EventTreshold").floatValue = num4; } } else if (num2 != -1 && animatorControllerParameterType == UnityEngine.AnimatorControllerParameterType.Bool) { string[] displayedOptions = new string[] { "true", "false" }; int num5 = (animatorConditionMode != AnimatorConditionMode.IfNot) ? 0 : 1; EditorGUI.BeginChangeCheck(); num5 = EditorGUI.Popup(rect3, num5, displayedOptions); if (EditorGUI.EndChangeCheck() || flag) { arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue = ((num5 != 0) ? 2 : 1); } } else if (animatorControllerParameterType == UnityEngine.AnimatorControllerParameterType.Trigger) { if (flag) { arrayElementAtIndex.FindPropertyRelative("m_ConditionMode").intValue = 1; } } else { EditorGUI.LabelField(rect3, "Parameter does not exist in Controller"); } }
private bool DrawAnimatorCondition(ref AnimatorCondition condition, out bool remove) { bool modified = false; remove = false; EditorGUILayout.BeginHorizontal(); { if (!nameToParameter.ContainsKey(condition.parameter)) { string name = EditorGUILayout.TextField(condition.parameter); if (name != condition.parameter) { condition.parameter = name; modified = true; } AnimatorConditionMode mode = (AnimatorConditionMode)EditorGUILayout.EnumPopup(condition.mode); if (mode != condition.mode) { condition.mode = mode; modified = true; } string result = EditorGUILayout.TextField("" + condition.threshold); float resultValue; if (float.TryParse(result, out resultValue) && resultValue != condition.threshold) { condition.threshold = resultValue; modified = true; } } else { int parameterIndex = nameToParameterIndex[condition.parameter]; int index = EditorGUILayout.Popup(parameterIndex, parameterNames); AnimatorControllerParameter parameter = parameters[index]; if (index != parameterIndex) { condition.parameter = parameter.name; modified = true; } if (parameter.type == AnimatorControllerParameterType.Bool) { int selectedCondition = Math.Max(0, System.Array.IndexOf(boolConditions, condition.mode)); int conditionIdx = EditorGUILayout.Popup(selectedCondition, boolConditionNames); if (conditionIdx != selectedCondition) { condition.mode = boolConditions[conditionIdx]; modified = true; } } else if (parameter.type != AnimatorControllerParameterType.Trigger) { int selectedCondition = System.Array.IndexOf(conditionModes, condition.mode); int conditionIdx = EditorGUILayout.Popup(selectedCondition, conditionModeNames); if (conditionIdx != selectedCondition) { condition.mode = conditionModes[conditionIdx]; modified = true; } AnimationStateSet set = null; if (parameter.name.EndsWith("ItemID")) { set = stateCollection.ItemIds; } else if (parameter.name.EndsWith("StateIndex")) { set = stateCollection.ItemStateIndexes; } else if (parameter.name.EndsWith("AbilityIndex")) { set = stateCollection.AbilityIndexes; } else { string result = EditorGUILayout.TextField("" + condition.threshold); float resultValue; if (float.TryParse(result, out resultValue) && resultValue != condition.threshold) { condition.threshold = resultValue; modified = true; } } if (null != set) { int id = set.DrawStateSet((int)condition.threshold); if (id != condition.threshold) { condition.threshold = id; modified = true; } } } } if (GUILayout.Button(InspectorStyles.DeleteIcon, InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(16), GUILayout.Height(16))) { remove = true; modified = true; } } EditorGUILayout.EndHorizontal(); return(modified); }
// [SerializeField] public float threshold; public ConditionJson(AnimatorCondition animatorCondition, Urho3DEngine engine, PrefabContext prefabContext) { this.mode = animatorCondition.mode; this.parameter = animatorCondition.parameter; // this.threshold = animatorCondition.threshold; }
public void parseXml(XmlElement elem) { m_name = ExportUtil.getXmlAttrStr(elem.Attributes["name"]); m_value = ExportUtil.getXmlAttrStr(elem.Attributes["value"]); string _opMode = ExportUtil.getXmlAttrStr(elem.Attributes["OpMode"]); if (XmlCondition.GREATER == _opMode) { m_opMode = AnimatorConditionMode.Greater; } else if (XmlCondition.LESS == _opMode) { m_opMode = AnimatorConditionMode.Less; } else if (XmlCondition.EQUALS == _opMode) { m_opMode = AnimatorConditionMode.Equals; } else if (XmlCondition.NOTEQUAL == _opMode) { m_opMode = AnimatorConditionMode.NotEqual; } }
public static bool HasCondition(this AnimatorStateTransition obj, string parameter, AnimatorConditionMode mode, float threshold) { var condition = new AnimatorCondition { parameter = parameter, mode = mode, threshold = threshold }; return(obj.HasCondition(condition)); }
protected void RemoveAllAndAddCondition(AnimatorTransitionBase transition, string paramName, AnimatorConditionMode mode, float threshold) { foreach (AnimatorCondition condition in transition.conditions) { if (condition.parameter == paramName) { transition.RemoveCondition(condition); } } transition.AddCondition(mode, threshold, paramName); }
public void CopyData(ref UnityEditor.Animations.AnimatorCondition pSource) { mode = (AnimatorConditionMode)pSource.mode; parameter = pSource.parameter; threshold = pSource.threshold; }
/// <summary> /// 显示过渡条件 /// </summary> /// <param name="state">State.</param> /// <param name="transitions">Transitions.</param> public void ShowTransitionConditionGUI(AnimatorState state, AnimatorStateTransition[] transitions) { GUILayout.BeginVertical(); { for (int i = 0; i < transitions.Length; i++) { AnimatorStateTransition transition = transitions[i]; GUILayout.BeginHorizontal(); { GUILayout.Space(50f); GUILayout.Label(state.name + "-> " + transition.destinationState.name); AnimatorCondition[] conditions = transition.conditions; for (int j = 0; j < conditions.Length; j++) { AnimatorCondition condition = conditions[j];//结构体值拷贝 int selectedParameterIndex = listStrParameter.FindIndex(str => str == condition.parameter); AnimatorControllerParameter parameter = listParameter[selectedParameterIndex]; //显示 int newSelectedParameterIndex = EditorGUILayout.Popup(selectedParameterIndex, listStrParameter.ToArray()); AnimatorConditionMode mode = condition.mode; float threshold = condition.threshold; ModeAndThresholdPopUp(ref mode, ref threshold, parameter.type); if (j < conditions.Length - 1) { GUILayout.Label("&&"); } GUILayout.FlexibleSpace();//使左对齐 //保存 if (newSelectedParameterIndex != selectedParameterIndex) { condition.parameter = listStrParameter[newSelectedParameterIndex]; AnimatorControllerParameter selectedParameter = listParameter[newSelectedParameterIndex]; switch (selectedParameter.type) { case AnimatorControllerParameterType.Bool: condition.mode = AnimatorConditionMode.If; condition.threshold = 0f; break; case AnimatorControllerParameterType.Int: condition.mode = AnimatorConditionMode.Equals; condition.threshold = (float)selectedParameter.defaultInt; break; case AnimatorControllerParameterType.Float: condition.mode = AnimatorConditionMode.Greater; condition.threshold = selectedParameter.defaultFloat; break; case AnimatorControllerParameterType.Trigger: condition.mode = AnimatorConditionMode.If; condition.threshold = 0f; break; } conditions[j] = condition; transition.conditions = conditions; } else if (mode != condition.mode || threshold > condition.threshold || threshold < condition.threshold) { condition.mode = mode; condition.threshold = threshold; conditions[j] = condition; transition.conditions = conditions; } } } GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); }
public void ReadFromFile(System.IO.BinaryReader pReader) { mode = (AnimatorConditionMode)pReader.ReadInt32(); parameter = pReader.ReadString(); threshold = pReader.ReadSingle(); }