Beispiel #1
0
    public void SaveGameCellsDict(int saveIndex)
    {
        var saveCellsDict = new SaveCellsDict();

        if (_storageProvider.LoadGameCellsDict() != null)
        {
            saveCellsDict = _storageProvider.LoadGameCellsDict();
        }

        var globalScore = Score.GetComponent <Score>().GlobalScore;
        var localScore  = Score.GetComponent <Score>().LocalScore;

        var ballsList = new List <Ball>();
        var balls     = GameObject.FindGameObjectsWithTag("Ball");

        foreach (var ball in balls)
        {
            var ballObject = new Ball
            {
                BallPosition = ball.GetComponent <BallMovement>().GetBallPosition(),
                BallMovement = ball.GetComponent <BallMovement>().GetTempBallMovement(),
                DirectionX   = ball.GetComponent <BallMovement>().DirectionX,
                DirectionY   = ball.GetComponent <BallMovement>().DirectionY,
                BallColor    = ball.GetComponent <SpriteRenderer>().color
            };
            ballsList.Add(ballObject);
        }

        var ballsCount = balls.Length;


        var racketPosition = RacketMovement.GetComponent <RacketMovement>().GetRacketPosition();

        var level      = BlockManager.Instance.CurrentLevel;
        var levelState = BlockManager.Instance.CurrentLevelState;

        var gameState = new GameState()
        {
            GlobalScore    = globalScore,
            LocalScore     = localScore,
            Balls          = ballsList,
            BallsCount     = ballsCount,
            RacketPosition = racketPosition,
            Level          = level,
            LevelState     = levelState
        };

        var timeStamp = DateTime.Now;

        var saveCell = new SaveCell()
        {
            GameState = gameState,
            TimeStamp = timeStamp
        };

        saveCellsDict.SaveCells[saveIndex] = saveCell;
        _storageProvider.SaveGameCellsDict(saveCellsDict);
    }
Beispiel #2
0
 private void SelectSaveCell(DateTime dateTime, SaveCell saveCell)
 {
     if (isSelected)
     {
         selectedSaveCell.SetButtonInteractable(true);
     }
     else
     {
         SetSaveDataSelected(false);
     }
     selectedSaveDateTime = dateTime;
     selectedSaveCell     = saveCell;
     SetSaveDataSelected(true);
     selectedSaveCell.SetButtonInteractable(false);
 }
