Example #1
0
    void Awake()
    {
        // Prevent multiple instances of Lumos from existing.
        // Necessary because DontDestroyOnLoad keeps the object between scenes.
        if (instance != null)
        {
            LumosUnity.Debug.Log("Destroying duplicate game object instance.");
            Destroy(gameObject);
            return;
        }

        credentials = LumosCredentials.Load();

        if (credentials == null || credentials.apiKey == null || credentials.apiKey == "")
        {
            LumosUnity.Debug.LogError("The Lumos API key is not set. Do this in the Lumos pane in Unity's preferences.", true);
            Destroy(gameObject);
            return;
        }

        instance = this;

        // Shorten the timer interval while developers are testing
        if (runWhileInEditor && Application.isEditor)
        {
            timerInterval = 3;
        }

        DontDestroyOnLoad(this);
    }
Example #2
0
    /// <summary>
    /// Sets up Lumos.
    /// </summary>
    void Awake()
    {
        // Prevent multiple instances of Lumos from existing.
        // Necessary because DontDestroyOnLoad keeps the object between scenes.
        if (instance != null)
        {
            Lumos.Log("Destroying duplicate game object instance.");
            Destroy(gameObject);
            return;
        }

        instance = this;
        DontDestroyOnLoad(this);
        appId = secretKey.Split('-')[0];

        if (appId == null || appId == "")
        {
            Lumos.Remove("Secret key not set.");
            return;
        }

        if (recordPresetEvents)
        {
            gameObject.AddComponent <LumosEvents>();
        }

        // Set up debug log redirect.
        Application.RegisterLogCallback(LumosLogs.Record);
    }
Example #3
0
    /// <summary>
    /// Sends data to Lumos' servers.
    /// </summary>
    /// <param name="successCallback">Callback to run on successful response.</param>
    /// <param name="errorCallback">Callback to run on failed response.</param>
    static IEnumerator SendCoroutine(string method, Dictionary <string, object> parameters, SuccessHandler successCallback, ErrorHandler errorCallback)
    {
        if (Application.isEditor && !Lumos.instance.runInEditor)
        {
            yield break;
        }

        // Skip out early if there's no internet connection
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            if (errorCallback != null)
            {
                errorCallback();
            }

            yield break;
        }

        // Generate request
        parameters.Add("app_id", Lumos.appId);
        var json = LumosUtil.Json.Serialize(parameters);
        //var json = LitJson.JsonMapper.ToJson(parameters);
        var postData = Encoding.ASCII.GetBytes(json);
        var www      = new WWW(url + method, postData, headers);

        // Send info to server
        yield return(www);

        Lumos.Log("Request: " + json);
        Lumos.Log("Response: " + www.text);

        // Parse the response
        try {
            if (www.error != null)
            {
                throw new Exception(www.error);
            }

            var response = LumosUtil.Json.Deserialize(www.text) as IDictionary;

            // Display returned info if there is any
            if (response.Count != 0 && response.Contains("result"))
            {
                var result = response["result"];
                Lumos.Log("Success: " + result);
            }

            if (successCallback != null)
            {
                successCallback();
            }
        } catch (Exception e) {
            Lumos.LogError("Failure: " + e.Message);

            if (errorCallback != null)
            {
                errorCallback();
            }
        }
    }
    /// <summary>
    /// Sends system information.
    /// </summary>
    public static void Record()
    {
        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            Lumos.LogWarning("Apple's ToS prevents device data from being sent on iOS");
            return;
        }

        var parameters = new Dictionary <string, object>()
        {
            { "player_id", Lumos.playerId },
            { "operating_system", SystemInfo.operatingSystem },
            { "processor_type", SystemInfo.processorType },
            { "processor_count", SystemInfo.processorCount },
            { "system_memory_size", SystemInfo.systemMemorySize },
            { "graphics_memory_size", SystemInfo.graphicsMemorySize },
            { "graphics_device_name", SystemInfo.graphicsDeviceName },
            { "graphics_device_vendor", SystemInfo.graphicsDeviceVendor },
            { "graphics_device_id", SystemInfo.graphicsDeviceID },
            { "graphics_device_vendor_id", SystemInfo.graphicsDeviceVendorID },
            { "graphics_device_version", SystemInfo.graphicsDeviceVersion },
            { "graphics_shader_level", SystemInfo.graphicsShaderLevel },
            { "graphics_pixel_fillrate", SystemInfo.graphicsPixelFillrate },
            { "supports_shadows", SystemInfo.supportsShadows },
            { "supports_render_textures", SystemInfo.supportsRenderTextures },
            { "supports_image_effects", SystemInfo.supportsImageEffects }
        };

        LumosWWW.Send("system-info.record", parameters);
    }
