示例#1
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);
        }
示例#2
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);
            }
        }