private void Build(Tetramino.TetraminoType tetrominoType) { Tetramino tetromino = new Tetramino(tetrominoType); Vector3 rotationPoint = tetromino.rotationPoint; Vector2Int[] poses = tetromino.Poses; Vector3 w_tetrominoPosition = transform.position; Vector3 l_rotationTransformPosition = rotationPoint; Vector3[] l_cellTransformPositions = CellPosesRelative2RotationPoint(poses, rotationPoint); GameObject rotation_gameObject = new GameObject("Rotation transform"); rotationTransform = AssignParentAndLocalPosition(rotation_gameObject, transform, l_rotationTransformPosition); List <Transform> cellTransformsList = new List <Transform>(); int cellIndex = 0; foreach (Vector3 pos in l_cellTransformPositions) { GameObject cell_go = Instantiate(tetrominoCellPrefab).gameObject; cell_go.name = $"Cell index: {cellIndex++}"; cellTransformsList.Add ( AssignParentAndLocalPosition(cell_go, rotationTransform, pos) ); } cellTransforms = cellTransformsList.ToArray(); }
public static Tetramino SetUp(Tetramino tetramino, Tetramino.TetraminoType type) { tetramino.type = type; switch (type) { case TetraminoType.I: tetramino.Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 } }); tetramino.rotationPoint = new Vector2(3f / 2f, -1f / 2f); break; case TetraminoType.J: tetramino.Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 1, 2 } }); tetramino.rotationPoint = new Vector2(1f, 1f); break; case TetraminoType.L: tetramino.Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 0, 2 } }); tetramino.rotationPoint = new Vector2(0f, 1f); break; case TetraminoType.O: tetramino.Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }); tetramino.rotationPoint = new Vector2(1f / 2f, 1f / 2f); break; case TetraminoType.S: tetramino.Poses = GetPoses(new int[4, 2] { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 2, 1 } }); tetramino.rotationPoint = new Vector2(1f, 0f); break; case TetraminoType.T: tetramino.Poses = GetPoses(new int[4, 2] { { 1, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 } }); tetramino.rotationPoint = new Vector2(1f, 1f); break; case TetraminoType.Z: tetramino.Poses = GetPoses(new int[4, 2] { { 0, 1 }, { 1, 1 }, { 1, 0 }, { 2, 0 } }); tetramino.rotationPoint = new Vector2(1f, 0f); break; default: Debug.LogError("Unsupported tetramino type: " + type); break; } return(tetramino); }
private void SetColor(Tetramino.TetraminoType type) { int childCount; SpriteRenderer[] spriteRenderers = GetComponentUtil.GetComponentsInChildren <SpriteRenderer>(transform, out childCount); LoopUtil.LoopAction((i) => spriteRenderers[i].color = TetraminoUtil.Color(type), childCount); }
public static GameObject Instantiate(Tetramino.TetraminoType type, string name = "") { GameObject instance = new GameObject(name); TetraminoMono tetraminoMono = instance.AddComponent <TetraminoMono>(); tetraminoMono.type = type; tetraminoMono.Init(); return(instance); }
private static string VectorPosesString(Tetramino.TetraminoType tetraminoType, RotationDirection rotationDirection) { Vector2Int[] tetraminoPoses = TetraminoTransformUtil.GetPoses(tetraminoType, RotationDirection.None); Vector2Int[] rotationVectorPoses = new Vector2Int[4]; Vector2 rotationPoint = new Tetramino(tetraminoType).rotationPoint; for (int i = 0; i < 4; i++) { Vector2 rotated = RotateVector.Rotate(tetraminoPoses[i], rotationPoint, rotationDirection); rotationVectorPoses[i] = VectorUtil.V2_V2Int(rotated); } return(string.Join("\t", rotationVectorPoses)); }
private void SetColor(Tetramino.TetraminoType type) { int childCount; SpriteRenderer[] spriteRenderers = GetSpriteRenderers(transform, out childCount); #region old version //for (int i = 0; i < 4; i++) //{ // Transform child = transform.GetChild(i); // SpriteRenderer spriteRenderer = child.GetComponent<SpriteRenderer>(); // spriteRenderer.color = TetraminoUtil.Color(type); //} #endregion LoopUtil.LoopAction((i) => spriteRenderers[i].color = TetraminoUtil.Color(type), childCount); }
public static Color Color(Tetramino.TetraminoType tetraminoType) { Color color = UnityEngine.Color.white; TetraminoColors tetraminoColors = ScriptableObjectsHolder.TetraminoColors; switch (tetraminoType) { case Tetramino.TetraminoType.I: color = tetraminoColors.I; break; case Tetramino.TetraminoType.J: color = tetraminoColors.J; break; case Tetramino.TetraminoType.L: color = tetraminoColors.L; break; case Tetramino.TetraminoType.O: color = tetraminoColors.O; break; case Tetramino.TetraminoType.S: color = tetraminoColors.S; break; case Tetramino.TetraminoType.T: color = tetraminoColors.T; break; case Tetramino.TetraminoType.Z: color = tetraminoColors.Z; break; default: Debug.LogError("Unsupported tetramino type: " + tetraminoType); break; } return(color); }
public static Vector2Int[] GetPoses(Tetramino.TetraminoType tetraminoType, RotationDirection rotationDirection) { Tetramino tetramino = new Tetramino(tetraminoType); switch (rotationDirection) { case RotationDirection.None: break; case RotationDirection.Clockwise: tetramino.RotateClockwise(); break; case RotationDirection.CounterClockwise: tetramino.RotateAntiClockwise(); break; default: throw new UnityException($"RotationDirection type<{rotationDirection}> not supported!"); } return(tetramino.Poses); }
//[SerializeField] RotationDirection rotationDirection; //[SerializeField] Tetramino.TetraminoType tetraminoType; //[ContextMenu("Test")] //public void Test() //{ // Vector2Int[] tetraminoRotatedPoses = Tetramino.GetPoses(tetraminoType, rotationDirection); // Vector2Int[] tetraminoPoses = Tetramino.GetPoses(tetraminoType, RotationDirection.None); // Vector2Int[] rotationVectorPoses = new Vector2Int[4]; // Vector2 rotationPoint = new Tetramino(tetraminoType).rotationPoint; // for (int i = 0; i < 4; i++) // { // Vector2 rotated = RotateVector.Rotate(tetraminoPoses[i] - rotationPoint, rotationDirection); // rotationVectorPoses[i] = VectorUtil.V2_V2Int(rotated + rotationPoint); // } // Debug.Log("RotateVector:"); // Debug.Log(string.Join("\t", rotationVectorPoses)); // Debug.Log("TetraminoRotate:"); // Debug.Log(string.Join("\t", tetraminoRotatedPoses)); //} private static string TetraminoString(Tetramino.TetraminoType tetraminoType, RotationDirection rotationDirection) { Vector2Int[] tetraminoRotatedPoses = TetraminoTransformUtil.GetPoses(tetraminoType, rotationDirection); return(string.Join("\t", tetraminoRotatedPoses)); }
public static Color Color(Tetramino.TetraminoType tetraminoType) { Color color = UnityEngine.Color.white; TetraminoColors tetraminoColors = ScriptableObjectsHolder.TetraminoColors; switch (tetraminoType) { case Tetramino.TetraminoType.I: color = //new Color(0f, 0.7686275f, 0.8666667f) tetraminoColors.I ; break; case Tetramino.TetraminoType.J: color = //new Color(0f, 0.4509804f, 0.8431373f) tetraminoColors.J ; break; case Tetramino.TetraminoType.L: color = //new Color(0.8078432f, 0.5333334f, 0f) tetraminoColors.L ; break; case Tetramino.TetraminoType.O: color = //new Color(0.8627452f, 0.7921569f, 0f) tetraminoColors.O ; break; case Tetramino.TetraminoType.S: color = //new Color(0f, 0.8392158f, 0.227451f) tetraminoColors.S ; break; case Tetramino.TetraminoType.T: color = //new Color(0.7019608f, 0f, 0.8470589f) tetraminoColors.T ; break; case Tetramino.TetraminoType.Z: color = //new Color(0.8274511f, 0f, 0f) tetraminoColors.Z ; break; default: Debug.LogError("Unsupported tetramino type: " + tetraminoType); break; } return(color); }
public void UploadNewTetraminoData(Tetramino.TetraminoType type) { this._tetramino = new Tetramino(type); }
public void UploadNewTetraminoData(Tetramino.TetraminoType type) { _tetramino = null; this.type = type; }