Пример #1
0
        public void Save(IPlayerFactory player, Transform camera, TaskObject[] tasks, TaskModel taskModel)
        {
            if (!Directory.Exists(Path.Combine(_path)))
            {
                Directory.CreateDirectory(_path);
            }

            var transform = player.GetTransform();

            var tasksDone       = new bool [tasks.Length];
            int doneTasksAmount = taskModel.TasksDone;

            for (int i = 0; i < tasks.Length; i++)
            {
                tasksDone[i] = tasks[i].IsDone;
            }

            var savedData = new SavedData
            {
                PlayerPosition  = transform.position,
                PlayerRotation  = transform.rotation,
                CameraRotation  = camera.rotation,
                PlayerName      = player.GetTransform().transform.name,
                IsEnabled       = player.GetTransform().gameObject.activeSelf,
                TasksDone       = tasksDone,
                DoneTasksAmount = doneTasksAmount,
            };

            _data.Save(savedData, Path.Combine(_path, _FILE_NAME));
        }
Пример #2
0
        public void Load(IPlayerFactory player, Transform cameraTransform, TaskObject[] tasks, TaskModel taskModel)
        {
            var file = Path.Combine(_path, _FILE_NAME);

            if (!File.Exists(file))
            {
                return;
            }
            var savedData = _data.Load(file);

            var playerTransform = player.GetTransform();

            playerTransform.position        = savedData.PlayerPosition;
            playerTransform.rotation        = savedData.PlayerRotation;
            cameraTransform.rotation        = savedData.CameraRotation;
            playerTransform.gameObject.name = savedData.PlayerName;
            playerTransform.gameObject.SetActive(savedData.IsEnabled);
            taskModel.TasksDone = savedData.DoneTasksAmount;

            for (int i = 0; i < savedData.TasksDone.Length; i++)
            {
                if (tasks[i].IsDone && !savedData.TasksDone[i])
                {
                    taskModel.LoadTask(tasks[i]);
                }
                tasks[i].IsDone = savedData.TasksDone[i];
            }
        }
Пример #3
0
 public PlayerModel(IPlayerFactory playerFactory)
 {
     playerFactory.CreatePlayer();
     _characterController = playerFactory.GetCharacterController();
     _transform           = playerFactory.GetTransform();
     _camera   = playerFactory.GetCamera();
     _animator = playerFactory.GetAnimator();
 }