Пример #1
0
 public void sendEvent(TrackingEvent trackingEvent, CustomData customData = null, string section = null, int[] coordinates = null)
 {
     //logMessage("RedMetricsManager::sendEvent");
     if (Application.isWebPlayer)
     {
         TrackingEventDataWithoutIDs data = new TrackingEventDataWithoutIDs(trackingEvent, customData, section, coordinates);
         string json = getJsonString(data);
         //logMessage("RedMetricsManager::sendEvent isWebPlayer will rmPostEvent json="+json);
         Application.ExternalCall("rmPostEvent", json);
     }
     else
     {
         //logMessage("RedMetricsManager::sendEvent non web player");
         //TODO wait on playerID using an IEnumerator
         if (!string.IsNullOrEmpty(playerID))
         {
             TrackingEventDataWithIDs data = new TrackingEventDataWithIDs(playerID, gameVersion, trackingEvent, customData, section, coordinates);
             string json = getJsonString(data);
             //logMessage("RedMetricsManager::sendEvent player already identified - pID="+playerID);
             sendDataStandalone(redMetricsEvent, json, value => wwwLogger(value, "sendEvent(" + trackingEvent + ")"));
         }
         else
         {
             logMessage("RedMetricsManager::sendEvent no registered player!", MessageLevel.ERROR);
         }
     }
 }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        CustomData customData = new CustomData();

        customData.Add("customKey1", "customValue1");
        customData.Add("customKey2", "customValue2");

        int[] coordinates = { 1, 2, 3 };

        TrackingEventData data = new TrackingEventDataWithoutIDs(
            TrackingEvent.START,
            customData,
            "map1.level1.section1",
            coordinates
            );

        //*
        JsonWriter writer = new JsonWriter();

        writer.PrettyPrint = true;

        JsonMapper.ToJson(data, writer);

        string json = writer.ToString();

        Debug.Log("obj=" + data);
        Debug.Log("serialized=" + json);

        TrackingEventData deserializedData = JsonMapper.ToObject <TrackingEventData>(json);

        /*/
         *
         * // If you don't need a JsonWriter, use this.
         * string json = JsonMapper.ToJson(exampleClass);
         *
         * //*/

        Debug.Log("deserialized:" + deserializedData);
    }
Пример #3
0
    public void sendEvent(TrackingEvent trackingEvent, CustomData customData = null, string section = null, int[] coordinates = null, string userTime = null)
    {
        string checkedSection = section;

        //TODO remove dependency to Hero class
        if (string.IsNullOrEmpty(section) && (null != Hero.get()))
        {
            checkedSection = Hero.get().getLastCheckpointName();
        }

        int[] checkedCoordinates = null;
        if (null != coordinates)
        {
            checkedCoordinates = new int[coordinates.Length];
            for (int i = 0; i < coordinates.Length; i++)
            {
                checkedCoordinates [i] = coordinates [i];
            }
        }
        else
        {
            if (null != Hero.get())
            {
                Vector3 position = Hero.get().gameObject.transform.position;
                checkedCoordinates = new int[2] {
                    Mathf.FloorToInt(position.x),
                    Mathf.FloorToInt(position.z)
                };
            }
        }

        //logMessage(MessageLevel.DEFAULT, "RedMetricsManager::sendEvent({0})", trackingEvent.ToString());
        if (Application.isWebPlayer)
        {
            TrackingEventDataWithoutIDs data = new TrackingEventDataWithoutIDs(trackingEvent, customData, checkedSection, checkedCoordinates, userTime);
            if (isGameSessionGUIDCreated)
            {
                string json = getJsonString(data);
                Application.ExternalCall("rmPostEvent", json);
            }
            else
            {
                addEventToSendLater(data);
                //TODO: what if connection fails, or even fails permanently? Should retry connection at different intervals
            }
        }
        else
        {
            //TODO wait on gameSessionGUID using an IEnumerator
            if (defaultGameSessionGUID != gameSessionGUID)
            {
            }
            else
            {
                logMessage(MessageLevel.ERROR, "sendEvent default player guid: no registered player!");
            }

            TrackingEventDataWithIDs data = new TrackingEventDataWithIDs(gameSessionGUID, gameVersionGuid, trackingEvent, customData, checkedSection, checkedCoordinates);
            string json = getJsonString(data);
            //logMessage (MessageLevel.DEFAULT, string.Format ("RedMetricsManager::sendEvent - gameSessionGUID={0}, gameVersionGuid={1}, json={2}", gameSessionGUID, gameVersionGuid, json));
            sendDataStandalone(redMetricsEvent, json, value => wwwLogger(value, "sendEvent(" + trackingEvent + ")"));
            //TODO pass data as parameter to sendDataStandalone so that it's serialized inside
        }
    }
