public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { position.x += 4; position.width -= 4; if (!executed) { AIEditorWindow[] windows = Resources.FindObjectsOfTypeAll <AIEditorWindow>(); if (windows.Length > 0) { controller = windows[0].controller; } if (controller != null && controller.runtimeAnimatorController != null) { FillStateNames(controller.runtimeAnimatorController); FillParameterArray(controller.runtimeAnimatorController, AnimatorControllerParameterType.Float); FillParameterArray(controller.runtimeAnimatorController, AnimatorControllerParameterType.Bool); FillParameterArray(controller.runtimeAnimatorController, AnimatorControllerParameterType.Int); FillParameterArray(controller.runtimeAnimatorController, AnimatorControllerParameterType.Trigger); } executed = true; } if (controller != null) { switch (paramterAttribute.type) { case AnimatorParameter.Bool: property.stringValue = UnityEditorTools.StringPopup(position, label.text, property.stringValue, boolNames); break; case AnimatorParameter.Float: property.stringValue = UnityEditorTools.StringPopup(position, label.text, property.stringValue, floatNames); break; case AnimatorParameter.Int: property.stringValue = UnityEditorTools.StringPopup(position, label.text, property.stringValue, intNames); break; case AnimatorParameter.Trigger: property.stringValue = UnityEditorTools.StringPopup(position, label.text, property.stringValue, triggerNames); break; case AnimatorParameter.State: property.stringValue = UnityEditorTools.StringPopup(position, label.text, property.stringValue, stateNames); break; } } else { EditorGUI.PropertyField(position, property, label); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (!initialized) { AIEditorWindow[] windows = Resources.FindObjectsOfTypeAll <AIEditorWindow>(); if (windows.Length > 0) { controller = windows[0].controller; } initialized = true; } if (controller != null) { List <BaseAttribute> attributes = new List <BaseAttribute> (); for (int i = 0; i < controller.states.Count; i++) { if (controller.states[i] is OnAttributeChanged) { attributes.Add((controller.states[i] as OnAttributeChanged).attribute); } } List <string> attributeNames = new List <string>(); attributeNames.AddRange(attributes.Select(x => x.name).ToArray()); int count = attributeNames.Count; if (count == 0) { attributeNames.Add("None"); } //EditorGUI.BeginChangeCheck(); GUI.color = count == 0?Color.red:Color.white; position.x += 4; position.width -= 4; selected = UnityEditorTools.StringPopup(position, label.text, selected, attributeNames.ToArray()); GUI.color = Color.white; //if (EditorGUI.EndChangeCheck()){ property.stringValue = selected; //} } }
public static void CreateAIControllerAsset() { UnityEditorTools.CreateAsset <AIController>(); }
private void DrawActionElement(int index) { BaseAction action = state.actions [index]; FieldInfo[] fields = action.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance); SerializedObject obj = new SerializedObject(action); obj.Update(); for (int cnt = fields.Length - 1; cnt >= 0; cnt--) { if (action is AISystem.Actions.WaitForSeconds && fields [cnt].Name.Equals("queue")) { obj.FindProperty(fields [cnt].Name).boolValue = true; GUI.enabled = false; } object[] attributes = action.GetType().GetCustomAttributes(true); bool hide = false; foreach (object attribute in attributes) { if (attribute is HideOwnerDefault && fields[cnt].Name.Equals("gameObject")) { hide = true; } } var attributeTypes = fields[cnt].GetCustomAttributes(false).Select(attr => attr.GetType()); if (attributeTypes.Contains(typeof(HideInInspector))) { hide = true; } if (!hide) { SerializedProperty mProperty = obj.FindProperty(fields [cnt].Name); if (mProperty != null) { EditorGUILayout.PropertyField(mProperty); } } GUI.enabled = true; } if (action is GetProperty) { GetProperty getPropertyAction = action as GetProperty; if (getPropertyAction.script != null) { FieldInfo[] propertyFields = getPropertyAction.script.GetClass() .GetFields(BindingFlags.Public | BindingFlags.Instance) .Where(x => x.FieldType.IsPrimitive || x.FieldType == typeof(string)) .ToArray(); if (propertyFields.Length > 0) { string[] propertyNames = propertyFields.Select(x => x.Name).ToArray(); getPropertyAction.property = UnityEditorTools.StringPopup("Property", getPropertyAction.property, propertyNames); Type type = propertyFields.ToList().Find(x => x.Name == getPropertyAction.property).FieldType; getPropertyAction.scriptName = getPropertyAction.script.GetClass().ToString(); SerializedProperty mProperty = null; if (type == typeof(int) || type == typeof(float)) { mProperty = obj.FindProperty("storeIntOrFloat"); } else if (type == typeof(bool)) { mProperty = obj.FindProperty("storeBool"); } else if (type == typeof(string)) { mProperty = obj.FindProperty("storeString"); } if (mProperty != null) { EditorGUILayout.PropertyField(mProperty, new GUIContent("Store")); } } } } GUILayout.Space(3); obj.ApplyModifiedProperties(); }