Ejemplo n.º 1
0
 public static void Initialize(this GameSenseConfig config)
 {
     GameSense.Initialize(config.GameName, config.DisplayGameName, config.Developer, config.IconColor);
     foreach (var e in config.Events)
     {
         var handlers = e.Handlers.Select(s => s.text).ToArray();
         GameSense.BindEvent(e.Name, e.MinValue, e.MaxValue, e.Icon, handlers);
     }
 }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        var config = ((GameSenseInit)target).Config;

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Editor event test", EditorStyles.boldLabel);

        using (new EditorGUI.DisabledScope(true))
        {
            EditorGUILayout.TextField("Active game", GameSense.GameName);
        }

        int index = Array.FindIndex(config.Events, s => s.Name == m_event);

        EditorGUI.BeginChangeCheck();
        index = EditorGUILayout.Popup("Event", index, config.Events.Select(s => s.Name).ToArray());
        if (EditorGUI.EndChangeCheck())
        {
            m_event = index >= 0 ? config.Events[index].Name : string.Empty;
        }

        var evnt = index >= 0 ? config.Events[index] : default;

        using (new EditorGUI.DisabledScope(index < 0))
        {
            EditorGUI.BeginChangeCheck();
            int newValue = EditorGUILayout.IntSlider("Event data", m_value, evnt.MinValue, evnt.MaxValue);
            if (EditorGUI.EndChangeCheck() && m_value != newValue)
            {
                m_value = newValue;
                GameSense.SendEvent(evnt.Name, m_value);
            }
        }

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Init"))
        {
            config.Initialize();
        }
        if (GUILayout.Button("Release"))
        {
            GameSense.Release();
        }
        if (GUILayout.Button("Reset"))
        {
            using (var client = new GameSenseClient())
            {
                client.RemoveGame(config.GameName);
            }
        }
        EditorGUILayout.EndHorizontal();
    }