Пример #4
0
 public void sendEvent(TrackingEventDataWithoutIDs data)
 {
     sendEvent(data.getTrackingEvent(), data.customData, data.section, data.coordinates, data.userTime);
 }
Пример #5
0
 private void addEventToSendLater(TrackingEventDataWithoutIDs data)
 {
     waitingList.AddLast(data);
 }
Пример #6
0
 public void sendEvent(TrackingEvent trackingEvent, CustomData customData = null, string section = null, int[] coordinates = null)
 {
     //logMessage("RedMetricsManager::sendEvent");
     if(Application.isWebPlayer) {
         TrackingEventDataWithoutIDs data = new TrackingEventDataWithoutIDs(trackingEvent, customData, section, coordinates);
         string json = getJsonString(data);
         //logMessage("RedMetricsManager::sendEvent isWebPlayer will rmPostEvent json="+json);
         Application.ExternalCall("rmPostEvent", json);
     } else {
         //logMessage("RedMetricsManager::sendEvent non web player");
         //TODO wait on playerID using an IEnumerator
         if(!string.IsNullOrEmpty(playerID))
         {
             TrackingEventDataWithIDs data = new TrackingEventDataWithIDs(playerID, gameVersion, trackingEvent, customData, section, coordinates);
             string json = getJsonString(data);
             //logMessage("RedMetricsManager::sendEvent player already identified - pID="+playerID);
             sendDataStandalone(redMetricsEvent, json, value => wwwLogger(value, "sendEvent("+trackingEvent+")"));
         } else {
             logMessage("RedMetricsManager::sendEvent no registered player!", MessageLevel.ERROR);
         }
     }
 }
Пример #7
0
    public void sendEvent (TrackingEvent trackingEvent, CustomData customData = null, string section = null, int[] coordinates = null, string userTime = null)
    {
        string checkedSection = section;

        //TODO remove dependency to Hero class
        if (string.IsNullOrEmpty (section) && (null != Hero.get ())) {
            checkedSection = Hero.get ().getLastCheckpointName ();
        }

        int[] checkedCoordinates = null;
        if (null != coordinates) {
            checkedCoordinates = new int[coordinates.Length];
            for (int i = 0; i < coordinates.Length; i++) {
                checkedCoordinates [i] = coordinates [i];
            }
        } else {
            if (null != Hero.get ()) {
                Vector3 position = Hero.get ().gameObject.transform.position;
                checkedCoordinates = new int[2] {
                    Mathf.FloorToInt (position.x),
                    Mathf.FloorToInt (position.z)
                };
            }
        }
             
        //logMessage(MessageLevel.DEFAULT, "RedMetricsManager::sendEvent({0})", trackingEvent.ToString());
        if (Application.isWebPlayer) {
            TrackingEventDataWithoutIDs data = new TrackingEventDataWithoutIDs (trackingEvent, customData, checkedSection, checkedCoordinates, userTime);   
            if(isGameSessionGUIDCreated) {
                string json = getJsonString (data);
                Application.ExternalCall ("rmPostEvent", json);
            } else {
                addEventToSendLater(data);
                //TODO: what if connection fails, or even fails permanently? Should retry connection at different intervals
            }
        } else {
            //TODO wait on gameSessionGUID using an IEnumerator
            if (defaultGameSessionGUID != gameSessionGUID) {
            } else {
                logMessage (MessageLevel.ERROR, "sendEvent default player guid: no registered player!");
            }

            TrackingEventDataWithIDs data = new TrackingEventDataWithIDs (gameSessionGUID, gameVersionGuid, trackingEvent, customData, checkedSection, checkedCoordinates);
            string json = getJsonString (data);
            //logMessage (MessageLevel.DEFAULT, string.Format ("RedMetricsManager::sendEvent - gameSessionGUID={0}, gameVersionGuid={1}, json={2}", gameSessionGUID, gameVersionGuid, json));
            sendDataStandalone (redMetricsEvent, json, value => wwwLogger (value, "sendEvent(" + trackingEvent + ")"));
            //TODO pass data as parameter to sendDataStandalone so that it's serialized inside
        }
    }
Пример #8
0
 public void sendEvent( TrackingEventDataWithoutIDs data) {
     sendEvent(data.getTrackingEvent(), data.customData, data.section, data.coordinates, data.userTime);
 }
Пример #9
0
 private void addEventToSendLater(TrackingEventDataWithoutIDs data) {
     waitingList.AddLast(data);
 }