示例#1
0
 //----------------------------------------------------------------------------------------------------------------
 private void stopReplay()
 {
     replayActive           = false;
     ctunity.lastSubmitTime = ctunity.ServerTime();                          // limit future replays to stopReplay time
     setStateText(liveLabel);
     slider.value = 1f;
 }
示例#2
0
    /// <summary>
    /// Create a CSV serialized version of the player information.
    /// </summary>
    /// <param name="ctunityI">Source of the information to be serialized.</param>
    /// <returns>Serialized player information.</returns>
    private static string serialize_csv(CTunity ctunityI)
    {
        // header line:
        string CTstateString = "#" + ctunityI.replayText + ":" + ctunityI.ServerTime().ToString() + ":" + ctunityI.Player + "\n";

        string delim       = ";";
        int    objectCount = 0;

        foreach (GameObject ct in ctunityI.CTlist.Values)
        {
            if (ct == null)
            {
                continue;
            }
            CTclient ctp = ct.GetComponent <CTclient>();
            if (ctp == null)
            {
                continue;
            }
            //			UnityEngine.Debug.Log("CTput: " + ct.name+", active: "+ct.activeSelf);

            String prefab = ctp.prefab;
            if (prefab.Equals("Ghost"))
            {
                continue;                                                                       // no save ghosts
            }
//			if (!ctunityI.replayActive && !ct.name.StartsWith(ctunityI.Player)) continue;  // only save locally owned objects
            if (!ctunityI.localPlayer(ct))
            {
                continue;                                                 // only save locally owned objects
            }
            CTstateString += ct.name;
            //            CTstateString += (delim + ct.tag);
            CTstateString += (delim + prefab);
            CTstateString += (delim + (ct.activeSelf ? "1" : "0"));
            CTstateString += (delim + ct.transform.localPosition.ToString("F4"));
            CTstateString += (delim + ct.transform.localRotation.eulerAngles.ToString("F4"));
            if (ctp.link != null && ctp.link.Length > 0)
            {
                CTstateString += (delim + ctp.link);
            }
            CTstateString += "\n";

            objectCount++;
        }

        if (objectCount == 0)
        {
            return(null);                           // no objects, don't bother
        }
        return(CTstateString);
    }
示例#3
0
    //----------------------------------------------------------------------------------------------------------------
    IEnumerator SaveJPG()
    {
        while (true)
        {
            yield return(new WaitForSeconds(ctunity.pollInterval));

            yield return(new WaitForEndOfFrame());

            if (ctunity.ctvideo == null)
            {
                continue;                                           // not ready to record
            }
//			saveActive = (!vidDisplay.showImage && !chartOptions.showMenu);			// no capture while menu or replay
//			saveActive = (!chartOptions.showMenu);			// notta

            if (VidCapMode)                             // enable based on video capture state
            // Create a texture the size of the screen, RGB24 format
            {
                width  = Screen.width;
                height = Screen.height;
                Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);

                // Read screen contents into the texture
                tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
                //		TextureScale.Bilinear(tex, width/2, height/2);		// scale smaller image
                tex.Apply();

                bytes = tex.EncodeToJPG(quality);
                Destroy(tex);
//				Debug.Log("save image!, vidcapmode:  " + VidCapMode);

                ctunity.ctvideo.setTime(ctunity.ServerTime());
                ctunity.ctvideo.putData("screen.jpg", bytes);   // let CTtrackset flush
                ctunity.ctvideo.flush();                        // todo: flush multiple per block
            }
        }
    }
