public static void Hide() { if( _window != null ) { DestroyImmediate( _window ); _window.Close(); _window = null; } }
public static void Hide() { if (_window != null) { DestroyImmediate(_window); _window.Close(); _window = null; } }
public static void Update(Rect pAnchorTo, Vector2 pMousePosition, GameObject pObject) { if (_window == null) { _window = ScriptableObject.CreateInstance <TeneDropTarget>(); } _window.ShowPopup(); _window._close = false; _window._repositioned = false; //_window._anchoredTo = pAnchorTo; _window.HadMouseOver = false; _window.title = pObject.name; _window.SetTarget(pObject); _window.SetPosition(pAnchorTo, pMousePosition); }
public static void Update( Rect pAnchorTo, Vector2 pMousePosition, GameObject pObject ) { if( _window == null ) _window = ScriptableObject.CreateInstance<TeneDropTarget>(); _window.ShowPopup(); _window._close = false; _window._repositioned = false; //_window._anchoredTo = pAnchorTo; _window.HadMouseOver = false; #if UNITY_5 && !UNITY_5_0 _window.titleContent = new GUIContent(pObject.name); #else _window.title = pObject.name; #endif _window.SetTarget( pObject ); _window.SetPosition( pAnchorTo, pMousePosition ); }
public static void Update(Rect pAnchorTo, Vector2 pMousePosition, GameObject pObject) { if (_window == null) { _window = ScriptableObject.CreateInstance <TeneDropTarget>(); } _window.ShowPopup(); _window._close = false; _window._repositioned = false; //_window._anchoredTo = pAnchorTo; _window.HadMouseOver = false; #if (UNITY_5 || UNITY_5_3_OR_NEWER) && !UNITY_5_0 _window.titleContent = new GUIContent(pObject.name); #else _window.title = pObject.name; #endif _window.SetTarget(pObject); _window.SetPosition(pAnchorTo, pMousePosition); }
private void Draw(int pInstanceID, Rect pDrawingRect) { // called per-line in the hierarchy window GameObject gameObject = EditorUtility.InstanceIDToObject(pInstanceID) as GameObject; if (gameObject == null) { return; } bool currentLock = (gameObject.hideFlags & HideFlags.NotEditable) != 0; bool doPreview = _setting_showHoverPreview && (!_setting_showHoverPreviewShift || (Event.current.modifiers & EventModifiers.Shift) != 0) && (!_setting_showHoverPreviewCtrl || (Event.current.modifiers & EventModifiers.Control) != 0) && (!_setting_showHoverPreviewAlt || (Event.current.modifiers & EventModifiers.Alt) != 0); bool doTooltip = _setting_showHoverTooltip && (!_setting_showHoverTooltipShift || (Event.current.modifiers & EventModifiers.Shift) != 0) && (!_setting_showHoverTooltipCtrl || (Event.current.modifiers & EventModifiers.Control) != 0) && (!_setting_showHoverTooltipAlt || (Event.current.modifiers & EventModifiers.Alt) != 0); bool doComponents = _setting_showComponents && (!_setting_showComponentsShift || (Event.current.modifiers & EventModifiers.Shift) != 0) && (!_setting_showComponentsCtrl || (Event.current.modifiers & EventModifiers.Control) != 0) && (!_setting_showComponentsAlt || (Event.current.modifiers & EventModifiers.Alt) != 0); bool doLockIcon = _setting_showLock && (!_setting_showLockShift || (Event.current.modifiers & EventModifiers.Shift) != 0) && (!_setting_showLockCtrl || (Event.current.modifiers & EventModifiers.Control) != 0) && (!_setting_showLockAlt || (Event.current.modifiers & EventModifiers.Alt) != 0); doLockIcon |= _setting_showLock && _setting_showLockLocked && currentLock; string tooltip = ""; Color originalColor = GUI.color; if (doLockIcon) { Rect r = pDrawingRect; r.x = r.x + r.width - 14; r.width = 12; GUI.color = currentLock ? new Color(1, 1, 1, 1) : new Color(1, 1, 1, 0.4f); bool newLock = GUI.Toggle(r, currentLock, "", (GUIStyle)"IN LockButton"); if (newLock != currentLock) { if (newLock) { gameObject.hideFlags |= HideFlags.NotEditable; } else { gameObject.hideFlags -= HideFlags.NotEditable; } } pDrawingRect.width -= 14; } float width = EditorStyles.label.CalcSize(new GUIContent(gameObject.name)).x; if (((1 << gameObject.layer) & Tools.visibleLayers) == 0) { Rect labelRect = pDrawingRect; labelRect.width = width; labelRect.x -= 2; labelRect.y -= 4; GUI.Label(labelRect, "".PadRight(gameObject.name.Length, '_')); } if (doTooltip) { tooltip = GetTooltip(gameObject); if (tooltip.Length > 0) { GUI.Label(pDrawingRect, new GUIContent(" ", tooltip)); } } if (doComponents) { Rect iconRect = pDrawingRect; iconRect.x = pDrawingRect.x + pDrawingRect.width - 16; iconRect.y--; iconRect.width = 16; iconRect.height = 16; _mousePosition = new Vector2(Event.current.mousePosition.x + Common.HierarchyWindow.position.x, Event.current.mousePosition.y + Common.HierarchyWindow.position.y); bool mouseIn = pDrawingRect.Contains(Event.current.mousePosition); if (doPreview && mouseIn) { _hoverObject = gameObject; } Object dragging = DragAndDrop.objectReferences.Length == 1 ? DragAndDrop.objectReferences[0] : null; if (DragAndDrop.objectReferences.Length == 1 && _setting_showHoverDropWindow && mouseIn) { if (_draggingHeldOver == null) { _draggingHeldStart = System.DateTime.Now; } if (_draggingHeldOver != gameObject) { _draggingShownQuickInspector = false; } _draggingHeldOver = gameObject; } bool suitableDrop = false; bool drawnEtc = false; foreach (Component c in gameObject.GetComponents <Component>()) { if (c is Transform) { continue; } if (c != null && !suitableDrop && dragging != null) { Type type = c.GetType(); foreach (FieldInfo f in TeneDropTarget.FieldsFor(type)) { if (TeneDropTarget.IsCompatibleField(f, dragging)) { suitableDrop = true; break; } } } if (c == null) { Rect rectX = new Rect(iconRect.x + 4, iconRect.y + 1, 14, iconRect.height); GUI.color = new Color(1.0f, 0.35f, 0.35f, 1.0f); GUI.Label(rectX, new GUIContent("X", "Missing Script"), Common.ColorLabel(new Color(1.0f, 0.35f, 0.35f, 1.0f))); iconRect.x -= 9; if (rectX.Contains(Event.current.mousePosition)) { _hoverObject = null; } continue; } GUI.color = c.GetEnabled() ? Color.white : new Color(0.5f, 0.5f, 0.5f, 0.5f); if (iconRect.x < pDrawingRect.x + width) { if (!drawnEtc) { GUI.Label(iconRect, " .."); drawnEtc = true; } continue; } if (doTooltip) { tooltip = GetTooltip(c); } Texture iconTexture = null; if (c is MonoBehaviour) { MonoScript ms = MonoScript.FromMonoBehaviour(c as MonoBehaviour); iconTexture = AssetDatabase.GetCachedIcon(AssetDatabase.GetAssetPath(ms)); } if (iconTexture == null) { iconTexture = Common.GetMiniThumbnail(c); } if (iconTexture != null) { if (doPreview) { if (iconRect.Contains(Event.current.mousePosition)) { _hoverObject = c; } } GUI.DrawTexture(iconRect, iconTexture, ScaleMode.ScaleToFit); if (GUI.Button(iconRect, new GUIContent("", tooltip), EditorStyles.label)) { c.SetEnabled(!c.GetEnabled()); Common.HierarchyWindow.Repaint(); return; } iconRect.x -= iconRect.width; } } if (suitableDrop) { Rect labelRect = pDrawingRect; labelRect.width = width; labelRect.x -= 2; labelRect.y += 1; GUI.color = Color.white; GUI.DrawTexture(new Rect(labelRect.x, labelRect.y, labelRect.width, 1), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(labelRect.x, labelRect.y, 1, labelRect.height), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(labelRect.x, labelRect.yMax, labelRect.width, 1), EditorGUIUtility.whiteTexture); GUI.DrawTexture(new Rect(labelRect.xMax, labelRect.y, 1, labelRect.height), EditorGUIUtility.whiteTexture); if (mouseIn) { DragAndDrop.visualMode = DragAndDropVisualMode.Generic; } } } GUI.color = originalColor; }
private void Update() { bool nowDragging = DragAndDrop.objectReferences.Length == 1; if (_wasDragging != nowDragging) { // detect when dragging state changes, so we force a refresh of the hierarchy _wasDragging = nowDragging; if (!nowDragging) { _draggingHeldOver = null; _draggingShownQuickInspector = false; } // doesn't appear to refresh when starting to drag stuff // but works ok when finishing Common.HierarchyWindow.Repaint(); } if (_lastHoverObject != null || _hoverObject != null) { if (_lastHoverObject != _hoverObject) { // don't currently support plain old gameobjects if (_hoverObject is GameObject) { if (PrefabUtility.GetPrefabParent(_hoverObject) == null) { _hoverObject = null; } } } if (_lastHoverObject != _hoverObject) { _lastHoverObject = _hoverObject; TeneEnhPreviewWindow.Update( Common.HierarchyWindow.position, _mousePosition, pAsset: _hoverObject ); } else { _updateThrottle++; if (_updateThrottle > 20) { _hoverObject = null; Common.HierarchyWindow.Repaint(); _updateThrottle = 0; } } } if (_draggingHeldOver != null) { if (!_draggingShownQuickInspector) { if ((System.DateTime.Now - _draggingHeldStart).TotalSeconds >= 0.5f) { // user held mouse over a game object, so we can show the // quick-drop popup window TeneDropTarget.Update( Common.HierarchyWindow.position, _mousePosition, _draggingHeldOver ); _draggingShownQuickInspector = true; } } } }