Example #5
0
    /// <summary>
    /// Records an event.
    /// </summary>
    /// <param name="name">The name of the event.</param>
    /// <param name="value">An arbitrary value to send with the event.</param>
    /// <param name="repeatable">Whether this event should only be logged once per player.</param>
    public static void Record(string name, float?value, bool repeatable)
    {
        if (name == null || name == "")
        {
            Lumos.LogWarning("Name must be sent. Event not recorded.");
            return;
        }

        // If the event should only be logged a maximum of one time, ensure it hasn't been recorded before
        if (!repeatable)
        {
            if (RecordedUnique(name))
            {
                return;
            }

            unsentUniqueEvents.Add(name);
        }

        var parameters = new Dictionary <string, object>()
        {
            { "name", name },
            { "level", Application.loadedLevelName },
        };

        if (value.HasValue)
        {
            //parameters.Add("value", value.Value);
            parameters.Add("value_str", value.Value.ToString());
        }

        events.Add(parameters);
    }
Example #6
0
    /// <summary>
    /// Executes a coroutine.
    /// </summary>
    /// <param name="routine">The coroutine to execute.</param>
    public static Coroutine RunRoutine(IEnumerator routine)
    {
        if (instance == null)
        {
            Lumos.LogError("Lumos game object must be instantiated " +
                           "before its methods can be called.");
            return(null);
        }

        return(instance.StartCoroutine(routine));
    }
Example #7
0
    /// <summary>
    /// Sends queued data on an interval.
    /// </summary>
    static IEnumerator SendQueuedData()
    {
        yield return(new WaitForSeconds(timerInterval));

        if (!timerPaused && OnTimerFinish != null)
        {
            // Notify subscribers that the timer has completed.
            OnTimerFinish();
        }

        Lumos.RunRoutine(SendQueuedData());
    }
Example #8
0
    /// <summary>
    /// Extra setup that needs to occur after Awake.
    /// </summary>
    void Start()
    {
        if (hasPlayer)
        {
            Lumos.Log("Using existing player " + playerId);
            LumosApp.Ping();
        }
        else
        {
            playerId = LumosUtil.GeneratePlayerId();
            Lumos.Log("Using new player " + playerId);
            LumosApp.Ping(true);
        }

        RunRoutine(SendQueuedRoutine());
    }
