예제 #1
0
 public void ListShipName(string path, GameCamp camp)
 {
     //获取指定文件夹的所有文件
     string[] paths = Directory.GetFiles(path);
     foreach (var item in paths)
     {
         //获取文件后缀名
         string extension = Path.GetExtension(item).ToLower();
         if (extension == ".ship")
         {
             string theName = Path.GetFileNameWithoutExtension(item);
             if (theName.Contains(camp.ToString()))
             {
                 ShipNames[camp].Add(Regex.Replace(theName, camp.ToString(), ""));
             }
         }
     }
 }
예제 #2
0
        public void SaveShip(Ship ship, GameCamp camp)
        {
            List <ShipData.PlaceRecord> records = new List <ShipData.PlaceRecord>();

            foreach (var component in ship.ShipComponents.Values)
            {
                ShipData.PlaceRecord record;
                record.id       = component.Id;
                record.level    = component.ShipCompoionentLevel;
                record.mirror   = (int)component.Mirror;
                record.pos      = component.pos;
                record.rotation = (int)component.Rotation;
                records.Add(record);
            }
            byte[] shipBytes = SerializeHelp.WriteObjectData(new ShipData(ship.ShipName, records));
            SerializeHelp.WriteFile(Application.dataPath + @"/Resources/Ship/" + camp.ToString() + ship.ShipName + ".ship", shipBytes);
        }
예제 #3
0
        public Ship LoadShipAtTransform(string shipName, Transform theTransform, GameCamp camp)
        {
            Debug.Log(camp.ToString() + shipName);
            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);
            return(ship);
        }