Skip to content

Commit

Permalink
SaveManager WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7c13 committed Oct 6, 2022
1 parent ca3b28a commit 23673aa
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/Core/Utils/UnitySupportedVideoFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static HashSet<string> GetSupportedVideoFormats(RuntimePlatform platform)
RuntimePlatform.IPhonePlayer => iOSSupportedVideoFormats,
RuntimePlatform.Android => AndroidSupportedVideoFormats,

_ => new () {".mp4" }
_ => new HashSet<string> {".mp4" }
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Editor/GameVariantSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static void AddSymbol(string symbolToAdd)
{
allDefines.Add(symbolToAdd);
}

allDefines.Sort();
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup,
string.Join(";", allDefines.ToArray()));
}
Expand Down
12 changes: 10 additions & 2 deletions Assets/Scripts/Pal3/Actor/HuaYingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class HuaYingController : FlyingActorController,
private const float FOLLOW_TARGET_X_OFFSET = -0.8f;
private const float FOLLOW_TARGET_Y_OFFSET = -0.8f;

private readonly PlayerActorId _followActorId = PlayerActorId.XueJian;
private const PlayerActorId FOLLOW_ACTOR_ID = PlayerActorId.XueJian;

private SceneManager _sceneManager;
private ActorController _actorController;
Expand All @@ -35,6 +35,7 @@ public sealed class HuaYingController : FlyingActorController,
private ActorActionController _targetActorActionController;
private float _targetHeight;
private bool _followTarget = true;
private int _currentMode = 1; // defaults to follow target actor

public void Init(ActorController actorController,
ActorActionController actionController)
Expand All @@ -44,6 +45,11 @@ public void Init(ActorController actorController,
_sceneManager = ServiceLocator.Instance.Get<SceneManager>();
}

public int GetCurrentMode()
{
return _currentMode;
}

private void OnEnable()
{
CommandExecutorRegistry<ICommand>.Instance.Register(this);
Expand Down Expand Up @@ -116,7 +122,7 @@ private void LateUpdate()

private void FindAndSetTarget()
{
_target = _sceneManager.GetCurrentScene().GetActorGameObject((byte) _followActorId);
_target = _sceneManager.GetCurrentScene().GetActorGameObject((byte) FOLLOW_ACTOR_ID);
_targetActorController = _target.GetComponent<ActorController>();
_targetActorActionController = _target.GetComponent<ActorActionController>();
_isTargetRegistered = true;
Expand All @@ -139,6 +145,8 @@ public void Execute(HuaYingSwitchBehaviourModeCommand command)
_followTarget = false;
break;
}

_currentMode = command.Mode;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Pal3/Audio/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ public IEnumerator PlayMusic(string musicFileVirtualPath, string musicFileCacheP
new CancellationToken(false))); // Should not stop music during scene switch
}

public string GetCurrentScriptMusic()
{
return _currentScriptMusic;
}

private void DestroyAllSfxAudioSource()
{
// Destroy current playing sfx
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Pal3/Pal3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ private void OnEnable()
_scriptManager,
_favorManager,
_cameraManager,
_audioManager,
_postProcessManager);
ServiceLocator.Instance.Register(_saveManager);

Expand Down
27 changes: 23 additions & 4 deletions Assets/Scripts/Pal3/State/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Pal3.State
using System.IO;
using System.Linq;
using Actor;
using Audio;
using Camera;
using Command;
using Command.InternalCommands;
Expand Down Expand Up @@ -40,6 +41,7 @@ public class SaveManager
private readonly ScriptManager _scriptManager;
private readonly FavorManager _favorManager;
private readonly CameraManager _cameraManager;
private readonly AudioManager _audioManager;
private readonly PostProcessManager _postProcessManager;

