Beispiel #1
0
    /// <summary>
    /// Deserialize a networked scene object from a string
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public static NetworkedSceneObject Deserialize(string data)
    {
        NetworkedSceneObject newObject = new NetworkedSceneObject();

        noCulture = System.Globalization.CultureInfo.InvariantCulture;



        var line = Regex.Match(data, "id: ?([0-9]+?) ?;");

        if (line.Success)
        {
            ushort.TryParse(line.Groups[1].Value, out newObject.NetworkID);
        }

        line = Regex.Match(data, "type:([\\s\\S]+?);");
        if (line.Success)
        {
            newObject.ObjectType = line.Groups[1].Value;
        }

        line = Regex.Match(data, "data:([\\s\\S]+?);");
        if (line.Success)
        {
            newObject.ObjectData = line.Groups[1].Value;
        }

        line = Regex.Match(data, @"pos: ?\(?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?)\)? ?;");
        if (line.Success)
        {
            newObject.position = new Vector3(float.Parse(line.Groups[1].Value, noCulture), float.Parse(line.Groups[2].Value, noCulture), float.Parse(line.Groups[3].Value, noCulture));
        }

        line = Regex.Match(data, @"rot: ?\(?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?)\)? ?;");
        if (line != null)
        {
            newObject.rotation = new Quaternion(
                float.Parse(line.Groups[1].Value, noCulture),
                float.Parse(line.Groups[2].Value, noCulture),
                float.Parse(line.Groups[3].Value, noCulture),
                float.Parse(line.Groups[4].Value, noCulture)
                );
        }

        return(newObject);
    }
Beispiel #2
0
    /// <summary>
    /// Deserialize a networked scene object from a string
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public static NetworkedSceneObject Deserialize(string data)
    {
        NetworkedSceneObject newObject = new NetworkedSceneObject();
        noCulture = System.Globalization.CultureInfo.InvariantCulture;




        var line = Regex.Match(data, "id: ?([0-9]+?) ?;");
        if (line.Success)
        {
            ushort.TryParse(line.Groups[1].Value, out newObject.NetworkID);
        }

        line = Regex.Match(data, "type:([\\s\\S]+?);");
        if (line.Success)
        {
            newObject.ObjectType = line.Groups[1].Value;
        }

        line = Regex.Match(data, "data:([\\s\\S]+?);");
        if (line.Success)
        {
            newObject.ObjectData = line.Groups[1].Value;
        }

        line = Regex.Match(data, @"pos: ?\(?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?)\)? ?;");
        if (line.Success)
        {
            newObject.position = new Vector3(float.Parse(line.Groups[1].Value, noCulture), float.Parse(line.Groups[2].Value, noCulture), float.Parse(line.Groups[3].Value, noCulture));
        }

        line = Regex.Match(data, @"rot: ?\(?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?), ?(-?\d+(?:\.\d*)?)\)? ?;");
        if (line != null)
        {
            newObject.rotation = new Quaternion(
                float.Parse(line.Groups[1].Value, noCulture),
                float.Parse(line.Groups[2].Value, noCulture),
                float.Parse(line.Groups[3].Value, noCulture),
                float.Parse(line.Groups[4].Value, noCulture)
                );
        }

        return newObject;
    }
Beispiel #3
0
        /// <summary>
        /// Create a static game object that can receive rpc's in the scene.
        /// The client should have a similar object in the scene matching the room with the same id
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <param name="gobj"></param>
        public void NetworkedRoomObject(NetworkedSceneObject sceneObject, GameObject gobj)
        {
            if (gobj.Room != this && gobj.Room != null)
            {
                Debug.LogError("cannot move the object to the room. it must have no room or be in this one.");
                return;
            }

            var sceneView = gobj.AddComponent <NetworkedSceneObjectView>();

            gobj.Room = this;

            sceneView.room      = this;
            sceneView.NetworkID = sceneObject.NetworkID;

            roomObjects[sceneObject.NetworkID] = sceneView;

            //sceneObject.OnFinishedCreation();
        }
Beispiel #4
0
        /// <summary>
        /// Create a static game object that can receive rpc's in the scene. 
        /// The client should have a similar object in the scene matching the room with the same id
        /// </summary>
        /// <param name="sceneObject"></param>
        /// <param name="gobj"></param>
        public void NetworkedRoomObject(NetworkedSceneObject sceneObject, GameObject gobj)
        {
            if (gobj.Room != this && gobj.Room != null)
            {
                Debug.LogError("cannot move the object to the room. it must have no room or be in this one.");
                return;
            }

            var sceneView = gobj.AddComponent<NetworkedSceneObjectView>();

            gobj.Room = this;

            sceneView.room = this;
            sceneView.NetworkID = sceneObject.NetworkID;

            roomObjects[sceneObject.NetworkID] = sceneView;

            //sceneObject.OnFinishedCreation();
        }