/// <summary> /// Shows a context menu callback to add a new state. /// </summary> void OnAddContextMenu() { var menu = new GenericMenu(); var stateScripts = FileUtility.GetScripts <InternalStateBehaviour>(); for (int i = 0; i < stateScripts.Length; i++) { System.Type childStateType = stateScripts[i].GetClass(); // Get the component path string componentPath; AddComponentMenu componentMenu = AttributeUtility.GetAttribute <AddComponentMenu>(childStateType, true); if (componentMenu != null && componentMenu.componentMenu != string.Empty) { componentPath = componentMenu.componentMenu; } else { componentPath = childStateType.ToString().Replace('.', '/'); } menu.AddItem(new GUIContent(componentPath), false, delegate() { StateUtility.AddState(m_Parent, childStateType); }); } // Shows the context menu menu.ShowAsContext(); }
/// <summary> /// Shows a context menu to add a new parent. /// </summary> void OnContextMenu() { var menu = new UnityEditor.GenericMenu(); // Get the active game object var gameObject = Selection.activeGameObject; // The selected game object is not null? if (gameObject != null) { // Gets all scripts that inherits from ParentBehaviour class MonoScript[] scripts = FileUtility.GetScripts <ParentBehaviour>(); for (int i = 0; i < scripts.Length; i++) { var type = scripts[i].GetClass(); // Get the component path string componentPath = "Add Parent/"; AddComponentMenu componentMenu = AttributeUtility.GetAttribute <AddComponentMenu>(type, false); if (componentMenu == null || componentMenu.componentMenu != string.Empty) { componentMenu = AttributeUtility.GetAttribute <AddComponentMenu>(type, true); if (componentMenu != null && componentMenu.componentMenu != string.Empty) { componentPath += componentMenu.componentMenu; } else { componentPath += type.ToString().Replace('.', '/'); } // Add to menu menu.AddItem(new GUIContent(componentPath), false, delegate() { BehaviourWindow.activeParent = StateUtility.AddState(gameObject, type) as ParentBehaviour; }); } } } else { menu.AddDisabledItem(new GUIContent("Add Parent/")); ShowNotification(new GUIContent("Select a Game Object and right click in this window!")); } // Add option to paste states if (Selection.activeGameObject != null && StateUtility.statesToPaste != null && StateUtility.statesToPaste.Length > 0) { menu.AddItem(new GUIContent("Paste State"), false, delegate() { StateUtility.CloneStates(Selection.activeGameObject, StateUtility.statesToPaste, null); }); } else { menu.AddDisabledItem(new GUIContent("Paste State")); } // Refresh window? // menu.AddSeparator(""); // menu.AddItem(new GUIContent("Refresh"), false ,Refresh); // Shows the controller menu menu.ShowAsContext(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { label.tooltip = EditorHelper.GetTooltipAttribute(fieldInfo)?.tooltip ?? string.Empty; using (new EditorGUI.PropertyScope(position, label, property)) { SerializedProperty assemblyQualifiedTypeNameProperty = property.FindPropertyRelative("assemblyQualifiedTypeName"); int?index = property.TryGetIndex(); label.text = index == null ? label.text : $"Element {index}"; Rect buttonPosition = EditorGUI.PrefixLabel(position, label); if (type?.AssemblyQualifiedName != assemblyQualifiedTypeNameProperty.stringValue) { type = Type.GetType(assemblyQualifiedTypeNameProperty.stringValue); } if (!GUI.Button(buttonPosition, new GUIContent(type?.Name, type?.FullName))) { return; } Rect creatorRect = new Rect { min = GUIUtility.GUIToScreenPoint(position.min), max = GUIUtility.GUIToScreenPoint(position.max) }; Type baseType = ((TypePickerAttribute)attribute).baseType; PickerWindow.Show( creatorRect, AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) .Where( possibleComponentType => { AddComponentMenu addComponentMenuAttribute = possibleComponentType .GetCustomAttributes <AddComponentMenu>(true) .FirstOrDefault(); return(baseType.IsAssignableFrom(possibleComponentType) && !possibleComponentType.IsAbstract && !possibleComponentType.IsNestedPrivate && (addComponentMenuAttribute == null || !string.IsNullOrWhiteSpace(addComponentMenuAttribute.componentMenu))); }) .OrderBy(componentType => componentType.Name), selectedType => { assemblyQualifiedTypeNameProperty.stringValue = selectedType.AssemblyQualifiedName; property.serializedObject.ApplyModifiedProperties(); }, searchedType => searchedType.Name, drawnType => new GUIContent( ObjectNames.NicifyVariableName(drawnType.Name), AssetPreview.GetMiniTypeThumbnail(drawnType), drawnType.FullName)); } }
private static int GetComponentMenuOrdering(Type klass) { object[] customAttributes = klass.GetCustomAttributes(typeof(AddComponentMenu), false); if (customAttributes.Length > 0) { AddComponentMenu addComponentMenu = (AddComponentMenu)customAttributes[0]; return(addComponentMenu.componentOrder); } return(0); }
private static int GetComponentMenuOrdering(System.Type type) { object[] customAttributes = type.GetCustomAttributes(typeof(AddComponentMenu), false); if (customAttributes.Length > 0) { AddComponentMenu menu = (AddComponentMenu)customAttributes[0]; return(menu.componentOrder); } return(0); }
private static string GetComponentMenuName(Type klass) { object[] customAttributes = klass.GetCustomAttributes(typeof(AddComponentMenu), false); if (customAttributes.Length > 0) { AddComponentMenu addComponentMenu = (AddComponentMenu)customAttributes[0]; return(addComponentMenu.componentMenu); } return(null); }
private static string GetComponentMenuName(System.Type type) { object[] customAttributes = type.GetCustomAttributes(typeof(AddComponentMenu), false); if (customAttributes.Length > 0) { AddComponentMenu menu = (AddComponentMenu)customAttributes[0]; return(menu.componentMenu); } return(null); }
private static string GetComponentMenuName(Type type) { object[] customAttributes = type.GetCustomAttributes(typeof(AddComponentMenu), false); string result; if (customAttributes.Length > 0) { AddComponentMenu addComponentMenu = (AddComponentMenu)customAttributes[0]; result = addComponentMenu.componentMenu; } else { result = null; } return(result); }
private static int GetComponentMenuOrdering(Type type) { object[] customAttributes = type.GetCustomAttributes(typeof(AddComponentMenu), false); int result; if (customAttributes.Length > 0) { AddComponentMenu addComponentMenu = (AddComponentMenu)customAttributes[0]; result = addComponentMenu.componentOrder; } else { result = 0; } return(result); }
// default constructor. public ComponentManager(int screenWidth, int screenHeight) { // these are flipped because screen is in landscape. _screenWidth = screenHeight; _screenHeight = screenWidth; // set initial state this.currentState = ComponentManagerState.noMenu; // create component list componentList = new LinkedList<Component>(); // create a RemoveComponentMenu removeMenu = new RemoveComponentMenu(); // create an AddComponentMenu addMenu = new AddComponentMenu(); }
public static void Show(Rect sourceRect, Type type, Action <Type> selectAction) { TypePickerWindow window = CreateInstance <TypePickerWindow>(); window.type = type; window.componentTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) .Where( possibleComponentType => { AddComponentMenu addComponentMenuAttribute = possibleComponentType.GetCustomAttributes <AddComponentMenu>(true).FirstOrDefault(); return(type.IsAssignableFrom(possibleComponentType) && !possibleComponentType.IsAbstract && (addComponentMenuAttribute == null || !string.IsNullOrWhiteSpace(addComponentMenuAttribute.componentMenu))); }) .OrderBy(componentType => componentType.Name) .ToArray(); window.selectAction = selectAction; window.ShowAsDropDown(sourceRect, new Vector2(Mathf.Max(250f, sourceRect.width), 250f)); }
private void DrawNodeFields() { inspectorView.StretchToParentSize(); string title = NodeData.GetType().Name; AddComponentMenu titleAttribute = NodeData.GetType().GetCustomAttribute <AddComponentMenu>(); if (titleAttribute != null) { title = titleAttribute.componentMenu; int splitI = title.LastIndexOf('/'); if (splitI != -1 && splitI < title.Length - 1) { title = title.Substring(splitI + 1); } } this.title = title; Label inspectorTitle = new Label(title); inspectorTitle.AddToClassList("inspector-title"); inspectorView.Add(inspectorTitle); Dictionary <string, NodeEditorField> markedFields = GetAttributes <NodeEditorField>(NodeData.GetType(), typeof(BehaviourT.Node)); List <FieldInfo> serializedFields = GetAttributesList <SerializeField>(NodeData.GetType(), typeof(Node)); foreach (FieldInfo fieldInfo in serializedFields) { VisualElement container = null; string elementName = fieldInfo.Name; if (markedFields.TryGetValue(fieldInfo.Name, out NodeEditorField attribute)) { switch (attribute.nodePlace) { case NodeEditorField.NodePlace.TitleContainer: container = titleContainer; break; case NodeEditorField.NodePlace.MainContainer: container = mainContainer; break; case NodeEditorField.NodePlace.PortContainer: container = Q <LogicPort>(inputContainer, p => Equals(p.basePort.Name, attribute.portContainer)); if (container == null) { container = Q <LogicPort>(outputContainer, p => Equals(p.basePort.Name, attribute.portContainer)); } if (container == null) { Debug.LogWarning("Port " + attribute.portContainer + " was not found for default value"); container = mainContainer; } break; case NodeEditorField.NodePlace.Hide: continue; } if (attribute.label != null) { elementName = attribute.label; } } Action <object> valueChanged = (o) => fieldInfo.SetValue(NodeData, o); VisualElement viewElement = null; if (container != null) { viewElement = ElementFieldConverter.GetVisualElement(fieldInfo.FieldType, fieldInfo.GetValue(NodeData), elementName, valueChanged, ref valueChanged); //valueChanged += (o) => getValue?.Invoke(o); } VisualElement inspectorElement = ElementFieldConverter.GetVisualElement(fieldInfo.FieldType, fieldInfo.GetValue(NodeData), elementName, valueChanged, ref valueChanged); //Debug.Log("GetValue 2: " + (getValue2 != null)); //getValue2?.Invoke("Hallo"); //if (getValue2 != null) //{ // valueChanged += (o) => { getValue2?.Invoke(o); Debug.Log("Invoke GetValue 2"); }; //} if (viewElement != null) { viewElement.style.alignSelf = Align.Stretch; } inspectorElement.style.alignSelf = Align.Stretch; if (attribute != null) { if (viewElement != null) { if (attribute.hideLabel) { viewElement.AddToClassList("hide-label"); } if (attribute.minWidth != -1) { viewElement.style.minWidth = attribute.minWidth; } if (attribute.nodePlace == NodeEditorField.NodePlace.TitleContainer) { viewElement.AddToClassList("simple-text-field"); } if (attribute.nodePlace == NodeEditorField.NodePlace.PortContainer) { viewElement.style.flexGrow = 2; } if (!attribute.editable) { viewElement.focusable = false; } } if (!attribute.editable) { inspectorElement.focusable = false; } } container?.Add(viewElement); inspectorView.Add(inspectorElement); } }
/// <summary> /// Shows the context menu. /// </summary> void OnContextMenu() { var menu = new GenericMenu(); var activeFsm = BehaviourWindow.activeFsm; if (activeFsm != null) { m_LastMousePos = Event.current.mousePosition; // Get the states scripts MonoScript[] stateScripts = FileUtility.GetScripts <InternalStateBehaviour>(); for (int i = 0; i < stateScripts.Length; i++) { System.Type type = stateScripts[i].GetClass(); // Get the component path string componentPath = "Add State/"; AddComponentMenu componentMenu = AttributeUtility.GetAttribute <AddComponentMenu>(type, false); if (componentMenu == null || componentMenu.componentMenu != string.Empty) { componentMenu = AttributeUtility.GetAttribute <AddComponentMenu>(type, true); if (componentMenu != null && componentMenu.componentMenu != string.Empty) { componentPath += componentMenu.componentMenu; } else { componentPath += type.ToString().Replace('.', '/'); } menu.AddItem(new GUIContent(componentPath), false, delegate() { InternalStateBehaviour newState = StateUtility.AddState(activeFsm, type); // Sets the newState position and dirty flag if (newState != null) { newState.position = m_LastMousePos - new Vector2(StateGUI.defaultWidth, StateGUI.defaultHeight) * .5f; EditorUtility.SetDirty(newState); } }); } } } else { menu.AddDisabledItem(new GUIContent("Add State")); } // Separator menu.AddSeparator(""); menu.AddItem(new GUIContent("Copy FSM"), false, delegate() { StateUtility.statesToPaste = new InternalStateBehaviour[] { activeFsm }; }); if (StateUtility.statesToPaste != null && StateUtility.statesToPaste.Length > 0 && activeFsm != null) { menu.AddItem(new GUIContent("Paste State"), false, delegate() { StateUtility.PasteStates(activeFsm); }); } else { menu.AddDisabledItem(new GUIContent("Paste State")); } // Separator menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete FSM"), false, delegate() { StateUtility.Destroy(activeFsm); }); // menu.AddSeparator(""); // Separator // if (BehaviourWindow.Instance != null) // menu.AddItem(new GUIContent("Refresh"), false, BehaviourWindow.Instance.Refresh); // else // menu.AddDisabledItem(new GUIContent("Refresh")); // Shows the context menu menu.ShowAsContext(); }