public void Delete() { float delay = 0.3f * HexGrid.GameSpeed; foundationPart = null; if (weapon1 != null) { HexGrid.Destroy(weapon1.gameObject, delay); weapon1 = null; } if (extractor1 != null) { HexGrid.Destroy(extractor1.gameObject, delay); extractor1 = null; } if (container != null) { HexGrid.Destroy(container.gameObject, delay); container = null; } if (assembler != null) { HexGrid.Destroy(assembler.gameObject, delay); assembler = null; } if (reactor1 != null) { HexGrid.Destroy(reactor1.gameObject, delay); reactor1 = null; } if (engine1 != null) { HexGrid.Destroy(engine1.gameObject, delay); engine1 = null; } }
public void Assemble() { MoveUpdateStats stats = MoveUpdateStats; if (stats == null) { return; } if (currentPos == null) { return; } /* * NextMove.Stats.EngineLevel * NextMove.Stats.ArmorLevel ** * NextMove.Stats.ContainerLevel * NextMove.Stats.ExtractorLevel * NextMove.Stats.WeaponLevel * NextMove.Stats.ReactorLevel * NextMove.Stats.ProductionLevel */ HexCell targetCell = HexGrid.GroundCells[currentPos]; // Place the engine if (stats.EngineLevel > 0) { if (engine1 == null && stats.EngineLevel == 1) { engine1 = HexGrid.InstantiatePrefab <Engine1>("Engine1"); engine1.UnitFrame = this; engine1.UnitId = UnitId; engine1.name = UnitId + "-Engine"; foundationPart = engine1; SetPlayerColor(playerId, engine1.gameObject); unitLayout.PlaceOnGround(engine1, targetCell, HexGrid); } } else { if (foundationPart != null && engine1 == foundationPart) { ReparentParts(); foundationPart = null; } if (engine1 != null) { HexGrid.Destroy(engine1.gameObject); engine1 = null; } } // Place big extractor if (stats.ExtractorLevel > 0) { if (extractor1 == null && stats.ExtractorLevel == 1) { if (foundationPart == null) { extractor1 = HexGrid.InstantiatePrefab <Extractor1>("ExtractorGround1"); unitLayout.PlaceOnGround(extractor1, targetCell, HexGrid); foundationPart = extractor1; extractor1.name = UnitId + "-Extractor"; extractor1.UnitFrame = this; SetPlayerColor(playerId, extractor1.gameObject); } } } else { if (foundationPart != null && extractor1 == foundationPart) { ReparentParts(); foundationPart = null; } if (extractor1 != null) { HexGrid.Destroy(extractor1.gameObject); extractor1 = null; } } if (stats.ProductionLevel > 0) { if (assembler == null || assembler.Level != stats.ProductionLevel) { if (assembler != null) { HexGrid.Destroy(assembler.gameObject); assembler = null; } assembler = HexGrid.InstantiatePrefab <Assembler1>("Assembler" + stats.ProductionLevel); assembler.UnitFrame = this; assembler.Level = stats.ProductionLevel; assembler.name = UnitId + "-Assembler"; SetPlayerColor(playerId, assembler.gameObject); if (foundationPart == null) { unitLayout.PlaceOnGround(assembler, targetCell, HexGrid); foundationPart = assembler; } else { if (unitLayout.frame1 != null) { HexGrid.Destroy(unitLayout.frame1.gameObject); unitLayout.frame1 = null; } unitLayout.PlaceBigPart(assembler, foundationPart, targetCell, HexGrid); } } } else { if (assembler != null) { HexGrid.Destroy(assembler.gameObject); assembler = null; } } if (stats.ContainerLevel > 0) { if (container == null || container.Level != stats.ContainerLevel) { if (container != null) { HexGrid.Destroy(container.gameObject); container = null; } container = HexGrid.InstantiatePrefab <Container1>("Container" + stats.ContainerLevel); container.UnitFrame = this; container.name = UnitId + "-Container"; container.Level = stats.ContainerLevel; SetPlayerColor(playerId, container.gameObject); if (foundationPart is Extractor1) { if (stats.ProductionLevel > 0) { // Put it on top of the assembler unitLayout.PlaceOnTop(container, foundationPart, targetCell, HexGrid, 0.6f); } else { unitLayout.PlaceOnTop(container, foundationPart, targetCell, HexGrid, 0.3f); } } else { if (foundationPart == null) { unitLayout.PlaceOnGround(container, targetCell, HexGrid); foundationPart = container; } else { // Blueprint if (!unitLayout.PlaceContainer(container, foundationPart, targetCell, HexGrid)) { } //unitLayout.PlacePart(container, foundationPart, targetCell, HexGrid); } } } container.UpdateContent(stats.ContainerFull); } else { if (container != null) { HexGrid.Destroy(container.gameObject); container = null; } } if (stats.ReactorLevel > 0) { if (reactor1 == null && stats.ReactorLevel == 1) { reactor1 = HexGrid.InstantiatePrefab <Reactor1>("Reactor1"); reactor1.UnitFrame = this; reactor1.name = UnitId + "-Reactor1"; SetPlayerColor(playerId, reactor1.gameObject); if (foundationPart is Extractor1) { if (stats.ProductionLevel > 0 && stats.ContainerLevel > 0) { // Put it on top of the container unitLayout.PlaceOnTop(reactor1, foundationPart, targetCell, HexGrid, 0.8f); } else { unitLayout.PlaceBigPart(reactor1, foundationPart, targetCell, HexGrid); } } else { if (foundationPart == null) { unitLayout.PlaceOnGround(reactor1, targetCell, HexGrid); foundationPart = reactor1; } else { unitLayout.PlacePart(reactor1, foundationPart, targetCell, HexGrid); } } } } else { if (reactor1 != null) { HexGrid.Destroy(reactor1.gameObject); reactor1 = null; } } if (stats.WeaponLevel > 0) { if (weapon1 == null && stats.WeaponLevel == 1) { weapon1 = HexGrid.InstantiatePrefab <Weapon1>("Weapon1"); weapon1.UnitFrame = this; weapon1.name = UnitId + "-Weapon"; SetPlayerColor(playerId, weapon1.gameObject); if (foundationPart == null) { unitLayout.PlaceOnGround(weapon1, targetCell, HexGrid); foundationPart = weapon1; } else if (foundationPart is Extractor1) { unitLayout.PlaceBigPart(weapon1, foundationPart, targetCell, HexGrid); } else { if (!unitLayout.PlaceWeapon(weapon1, foundationPart, targetCell, HexGrid)) { } } } weapon1.UpdateContent(stats.WeaponLoaded); } else { if (weapon1 != null) { HexGrid.Destroy(weapon1.gameObject); weapon1 = null; } } // Place small extractor if (stats.ExtractorLevel > 0) { if (extractor1 == null && stats.ExtractorLevel == 1) { if (foundationPart != null) { extractor1 = HexGrid.InstantiatePrefab <Extractor1>("Extractor1"); unitLayout.PlacePart(extractor1, foundationPart, targetCell, HexGrid); extractor1.name = UnitId + "-Extractor"; extractor1.UnitFrame = this; SetPlayerColor(playerId, extractor1.gameObject); } } } }