public static bool ValidateBlueprint(BlueprintNew bp)
 {
     // All Ids must be valid
     // Equipment must not exceed internal cargo space on ship
     // Ship must have enough power?? (somehow handle low power case...)
     return(true);
 }
    public void InitShipWithBlueprint(Ship ship, BlueprintNew bp)
    {
        ship.Id        = IdGenerator.GenShipId();
        ship.Blueprint = bp;
        ShipClass shipClass = BlueprintManager.Instance.GetShipClass(bp.ShipClassId);

        ship.ShipClass = shipClass;

        // All ships have a cargo component
        CmpCargo cargo = ship.gameObject.AddComponent <CmpCargo>() as CmpCargo;

        foreach (string id in bp.ShipAttachmentIds)
        {
            var attachment = BlueprintManager.Instance.GetAttachment(id);
            AddAttachmentByType[attachment.Type](ship, attachment);
        }

        foreach (string id in bp.ShipThrusterIds)
        {
            var thruster = BlueprintManager.Instance.GetThruster(id);
            AddThruster(ship, thruster);
        }

        foreach (string id in bp.ShipEquipmentIds)
        {
            var equipment = BlueprintManager.Instance.GetEquipment(id);
            AddEquipmentByType[equipment.Type](ship, equipment);
        }

        InitShipComponents(ship);
        FinalizeShip(ship);
    }
示例#3
0
    public void DebugAddship()
    {
        BlueprintNew bp = BlueprintUtils.ReadBlueprintFile(
            Application.persistentDataPath + "/" + BlueprintUtils.FormatBlueprintFilename(DebugBlueprintNew)
            );

        InstantiateShip(DebugShipAssembler.transform, bp);
    }
示例#4
0
    // parent represents the thing that spawns this ship (eg. the ship assembler)
    public void InstantiateShip(Transform parent, BlueprintNew bp)
    {
        // Instantiate the ship in game
        GameObject shipObject = Instantiate(ShipPrefab, parent);
        var        ship       = shipObject.GetComponent <Ship>();

        ShipBuilder.Instance.InitShipWithBlueprint(ship, bp);

        // All ships register to central manager
        AllShips.Add(ship.Id, ship);
    }
    public static BlueprintNew ReadBlueprintFile(string filepath)
    {
        BlueprintNew bp   = null;
        FileStream   file = new FileStream(filepath, FileMode.Open);

        try {
            BinaryFormatter formatter = new BinaryFormatter();
            bp = (BlueprintNew)formatter.Deserialize(file);
        } catch (SerializationException e) {
            Debug.Log("Failed to deserialize. Reason: " + e.Message);
            throw;
        } finally {
            file.Close();
        }

        return(bp);
    }
    public static string SaveBlueprint(BlueprintNew bp)
    {
        string filepath = Application.persistentDataPath + "/" + FormatBlueprintFilename(bp);

        Debug.Log(filepath);
        FileStream file = File.Create(filepath);

        try {
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(file, bp);
        } catch (SerializationException e) {
            Debug.Log("Failed to Serialize. Reason: " + e.Message);
            throw;
        } finally {
            file.Close();
        }

        return(filepath);
    }
 public static string FormatBlueprintFilename(BlueprintNew bp)
 {
     return(bp.Name + ".bp");
 }