using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine.Serialization;
namespace UnityEngine.ResourceManagement.Diagnostics
{
///
/// Diagnostic event data.
///
[Serializable]
public struct DiagnosticEvent
{
[SerializeField]
string m_Graph; //id of graph definition to use
[SerializeField]
int[] m_Dependencies; //used to nest datagraphs
[SerializeField]
int m_ObjectId; //id of a set of data streams
[SerializeField]
string m_DisplayName;
[SerializeField]
int m_Stream; //data stream
[SerializeField]
int m_Frame; //frame of the event
[SerializeField]
int m_Value; //data value of event
///
/// Gets the graph id that this event is intended for
///
/// The graph Id
public string Graph { get { return m_Graph; } }
///
/// Unique object identifier for this event
///
public int ObjectId { get { return m_ObjectId; } }
///
/// Display name for event
///
public string DisplayName { get { return m_DisplayName; } }
///
/// Array of object identifiers that are dependencies for this event
///
public int[] Dependencies { get { return m_Dependencies; } }
///
/// The stream id for the event. Each graph may display multiple streams of data for the same event Id
///
/// Stream Id
public int Stream { get { return m_Stream; } }
///
/// The frame that the event occurred
///
/// Frame number
public int Frame { get { return m_Frame; } }
///
/// The value of the event. This value depends on the event type
///
/// Event value
public int Value { get { return m_Value; } }
///
/// DiagnosticEvent constructor
///
/// Graph id.
/// Event name.
/// Event id.
/// Stream index.
/// Frame number.
/// Event value.
/// Array of dependency event ids.
public DiagnosticEvent(string graph, string name, int id, int stream, int frame, int value, int[] deps)
{
m_Graph = graph;
m_DisplayName = name;
m_ObjectId = id;
m_Stream = stream;
m_Frame = frame;
m_Value = value;
m_Dependencies = deps;
}
///
/// Serializes the event into JSON and then encodes with System.Text.Encoding.ASCII.GetBytes
///
/// Byte array containing serialized version of the event
internal byte[] Serialize()
{
return Encoding.ASCII.GetBytes(JsonUtility.ToJson(this));
}
///
/// Deserializes event from a byte array created by the method
///
/// Deserialized DiagnosticEvent struct
/// Serialized data
public static DiagnosticEvent Deserialize(byte[] data)
{
return JsonUtility.FromJson(Encoding.ASCII.GetString(data));
}
}
}