private static void DeserializeQualifier(StageElement aiElement, StageElement viewElement, AIUI targetUI) { var parent = targetUI.currentSelector; if (parent == null) { EditorUtility.DisplayDialog("Invalid Action", "You must select a Selector before pasting a Qualifier.", "Ok"); } var requiresInit = new List <IInitializeAfterDeserialization>(); var qualifierView = ReadQualifierView(viewElement, parent); var qualifier = SerializationMaster.Unstage <IQualifier>(aiElement, requiresInit); qualifierView.Reconnect(qualifier); //Do the post deserialize initialization here if (requiresInit.Count == 1) { requiresInit[0].Initialize(targetUI.ai); } qualifierView.PruneBrokenConnections(); if (qualifierView.isDefault) { if (EditorUtility.DisplayDialog("Confirm Replacement", "Do you wish to replace the current Default Qualifier?", "Yes", "No")) { targetUI.ReplaceDefaultQualifier(qualifierView, parent); } } else { targetUI.AddQualifier(qualifierView, parent); } }
internal static void ShowViewMenu(AIUI ui, Vector2 mousePos) { var menu = new GenericMenu(); var screenPos = EditorGUIUtility.GUIToScreenPoint(mousePos); bool allowDelete = true; if (ui.currentAction != null) { var qv = ui.currentQualifier; Action <Type> cb = (t) => { var newInstance = (IAction)Activator.CreateInstance(t); ui.ReplaceAction(qv, newInstance); }; menu.AddItem(new GUIContent("Change Type"), false, () => AIEntitySelectorWindow.Get <IAction>(screenPos, cb)); } else if (ui.currentQualifier != null) { string label = (ui.currentAction == null && ui.currentQualifier.actionView == null) ? "Add Action" : "Replace Action"; menu.AddItem(new GUIContent(label), false, () => AIEntitySelectorWindow.Get <IAction>(screenPos, (actionType) => { ui.SetAction(actionType); })); menu.AddItem(new GUIContent("Add Qualifier (sibling)"), false, () => AIEntitySelectorWindow.Get <IQualifier>(screenPos, (qualifierType) => { ui.AddQualifier(qualifierType); })); var qv = ui.currentQualifier; if (qv.isDefault) { allowDelete = false; } else { Action <Type> cb = (t) => { var newInstance = (IQualifier)Activator.CreateInstance(t); ui.ReplaceQualifier(qv, newInstance); }; menu.AddSeparator(string.Empty); menu.AddItem(new GUIContent("Change Type"), false, () => AIEntitySelectorWindow.Get <IQualifier>(screenPos, cb)); } } else if (ui.currentSelector != null) { var sv = ui.currentSelector; menu.AddItem(new GUIContent("Add Qualifier"), false, () => AIEntitySelectorWindow.Get <IQualifier>(screenPos, (qualifierType) => { ui.AddQualifier(qualifierType); })); menu.AddSeparator(string.Empty); if (sv.isRoot) { allowDelete = false; } else { menu.AddItem(new GUIContent("Set as Root"), false, () => ui.SetRoot(sv.selector)); } Action <Type> cb = (t) => { var newInstance = (Selector)Activator.CreateInstance(t); ui.ReplaceSelector(sv, newInstance); }; menu.AddItem(new GUIContent("Change Type"), false, () => AIEntitySelectorWindow.Get <Selector>(screenPos, cb)); } else if (ui.currentAILink != null) { var alv = ui.currentAILink; Action <AIStorage> cb = (ai) => { ui.ChangeAILink(alv, new Guid(ai.aiId)); }; menu.AddItem(new GUIContent("Change AI"), false, () => AISelectorWindow.Get(screenPos, cb)); } AddSharedItems(menu, ui, allowDelete, mousePos); }