コード例 #1
0
    /// <summary>
    /// 初始化Point列表
    /// </summary>
    public void Init()
    {
        //获得Point列表
        var points = wmanager.Points;

        for (int i = 0; i < points.Length; i++)
        {
            //每个Point实例化一个GO
            GameObject go = GameObject.Instantiate <GameObject>(PointPrefab, ContentObject);
            //初始化PointController
            PointController controller = go.GetComponent <PointController>();
            controller.Init(points[i], wmanager.IsEnabled(points[i]));
        }
    }
コード例 #2
0
    private void SpawnPoint(DIRECTION direction, POINTTYPE type)
    {
        GameObject      pointObject = Instantiate(GetPointPrefab(type));
        PointController point       = pointObject.GetComponent <PointController>();

        point.Init(direction);

        pointsList.Add(point);

        // Determine what row/column to spawn in
        int row    = 0;
        int column = 0;

        switch (direction)
        {
        case DIRECTION.UP:
            row    = 0;
            column = Random.Range(0, 10);
            break;

        case DIRECTION.DOWN:
            row    = 9;
            column = Random.Range(0, 10);
            break;

        case DIRECTION.LEFT:
            row    = Random.Range(0, 10);
            column = 9;
            break;

        case DIRECTION.RIGHT:
            row    = Random.Range(0, 10);
            column = 0;
            break;
        }

        // Determine starting location
        Vector2 offsetDir    = GridManager.DirectionToVector(GridManager.GetOppositeDirection(direction));
        Vector2 baseLocation = gridManager.GetRealLocation(row, column);

        pointObject.transform.position = baseLocation + offsetDir * offscreenOffset;
    }