private static void LayoutAsDerivedTypePicker(GenericParameter parameter, bool label) { EditorGUILayout.BeginHorizontal(); { if (label) { parameter.Name = EditorGUILayout.TextField(parameter.Name, GUILayout.Width(LabelWidth)); } var type = parameter.GetAs <DerivedType>(); string content = "None"; if (type.BaseType != null && type.BaseType.Type != null) { if (type.TypeValue != null && type.TypeValue.Type != null) { content = $"{type.TypeValue.Type.Name} ({type.BaseType.Type.Name})"; } else { content = "None ({type.BaseType.Type.Name})"; } } if (EditorGUILayout.DropdownButton(new GUIContent(content), FocusType.Keyboard)) { SerializedType sysType = type.BaseType ?? new SerializedType(parameter.HoldType.Metadata); ReferenceTypePicker.ShowWindow(sysType.Type, BuildDerivedTypeCallback(parameter, sysType.Type), t => t.IsSubclassOf(sysType.Type)); } } EditorGUILayout.EndHorizontal(); }
private static void DrawAsDerivedTypePicker(Rect rect, Variant parameter, bool label) { if (label) { var width = rect.width; rect.width = width * 0.45f; parameter.Name = EditorGUI.TextField(rect, parameter.Name, SpaceEditorStyles.EditableLabel); rect.width = width * 0.5f; rect.x += rect.width; } var type = parameter.GetAs <DerivedType>(); string content = type.DisplayedName; if (EditorGUI.DropdownButton(rect, new GUIContent(content), FocusType.Keyboard)) { SerializedType sysType = type.BaseType ?? new SerializedType(parameter.HoldType.Metadata); ReferenceTypePicker.ShowWindow(sysType.Type, BuildDerivedTypeCallback(parameter, sysType.Type), t => t.IsSubclassOf(sysType.Type)); } }
public static void ShowWindow(Type baseType, Action <Type> onObjectPicked, Predicate <Type> predicate = null) { if (_instance == null) { _instance = CreateInstance <ReferenceTypePicker>(); _instance.OnInit(baseType, onObjectPicked, predicate); _instance.ShowUtility(); } }
private void AddCondition(Rect buttonrect, ReorderableList list) { ReferenceTypePicker.ShowWindow(typeof(Condition), t => { OnConditionAdded(list, t); }, t => t.IsSubclassOf(typeof(Condition))); }
private void OnAddNewParameter(Type type) { if (type.IsSubclassOf(typeof(UnityEngine.Object)) && type != typeof(GameObject)) { ReferenceTypePicker.ShowWindow(type, OnObjectReferenceTypeSelected, t => t.IsSubclassOf(type)); } else { AddNewParam(type); } }
private void ShowNodeCreationPopup(Vector2 mousePos, Action <Type> callback) { var picker = ScriptableObject.CreateInstance <ActionNodePicker>(); var size = new Vector2(300, 400); var rect = new Rect(mousePos.x, mousePos.y, 100, 100); picker.Data = ReferenceTypePicker.BuildTypeList(string.Empty, type => type.IsSubclassOf(typeof(ActionGraphNode))).ToList(); // picker.position = rect; picker.OnElementPicked = callback; // picker.CloseOnLostFocus = false; picker.ShowAsDropDown(rect, size); }
public void RecreateNodes(ActionGraph asset) { if (NodeLookup != null) { NodeLookup.Clear(); } else { NodeLookup = new Dictionary <ActionGraphNode, ActionGraphEditorNode>(); } Begin = null; Nodes.ClearNodes(); if (asset) { Nodes.ScrollPos = asset.EditorPos; Begin = new BeginNode(asset, Presenter); Nodes.AddNode(Begin); NodeEditors = ReferenceTypePicker.BuildTypeList(string.Empty, t => t.IsSubclassOf(typeof(ActionGraphEditorNode)) ).ToList(); foreach (ActionGraphNode node in asset.Nodes) { CreateNodeEditor(node, asset); } foreach (GraphNode graphNode in Nodes.AllNodes.Where(t => t is ActionGraphEditorNode)) { var asGraph = (ActionGraphEditorNode)graphNode; foreach (var childNode in asGraph.ActionNode.Connections) { ConnectNodeEditor(asGraph, childNode); } } foreach (ActionGraphNode graphNode in asset.Inputs.SelectMany(i => i.Nodes)) { if (!graphNode) { continue; } ConnectNodeEditor(Begin, graphNode); } } }
public void RecreateNodes(ActionGraph asset) { using (new GraphNode.NodeRecreationContext()) { if (NodeLookup != null) { NodeLookup.Clear(); } else { NodeLookup = new Dictionary <ActionGraphNodeBase, ActionGraphEditorNode>(); } ActionGraphEditorNode.WindowStyle = SpaceEditorStyles.GraphNodeBackground; Nodes.ClearNodes(); if (asset) { Nodes.ScrollPos = asset.EditorPos; NodeEditors = ReferenceTypePicker.BuildTypeList(string.Empty, t => t.IsSubclassOf(typeof(ActionGraphEditorNode)) ).ToList(); if (asset.AnyEntryNode) { CreateNodeEditor(asset.AnyEntryNode, asset); } foreach (var entry in asset.NamedEventEntries) { CreateNodeEditor(entry, asset); } foreach (ActionGraphNode node in asset.Nodes) { CreateNodeEditor(node, asset); } foreach (GraphNode graphNode in Nodes.AllNodes.Where(t => t is ActionGraphEditorNode)) { var asGraph = (ActionGraphEditorNode)graphNode; asGraph.RebuildConnections(LookupEditorNode); } } } }
private static void OnAddNewParameter(System.Type type, System.Action <SerializedType> callback) { if (type == typeof(DerivedType)) { ReferenceTypePicker.ShowWindow(KnownType.ObjectType, t => callback(new SerializedType(type, t.AssemblyQualifiedName)), t => t.IsSubclassOf(KnownType.ObjectType)); } else if (type.IsSubclassOf(typeof(UnityEngine.Object)) && type != typeof(GameObject)) { ReferenceTypePicker.ShowWindow(type, t => callback(new SerializedType(t)), t => t.IsSubclassOf(type)); } else { callback(new SerializedType(type)); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var type = property.GetAs <DerivedType>(); if (type == null) { return; } position.width *= 0.5f; string baseContent = type.BaseType != null && type.BaseType.Type != null ? $"{type.BaseType.Type.Name} (System.Type)" : "None (System.Type)"; if (EditorGUI.DropdownButton(position, new GUIContent(baseContent), FocusType.Keyboard)) { KnownTypeUtils.ShowAddParameterMenu(t => { if (t != type.BaseType) { type.BaseType = t; type.TypeValue = null; } }); } position.x += position.width; string derivedContent = type.DisplayedName; if (EditorGUI.DropdownButton(position, new GUIContent(derivedContent), FocusType.Keyboard)) { ReferenceTypePicker.ShowWindow(type.BaseType.Type, t => { type.TypeValue = new SerializedType(t); }, t => t.IsSubclassOf(type.BaseType.Type)); } }
void OnDestroy() { _instance = null; }