private void GUINullOption() { IUnifiedGUIHelper.HorizontalBlock(() => { IUnifiedGUIHelper.EnabledBlock(() => { GUI.enabled = _allObjects.Any(); if (GUILayout.Button(new GUIContent("▼", "Expand All"), GUILayout.ExpandWidth(false))) { FoldoutAll(_allObjects, true); } if (GUILayout.Button(new GUIContent("▲", "Collapse All"), GUILayout.ExpandWidth(false))) { FoldoutAll(_allObjects, false); } }); var style = _serializedContainer.ObjectField == null && string.IsNullOrEmpty(_serializedContainer.ResultType) ? IUnifiedGUIHelper.SelectWindowStyles.NullSelected : IUnifiedGUIHelper.SelectWindowStyles.NullOption; if (GUILayout.Button("NULL", style, GUILayout.ExpandWidth(true))) { _serializedContainer.ObjectField = null; _serializedContainer.ApplyModifiedProperties(); } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); GUILayout.Space(5.0f); }); }
public void GetContainerContents(Rect rect, bool droppingFor, out GUIContentRect iconContent, out GUIContentRect labelContent) { Texture icon; string resultString, resultTip; if (ObjectFieldProperty.hasMultipleDifferentValues) { icon = null; resultString = "-"; resultTip = null; } else { var @object = ObjectField; if (IUnifiedGUIHelper.IsProjectAsset(@object) && (@object is Component || @object is GameObject)) { icon = EditorGUIUtility.FindTexture("PrefabNormal Icon"); } else { icon = EditorGUIUtility.ObjectContent(@object, null).image; } resultString = resultTip = BuildEditorResultString(ResultType, ObjectField); if (resultString == null) { resultString = "null"; } } iconContent = icon == null ? new GUIContentRect(null, rect) : new GUIContentRect(new GUIContent(icon, resultTip), rect); labelContent = new GUIContentRect(new GUIContent(resultString, !droppingFor ? resultTip : null), rect); }
private void OnGUI() { if (!IsValid) { return; } GUINullOption(); if (!_allObjects.Any()) { GUILayout.Space(10.0f); GUILayout.Label(string.Format(NoResultsMessage, _selectingForProjectAsset ? "project " : "", _resultTypeName), IUnifiedGUIHelper.SelectWindowStyles.DontPanic, GUILayout.ExpandWidth(true)); return; } if (!_selectingForProjectAsset) { GUISelectObjectType(); } _scrollPos = IUnifiedGUIHelper.ScrollViewBlock(_scrollPos, false, false, () => { _switchBoxStyle = false; foreach (var selectableObject in (_selectingProjectAssets ? _projectAssets : _sceneAssets)) { GUIObjectNode(selectableObject); } }); }
private void OnGUI() { if (!IsValid) { return; } GUINullOption(); if (!_allObjects.Any()) { GUILayout.Space(10.0f); GUILayout.Label($"\nNo {(_selectingForProjectAsset ? "project " : "")}assets found that implement or derive from {_resultTypeName}.\n", IUnifiedGUIHelper.SelectWindowStyles.DontPanic, GUILayout.ExpandWidth(true)); return; } if (!_selectingForProjectAsset) { GUISelectObjectType(); } _scrollPos = IUnifiedGUIHelper.ScrollViewBlock(_scrollPos, false, false, () => { _switchBoxStyle = false; foreach (var selectableObject in (_selectingProjectAssets ? _projectAssets : _sceneAssets)) { GUIObjectNode(selectableObject); } }); }
public static void ObjectNodeGUI(ObjectNode objectNode, IUnifiedContainerPropertyDrawer.SerializedContainer serializedContainer, GUIStyle style, int indentLevel) { IUnifiedGUIHelper.HorizontalBlock(() => { var helper = new GUIObjectNodeHelper(objectNode, serializedContainer); helper.DrawGUI(style, indentLevel); }); }
private static IEnumerable <SelectableObject> GetSelectable <TResult>(bool projectAssetsOnly) where TResult : class { var objects = IUnifiedGUIHelper.EnumerateSavedObjects().Concat(projectAssetsOnly ? new Object[0] : Object.FindObjectsOfType <Object>()); var implementations = new HashSet <TResult>(); foreach (var implementation in objects.SelectMany(o => GetObjectImplementationsOf <TResult>(o))) { implementations.Add(implementation); } return(implementations.Select(i => SelectableObject.GetSelectableObject(i))); }
private void ExecuteActions() { if (_toggleFoldout) { _objectNode.Foldout = !_objectNode.Foldout; } if (_select) { _serializedContainer.ObjectField = _objectNode.Object; _serializedContainer.ResultType = null; _serializedContainer.ApplyModifiedProperties(); } if (_ping) { IUnifiedGUIHelper.PingObject(_objectNode.Object); } }
private static TResult GetDragAndDropResult <TResult>(Rect dropArea, bool selectingForProjectAsset, SerializedContainer serializedContainer) where TResult : class { TResult result = null; bool? dropping = null; switch (_currentEvent.rawType) { case EventType.DragExited: case EventType.DragUpdated: case EventType.DragPerform: dropping = false; if (!serializedContainer.MouseInRects(dropArea, _currentEvent.mousePosition)) { break; } var single = DragAndDrop.objectReferences.SelectMany(o => GetObjectImplementationsOf <TResult>(o)).FirstOrDefault(); if (single != null) { var singleObject = single as Object; if (singleObject != null && (!selectingForProjectAsset || IUnifiedGUIHelper.IsProjectAsset(singleObject))) { dropping = true; } } DragAndDrop.visualMode = SerializedContainer.AnyDropping ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; if (_currentEvent.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); _currentEvent.Use(); dropping = false; result = single; } break; } if (dropping != null) { serializedContainer.SetDropping(dropping.Value); } return(result); }
public List <ObjectNode> BuildSelectableObjectsList(IEnumerable <IUnifiedContainerPropertyDrawer.SelectableObject> selectableObjects, Object selectedObject, out bool selectingProjectAssets) { selectingProjectAssets = false; _rootNodes = new List <ObjectNode>(); _parentNodes = new Dictionary <Object, ObjectNode>(); foreach (var selectableObject in selectableObjects) { if (selectedObject == selectableObject.Object) { selectingProjectAssets = selectableObject.IsProjectAsset; } var selectableObjectNode = new ObjectNode { Object = selectableObject.Object, NodeName = IUnifiedGUIHelper.GetObjectName(selectableObject.Object), IsSelectable = true, IsPingable = !selectableObject.IsComponent && IUnifiedGUIHelper.IsPingable(selectableObject.Object), IsProjectAsset = selectableObject.IsProjectAsset, }; if (selectableObject.IsComponent) { selectableObjectNode.Parent = GetOrCreateParentNode(selectableObjectNode); } else { _rootNodes.Add(selectableObjectNode); } } var missingParents = _parentNodes.Values.Where(n => n.Parent == null && !_rootNodes.Contains(n)).ToList(); _rootNodes.AddRange(missingParents); var @return = SortedNodes(_rootNodes); _parentNodes.Clear(); _rootNodes.Clear(); return(@return); }
private ObjectNode GetOrCreateParentNode(ObjectNode childNode) { GameObject parent = null; var component = childNode.Object as Component; if (component != null) { parent = component.gameObject; } else { var gameobject = childNode.Object as GameObject; if (gameobject != null && gameobject.transform.parent != null) { parent = gameobject.transform.parent.gameObject; } } if (parent != null) { ObjectNode parentNode; if (!_parentNodes.TryGetValue(parent, out parentNode)) { parentNode = new ObjectNode { Object = parent, IsSelectable = false, IsPingable = IUnifiedGUIHelper.IsPingable(parent), IsProjectAsset = IUnifiedGUIHelper.IsProjectAsset(parent), NodeName = IUnifiedGUIHelper.GetObjectName(parent) }; _parentNodes.Add(parent, parentNode); parentNode.Parent = GetOrCreateParentNode(parentNode); } parentNode.Children.Add(childNode); return(parentNode); } return(null); }
private void CreateContentRects(GUIStyle style, int indentLevel, out GUIContentRect nodeGUI, out GUIContentRect foldoutGUI, out GUIContentRect iconGUI, out GUIContentRect labelGUI) { GUIContent iconContent, labelContent; var foldoutContent = GetFoldoutContent(indentLevel); GetObjectNodeContents(_objectNode, out iconContent, out labelContent); nodeGUI = new GUIContentRect(GUIContent.none, GUILayoutUtility.GetRect(foldoutContent, style)); foldoutGUI = new GUIContentRect(foldoutContent, nodeGUI); iconGUI = new GUIContentRect(iconContent, nodeGUI); labelGUI = new GUIContentRect(labelContent, nodeGUI); foldoutGUI.SetWidth(IUnifiedGUIHelper.GetMinWidth(foldoutContent, style) + 2.0f); iconGUI.MoveNextTo(foldoutGUI); iconGUI.SetWidth(iconContent == null ? 0.0f : (IUnifiedGUIHelper.GetScaledTextureWidth(iconContent.image, foldoutGUI.Rect.height, style) + 2.0f)); labelGUI.MoveNextTo(iconGUI); labelGUI.SetWidth(IUnifiedGUIHelper.GetMinWidth(labelContent, style)); }
private static string BuildEditorResultString(string resultType, Object @object) { if (@object != null) { var component = @object as Component; if (component != null) { return($"{component.gameObject.name} ( {IUnifiedContainerBase.IUnifiedContainerBase.ConstructResolvedName(@object.GetType())} )"); } return(IUnifiedGUIHelper.GetObjectName(@object)); } if (!string.IsNullOrEmpty(resultType)) { return(resultType); } return(null); }
private static string BuildEditorResultString(string resultType, Object @object) { if (@object != null) { var component = @object as Component; if (component != null) { return(string.Format("{0} ( {1} )", component.gameObject.name, IUnifiedGUIHelper.ConstructResolvedName(@object.GetType()))); } return(IUnifiedGUIHelper.GetObjectName(@object)); } if (!string.IsNullOrEmpty(resultType)) { return(resultType); } return(null); }
private void GUISelectObjectType() { IUnifiedGUIHelper.HorizontalBlock(() => { IUnifiedGUIHelper.EnabledBlock(() => { GUI.enabled = _sceneAssetsExist; if (GUILayout.Button("Scene Assets", _selectingProjectAssets ? GUI.skin.button : IUnifiedGUIHelper.SelectWindowStyles.SelectedButton)) { _selectingProjectAssets = false; } }); IUnifiedGUIHelper.EnabledBlock(() => { GUI.enabled = _projectAssetsExist; if (GUILayout.Button("Project Assets", _selectingProjectAssets ? IUnifiedGUIHelper.SelectWindowStyles.SelectedButton : GUI.skin.button)) { _selectingProjectAssets = true; } }); }); }
private SelectableObject(Object @object) { Object = @object; IsProjectAsset = IUnifiedGUIHelper.IsProjectAsset(Object); IsComponent = Object is Component; }
private static void DrawIUnifiedContainer <TResult>(Rect position, GUIContent label, SerializedContainer serializedContainer) where TResult : class { _currentEvent = Event.current; var resultTypeName = IUnifiedContainerBase.IUnifiedContainerBase.ConstructResolvedName(CachedType <TResult> .Type); if (string.IsNullOrEmpty(label.tooltip)) { label.tooltip = resultTypeName; } var labelRect = new GUIContentRect(label, position); labelRect.SetWidth(EditorGUIUtility.labelWidth); var resultRect = new GUIContentRect(null, position); resultRect.MoveNextTo(labelRect); resultRect.Rect.xMax -= (ButtonSpace + ButtonWidth) * 2; var nullButonRect = new GUIContentRect(null, position); nullButonRect.MoveNextTo(resultRect, ButtonSpace); nullButonRect.SetWidth(ButtonWidth); var listButtonRect = new GUIContentRect(null, position); listButtonRect.MoveNextTo(nullButonRect, ButtonSpace); listButtonRect.SetWidth(ButtonWidth); var isProjectAsset = serializedContainer.IsProjectAsset; var pingable = !serializedContainer.ObjectFieldProperty.hasMultipleDifferentValues && IUnifiedGUIHelper.IsPingable(serializedContainer.ObjectField); var dragDropResult = GetDragAndDropResult <TResult>(resultRect, isProjectAsset, serializedContainer); EditorGUI.LabelField(labelRect, label); IUnifiedGUIHelper.EnabledBlock(() => { GUI.enabled = pingable; IUnifiedGUIHelper.ColorBlock(() => { if (serializedContainer.Selecting || serializedContainer.Dropping) { GUI.color = new Color(1, 1, 1, 2); } else { GUI.color = pingable ? new Color(1, 1, 1, 2) : Color.white; } DrawField(serializedContainer, resultRect, pingable); }); }); if (dragDropResult != null) { serializedContainer.ObjectField = dragDropResult as Object; GUI.changed = true; } if (GUI.Button(nullButonRect, new GUIContent("○", "Set to null"), IUnifiedGUIHelper.InspectorStyles.NullOutButton)) { serializedContainer.ObjectField = null; } IUnifiedGUIHelper.EnabledBlock(() => { if (GUI.Button(listButtonRect, new GUIContent("◉", "Select from list"), IUnifiedGUIHelper.InspectorStyles.SelectFromListButton)) { _selectWindow = IUnifiedContainerSelectWindow.ShowSelectWindow(resultTypeName, isProjectAsset, serializedContainer, GetSelectable <TResult>(isProjectAsset)); } }); }
private static void DrawField(SerializedContainer serializedContainer, Rect rect, bool pingable) { var buttonId = GUIUtility.GetControlID(FocusType.Passive) + 1; if (GUI.Button(rect, GUIContent.none, GUIStyle.none)) { if (pingable) { IUnifiedGUIHelper.PingObject(serializedContainer.ObjectField); } } var pinging = GUIUtility.hotControl == buttonId && pingable; GUIStyle style; if (serializedContainer.Dropping) { style = IUnifiedGUIHelper.InspectorStyles.DropBox; } else if (pinging) { style = IUnifiedGUIHelper.InspectorStyles.Pinging; } else if (serializedContainer.Selecting) { style = IUnifiedGUIHelper.InspectorStyles.Selecting; } else { style = IUnifiedGUIHelper.InspectorStyles.Result; } if (serializedContainer.ObjectFieldProperty.hasMultipleDifferentValues || serializedContainer.ObjectField == null) { style.alignment = TextAnchor.MiddleCenter; style.imagePosition = ImagePosition.TextOnly; } else { style.alignment = TextAnchor.MiddleLeft; style.imagePosition = ImagePosition.ImageLeft; } GUI.Label(rect, GUIContent.none, style); GUIContentRect icon, label; serializedContainer.GetContainerContents(rect, serializedContainer.Dropping, out icon, out label); style.normal.background = null; if (icon.Content != null) { icon.SetWidth(IUnifiedGUIHelper.GetScaledTextureWidth(icon.Content.image, rect.height + 2.0f)); label.MoveNextTo(icon, -3.0f); GUI.Label(icon, icon, style); } GUI.Label(label, label, style); if (!SerializedContainer.AnyDropping && pingable) { EditorGUIUtility.AddCursorRect(rect, MouseCursor.Zoom); } }