Exemple #1
0
        public Ship LoadShipWithData(SerializeShipData data)
        {
            byte[]     shipBytes  = SerializeHelp.ReadFile(Application.dataPath + "/Resources/Ship/" + data.shipCamp.ToString() + data.shipName + ".ship");
            ShipData   shipData   = SerializeHelp.ReadObjectData <ShipData>(shipBytes);
            GameObject shipObject = Instantiate(EmptyShip, (Vector3)data.position, Quaternion.Euler((Vector3)data.rotation));
            Ship       ship       = shipObject.GetComponent <Ship>();

            ship.ShipName = ship.name = shipData.ShipName;
            foreach (var component in shipData.Records)
            {
                ship.AddComponent(component.id, component.level, new Vector2Int((int)component.pos.x, (int)component.pos.y),
                                  (ShipEnum.ShipUnitRotation)Enum.ToObject(typeof(ShipEnum.ShipUnitRotation), component.rotation),
                                  (ShipEnum.ShipUnitMirror)Enum.ToObject(typeof(ShipEnum.ShipUnitMirror), component.mirror));
            }
            ship.SetCamp(data.shipCamp);
            foreach (Block block in ship.Blocks.Values)
            {
                BlockHealth health = block.GetComponent <BlockHealth>();
                if (health != null)
                {
                    health.ReceiveDamage(null, data.blockHealthData[(SerializableVector2Int)block.Pos].health);
                }
            }
            Debug.Log("debug太多免得我看不见所以才打这一行字" + data.mode.ToString());
            ship.control.mode = data.mode;
            Debug.Assert(ShipManager.Instance.enabled);
            ship.control.Sp = data.Sp;
            Debug.Assert(ShipManager.Instance.enabled);
            ship.control.SpColding = data.isColding;
            Debug.Assert(ShipManager.Instance.enabled);
            ShipManager.Instance.ships[data.shipCamp].Add(ship);
            Debug.Assert(ShipManager.Instance.enabled);
            return(ship);
        }
Exemple #2
0
        public void LoadShipAtTransform(string shipName, Transform theTransform)
        {
            byte[]     shipBytes  = SerializeHelp.ReadFile(Application.dataPath + "/Resources/Ship/" + shipName);
            ShipData   shipData   = SerializeHelp.ReadObjectData <ShipData>(shipBytes);
            GameObject shipObject = Instantiate(EmptyShip, theTransform.position, theTransform.rotation);
            Ship       ship       = shipObject.GetComponent <Ship>();

            ship.ShipName = ship.name = shipData.ShipName;
            foreach (var component in shipData.Records)
            {
                ship.AddComponent(component.id, component.level, new Vector2Int((int)component.pos.x, (int)component.pos.y),
                                  (ShipEnum.ShipUnitRotation)Enum.ToObject(typeof(ShipEnum.ShipUnitRotation), component.rotation),
                                  (ShipEnum.ShipUnitMirror)Enum.ToObject(typeof(ShipEnum.ShipUnitMirror), component.mirror));
            }
        }
Exemple #3
0
        public Ship LoadShipAtTransform(string shipName, Transform theTransform, GameCamp camp, ShipControlMode mode = ShipControlMode.Building)
        {
            byte[]     shipBytes  = SerializeHelp.ReadFile(Application.dataPath + "/Resources/Ship/" + camp.ToString() + shipName + ".ship");
            ShipData   shipData   = SerializeHelp.ReadObjectData <ShipData>(shipBytes);
            GameObject shipObject = Instantiate(EmptyShip, theTransform.position, theTransform.rotation);
            Ship       ship       = shipObject.GetComponent <Ship>();

            ship.ShipName = ship.name = shipData.ShipName;
            foreach (var component in shipData.Records)
            {
                ship.AddComponent(component.id, component.level, new Vector2Int((int)component.pos.x, (int)component.pos.y),
                                  (ShipEnum.ShipUnitRotation)Enum.ToObject(typeof(ShipEnum.ShipUnitRotation), component.rotation),
                                  (ShipEnum.ShipUnitMirror)Enum.ToObject(typeof(ShipEnum.ShipUnitMirror), component.mirror));
            }
            ship.SetCamp(camp);
            ShipManager.Instance.ships[camp].Add(ship);
            ship.control.mode = mode;
            return(ship);
        }
Exemple #4
0
    void Start()
    {
        info.name  = "test";
        info.value = 123.456f;

        info.nameList = new List <string>();
        info.nameList.Add("1");
        info.nameList.Add("22");
        info.nameList.Add("333");

        byte[] bytes = SerializeHelp.WriteObjectData(info);
        SerializeHelp.WriteFile(Application.dataPath + "/SSuite/Examples/test.info", bytes);
        Debug.Log("info bytes.Length :" + bytes.Length + " bytes");

        byte[] readBytes = SerializeHelp.ReadFile(Application.dataPath + "/SSuite/Examples/test.info");
        Info   readInfo  = SerializeHelp.ReadObjectData <Info>(readBytes);

        Debug.Log(readInfo.name);
        Debug.Log(readInfo.value);
        foreach (string str in readInfo.nameList)
        {
            Debug.Log(str);
        }

        Dictionary <string, string> dic = new Dictionary <string, string>();

        dic["monster"] = "Slime";
        dic["wepon"]   = "Gun";
        dic["state"]   = "living";

        bytes = SerializeHelp.WriteObjectData(dic);
        SerializeHelp.WriteFile(Application.dataPath + "/SSuite/Examples/dic.info", bytes);

        readBytes = SerializeHelp.ReadFile(Application.dataPath + "/SSuite/Examples/dic.info");
        Dictionary <string, string> readDic = SerializeHelp.ReadObjectData <Dictionary <string, string> >(readBytes);

        Debug.Log(readDic["monster"]);
        Debug.Log(readDic["wepon"]);
        Debug.Log(readDic["state"]);
    }