Пример #1
0
 public StageData(Vector3 playerPos, Quaternion playerRot)
 {
     m_playerPos      = Serializer.Serializevector3(playerPos);
     m_playerRot      = Serializer.SerializeQuaternion(playerRot);
     m_disallowPlayer = false;
     NewEntry         = true;
 }
Пример #2
0
 /// <summary>
 /// Translate to a serializable form the given position and rotation
 /// to register the last player location of this stage
 /// </summary>
 public void OverridePlayerLocation(Vector3 pos, Quaternion rot)
 {
     m_playerPos       = Serializer.Serializevector3(pos);
     m_playerRot       = Serializer.SerializeQuaternion(rot);
     NewEntry          = false;
     OverridedLocation = true;
 }
Пример #3
0
 public static SerializedVector3 Serializevector3(Vector3 source)
 {
     SerializedVector3 sv = new SerializedVector3();
     sv.x = source.x;
     sv.y = source.y;
     sv.z = source.z;
     return sv;
 }
Пример #4
0
    public static Vector3 DeserializeVector3(SerializedVector3 sv3)
    {
        Vector3 v3;

        v3.x = sv3.x;
        v3.y = sv3.y;
        v3.z = sv3.z;
        return(v3);
    }
Пример #5
0
    public static SerializedVector3 Serializevector3(Vector3 source)
    {
        SerializedVector3 sv = new SerializedVector3();

        sv.x = source.x;
        sv.y = source.y;
        sv.z = source.z;
        return(sv);
    }
Пример #6
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            SerializedVector3 sv = JsonConvert.DeserializeObject <SerializedVector3>(JToken.Load(reader).ToString());

            if (sv == null)
            {
                return(null);
            }
            return(new Vector3(sv.x, sv.y, sv.z));
        }
Пример #7
0
 public SerializedPlant(string plantName, int plantTypeIndex, float plantTime, Vector3 initialPosition, Vector3 initialDirection, int fruitSequence, int seed, int indexInGameData)
 {
     this.plantName        = plantName;
     this.plantTypeIndex   = plantTypeIndex;
     this.plantTime        = plantTime;
     this.initialPosition  = new SerializedVector3(initialPosition);
     this.initialDirection = new SerializedVector3(initialDirection);
     this.fruitSequence    = fruitSequence;
     this.seed             = seed;
     this.indexInGameData  = indexInGameData;
 }
        public void RemoveComponent(BuildingPart bp)
        {
            var v3        = new SerializedVector3(bp.Location - Origo.Position.ToVector3());
            var q         = new SerializedQuaternion(bp.buildingBlock.transform.rotation);
            var component = new StructureComponent(bp, v3, q);

            if (StructureComponents.ContainsKey(component.ToString()))
            {
                StructureComponents.Remove(component.ToString());
            }
        }
Пример #9
0
        public void RegisterLocation(Transform transform, bool registerScale)
        {
            m_position = Serializer.Serializevector3(transform.position);
            m_rotation = Serializer.SerializeQuaternion(transform.rotation);

            if (registerScale)
            {
                m_scale           = Serializer.Serializevector3(transform.localScale);
                m_scaleRegistered = true;
            }
        }
        public void RemoveComponent(Spawnable spawnable)
        {
            var v3        = new SerializedVector3(spawnable.transform.position - Origo.Position.ToVector3());
            var q         = new SerializedQuaternion(spawnable.transform.rotation);
            var component = new SpawnableComponent(spawnable, v3, q);

            if (SpawnableComponents.ContainsKey(component.ToString()))
            {
                SpawnableComponents.Remove(component.ToString());
            }
        }
Пример #11
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value != null)
     {
         SerializedVector3 sv = new SerializedVector3(((Vector3)value).x, ((Vector3)value).y, ((Vector3)value).z);
         JToken.FromObject(JsonConvert.SerializeObject(sv)).WriteTo(writer);
     }
     else
     {
         writer.WriteNull();
     }
 }
Пример #12
0
 public void RegisterPlayerLocation(Vector3 pos, Quaternion rot)
 {
     if (OverridedLocation)
     {
         OverridedLocation = false;
     }
     else
     {
         m_playerPos = Serializer.Serializevector3(pos);
         m_playerRot = Serializer.SerializeQuaternion(rot);
     }
     NewEntry = false;
 }
