public bool isPipeConnectionLegal(Pipe.PipeType pt, int x, int y) { switch (pt) { case Pipe.PipeType.LeftDownPipe: return(x == -1 || y == -1); case Pipe.PipeType.RightDownPipe: return(x == 1 || y == 1); case Pipe.PipeType.LeftUpPipe: return(x == -1 || y == 1); case Pipe.PipeType.RightUpPipe: return(x == 1 || y == -1); case Pipe.PipeType.VerticalPipe: return(y == 1 || y == -1); case Pipe.PipeType.HorizontalPipe: return(x == 1 || x == -1); default: return(false); } }
private void GenerateObject(int x, int y, Texture2D mapTexture, SerializedProperty pipes) { pixelColor = mapTexture.GetPixel(x, y); if (pixelColor.a == 0) { return; } foreach (PixelToObject pixelColorMapping in lm.pixelColorMappings) { if (pixelColorMapping.pixelColor.Equals(pixelColor)) { Vector3 pos = new Vector3(0, (y * prefabSize) + prefabSize / 2, (x * prefabSize) + prefabSize / 2); GameObject obj = pixelColorMapping.prefab; Pipe.PipeType type = (Pipe.PipeType)System.Enum.Parse(typeof(Pipe.PipeType), obj.name); //pipes.InsertArrayElementAtIndex(pipes.arraySize); pipes.arraySize++; pipes.GetArrayElementAtIndex(pipes.arraySize - 1).FindPropertyRelative("Type").intValue = (int)type; pipes.GetArrayElementAtIndex(pipes.arraySize - 1).FindPropertyRelative("pos").vector3Value = pos; pipes.GetArrayElementAtIndex(pipes.arraySize - 1).FindPropertyRelative("prefab").objectReferenceValue = obj; } } }