//============================================= // конструктор public void Create_Queue_Figura(CarcasType type, Transform parent) { carcas_type = type; carcas = FiguraCarcasesList.get_Carcas_byType(carcas_type); // создание плашки DestroyGraphicsObjects(); plashka = (GameObject)Instantiate(Resources.Load(GameConstants.PREFAB_PLASHKA), parent); //, parent plashka.transform.SetParent(parent); plashka.transform.localPosition = new Vector3(0f, 0f, 0f); //localPosition GameConstants.QUEUE_ITEM_HEIGHT / 2f plashka.GetComponent <SpriteRenderer>().maskInteraction = SpriteMaskInteraction.VisibleInsideMask; //plashka.transform.localScale = GameConstants.PLASHKA_SCALE; //Animator anim = prefab.GetComponent<Animator>(); //anim.runtimeAnimatorController = (RuntimeAnimatorController)Instantiate(Resources.Load(animation)) as RuntimeAnimatorController; //anim.Play("Idle"); //создание фигуры по центру плашки Vector2 min = new Vector2((float)carcas.getMinD(0), (float)carcas.getMinD(1)); Vector2 size = new Vector2((float)carcas.getMaxD(0) - min.x + 1f, (float)carcas.getMaxD(1) - min.y + 1f); //Ширина плашки = 5 x Ширина квадрата , поэтому crd = Xn-Xmin - FIGURA_WIDTH/2 + 1/2 //Высота плашки = 3.9 x Высоты квадрата for (int i = 0; i < carcas.numPoints; i++) { float dx = (0.5f - min.x - size.x / 2f + (float)carcas.coords[i, 0]) * GameConstants.QUEUE_SQUARE_SIZE.x; //f - maxwidth float dy = (0.45f - min.y - size.y / 2f + (float)carcas.coords[i, 1]) * GameConstants.QUEUE_SQUARE_SIZE.y; //myUtils.console_log(dx, dy); OneSquare square = myUtils.create_OneSquare(new Vector3(dx, dy, 0f), plashka.transform, GameConstants.QUEUE_SQUARE_SCALE, -1, GameConstants.sANIM_BASE); squaresList.Add(square); } //plashka.transform.localPosition = plashka.transform.localPosition + new Vector3(0f, GameConstants.QUEUE_ITEM_HEIGHT/2f, 0f); //localPosition }
//============================================= //создать новую фигуру на базе фигуры из очереди (взять из нее каркас и типы камней) //queueFigura - каркас + типы квадратов (без графики) public void Create_Figura(OneQueueFigura queueFigura, Transform parent) { carcas_type = queueFigura.carcas_type; carcas = queueFigura.carcas; //myUtils.console_log(carcas_type, carcas); //создание фигуры по центру плашки Vector2 min = new Vector2((float)carcas.getMinD(0), (float)carcas.getMinD(1)); Vector2 pt_center = new Vector2((float)GameConstants.AREA_WIDTH / 2f, -min.y + (float)GameConstants.AREA_VISUAL_HEIGHT); for (int i = 0; i < carcas.numPoints; i++) { int type = queueFigura.squaresList[i].type; float dx = GameConstants.AREA_START.x + ((float)carcas.coords[i, 0] + pt_center.x + 0.5f) * GameConstants.AREA_SQUARE_SIZE.x; float dy = GameConstants.AREA_START.y + ((float)carcas.coords[i, 1] + pt_center.y + 0.5f) * GameConstants.AREA_SQUARE_SIZE.y; OneSquare square = myUtils.create_OneSquare(new Vector3(dx, dy, 0f), parent, GameConstants.AREA_SQUARE_SCALE, type, GameConstants.sANIM_BASE); squaresList.Add(square); } coords = new Vector2Int( Mathf.RoundToInt(pt_center.x), Mathf.RoundToInt(pt_center.y) ); delta = new Vector2(0f, 0f); last_move_time = 0f; rotate_index = 0; flagFastSpeed = false; figure_area_acept_time = 0; anti_click_space_first_frame = true; }
//======================================================================= public static OneSquare create_OneSquare(Vector3 crd, Transform parent, Vector3 scale, int brick_type = -1, string animation = GameConstants.sANIM_BASE) { OneSquare square = new OneSquare(); square.Create(crd, parent, scale, brick_type, animation); /* * if (brick_type < 0) { * brick_type = (int)UnityEngine.Random.Range(0f, 5f); * } * square.type = brick_type; * square.brick_name = "Brick_" + square.type.ToString(); * string path_to_prefab = "Prefab/bricks/" + square.brick_name; * GameObject prefab = (GameObject)Instantiate(Resources.Load(path_to_prefab)); //, parent * prefab.transform.SetParent(parent); * prefab.transform.localPosition = crd; * prefab.transform.localScale = scale; * * Animator anim = prefab.GetComponent<Animator>(); * //myUtils.console_log(animation); * anim.runtimeAnimatorController = (RuntimeAnimatorController) Instantiate(Resources.Load(animation)) as RuntimeAnimatorController; * anim.Play("Idle"); */ return(square); }