コード例 #1
0
 public static void RegisterVisualizer(Type forType, ICustomVisualizer visualizer, bool registerDerivedTypes = false)
 {
     Ensure.ArgumentNotNull(visualizer, "visualizer");
     if (VisualizationManager._visualizerLookup == null)
     {
         VisualizationManager._visualizerLookup = new Dictionary <Type, ICustomVisualizer>();
     }
     if (!(forType.IsAbstract | registerDerivedTypes))
     {
         if (VisualizationManager._visualizerLookup.ContainsKey(forType))
         {
             Debug.LogWarning(string.Format("A visualizer for type {0} has already been registered, skipping {1}.", forType.Name, visualizer.GetType().Name));
             return;
         }
         VisualizationManager._visualizerLookup.Add(forType, visualizer);
     }
     else
     {
         foreach (Type derived in VisualizationManager.GetDerived(forType))
         {
             if (!VisualizationManager._visualizerLookup.ContainsKey(derived))
             {
                 VisualizationManager._visualizerLookup.Add(derived, visualizer);
             }
             else
             {
                 Debug.LogWarning(string.Format("A visualizer for type {0} has already been registered, skipping {1}.", derived.Name, visualizer.GetType().Name));
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Registers a custom visualizer.
        /// </summary>
        /// <param name="forType">The type visualized by the custom visualizer.</param>
        /// <param name="visualizer">The visualizer.</param>
        /// <param name="registerDerivedTypes">Whether to register the visualizer for all types derived from <paramref name="forType"/></param>
        public static void RegisterVisualizer(Type forType, ICustomVisualizer visualizer, bool registerDerivedTypes = false)
        {
            Ensure.ArgumentNotNull(visualizer, "visualizer");

            if (_visualizerLookup == null)
            {
                _visualizerLookup = new Dictionary <Type, ICustomVisualizer>();
            }

            if (forType.IsAbstract || registerDerivedTypes)
            {
                var types = GetDerived(forType);
                foreach (var t in types)
                {
                    if (_visualizerLookup.ContainsKey(t))
                    {
                        Debug.LogWarning(string.Format("A visualizer for type {0} has already been registered, skipping {1}.", t.Name, visualizer.GetType().Name));
                    }
                    else
                    {
                        _visualizerLookup.Add(t, visualizer);
                    }
                }
            }
            else
            {
                if (_visualizerLookup.ContainsKey(forType))
                {
                    Debug.LogWarning(string.Format("A visualizer for type {0} has already been registered, skipping {1}.", forType.Name, visualizer.GetType().Name));
                    return;
                }

                _visualizerLookup.Add(forType, visualizer);
            }
        }
コード例 #3
0
 internal static bool TryGetVisualizerFor(Type t, out ICustomVisualizer visualizer)
 {
     if (VisualizationManager._visualizerLookup == null)
     {
         visualizer = null;
         return(false);
     }
     return(VisualizationManager._visualizerLookup.TryGetValue(t, out visualizer));
 }
コード例 #4
0
 public static void RegisterVisualizer <TFor>(ICustomVisualizer visualizer, bool registerDerivedTypes = false)
 {
     VisualizationManager.RegisterVisualizer(typeof(TFor), visualizer, registerDerivedTypes);
 }