Example #1
0
        internal static void DrawHint(Rect hintTriggerRect, Vector2 mousePosition, AssetReference assetReference)
        {
            if (!hintTriggerRect.Contains(mousePosition) || !GUIClip.visibleRect.Contains(mousePosition))
            {
                return;
            }

            string assetPath = AssetDatabase.GUIDToAssetPath(assetReference.guid);
            var    assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);

            if (assetType == null) //this means the object or its base script has been deleted and is "Missing"
            {
                return;
            }

            var hintGenerators = TypeCache.GetMethodsWithAttribute <DynamicHintGeneratorAttribute>();

            if (assetType.IsSubclassOf(typeof(ScriptableObject)))
            {
                DynamicHintContent hint = GetDynamicHintContentOf(hintGenerators, assetType, assetPath);
                if (hint != null)
                {
                    DrawMouseTooltip(hint, hintTriggerRect);
                }
                return;
            }

            if (assetType == typeof(GameObject))
            {
                /* GameObjects can have multiple components with custom tooltips
                 * so for now we'll just display the first one.
                 * If needed, we could:
                 * 1) Implement a "priority system" (like OrderedCallbacks)
                 * 2) Display one big tooltip made up with all elements from custom tooltip
                 */

                GameObject assetGameObject = (GetLoadedObjectFromInstanceID(assetReference.instanceID) as GameObject);
                if (!assetGameObject)
                {
                    /* this seems to happen non-deterministically at project startup depending of what the user is hovering when the editor opens,
                     * or while the user is scrolling a list of objects and hovers one of them casually, even if the object hovered is actually a
                     * GameObject.
                     * */
                    return;
                }

                foreach (var component in assetGameObject.GetComponents <Component>())
                {
                    if (component == null)
                    {
                        continue;
                    }                                    //this means its script has been deleted and is "Missing"

                    DynamicHintContent hint = GetDynamicHintContentOf(hintGenerators, component.GetType(), string.Empty, component);
                    if (hint == null)
                    {
                        continue;
                    }

                    DrawMouseTooltip(hint, hintTriggerRect);
                    return;
                }
            }
        }
Example #2
0
 protected Dictionary <Type, string> GetAvailableWindowTypes()
 {
     return(m_AvailableWindowTypes ?? (m_AvailableWindowTypes = TypeCache.GetTypesDerivedFrom(typeof(PlayModeView)).OrderBy(GetWindowTitle).ToDictionary(t => t, GetWindowTitle)));
 }