Пример #13
0
        public void AddVector3(string key, Vector3 v3)
        {
            SerializedVector3 _sv3 = Serializer.Serializevector3(v3);

            if (m_vectors == null)
            {
                m_vectors = new Dictionary <string, SerializedVector3>();
                m_vectors.Add(key, _sv3);
            }
            else
            {
                if (m_vectors.ContainsKey(key))
                {
                    m_vectors[key] = _sv3;
                }
                else
                {
                    m_vectors.Add(key, _sv3);
                }
            }
        }
 public StructureComponent(BuildingPart bp, SerializedVector3 v3, SerializedQuaternion q)
 {
     Grade         = bp.buildingBlock.grade;
     Prefab        = bp.buildingBlock.LookupPrefabName();
     LocalPosition = v3;
     LocalRotation = q;
     Health        = (float)((int)Math.Floor((double)(bp.Health / 85)) * 85);
     if (bp.buildingBlock.HasSlot(BaseEntity.Slot.Lock))
     {
         var baseLock = bp.buildingBlock.GetSlot(BaseEntity.Slot.Lock) as BaseLock;
         if (baseLock == null)
         {
             HasCodeLock = false;
             HasKeyLock  = false;
         }
         else if (baseLock.GetComponent <CodeLock>())
         {
             HasCodeLock = true;
             HasKeyLock  = false;
             CodeLock codeLock = baseLock.GetComponent <CodeLock>();
             if (!string.IsNullOrEmpty((string)codeLock.GetFieldValue("code")))
             {
                 LockCode  = (string)codeLock.GetFieldValue("code");
                 LockWList = new List <ulong>();
                 LockWList = (List <ulong>)codeLock.GetFieldValue("whitelistPlayers");
             }
         }
         else if (baseLock.GetComponent <KeyLock>())
         {
             HasCodeLock = false;
             HasKeyLock  = true;
             KeyLock keyLock = baseLock.GetComponent <KeyLock>();
             int     keyCode = (int)keyLock.GetFieldValue("keyCode");
             keyCode  = (bool)keyLock.GetFieldValue("firstKeyCreated") ? keyCode |= 0x80 : (int)keyLock.GetFieldValue("keyCode");
             LockCode = keyCode.ToString();
         }
     }
 }
        public void AddComponent(Spawnable spawnable)
        {
            if (Origo == null)
            {
                Origo = new Origo(new SerializedVector3(spawnable.transform.position), new SerializedQuaternion(spawnable.transform.rotation));
            }
            var v3        = new SerializedVector3(spawnable.transform.position - Origo.Position.ToVector3());
            var q         = new SerializedQuaternion(spawnable.transform.rotation);
            var component = new SpawnableComponent(spawnable, v3, q);

            if (component == null)
            {
                Pluton.Logger.LogDebug("[StructureRecorder] Deployable component is null!");
                return;
            }
            if (!SpawnableComponents.ContainsKey(component.ToString()))
            {
                SpawnableComponents.Add(component.ToString(), component);
            }
            else
            {
                SpawnableComponents[component.ToString()] = component;
            }
        }
        public void AddComponent(BuildingPart bp)
        {
            if (Origo == null)
            {
                Origo = new Origo(new SerializedVector3(bp.Location), new SerializedQuaternion(bp.buildingBlock.transform.rotation));
            }
            var v3        = new SerializedVector3(bp.Location - Origo.Position.ToVector3());
            var q         = new SerializedQuaternion(bp.buildingBlock.transform.rotation);
            var component = new StructureComponent(bp, v3, q);

            if (component == null)
            {
                Pluton.Logger.LogDebug("[StructureRecorder] BuildingPart component is null!");
                return;
            }
            if (!StructureComponents.ContainsKey(component.ToString()))
            {
                StructureComponents.Add(component.ToString(), component);
            }
            else
            {
                StructureComponents[component.ToString()] = component;
            }
        }
Пример #17
0
 public static Vector3 Parse(this SerializedVector3 simpleVector3)
 => new Vector3(simpleVector3.X, simpleVector3.Y, simpleVector3.Z);
Пример #18
0
 private void Save()
 {
     saveData.lastPosition = SerializedVector3.FromVector3(player.position);
     saveSystem.Save(saveData);
 }
Пример #19
0
    public void SerializeWorld()
    {
        //(new GameObject ("Before serilisation")).AddComponent<Test> ().wd = new WorldData(worldData);


        //Debug.Log ("je serialise le monde");

        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

        List <string> playersName = new List <string>(worldData.playersName);

        //Debug.Log (worldData.playersName.Length + " ----------  " + playersName.Count);


        List <SerializedVector3>         playerPositions   = new List <SerializedVector3> (worldData.playerPositions);
        List <SerializedPlayerInventory> playerInventories = new List <SerializedPlayerInventory> (worldData.playerInventories);



        foreach (var p in players)
        {
            Player player = p.GetComponent <Player> ();

            if (player.synched)
            {
                int index = -1;
                for (int i = 0; i < playersName.Count; i++)
                {
                    if (player.playerName == playersName [i])
                    {
                        index = i;
                        playerPositions [i] = new SerializedVector3(player.transform.position);

                        playerInventories [i] = new SerializedPlayerInventory(player.GetComponent <PlayerInventory> ());
                    }
                }
                if (index == -1)
                {
                    playersName.Add(player.playerName);
                    playerPositions.Add(new SerializedVector3(player.transform.position));
                    playerInventories.Add(new SerializedPlayerInventory(player.GetComponent <PlayerInventory> ()));
                }
            }
        }

        worldData.playersName       = playersName.ToArray();
        worldData.playerPositions   = playerPositions.ToArray();
        worldData.playerInventories = playerInventories.ToArray();


        GameManager.gm.pm.SerializePlants(worldData);
        //Debug.Log(worldData.plants.Length);

        //GameManager.gm.zd.Init ();
        GameManager.gm.zd.SerializeZones(worldData);
        GameManager.gm.zd.SerializeDoors(worldData);

        //(new GameObject ("After serilisation")).AddComponent<Test> ().wd = new WorldData(worldData);

        //(new GameObject ()).AddComponent<Test> ().wd = worldData;
    }
