private static MultiBlockInfo AddMulti(BlockType type, uint health, uint mass) { MultiBlockInfo info = new MultiBlockInfo(type, health, mass, Resources.Load("Blocks/" + type) as GameObject); Blocks[(ushort)type] = info; return(info); }
private static void InitializeMulti(IMultiBlockParent parent, MultiBlockInfo info, byte rotation, BlockPosition position, KeyValuePair <BlockPosition, BlockSides>[] partPositions, Function <int, IMultiBlockPart[]> partsArrayConstructor, Function <KeyValuePair <BlockPosition, BlockSides>, IMultiBlockPart> partConstructor, out IMultiBlockPart[] parts) { BlockSides parentSides = BlockSides.None; parts = partsArrayConstructor(partPositions.Length - 1); int partsIndex = 0; foreach (KeyValuePair <BlockPosition, BlockSides> pair in partPositions) { if (pair.Key.Equals(position)) { parentSides = pair.Value; } else { parts[partsIndex++] = partConstructor(pair); } } foreach (IMultiBlockPart part in parts) { part.Initialize(parent); } parent.Initialize(parentSides, position, info, rotation, parts); }
public void Initialize(BlockSides connectSides, BlockPosition position, MultiBlockInfo info, byte rotation, IMultiBlockPart[] parts) { ConnectSides = connectSides; Position = position; Type = info.Type; Rotation = rotation; Parts = (PlacedMultiBlockPart[])parts; }
public void Initialize(BlockSides connectSides, BlockPosition position, MultiBlockInfo info, byte rotation, IMultiBlockPart[] parts) { ConnectSides = connectSides; Position = position; Info = info; Rotation = rotation; Parts = (LiveMultiBlockPart[])parts; InitializeBase(); }
public static PlacedMultiBlockParent MakeMultiPlaced(Transform parent, MultiBlockInfo info, byte rotation, BlockPosition position, out PlacedMultiBlockPart[] parts) { if (!info.GetRotatedPositions(position, rotation, out KeyValuePair <BlockPosition, BlockSides>[] partPositions)) { parts = null; return(null); } GameObject block = InstantiatePrefab(parent, info, rotation, position); PlacedMultiBlockParent component = block.AddComponent <PlacedMultiBlockParent>(); // ReSharper disable once CoVariantArrayConversion InitializeMulti(component, info, rotation, position, partPositions, count => new PlacedMultiBlockPart[count], pair => new PlacedMultiBlockPart(pair.Value, pair.Key), out IMultiBlockPart[] tempParts); parts = (PlacedMultiBlockPart[])tempParts; return(component); }