Esempio n. 1
0
        /// <summary>
        /// Send an event to all registered event handlers
        /// </summary>
        /// <param name="type">The event type.</param>
        /// <param name="context">The context of the event. If this is an IResourceLocation, information will be passed along in the event data field.</param>
        /// <param name="eventValue">The value of the event.</param>
        public static void PostEvent(EventType type, object context, int eventValue)
        {
            if (!DiagnosticEventCollector.ResourceManagerProfilerEventsEnabled)
            {
                return;
            }
            var parent = "";
            var id     = context.ToString();

            byte[] data = null;
            var    loc  = context as IResourceLocation;

            if (loc != null)
            {
                id = PrettyPath(loc.InternalId, false);
                var sb = new StringBuilder(256);
                sb.Append(loc.ProviderId.Substring(loc.ProviderId.LastIndexOf('.') + 1));
                sb.Append('!');
                sb.Append(loc.InternalId);
                sb.Append('!');
                if (loc.HasDependencies)
                {
                    parent = PrettyPath(loc.Dependencies[0].InternalId, false);
                    for (int i = 0; i < loc.Dependencies.Count; i++)
                    {
                        sb.Append(PrettyPath(loc.Dependencies[i].InternalId, true));
                        sb.Append(',');
                    }
                }
                data = Encoding.ASCII.GetBytes(sb.ToString());
            }
            var category = type >= EventType.DiagnosticEvents ? type.ToString() : EventCategory;

            DiagnosticEventCollector.PostEvent(new DiagnosticEvent(category, parent, id, (int)type, Time.frameCount, eventValue, data));
        }
Esempio n. 2
0
 /// <summary>
 /// Retrieves the global event collector.  A new one is created if needed.
 /// </summary>
 /// <returns>The event collector global instance.</returns>
 public static DiagnosticEventCollector FindOrCreateGlobalInstance()
 {
     if (s_Collector == null)
     {
         var go = new GameObject("EventCollector", typeof(DiagnosticEventCollector));
         s_Collector  = go.GetComponent <DiagnosticEventCollector>();
         go.hideFlags = HideFlags.DontSave;// HideFlags.HideAndDontSave;
     }
     return(s_Collector);
 }