Example #9
0
    /// <summary>
    /// Sends the queued logs to the server.
    /// </summary>
    public static void Send()
    {
        if (logs.Count == 0)
        {
            return;
        }

        var parameters = new Dictionary <string, object>()
        {
            { "logs", logs }
        };

        LumosWWW.Send("logs.record", parameters,
                      delegate {   // Success
            logs.Clear();
        },
                      delegate {   // Error
            Lumos.LogWarning("Log messages not sent. Will try again at next timer interval.");
        });
    }
    /// <summary>
    /// Records an event.
    /// </summary>
    /// <param name="name">The name of the event.</param>
    /// <param name="value">An arbitrary value to send with the event.</param>
    /// <param name="repeatable">
    /// Whether this event should only be logged once.
    /// </param>
    public static void Record(string name, float?value, bool repeatable)
    {
        if (!Lumos.servicesAvailable.Contains(Lumos.service.Events))
        {
            return;
        }

        if (name == null || name == "")
        {
            Lumos.LogWarning("Name must be sent. Event not recorded.");
            return;
        }

        // Ensure unrepeatable event hasn't been logged before.
        if (!repeatable)
        {
            if (RecordedUnique(name))
            {
                return;
            }

            unsentUniqueEvents.Add(name);
        }

        var parameters = new Dictionary <string, object>()
        {
            { "name", name },
            { "level", Application.loadedLevelName },
        };

        if (value.HasValue)
        {
            //parameters.Add("value", value.Value);
            parameters.Add("value_str", value.Value.ToString());
        }

        events.Add(parameters);
    }
Example #11
0
 void OnLevelWasLoaded()
 {
     Lumos.Event("Level Completion Time", Time.time - levelStartTime);
     levelStartTime = Time.time;
     Lumos.Event("Level Started", false);
 }
Example #12
0
 void Awake()
 {
     levelStartTime = Time.time;
     Lumos.Event("Level Started", false);
 }
Example #13
0
 /// <summary>
 /// Sends data to Lumos' servers.
 /// </summary>
 /// <param name="powerup">The powerup instance.</param>
 /// <param name="endpoint">The URL endpoint.</param>
 /// <param name="method">The HTTP method to use.</param>
 /// <param name="parameters">Data to send.</param>
 /// <param name="successCallback">Callback to run on successful response.</param>
 /// <param name="errorCallback">Callback to run on failed response.</param>
 public static Coroutine Send(ILumosPowerup powerup, string endpoint, Method method, object parameters, Action <object> successCallback, Action <object> errorCallback)
 {
     return(Lumos.RunRoutine(SendCoroutine(powerup, endpoint, method, parameters, successCallback, errorCallback)));
 }
Example #14
0
    // With parameters:

    /// <summary>
    /// Sends data to Lumos' servers.
    /// </summary>
    /// <param name="powerup">The powerup instance.</param>
    /// <param name="endpoint">The URL endpoint.</param>
    /// <param name="method">The HTTP method to use.</param>
    /// <param name="parameters">Data to send.</param>
    public static Coroutine Send(ILumosPowerup powerup, string endpoint, Method method, object parameters)
    {
        return(Lumos.RunRoutine(SendCoroutine(powerup, endpoint, method, parameters, null, null)));
    }
Example #15
0
 /// <summary>
 /// Sends data to Lumos' servers.
 /// </summary>
 /// <param name="powerup">The powerup instance.</param>
 /// <param name="endpoint">The URL endpoint.</param>
 /// <param name="method">The HTTP method to use.</param>
 public static Coroutine Send(ILumosPowerup powerup, string endpoint, Method method, Action <object> successCallback)
 {
     return(Lumos.RunRoutine(SendCoroutine(powerup, endpoint, method, null, successCallback, null)));
 }
Example #16
0
 /// <summary>
 /// Loads a remote image into a texture.
 /// </summary>
 /// <param name="imageLocation">The URL the image resides at.</param>
 /// <param name="texture">The URL the image resides at.</param>
 public static Coroutine LoadImage(string imageLocation, Texture2D texture)
 {
     return(Lumos.RunRoutine(LoadImageCoroutine(imageLocation, texture)));
 }
 public void Ranged(string level, string activity, int val)
 {
     //Playtomic.Log.LevelRangedMetric(activity, level, val);
     Lumos.Event(string.Format("{0}-{1}", level, activity), val);
     //Debug.LogError(string.Format("Ranged: {0}, {1} = {2}", level, activity, val));
 }