private const string SAVE_FILE_NAME = "save.txt";
Expand All @@ -51,6 +53,7 @@ public SaveManager(SceneManager sceneManager,
ScriptManager scriptManager,
FavorManager favorManager,
CameraManager cameraManager,
AudioManager audioManager,
PostProcessManager postProcessManager)
{
_sceneManager = sceneManager ?? throw new ArgumentNullException(nameof(sceneManager));
Expand All @@ -60,6 +63,7 @@ public SaveManager(SceneManager sceneManager,
_scriptManager = scriptManager ?? throw new ArgumentNullException(nameof(scriptManager));
_favorManager = favorManager ?? throw new ArgumentNullException(nameof(favorManager));
_cameraManager = cameraManager != null ? cameraManager : throw new ArgumentNullException(nameof(cameraManager));
_audioManager = audioManager != null ? audioManager : throw new ArgumentNullException(nameof(audioManager));
_postProcessManager = postProcessManager != null ? postProcessManager : throw new ArgumentNullException(nameof(postProcessManager));
}

Expand Down Expand Up @@ -122,16 +126,24 @@ public List<ICommand> ConvertCurrentGameStateToCommands(SaveLevel saveLevel)

commands.AddRange(varsToSave.Select(var =>
new ScriptVarSetValueCommand(var.Key, var.Value)));

var currentPlayerActorId = (int)_playerManager.GetPlayerActor();

var currentScriptMusic = _audioManager.GetCurrentScriptMusic();
if (!string.IsNullOrEmpty(currentScriptMusic))
{
commands.Add(new PlayMusicCommand(currentScriptMusic, 1));
}

commands.AddRange(new List<ICommand>()
{
new SceneLoadCommand(currentSceneInfo.CityName, currentSceneInfo.Name),
new ActorActivateCommand(ActorConstants.PlayerActorVirtualID, 1),
new ActorEnablePlayerControlCommand(ActorConstants.PlayerActorVirtualID),
new ActorActivateCommand(currentPlayerActorId, 1),
new ActorEnablePlayerControlCommand(currentPlayerActorId),
new PlayerEnableInputCommand(1),
new ActorSetNavLayerCommand(ActorConstants.PlayerActorVirtualID,
new ActorSetNavLayerCommand(currentPlayerActorId,
playerActorMovementController.GetCurrentLayerIndex()),
new ActorSetTilePositionCommand(ActorConstants.PlayerActorVirtualID,
new ActorSetTilePositionCommand(currentPlayerActorId,
playerActorTilePosition.x, playerActorTilePosition.y)
});

Expand Down Expand Up @@ -167,6 +179,13 @@ public List<ICommand> ConvertCurrentGameStateToCommands(SaveLevel saveLevel)
{
commands.Add(new LongKuiSwitchModeCommand(longKuiCurrentMode));
}
var huaYingCurrentMode = currentScene.GetActorGameObject((byte) PlayerActorId.HuaYing)
.GetComponent<HuaYingController>()
.GetCurrentMode();
if (longKuiCurrentMode != 1)
{
commands.Add(new HuaYingSwitchBehaviourModeCommand(huaYingCurrentMode));
}
#endif

commands.AddRange(_bigMapManager.GetRegionEnablementInfo()
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ PlayerSettings:
webGLThreadsSupport: 0
webGLDecompressionFallback: 0
scriptingDefineSymbols:
Android: UNITY_POST_PROCESSING_STACK_V2;PAL3
Android: PAL3;UNITY_POST_PROCESSING_STACK_V2
CloudRendering: UNITY_POST_PROCESSING_STACK_V2
EmbeddedLinux: UNITY_POST_PROCESSING_STACK_V2
GameCoreXboxOne: UNITY_POST_PROCESSING_STACK_V2
Expand All @@ -886,7 +886,7 @@ PlayerSettings:
PS4: UNITY_POST_PROCESSING_STACK_V2
PS5: UNITY_POST_PROCESSING_STACK_V2
Stadia: UNITY_POST_PROCESSING_STACK_V2
Standalone: UNITY_POST_PROCESSING_STACK_V2;PAL3
Standalone: PAL3;UNITY_POST_PROCESSING_STACK_V2
WebGL: UNITY_POST_PROCESSING_STACK_V2
Windows Store Apps: UNITY_POST_PROCESSING_STACK_V2
XboxOne: UNITY_POST_PROCESSING_STACK_V2
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
因为项目本身不含有仙剑奇侠传三或仙剑奇侠传三外传的游戏数据,所以你需要持有一份仙剑三或外传的游戏原始文件(Steam或者方块游戏获得皆可,注意:暂时仅支持简体版游戏)。
- 第一次打开Unity项目之后,先双击选择Scenes\Game作为当前场景,然后点播放键即可。如果选择Scenes\ResourceViewer,则会打开游戏资源查看器。
- 第一次打开的时候会自动弹出文件夹选择窗口,请选择当前电脑上仙剑奇侠传三(或者外传)的安装文件夹即可。
- 因为原始游戏的过场动画为Bink格式,Unity并不原生支持,所以请自行转码视频为Unity所支持的格式放在游戏根目录下的movie文件夹即可(大部分设备和系统支持.mp4等主流格式视频,Linux下仅支持.webm格式视频)。
* Linux用户可以使用FFmpeg转码视频为.webm格式封装(vp8 + vorbis):ffmpeg -i input.mp4 -c:v libvpx -b:v 3M -c:a libvorbis output.webm

## 如何在手持设备上运行
- 在打包后的运行时,所有平台都默认使用Application.persistentDataPath目录读取仙剑三文件,具体这个目录在哪里,根据平台决定,请阅读Unity文档:[Application.persistentDataPath](https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html)
Expand Down Expand Up @@ -62,9 +64,8 @@ https://www.bilibili.com/video/BV1Fu411R7jM

## 如何贡献?
因为项目还处于早期实现过程中,很多系统还没有实现,暂时不接受比较大的Pull request,特别是feature类型,如果您有好的想法,意见或者发现了Bug请欢迎提交issue或者加入交流群与我讨论。

另外您还可以参考这个项目解析视频:https://www.bilibili.com/video/BV1Pr4y167sF

## 技术交流以及测试
## 社区
仙剑三(及外传)复刻版讨论群:252315306

仙剑三(及外传)复刻版开发群:330680869

0 comments on commit 23673aa

Please sign in to comment.