예제 #1
0
    public TurnBasedUnit BuildShip(ShipType shipType, BlueprintTemplate bpTemplate, Vector3 position, Quaternion rotation)
    {
        hullBeingBuilt = GameObject.Instantiate(bpTemplate.Hull, position, rotation) as Hull;
        #if FULL_DEBUG ||LOW_DEBUG
        if (!hullBeingBuilt)
        {
            Debug.LogError("ship null");
        }
        else
        {
            Debug.Log("Building ship from template " + bpTemplate.MetaData.BlueprintName);
        }
        #endif
        hullBeingBuilt.Init();

        bpTemplate.GetBlueprint(out blueprintBeingBuilt, hullBeingBuilt);

        return InstantiateShip(true, shipType, position, rotation);
    }
예제 #2
0
    private TurnBasedUnit InstantiateShip(bool hullSpawnedAlready, ShipType shipType, Vector3 position, Quaternion rotation)
    {
        if (!hullSpawnedAlready)
        {
            hullBeingBuilt = GameObject.Instantiate(blueprintBeingBuilt.Hull, position, rotation) as Hull;
            #if FULL_DEBUG ||LOW_DEBUG
            if (!hullBeingBuilt)
            {
                Debug.LogError("ship null");
            }
            #endif
            hullBeingBuilt.Init();
        }

        for (int i = 0; i < blueprintBeingBuilt.Slot_component_table.Count; i++)
        {
            var slot_component = blueprintBeingBuilt.Slot_component_table.ElementAt(i);
            int slotIndex = slot_component.Key.index;

        #if !NO_DEBUG
            if (hullBeingBuilt.index_slot_table.ContainsKey(slotIndex))
            {
                Transform slotTrans = hullBeingBuilt.index_slot_table[slotIndex].transform;
                ShipComponent builtComponent = GameObject.Instantiate(slot_component.Value, slotTrans.position, slotTrans.rotation) as ShipComponent;
                blueprintBeingBuilt.Slot_component_table[slot_component.Key] = builtComponent;
                builtComponent.transform.SetParent(slotTrans, true);
                builtComponent.Placement = slot_component.Key.Placement;
                builtComponent.CompSpecificType = slot_component.Value.CompSpecificType;
                slot_component.Key.InstalledComponent = slot_component.Value;
            }
            else
            {
                Debug.LogError("Slot " + slotIndex + " not found in Hull " + hullBeingBuilt.hullName);
            }
        #else
            Transform slotTrans = hullBeingBuilt.index_slot_table[slotIndex].transform;
            GameObject component = GameObject.Instantiate(slot_component.Value, slotTrans.position, slotTrans.rotation) as GameObject;
            component.transform.SetParent(slotTrans, true);
        #endif
        }

        return SetupScriptsOnShip(shipType);
    }