Example #18
0
 /// <summary>
 /// Sends data to Lumos' servers.
 /// </summary>
 public static Coroutine Send(string method, Dictionary <string, object> parameters)
 {
     return(Lumos.RunRoutine(SendCoroutine(method, parameters, null, null)));
 }
Example #19
0
	void Awake ()
	{
		// Prevent multiple instances of Lumos from existing.
		// Necessary because DontDestroyOnLoad keeps the object between scenes.
		if (instance != null) {
			LumosUnity.Debug.Log("Destroying duplicate game object instance.");
			Destroy(gameObject);
			return;
		}

		credentials = LumosCredentials.Load();

		if (credentials == null || credentials.apiKey == null || credentials.apiKey == "") {
			LumosUnity.Debug.LogError("The Lumos API key is not set. Do this in the Lumos pane in Unity's preferences.", true);
			Destroy(gameObject);
			return;
		}

		instance = this;

		// Shorten the timer interval while developers are testing
		if (runWhileInEditor && Application.isEditor) {
			timerInterval = 3;
		}

		DontDestroyOnLoad(this);
	}
Example #20
0
 /// <summary>
 /// Sends data to Lumos' servers.
 /// </summary>
 /// <param name="successCallback">Callback to run on successful response.</param>
 /// <param name="errorCallback">Callback to run on failed response.</param>
 public static Coroutine Send(string method, Dictionary <string, object> parameters, SuccessHandler successCallback, ErrorHandler errorCallback)
 {
     return(Lumos.RunRoutine(SendCoroutine(method, parameters, successCallback, errorCallback)));
 }
    /// <summary>
    /// Notifies the server that the player is playing.
    /// </summary>
    /// <param name="sendPlayerInfo">Whether to send player info.</param>
    public static void Ping(bool sendPlayerInfo)
    {
        var parameters = new Dictionary <string, object>()
        {
            { "player_id", Lumos.playerId },
            { "lumos_version", Lumos.version.ToString() }
        };

        if (sendPlayerInfo)
        {
            // Attach extra information about the player.
            var playerInfo = new Dictionary <string, object>()
            {
                { "language", Application.systemLanguage.ToString() }
            };

            // Report the domain if the game is deployed on the web.
            if (Application.isWebPlayer)
            {
                playerInfo.Add("domain", Application.absoluteURL);
            }

            parameters.Add("player_info", playerInfo);
        }

        LumosWWW.Send("app.ping", parameters, delegate {
            // Parse which services are available.
            var response = LumosWWW.lastResponse;

            if (!response.Contains("services_available"))
            {
                Lumos.Remove("Available services unknown.");
                return;
            }

            var servicesAvailable = response["services_available"] as IList;

            if (servicesAvailable.Contains("none"))
            {
                Lumos.Remove("No services available. " +
                             "The game is either over quota or nonexistant.");
                return;
            }

            foreach (string service in servicesAvailable)
            {
                if (service == "system-info")
                {
                    Lumos.servicesAvailable.Add(Lumos.service.SystemInfo);
                }
                else if (service == "events")
                {
                    Lumos.servicesAvailable.Add(Lumos.service.Events);
                }
                else if (service == "logs")
                {
                    Lumos.servicesAvailable.Add(Lumos.service.Logs);
                }
                else if (service == "feedback")
                {
                    Lumos.servicesAvailable.Add(Lumos.service.Feedback);
                }
                else if (service == "realtime")
                {
                    Lumos.servicesAvailable.Add(Lumos.service.Realtime);
                }
            }

            if (sendPlayerInfo)
            {
                LumosSystemInfo.Record();
            }
        });
    }
    // Playtomic: https://playtomic.com/api/unity#Analytics
    // Lumos: http://www.uselumos.com/support/docs

    public void Counter(string level, string activity)
    {
        //Playtomic.Log.LevelCounterMetric(activity, level);
        Lumos.Event(string.Format("{0}-{1}", level, activity));
        //Debug.LogError(string.Format("Counter: {0}, {1}", level, activity));
    }