示例#4
0
    /// <summary>
    /// Create a JSON serialized version of the player information.
    /// </summary>
    /// <param name="ctunityI">Source of the information to be serialized.</param>
    /// <returns>Serialized player information.</returns>
    private static string serialize_json(CTunity ctunityI)
    {
        CTworldJson world = new CTworldJson();

        world.player = ctunityI.Player;
        world.time   = ctunityI.ServerTime();
//		world.mode = ctunityI.replayText;
        world.objects = new List <CTobjectJson>();

        int objectCount = 0;

        foreach (GameObject ct in ctunityI.CTlist.Values)
        {
            if (!ctunityI.localPlayer(ct))
            {
                continue;                                                 // only save locally owned objects
            }
//			Debug.Log("CTserdes ct.name: " + fullName);

            if (ct == null)
            {
                continue;
            }
            CTclient ctp = ct.GetComponent <CTclient>();
            if (ctp == null)
            {
                continue;
            }
            String prefab = ctp.prefab;
            if (prefab.Equals("Ghost"))
            {
                continue;                                      // no save ghosts
            }
//			if (!ctunityI.replayActive && !ct.name.StartsWith(ctunityI.Player)) continue;  // only save locally owned objects
//			if (!ctunityI.doCTwrite(fullName)) continue;          // only save locally owned objects

            CTobjectJson obj = new CTobjectJson();
//			obj.id = ct.name;

            // strip leading world-name from embedded object name
            String fullName = CTunity.fullName(ct);
            if (fullName.StartsWith(world.player + "/"))
            {
                fullName = fullName.Remove(0, world.player.Length + 1);
            }
            //           Debug.Log("CTserdes obj.id: " + obj.id + ", world.player: " + world.player+", fullName: "+fullName);
            obj.id = fullName;

            obj.model = prefab;
//			obj.state = (ct.activeSelf ? true : false);
            // NOTE: limit floating point values to 4 decimal places
            obj.pos = new List <Double>();
            obj.pos.Add(LimitPrecision(ct.transform.localPosition.x, 4));                //  was .position
            obj.pos.Add(LimitPrecision(ct.transform.localPosition.y, 4));
            obj.pos.Add(LimitPrecision(ct.transform.localPosition.z, 4));
            obj.rot = new List <Double>();
            obj.rot.Add(LimitPrecision(ct.transform.localRotation.eulerAngles.x, 4));                // was .rotation
            obj.rot.Add(LimitPrecision(ct.transform.localRotation.eulerAngles.y, 4));
            obj.rot.Add(LimitPrecision(ct.transform.localRotation.eulerAngles.z, 4));
            obj.scale = new List <Double>();
            obj.scale.Add(LimitPrecision(ct.transform.localScale.x, 4));
            obj.scale.Add(LimitPrecision(ct.transform.localScale.y, 4));
            obj.scale.Add(LimitPrecision(ct.transform.localScale.z, 4));

            Renderer renderer = ct.transform.gameObject.GetComponent <Renderer>();
            if (renderer != null)
            {
//				Color mycolor = renderer.material.color;    // this NG for multi-part prefabs (e.g. biplane)
                Color mycolor = ctp.myColor;                                // NG?
                obj.color = new List <Double>();
                obj.color.Add(LimitPrecision(mycolor.r, 4));
                obj.color.Add(LimitPrecision(mycolor.g, 4));
                obj.color.Add(LimitPrecision(mycolor.b, 4));
                obj.color.Add(LimitPrecision(mycolor.a, 4));
            }

//			if (ctp.link != null && ctp.link.Length > 0) obj.link = ctp.link;
            if (ctp.custom != null && ctp.custom.Length > 0)
            {
                obj.custom = ctp.custom;
            }

            world.objects.Add(obj);
            objectCount++;
        }
//		Debug.Log("serialize: "+ world.player+", count: "+ objectCount);
        //		if (objectCount == 0) return null;  // notta.  (returning no-object string writes header-only)

        string jsonData = null;

        try
        {
            jsonData = JsonUtility.ToJson(world);
        }
        catch (Exception e)
        {
            UnityEngine.Debug.Log("Exception serializing JSON: " + e.Message);
            return(null);
        }

//		jsonData = jsonData.Replace("},", "},\n");     // for readability
        jsonData = jsonData.Replace("{\"id", "\n{\"id");             // for readability

        return(jsonData);
    }