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)); } }
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); }