/// <summary> /// Подвинуть курсор /// </summary> void MoveCursor(int dX, int dY) { x += dX; y += dY; if (x < 0) { x = Gaborites.X - 1; } if (x >= Gaborites.X) { x = 0; } if (y < 0) { y = Gaborites.Y - 1; } if (y >= Gaborites.Y) { y = 0; } XX.Value = x + 1; YY.Value = y + 1; TheCell cell = getCell(x, y); cursor.transform.parent = cell.transform; RectTransform rt = cursor.GetComponent <RectTransform> (); rt.anchoredPosition = Vector2.zero; rt.sizeDelta = Vector2.zero; // cell.GetComponent<RectTransform> ().sizeDelta; mooved = true; }
void generate() { if (field == null) { TheCell img = null; field = new TheCell[Gaborites.X, Gaborites.Y]; for (int j = 0; j < Gaborites.Y; j++) { for (int i = 0; i < Gaborites.X; i++) { if (img == null) { img = imgPrefab; } else { img = Instantiate(imgPrefab.gameObject).GetComponent <TheCell> (); } RectTransform irt = img.GetComponent <RectTransform> (); irt.parent = GetComponent <RectTransform> (); img.transform.localScale = Vector3.one; img.sprite = 0; img.position = new Point(i, j); irt.anchoredPosition = (img.position * CellSize).ToVector2(); img.name = "Cell_" + i.ToString() + "_" + j.ToString(); field [i, j] = img; } } } }
/// <summary> /// Слопать яблоко /// </summary> public static void Catch(Point pPoint) { TheCell cell = instance.field[pPoint.X, pPoint.Y]; if (cell.sprite != 0) { fruitCount--; Debug.Log("Fruits: " + fruitCount.ToString()); cell.sprite = 0; RectTransform ert = Instantiate(instance.catchEffect).GetComponent <RectTransform> (); ert.transform.parent = cell.transform; ert.anchoredPosition = Vector2.zero; if (fruitCount <= 0) { TheGame.theGirl.ChangeState(GirlMode.Ready); TheGame.PlaySound(AnimState.Done); } else { TheGame.PlaySound(AnimState.Eat); } } }
public void drop(Vector2 startPoint, Vector2 pDirection, bool isPlayer, TheCell owner) { myOwner = owner; rt = GetComponent <RectTransform> (); rt.anchoredPosition = startPoint; flying = true; playerBy = isPlayer; endPoint = startPoint + pDirection * 3 * TheMap.cellSize; direction = pDirection; gameObject.SetActive(true); Sounds.Play(SoundType.DROP); if (pDirection.x > 0) { rt.localScale = new Vector2(-rt.localScale.x, rt.localScale.y); // right } else if (pDirection.y < 0) { rt.localRotation = Quaternion.Euler(0, 0, 90); // up } else if (pDirection.y > 0) { rt.localRotation = Quaternion.Euler(0, 0, -90); // down } }
public void LayOutGrid() { int cellNum = 23; for (int i = 0; i < cellList.Count; i++) { grid.RemoveChild(cellList[i].transform); Destroy(cellList[i].gameObject); } cellList.Clear(); for (int i = 0; i < cellNum; i++) { GameObject cellInstance = Instantiate(cellPrefab); cellInstance.transform.SetParent(grid.transform, false); TheCell theCell = cellInstance.GetComponent <TheCell>(); theCell.theLabel.text = i.ToString(); cellList.Add(theCell); //theCell.theButton.onClick if (null == theCell.theButton) { Debug.Log("~~~~~~~~~~~~"); } UIEventListener.Get(theCell.theButton.gameObject).onClick = ButtonTouched; } grid.repositionNow = true; }
public void DropSword(Vector2 pPosition, Vector2 pDirection, bool isPlayer, TheCell owner) { GameObject go = Instantiate(swordPrefab.gameObject); go.GetComponent <RectTransform>().SetParent(parentObject); go.transform.localScale = Vector3.one; Sword sw = go.GetComponent <Sword>(); sw.drop(pPosition, pDirection, isPlayer, owner); }
public void ButtonTouched(GameObject buttonObj) { int touchIndex = -1; for (int i = 0; i < cellList.Count; i++) { TheCell cell = cellList[i]; if (cell.theButton.gameObject == buttonObj) { touchIndex = i; break; } } Debug.Log("AAAAAAAAA" + touchIndex); }
/// <summary> /// Очистить шаги /// </summary> public static Step FindNextCell(Point pFrom, Point pTo, int pActionPrime, int pActionSec) { TheCell cellFrom = getCell(pFrom); cellFrom.stepIttNo = ++ittNo; heap.Clear(); heap.Enqueue(cellFrom); bool first = true; while (heap.Count > 0) { TheCell cell = heap.Dequeue(); foreach (Step stp in cell.Neighbors) { if (stp.cell.stepIttNo != ittNo) { stp.cell.stepIttNo = ittNo; stp.cell.firstStep = first ? stp:cell.firstStep; if (pTo == stp.cell.position) { return(stp.cell.firstStep); } heap.Enqueue(stp.cell); } } first = false; } /*if (cell == null) * { * foreach (Step s in cellFrom.Neighbors) * { * if ((s.stepType & pActionPrime) == pActionPrime) * return s.cell; * } * foreach (Step s in cellFrom.Neighbors) * { * if ((s.stepType & pActionSec) == pActionSec) * return s.cell; * } * } */ return(null); }
/// <summary> /// Получить тип ячейки по координатам /// </summary> public static EntityType getType(Point pPoint, bool pCorrect = false) { /* * if (pPoint.X < 0) * pPoint.X = Gaborites.X - pPoint.X; * else if (pPoint.X >= Gaborites.X) * pPoint.X -= Gaborites.X; */ TheCell cell = getCell(pPoint.X, pPoint.Y, pCorrect); if (cell == null) { return(EntityType.UnkNown); } return(instance.spriteSet [cell.sprite].type); }
/// <summary> /// Поменять спрайт /// </summary> void ChangeSprite(int pMoveTo) { if (!mooved) { sprNo += pMoveTo; if (sprNo >= spriteSet.Length) { sprNo = 0; } if (sprNo < 0) { sprNo = spriteSet.Length - 1; } } TheCell cell = getCell(x, y); cell.sprite = sprNo; mooved = false; SS.Value = sprNo; }
public static void UpdateCell(int pNo, string pNewName, TheCell who) { instance.map[pNo] = (byte)instance.GETSpriteNo(pNewName); who.init(pNo); }