public override void Setup(GridObject gridObject, Direction dir, FactoryNeighbors customNeighbors = null) { base.Setup(gridObject, dir, customNeighbors); FactoryObject outputNeighbor = Neighbors.GetSide(OutputDirection); if (outputNeighbor != null) { FactoryBelt belt = outputNeighbor.GetComponent <FactoryBelt>(); if (belt != null) { _output = new BeltConnection(belt); } //FactoryAssembler assembler = outputNeighbor.GetComponent<FactoryAssembler>(); //if (assembler != null) _output = new AssemblerConnection(assembler); } FactoryObject inputNeighbor = Neighbors.GetSide(InputDirection); if (inputNeighbor != null) { FactoryBelt belt = inputNeighbor.GetComponent <FactoryBelt>(); if (belt != null) { _input = new BeltConnection(belt); } FactoryCreativeOutput creativeOutput = inputNeighbor.GetComponent <FactoryCreativeOutput>(); if (creativeOutput != null) { _input = new CreativeOutputConnection(creativeOutput); } //FactoryAssembler assembler = inputNeighbor.GetComponent<FactoryAssembler>(); //if (assembler != null) _input = new AssemblerConnection(assembler); } }
public override void Setup(GridObject gridObject, Direction dir, FactoryNeighbors customNeighbors = null) { base.Setup(gridObject, dir, customNeighbors); FactoryBelt frontBelt = Neighbors.GetSide(OutputDirection)?.GetComponent <FactoryBelt>(); if (frontBelt != null && MatchesIO(frontBelt.InputDirection, frontBelt.Dir, OutputDirection)) { //Fix weird cases if (Vector3.Distance(LeftOutputSlot.transform.position, frontBelt.LeftInputSlot.transform.position) < 1) { LeftOutputSlot.NextPosition = frontBelt.LeftInputSlot; frontBelt.LeftInputSlot.PreviousPosition = LeftOutputSlot; } if (Vector3.Distance(RightOutputSlot.transform.position, frontBelt.RightInputSlot.transform.position) < 1) { RightOutputSlot.NextPosition = frontBelt.RightInputSlot; frontBelt.RightInputSlot.PreviousPosition = RightOutputSlot; } } FactoryBelt backBelt = Neighbors.GetSide(InputDirection)?.GetComponent <FactoryBelt>(); if (backBelt != null && MatchesIO(backBelt.OutputDirection, backBelt.Dir, InputDirection)) { //Fix weird cases if (Vector3.Distance(backBelt.LeftOutputSlot.transform.position, LeftInputSlot.transform.position) < 1) { backBelt.LeftOutputSlot.NextPosition = LeftInputSlot; LeftInputSlot.PreviousPosition = backBelt.LeftOutputSlot; } if (Vector3.Distance(backBelt.RightOutputSlot.transform.position, RightInputSlot.transform.position) < 1) { backBelt.RightOutputSlot.NextPosition = RightInputSlot; RightInputSlot.PreviousPosition = backBelt.RightOutputSlot; } } FactoryCreativeOutput creativeOutput = Neighbors.GetSide(InputDirection)?.GetComponent <FactoryCreativeOutput>(); if (creativeOutput != null) { creativeOutput.AddBelt(this); } FactoryAssembler assembler = Neighbors.GetSide(InputDirection)?.GetComponent <FactoryAssembler>(); if (assembler != null) { if (Dir == assembler.Dir) { assembler.AddBelt(this, true); } } assembler = Neighbors.GetSide(OutputDirection)?.GetComponent <FactoryAssembler>(); if (assembler != null) { assembler.AddBelt(this, false); } }
public override void Setup(GridObject gridObject, Direction dir, FactoryNeighbors customNeighbors = null) { base.Setup(gridObject, dir, customNeighbors); FactoryObject northFactory = Neighbors.GetNeighbor(Direction.North); if (northFactory != null) { FactoryBelt belt = northFactory.GetComponent <FactoryBelt>(); if (belt != null && belt.Dir == Direction.North) { AddBelt(belt, Dir == Direction.North); } } FactoryObject eastFactory = Neighbors.GetNeighbor(Direction.East); if (eastFactory != null) { FactoryBelt belt = eastFactory.GetComponent <FactoryBelt>(); if (belt != null && belt.Dir == Direction.East) { AddBelt(belt, Dir == Direction.East); } } FactoryObject southFactory = Neighbors.GetNeighbor(Direction.South); if (southFactory != null) { FactoryBelt belt = southFactory.GetComponent <FactoryBelt>(); if (belt != null && belt.Dir == Direction.South) { AddBelt(belt, Dir == Direction.South); } } FactoryObject westFactory = Neighbors.GetNeighbor(Direction.West); if (westFactory != null) { FactoryBelt belt = westFactory.GetComponent <FactoryBelt>(); if (belt != null && belt.Dir == Direction.West) { AddBelt(belt, Dir == Direction.West); } } }
private void AddObject(Position pos, Direction dir, FactoryObject factoryObject, bool instantiate = true, FactoryNeighbors customNeighbors = null) { if (_grid.ContainsKey(pos)) { return; } GridObject gridObject = new GameObject("Object(" + pos.X + "," + pos.Y + ")").AddComponent <GridObject>(); gridObject.transform.SetParent(transform); gridObject.transform.localPosition = pos.GetLocalPosition(); gridObject.NorthNeighbor = FindNeighbor(pos, Direction.North); gridObject.EastNeighbor = FindNeighbor(pos, Direction.East); gridObject.SouthNeighbor = FindNeighbor(pos, Direction.South); gridObject.WestNeighbor = FindNeighbor(pos, Direction.West); if (gridObject.NorthNeighbor != null) { gridObject.NorthNeighbor.SouthNeighbor = gridObject; } if (gridObject.EastNeighbor != null) { gridObject.EastNeighbor.WestNeighbor = gridObject; } if (gridObject.SouthNeighbor != null) { gridObject.SouthNeighbor.NorthNeighbor = gridObject; } if (gridObject.WestNeighbor != null) { gridObject.WestNeighbor.EastNeighbor = gridObject; } if (instantiate) { gridObject.FactoryObject = Instantiate(factoryObject, gridObject.transform).GetComponent <FactoryObject>(); gridObject.FactoryObject.Setup(gridObject, dir, customNeighbors); } else { gridObject.FactoryObject = factoryObject; } if (gridObject.FactoryObject != null) { gridObject.FactoryObject.ConnectedObjects.Add(gridObject); } gridObject.Chunk = this; gridObject.ChunkPosition = pos; _grid.Add(pos, gridObject); }