Exemplo n.º 1
0
        public void RemoveBall(int col, int row)
        {
            GridPosition gridId = new GridPosition(col, row);

            if (Balls.ContainsKey(gridId))
            {
                LevelBall        deleteball     = Balls[gridId];
                List <LevelBall> connectedBalls = new List <LevelBall>();
                GetConnectedBalls(col, row, connectedBalls);
                foreach (var b in connectedBalls)
                {
                    b.Connections.Remove(deleteball);
                }
                Balls.Remove(gridId);
                DestroyImmediate(deleteball.gameObject);
            }
        }
Exemplo n.º 2
0
        public void AddBall(int col, int row, ELevelBallType type)
        {
            GameObject prefab = BallPrefabs[type];
            GameObject ball   = PrefabUtility.InstantiatePrefab(prefab) as GameObject;

            ball.name = string.Format("[{0},{1}][{2}]", col, row, type.ToString());
            ball.transform.SetParent(this.transform);
            ball.transform.localPosition = GridToPosition(col, row);
            //ball.hideFlags = HideFlags.HideInHierarchy;
            LevelBall newball = ball.GetComponent <LevelBall>();

            newball.Id = NewBallId;
            List <LevelBall> connectedBalls = new List <LevelBall>();

            GetConnectedBalls(col, row, connectedBalls);
            foreach (var b in connectedBalls)
            {
                newball.Connections.Add(b);
                b.Connections.Add(newball);
            }

            Balls.Add(new GridPosition(col, row), newball);
        }
Exemplo n.º 3
0
        public void LoadLevelMap()
        {
            byte[]       databytes = File.ReadAllBytes(GetLevelDataPath(LevelId));
            LevelMapData data      = new LevelMapData();

            data.LoadFromBytes(databytes);
            MapType = (ELevelMapType)data.mapType;

            nextBallId = data.maxBallId + 1;

            foreach (var ballData in data.balls)
            {
                ELevelBallType type   = (ELevelBallType)ballData.type;
                int            col    = ballData.grids[0].col;
                int            row    = ballData.grids[0].row;
                int            ballId = ballData.id;

                GameObject prefab = BallPrefabs[type];
                GameObject ball   = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                ball.name = string.Format("[{0},{1}][{2}]", col, row, type.ToString());
                ball.transform.SetParent(this.transform);
                ball.transform.localPosition = GridToPosition(col, row);
                ball.hideFlags = HideFlags.HideInHierarchy;
                LevelBall newball = ball.GetComponent <LevelBall>();
                newball.Id = ballId;

                List <LevelBall> connectedBalls = new List <LevelBall>();
                GetConnectedBalls(col, row, connectedBalls);
                foreach (var b in connectedBalls)
                {
                    newball.Connections.Add(b);
                    b.Connections.Add(newball);
                }

                Balls.Add(new GridPosition(col, row), newball);
            }
        }