コード例 #1
0
        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;
                },
            };
        }
コード例 #2
0
        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);
                }
            };
        }