private void Update() { if ((blocInstantie) && (Input.GetMouseButton(0))) { blocPosition.Set(Input.mousePosition.x, Input.mousePosition.y, 5); blocPosition = cam.ScreenToWorldPoint(blocPosition); blocPosition.Set(blocPosition.x, blocPosition.y, 4.9f); blocInstantie.transform.position = blocPosition; blocInstantie.transform.localScale = blocScale; } if ((blocInstantie) && (Input.GetMouseButtonUp(0))) { grille.VerifierContenu(blocInstantie, blocPosition, (int)blocRotation); DestroyImmediate(blocInstantie.gameObject); blocInstantie = null; blocPosition.Set(0, 0, 0); //blocRotation.Set(0, 0, 0); } }
public void VerifierContenu(BlocObject blocObject, Vector3 position, int rotation) { Debug.Log("Rotation = " + rotation); for (int i = 0; i < TAILLE; ++i) { for (int j = 0; j < TAILLE; ++j) { GameObject quad = quads[i, j]; Collider collider = quad.GetComponent <Collider>(); Renderer renderer = quad.GetComponent <Renderer>(); Vector2Int min = Vector2Int.zero; Vector2Int max = Vector2Int.zero; int deltaX = 0; int deltaY = 0; switch (rotation) { case 0: min.x = i + blocObject.bloc.min.x; min.y = j + blocObject.bloc.min.y; max.x = i + blocObject.bloc.max.x; max.y = j + blocObject.bloc.max.y; break; case 90: min.x = i - blocObject.bloc.max.y; min.y = j + blocObject.bloc.min.x; max.x = i - blocObject.bloc.min.y; max.y = j + blocObject.bloc.max.x; break; case 180: break; case 270: break; } if (collider.bounds.Contains(position) && (min.x >= 0) && (min.y >= 0) && (max.x < TAILLE) && (max.y < TAILLE)) { foreach (Case c in blocObject.bloc.cases) { switch (rotation) { case 0: if (!contenus[i - c.XD, j - c.YD]) { return; } break; case 90: if (!contenus[i - c.XD, j - c.YD]) { return; } break; case 180: if (!contenus[i - c.XD, j - c.YD]) { return; } break; case 270: if (!contenus[i - c.XD, j - c.YD]) { return; } break; } if (!contenus[i - c.XD, j - c.YD]) { return; } } int ID = Master.mastersing.currentTuileActive; Bloc blocTuile = blocObject.bloc; foreach (Case c in blocObject.bloc.cases) { quads[i - c.XD, j - c.YD].GetComponent <Renderer>().material = c.Mat; contenus[i - c.XD, j - c.YD] = false; quads[i - c.XD, j - c.YD].GetComponent <CaseBlock>().caseblock = c; } Master.mastersing.TuilesMap[ID].blockList.Add(blocTuile); return; } } } /*foreach (Case c in blocObject.bloc.cases) * { * c. * }*/ /*switch (rotation) * { * case 0: * for (int i = 0; i < TAILLE; ++i) * { * for (int j = 0; j < TAILLE; ++j) * { * GameObject quad = quads[i, j]; * Collider collider = quad.GetComponent<Collider>(); * Renderer renderer = quad.GetComponent<Renderer>(); * * if (collider.bounds.Contains(position) && * (i + 1 < TAILLE) && (j + 2 < TAILLE) && * !contenus[i, j] && !contenus[i, j + 1] && !contenus[i + 1, j] && !contenus[i, j + 2]) * { * renderer.material = rouge; * quads[i, j + 1].GetComponent<Renderer>().material = rouge; * quads[i + 1, j].GetComponent<Renderer>().material = rouge; * quads[i, j + 2].GetComponent<Renderer>().material = rouge; * * contenus[i, j] = true; * contenus[i, j + 1] = true; * contenus[i + 1, j] = true; * contenus[i, j + 2] = true; * } * } * } * break; * }*/ }
public void CreerBloc() { blocInstantie = Instantiate(blocObject, canvas.transform); }