private void TransitionList() { Reo_List_Transitions = new ReorderableList(serializedObject, transitions, true, true, true, true) { drawElementCallback = (rect, index, isActive, isFocused) => { var r1 = new Rect(rect) { y = rect.y + 2, height = EditorGUIUtility.singleLineHeight }; var r2 = new Rect(r1); var r3 = new Rect(r2); var element = transitions.GetArrayElementAtIndex(index); var decision = element.FindPropertyRelative("decision"); var TrueState = element.FindPropertyRelative("trueState"); var FalseState = element.FindPropertyRelative("falseState"); var empty = decision.objectReferenceValue == null; if (empty) { r1.width -= 30; } EditorGUI.PropertyField(r1, decision, new GUIContent("[" + index + "] Decision", "If the Decision is true it will go to the True State, else it will go to the False state")); if (empty) { var AddButtonRect = new Rect(r1) { x = rect.width + 12, width = 25, height = EditorGUIUtility.singleLineHeight }; if (GUI.Button(AddButtonRect, "+")) { // OnAddCallback_Decision(index); MTools.AddScriptableAssetContextMenu(decision, typeof(MAIDecision), MTools.GetSelectedPathOrFallback()); } } empty = TrueState.objectReferenceValue == null; if (empty) { r2.width -= 30; } r2.y += EditorGUIUtility.singleLineHeight + 3; EditorGUI.PropertyField(r2, TrueState, new GUIContent("True" + (empty ? " (Do Nothing)" : ""), "If the Decision is TRUE, It will execute this state. if is Empty, it will do nothing")); if (empty) { var AddButtonRect = new Rect(r2) { x = rect.width + 12, width = 25, height = EditorGUIUtility.singleLineHeight }; if (GUI.Button(AddButtonRect, "+")) { MTools.CreateScriptableAsset(TrueState, typeof(MAIState), MTools.GetSelectedPathOrFallback()); } } empty = FalseState.objectReferenceValue == null; if (empty) { r3.width -= 30; } r3.y += (EditorGUIUtility.singleLineHeight + 3) * 2; EditorGUI.PropertyField(r3, FalseState, new GUIContent("False" + (empty ? " (Do Nothing)" : ""), "If the Decision is FALSE, It will execute this state. if is Empty, it will do nothing")); if (empty) { var AddButtonRect = new Rect(r3) { x = rect.width + 12, width = 25, height = EditorGUIUtility.singleLineHeight }; if (GUI.Button(AddButtonRect, "+")) { MTools.CreateScriptableAsset(FalseState, typeof(MAIState), MTools.GetSelectedPathOrFallback()); } } }, drawHeaderCallback = rect => EditorGUI.LabelField(rect, new GUIContent(" Decisions", "Transitions for other States")), onAddCallback = list => OnAddCallback_Decision(), onRemoveCallback = list => { var decision = m.transitions[list.index].decision; string Path = AssetDatabase.GetAssetPath(decision); if (Path == AssetDatabase.GetAssetPath(target)) //mean it was created inside the AI STATE { DestroyImmediate(decision, true); //Delete the internal asset! transitions.DeleteArrayElementAtIndex(list.index); // Removed double //HACK HACK AssetDatabase.SaveAssets(); } else { transitions.DeleteArrayElementAtIndex(list.index); } CheckListIndex(list); EditorUtility.SetDirty(target); }, elementHeightCallback = (index) => { var DefaultHeight = EditorGUIUtility.singleLineHeight + 5; //if (Reo_List_Transitions.index == index) return(DefaultHeight * 3); //else // return DefaultHeight; }, }; }
// private Color color = new Color(1,0.4f,0.4f,1); public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label) { var element = property.objectReferenceValue; var attr = attribute as CreateScriptableAssetAttribute; if (element == null) { position.width -= 22; //var oldColor = GUI.color; //GUI.color = color; UnityEditor.EditorGUI.PropertyField(position, property); // GUI.color = oldColor; var AddButtonRect = new Rect(position) { x = position.width + position.x + 2, width = 20 }; if (GUI.Button(AddButtonRect, "+")) { if (attr.isAsset) { MTools.CreateScriptableAsset(property, MTools.Get_Type(property), MTools.GetSelectedPathOrFallback()); } else { MTools.CreateScriptableAssetInternal(property, MTools.Get_Type(property)); } } } else { UnityEditor.EditorGUI.PropertyField(position, property); } if (property.isArray) { } }
private void TasksList() { Reo_List_Tasks = new ReorderableList(serializedObject, tasks, true, true, true, true) { drawElementCallback = (rect, index, isActive, isFocused) => { var element = tasks.GetArrayElementAtIndex(index); var r = new Rect(rect) { y = rect.y + 2, height = EditorGUIUtility.singleLineHeight }; var space = element.objectReferenceValue == null; if (space) { r.width -= 22; } EditorGUI.PropertyField(r, element, GUIContent.none); if (space) { var AddButtonRect = new Rect(rect) { x = rect.width + 22, width = 22, y = rect.y + 2, height = EditorGUIUtility.singleLineHeight }; // if (!internalData.boolValue) if (GUI.Button(AddButtonRect, new GUIContent("+", "Create New Task Asset Externally"))) { MTools.AddScriptableAssetContextMenu(element, typeof(MTask), MTools.GetSelectedPathOrFallback()); } } }, drawHeaderCallback = rect => { var r = new Rect(rect); var ColorRect = new Rect(rect) { x = rect.width - 40, width = 60, height = rect.height - 2, y = rect.y + 1, }; EditorGUI.LabelField(rect, new GUIContent(" Tasks", "Tasks for the state")); EditorGUI.PropertyField(ColorRect, GizmoStateColor, GUIContent.none); }, onAddCallback = list => OnAddCallback_Task(list), onRemoveCallback = list => { var task = tasks.GetArrayElementAtIndex(list.index).objectReferenceValue; string Path = AssetDatabase.GetAssetPath(task); if (Path == AssetDatabase.GetAssetPath(target)) //mean it was created inside the AI STATE { DestroyImmediate(task, true); //Delete the internal asset! tasks.DeleteArrayElementAtIndex(list.index); //Delete the Index tasks.DeleteArrayElementAtIndex(list.index); //Double Hack AssetDatabase.SaveAssets(); } else// is an Outside Element // if () { tasks.DeleteArrayElementAtIndex(list.index); } CheckListIndex(list); EditorUtility.SetDirty(target); } }; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (popupStyle == null) { popupStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions")) { imagePosition = ImagePosition.ImageOnly } } ; if (AddStyle == null) { AddStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions")) { imagePosition = ImagePosition.ImageOnly } } ; position.y -= 0; label = EditorGUI.BeginProperty(position, label, property); Rect variableRect = new Rect(position); position = EditorGUI.PrefixLabel(position, label); EditorGUI.BeginChangeCheck(); float height = EditorGUIUtility.singleLineHeight; // Get properties SerializedProperty useConstant = property.FindPropertyRelative("UseConstant"); SerializedProperty constantValue = property.FindPropertyRelative("ConstantValue"); SerializedProperty variable = property.FindPropertyRelative("Variable"); Rect prop = new Rect(position) { height = height }; // Calculate rect for configuration button Rect buttonRect = new Rect(position); buttonRect.yMin += popupStyle.margin.top; buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right; buttonRect.x -= 20; buttonRect.height = height; position.xMin = buttonRect.xMax; var AddButtonRect = new Rect(prop) { x = prop.width + prop.x - 20, width = 22 }; // Store old indent level and set it to 0, the PrefixLabel takes care of it int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; int result = EditorGUI.Popup(buttonRect, useConstant.boolValue ? 0 : 1, popupOptions, popupStyle); useConstant.boolValue = (result == 0); bool varIsEmpty = variable.objectReferenceValue == null; if (varIsEmpty && !useConstant.boolValue) { prop.width -= 22; } EditorGUI.PropertyField(prop, useConstant.boolValue ? constantValue : variable, GUIContent.none, false); if (varIsEmpty && !useConstant.boolValue) { if (GUI.Button(AddButtonRect, new GUIContent("+", "Create"))) { MTools.CreateScriptableAsset(variable, MTools.Get_Type(variable), MTools.GetSelectedPathOrFallback()); } } // ShowScriptVar(variableRect, height, useConstant, variable); if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); } EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); }