/// <summary>
    /// Movement coroutine. Approaches a specified point, then fires a callback on completion.
    /// </summary>
    /// <returns>The to coroutine.</returns>
    /// <param name="target">Target.</param>
    /// <param name="onComplete">On complete.</param>
    /// <param name="minDistance">Minimum distance.</param>
    protected virtual IEnumerator MoveToCoroutine(Vector2 target, MovementCallback2d onComplete, float minDistance)
    {
        while (!SaFrMo.CloseEnough2d((Vector2)transform.position, target, minDistance))
        {
            Vector2 nextPoint = Vector2.MoveTowards((Vector2)transform.position, target, speed * Time.deltaTime);
            if (rigid2d != null)
            {
                rigid2d.MovePosition(nextPoint);
            }
            else
            {
                rigid.MovePosition((Vector3)nextPoint);
            }
            yield return(new WaitForEndOfFrame());
        }

        // Fire callback if specified
        if (onComplete != null)
        {
            onComplete.Invoke();
        }

        // Clean out current coroutine reference
        currentCoroutine = null;
    }
Пример #2
0
 void Start()
 {
     ToSlow   = SaFrMo.GetRandomBool();
     ToPlayer = SaFrMo.GetRandomBool();
     LifeSpan = 5f;
     Rate     = 0.05f;
 }
Пример #3
0
        public void RefreshBuilder()
        {
            // Refresh board state selectors
            allBoardStates.Setup <Board.BoardState> (
                board.boardStates.ToArray(),
                (button, boardState) => {
                RefreshStateButton(button, boardState);
            }
                );

            // Refresh grid size
            displayArray = new Cell[gridHeight][];
            for (int i = 0; i < gridHeight; i++)
            {
                displayArray [i] = new Cell[gridWidth];

                for (int j = 0; j < gridWidth; j++)
                {
                    int index = i * gridWidth + j;

                    // create an existing Cell and add to the master list if we need to
                    if (masterCellList.Count <= index)
                    {
                        Cell newCell = new Cell(SaFrMo.GenerateRandomString(), "Cell " + index);
                        masterCellList.Add(newCell);
                    }

                    displayArray [i] [j] = masterCellList [index];
                }
            }
            boardRows.Setup <Cell[]> (
                displayArray,
                (row, cells) => {
                row.GetComponent <MenuRefresher> ().Setup <Cell> (
                    cells,
                    (button, cell) => {
                    button.GetComponentInChildren <CellLink>().LinkTo(cell);
                }
                    );
            }
                );

            // Refresh cell selectors
            allCells.Setup <Cell> (
                board.cells.ToArray(),
                (button, cell) => {
                RefreshCellButton(button, cell);
            }
                );

            // Make sure each cell has a GameObject
//			cellActors.Setup<Cell> (
//				board.cells.ToArray (),
//				(createdObject, originalCell) => {
//
//				}
//			);
        }
    protected virtual void Start()
    {
        // Check for existing Rigidbody2D or Rigidbody
        rigid2d = GetComponent <Rigidbody2D>();
        rigid   = GetComponent <Rigidbody>();

        // Create Rigidbody2D if no Rigidbody2D or Rigidbody exists
        if (rigid2d == null && rigid == null)
        {
            rigid2d = SaFrMo.GetOrCreate <Rigidbody2D>(gameObject);
        }
    }
Пример #5
0
 public Board.BoardState AddState(string id, string name = "New State")
 {
     // Make sure our ID is unique
     while (board.boardStates.FindAll(x => x.id == id).Count > 0)
     {
         id = SaFrMo.GenerateRandomString();
     }
     Board.BoardState newState = new Board.BoardState(id, name);
     board.boardStates.Add(newState);
     RefreshBuilder();
     return(newState);
 }
Пример #6
0
 private void Start()
 {
     // Remove duplicates from enemyTypes
     enemyTypes = enemyTypes.Distinct().ToList();
     // Populate spawner UI with all spawnable prefabs
     spawnMenu.Setup <GameObject>(enemyTypes.ToArray(), (createdButton, enemy) => {
         // Change button text to reflect enemy name
         Text text = SaFrMo.GetComponentInTree <Text>(createdButton);
         text.text = enemy.name;
         // Callback to spawn enemy
         AttachEnemyAndSpawn(createdButton, enemy);
     });
 }
Пример #7
0
        public Cell AddCell(string id, string name = "New Cell")
        {
            // Make sure our ID is unique
            while (board.cells.FindAll(x => x.id == id).Count > 0)
            {
                id = SaFrMo.GenerateRandomString();
            }
            Cell newCell = new Cell(id, name);

            board.cells.Add(newCell);
            RefreshBuilder();
            return(newCell);
        }
Пример #8
0
    /// <summary>
    /// Gets a random object instantiated by the ResourceLibrary.
    /// </summary>
    /// <returns>The random original (ie, the GameObject instantiated by Resource.Load).</returns>
    public GameObject GetRandomOriginal()
    {
        string key = SaFrMo.Pick <string> (keys);

        return(dictionary [key]);
    }
Пример #9
0
    /// <summary>
    /// Copies a random resource held in this ResourceLibrary.
    /// </summary>
    /// <returns>The random resource.</returns>
    public GameObject CopyRandomResource()
    {
        string key = SaFrMo.Pick <string> (keys);

        return(CopyResource(key));
    }
Пример #10
0
 protected virtual void Start()
 {
     rigid = SaFrMo.GetOrCreate <Rigidbody> (gameObject);
 }
Пример #11
0
 public static void ShowToolTip(string message)
 {
     GUI.Window(0, new Rect(Input.mousePosition.x + 10f, SaFrMo.InputYToGUIY(Input.mousePosition.y), 300f, 150f), WindowFun, message);
     GUI.BringWindowToFront(0);
 }