Beispiel #3
0
        /// <summary>
        /// Init saved properties
        /// </summary>
        /// <param name="savedProperties"></param>
        public void Init(SaveCell savedProperties)
        {
            _state    = savedProperties.state;
            _walkable = savedProperties.walkable;

            if (savedProperties.state == CellState.SEA)
            {
                _walkable = false;
            }
            UpdateHeight(savedProperties.elevation - _groundMesh.centerPosition.magnitude);
            InitColor();

            if (savedProperties.Names != null)
            {
                SpawnSavedProps(savedProperties);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Spawn saved Props
        /// </summary>
        /// <param name="savedItem"></param>
        protected void SpawnSavedProps(SaveCell savedItem)
        {
            int nbProps = savedItem.Names.Length;

            for (int i = 0; i < nbProps; i++)
            {
                if (savedItem.Names[i] == null || savedItem.Names[i] == string.Empty)
                {
                    continue;
                }

                GameObject model = Resources.Load <GameObject>("Game/" + savedItem.Names[i]);
                if (savedItem.buildingLinkedItems[i].type != EnumClass.TypeBuilding.None && model)
                {
                    EarthManager.Instance.CreateSavedProps(
                        model,
                        new Vector3(savedItem.propsX[i], savedItem.propsY[i], savedItem.propsZ[i]),
                        this,
                        new Quaternion(savedItem.propsRotX[i], savedItem.propsRotY[i], savedItem.propsRotZ[i], savedItem.propsRotW[i]),
                        savedItem.buildingLinkedItems[i]
                        );
                }
                else if (model)
                {
                    EarthManager.Instance.CreateSavedProps(
                        model,
                        new Vector3(savedItem.propsX[i], savedItem.propsY[i], savedItem.propsZ[i]),
                        this,
                        new Quaternion(savedItem.propsRotX[i], savedItem.propsRotY[i], savedItem.propsRotZ[i], savedItem.propsRotW[i])
                        );
                }
                else
                {
                    Debug.LogError("Modele de props non existant (" + savedItem.Names[i] + ") dans le dossier cible !");
                }
            }
        }
Beispiel #5
0
 private void InitialiseSaveCell(SaveCell saveCell, Saves.SaveData saveData) => saveCell.Initialise(saveData, SelectSaveCell);
        protected void CreateCells(EPartyType partyType)
        {
            foreach (GroundMesh ground in planetLink.allGroundMesh)
            {
                GameObject newGo = Instantiate(_cellPrefab, Vector3.zero, Quaternion.identity, planetLink.transform);
                _cellsObj.Add(newGo);

                Cell newCell = newGo.GetComponent <Cell>();
                newCell.SetID();
                newCell.Init(ground);

                Mesh finalMesh = newCell.gameObject.GetComponent <MeshFilter>().mesh;
                finalMesh.vertices  = ground.smoothVertex;
                finalMesh.triangles = ground.smoothTriangles;
                finalMesh.normals   = ground.smoothNormals;
                finalMesh.uv        = ground.UVs;
                newCell.gameObject.GetComponent <MeshCollider>().sharedMesh = finalMesh;
                finalMesh.RecalculateBounds();

                _cells.Add(newCell);
            }

            planetLink.GenerateNeighborLinks(planetLink.GetMinimalNeighborDistance(), _cells);

            if (partyType == EPartyType.SAVE)
            {
                int  l = _cells.Count;
                Cell cCell;
                for (int i = 0; i < l; i++)
                {
                    cCell = _cells[i];
                    Mesh            finalMesh = cCell.gameObject.GetComponent <MeshFilter>().mesh;
                    List <SaveCell> outCells;
                    ArrayExtensions.ToList(PlanetSave.GameStateSave.SavedCells, out outCells);
                    SaveCell sCell = outCells.Find(c => c.ID == cCell.ID);
                    cCell.Init(sCell);

                    cCell.SetPolution(sCell.poluted);
                    if (sCell.poluted)
                    {
                        PolutionArea.CELLS_USED.Add(cCell);
                    }
                    cCell.SetDeforestation(sCell.deforested);
                    if (sCell.deforested)
                    {
                        DeforestationArea.CELLS_USED.Add(cCell);
                    }

                    UpdateNbCell(cCell.State);

                    finalMesh.vertices  = cCell.GroundMesh.smoothVertex;
                    finalMesh.triangles = cCell.GroundMesh.smoothTriangles;
                    finalMesh.normals   = cCell.GroundMesh.smoothNormals;
                    finalMesh.uv        = cCell.GroundMesh.UVs;

                    cCell.gameObject.GetComponent <MeshCollider>().sharedMesh = finalMesh;
                    finalMesh.RecalculateBounds();
                }
            }
            else if (partyType == EPartyType.NEW)
            {
                if (PlanetSave.LoadCells(playingPlanetName))
                {
                    foreach (Cell cCell in _cells)
                    {
                        Mesh     finalMesh = cCell.gameObject.GetComponent <MeshFilter>().mesh;
                        SaveCell sCell     = PlanetSave.BaseCells.Find(c => c.ID == cCell.ID);
                        cCell.Init(sCell);

                        UpdateNbCell(cCell.State);

                        finalMesh.vertices  = cCell.GroundMesh.smoothVertex;
                        finalMesh.triangles = cCell.GroundMesh.smoothTriangles;
                        finalMesh.normals   = cCell.GroundMesh.smoothNormals;
                        finalMesh.uv        = cCell.GroundMesh.UVs;

                        cCell.gameObject.GetComponent <MeshCollider>().sharedMesh = finalMesh;
                        finalMesh.RecalculateBounds();
                    }
                }
            }
        }