예제 #1
0
    public void RemoveModule(ConstructionModule module)
    {
        if (module.inventorySlot == null)
        {
            return;
        }
        InventorySlot slot = module.inventorySlot;

        if (slot.number > 1)
        {
            var prefab            = game.GetConstructionModulePrefab(module.GetModuleType());
            var newModuleInstance = Instantiate(prefab) as ConstructionModule;

            newModuleInstance.transform.parent        = slot.transform;
            newModuleInstance.transform.localPosition = Vector2.zero;
            newModuleInstance.inventorySlot           = slot;
            newModuleInstance.manifest      = new ModuleManifest(module);
            newModuleInstance.manifest.name = module.manifest.name;
            slot.module          = newModuleInstance;
            module.inventorySlot = null;
        }
        else
        {
            slot.module          = null;
            module.inventorySlot = null;
            modules.Remove(module);
            slot.Activate();
        }
        if (slot.number > 0)
        {
            slot.number--;
        }
    }