Пример #20
0
 public SpawnableComponent(Spawnable spawnable, SerializedVector3 v3, SerializedQuaternion q)
 {
     Prefab        = spawnable.GetComponent <BaseNetworkable>().LookupPrefabName();
     LocalPosition = v3;
     LocalRotation = q;
 }
 public StructureComponent(string str, SerializedVector3 v3, SerializedQuaternion q, int i)
 {
     throw new NotImplementedException();
 }
Пример #22
0
 public static Vector3 DeserializeVector3(SerializedVector3 source)
 {
     return new Vector3(source.x, source.y, source.z);
 }
Пример #23
0
 public DeployableComponent(Deployable deployable, SerializedVector3 v3, SerializedQuaternion q)
 {
     Prefab        = deployable.GetComponent <BaseNetworkable>().LookupPrefabName();
     LocalPosition = v3;
     LocalRotation = q;
     if (deployable.GetComponent <SleepingBag>())
     {
         SleepingBag sleepingBag = deployable.GetComponent <SleepingBag>();
         DeployedBy  = sleepingBag.deployerUserID;
         BagName     = sleepingBag.niceName;
         HasOwner    = true;
         HasStorage  = false;
         HasPainting = false;
         IsCupBoard  = false;
     }
     else if (deployable.GetComponent <BuildingPrivlidge>())
     {
         IsCupBoard = true;
         BuildingPrivlidge buildingPrivlidge = deployable.GetComponent <BuildingPrivlidge>();
         AuthedPlayers = new List <ProtoBuf.PlayerNameID>();
         AuthedPlayers = buildingPrivlidge.authorizedPlayers;
     }
     else if (deployable.GetComponent <StorageContainer>())
     {
         HasOwner    = false;
         HasStorage  = true;
         HasPainting = false;
         IsCupBoard  = false;
         StorageContainer storageContainer = deployable.GetComponent <StorageContainer>();
         ItemList = new List <Dictionary <string, object> >();
         foreach (Item item in storageContainer.inventory.itemList)
         {
             var itemData = new Dictionary <string, object>();
             itemData.Add("blueprint", item.IsBlueprint());
             itemData.Add("id", item.info.itemid);
             itemData.Add("amount", item.amount);
             ItemList.Add(itemData);
         }
         if (storageContainer.HasSlot(BaseEntity.Slot.Lock))
         {
             var baseLock = storageContainer.GetSlot(BaseEntity.Slot.Lock) as BaseLock;
             if (baseLock == null)
             {
                 HasCodeLock = false;
                 HasKeyLock  = false;
             }
             else if (baseLock.GetComponent <CodeLock>())
             {
                 HasCodeLock = true;
                 HasKeyLock  = false;
                 CodeLock codeLock = baseLock.GetComponent <CodeLock>();
                 if (!string.IsNullOrEmpty((string)codeLock.GetFieldValue("code")))
                 {
                     LockCode  = (string)codeLock.GetFieldValue("code");
                     LockWList = new List <ulong>();
                     LockWList = (List <ulong>)codeLock.GetFieldValue("whitelistPlayers");
                 }
             }
             else if (baseLock.GetComponent <KeyLock>())
             {
                 HasCodeLock = false;
                 HasKeyLock  = true;
                 KeyLock keyLock = baseLock.GetComponent <KeyLock>();
                 int     keyCode = (int)keyLock.GetFieldValue("keyCode");
                 keyCode  = (bool)keyLock.GetFieldValue("firstKeyCreated") ? keyCode |= 0x80 : (int)keyLock.GetFieldValue("keyCode");
                 LockCode = keyCode.ToString();
             }
         }
     }
     else if (deployable.GetComponent <Signage>())
     {
         HasOwner    = false;
         HasStorage  = false;
         HasPainting = true;
         IsCupBoard  = false;
         Signage signage = deployable.GetComponent <Signage>();
         byte[]  tempImg = FileStorage.server.Get(signage.textureID, FileStorage.Type.png, signage.net.ID);
         if (signage.textureID > 0 && tempImg != null)
         {
             Painting = tempImg;
         }
         PaintingLocked = signage.IsLocked();
     }
     else
     {
         HasOwner    = false;
         HasStorage  = false;
         HasPainting = false;
         IsCupBoard  = false;
     }
 }
Пример #24
0
 public Origo(SerializedVector3 v3, SerializedQuaternion q)
 {
     Position = v3;
     Rotation = q;
 }
Пример #25
0
 public static Vector3 DeserializeVector3(SerializedVector3 source)
 {
     return(new Vector3(source.x, source.y, source.z));
 }