mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-27 01:48:06 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97272bbf0f | ||
|
|
4a68472423 | ||
|
|
51a5163fc1 | ||
|
|
fd3e89c23b | ||
|
|
170a78a0bf | ||
|
|
5b69fd1c7f |
No files matched your search
@@ -5,6 +5,7 @@
|
||||
|
||||
namespace Core.DataReader.Scn
|
||||
{
|
||||
using System;
|
||||
using GameBox;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
@@ -139,6 +140,34 @@ namespace Core.DataReader.Scn
|
||||
public int LightMap; // 0日景灯光, 1夜景灯光, -1不知道是什么意思(比如M01)
|
||||
public uint SkyBox;
|
||||
public uint[] Reserved; // 6 DWORDs
|
||||
|
||||
/// <summary>
|
||||
/// Check if two scene share the same model.
|
||||
/// </summary>
|
||||
/// <param name="sceneInfo">ScnSceneInfo</param>
|
||||
/// <returns>True if two scene share the same model</returns>
|
||||
public bool ModelEquals(ScnSceneInfo sceneInfo)
|
||||
{
|
||||
#if PAL3
|
||||
return string.Equals(CityName, sceneInfo.CityName, StringComparison.OrdinalIgnoreCase) &&
|
||||
string.Equals(Model, sceneInfo.Model, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
#elif PAL3A
|
||||
var modelAName = Model;
|
||||
if (modelAName.EndsWith("y", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
modelAName = modelAName[..^1];
|
||||
}
|
||||
var modelBName = sceneInfo.Model;
|
||||
if (modelBName.EndsWith("y", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
modelBName = modelBName[..^1];
|
||||
|
||||
}
|
||||
return string.Equals(CityName, sceneInfo.CityName, StringComparison.OrdinalIgnoreCase) &&
|
||||
string.Equals(modelAName, modelBName, StringComparison.OrdinalIgnoreCase);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
||||
@@ -103,7 +103,8 @@ namespace Pal3.Audio
|
||||
_currentMusicClipName = musicName;
|
||||
var musicFileVirtualPath = GetMusicFileVirtualPath(musicName);
|
||||
var musicFileCachePath = _resourceProvider.GetMp3FilePathInCacheFolder(musicFileVirtualPath);
|
||||
yield return PlayMusic(musicFileVirtualPath, musicFileCachePath, -1);
|
||||
|
||||
yield return PlayMusic(musicName, musicFileVirtualPath, musicFileCachePath, -1);
|
||||
}
|
||||
|
||||
private IEnumerator PlayAudioClip(AudioSource audioSource,
|
||||
@@ -225,17 +226,27 @@ namespace Pal3.Audio
|
||||
$"{FileConstants.MusicCpkPathInfo.relativePath}{separator}{musicName}.mp3";
|
||||
}
|
||||
|
||||
public IEnumerator PlayMusic(string musicFileVirtualPath, string musicFileCachePath, int loopCount)
|
||||
public IEnumerator PlayMusic(string musicName,
|
||||
string musicFileVirtualPath,
|
||||
string musicFileCachePath,
|
||||
int loopCount)
|
||||
{
|
||||
yield return _resourceProvider.ExtractAndMoveMp3FileToCacheFolder(musicFileVirtualPath, musicFileCachePath);
|
||||
|
||||
AudioClip musicClip = null;
|
||||
yield return _resourceProvider.LoadAudioClip(musicFileCachePath, AudioType.MPEG, audioClip =>
|
||||
{
|
||||
musicClip = audioClip;
|
||||
});
|
||||
if (musicClip == null) yield break;
|
||||
StartCoroutine(PlayAudioClip(_musicPlayer, musicClip, loopCount, 0f, DefaultMusicVolume,
|
||||
new CancellationToken(false))); // Should not stop music during scene switch
|
||||
|
||||
// We need to check if current music clip is the same as the one we are trying to play,
|
||||
// since we are using coroutine to load and play music, there is a chance that the music
|
||||
// clip we are trying to play is not the same as the one we supposed to play.
|
||||
if (musicClip == null ||
|
||||
!string.Equals(_currentMusicClipName, musicName, StringComparison.OrdinalIgnoreCase)) yield break;
|
||||
|
||||
yield return PlayAudioClip(_musicPlayer, musicClip, loopCount, 0f, DefaultMusicVolume,
|
||||
new CancellationToken(false)); // Should not stop music during scene switch
|
||||
}
|
||||
|
||||
public string GetCurrentScriptMusic()
|
||||
@@ -402,7 +413,8 @@ namespace Pal3.Audio
|
||||
_currentMusicClipName = command.MusicName;
|
||||
var musicFileVirtualPath = GetMusicFileVirtualPath(command.MusicName);
|
||||
var musicFileCachePath = _resourceProvider.GetMp3FilePathInCacheFolder(musicFileVirtualPath);
|
||||
StartCoroutine(PlayMusic(musicFileVirtualPath,
|
||||
StartCoroutine(PlayMusic(command.MusicName,
|
||||
musicFileVirtualPath,
|
||||
musicFileCachePath,
|
||||
command.Loop == 0 ? -1 : command.Loop));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace Pal3.Camera
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
@@ -46,7 +48,9 @@ namespace Pal3.Camera
|
||||
ICommandExecutor<CameraFocusOnActorCommand>,
|
||||
ICommandExecutor<CameraFocusOnSceneObjectCommand>,
|
||||
ICommandExecutor<ScenePreLoadingNotification>,
|
||||
ICommandExecutor<GameStateChangedNotification>
|
||||
ICommandExecutor<SceneLeavingCurrentSceneNotification>,
|
||||
ICommandExecutor<GameStateChangedNotification>,
|
||||
ICommandExecutor<ResetGameStateCommand>
|
||||
{
|
||||
private const float FADE_ANIMATION_DURATION = 3f;
|
||||
private const float SCENE_STORY_B_ROOM_HEIGHT = 32f;
|
||||
@@ -89,6 +93,12 @@ namespace Pal3.Camera
|
||||
private CancellationTokenSource _asyncCameraAnimationCts = new ();
|
||||
private CancellationTokenSource _cameraFadeAnimationCts = new ();
|
||||
|
||||
private const int LAST_KNOWN_SCENE_STATE_LIST_MAX_LENGTH = 1;
|
||||
private readonly List<(ScnSceneInfo sceneInfo,
|
||||
Vector3 cameraPosition,
|
||||
Quaternion cameraRotation,
|
||||
Vector3 cameraOffset)> _cameraLastKnownSceneState = new ();
|
||||
|
||||
public void Init(PlayerInputActions inputActions,
|
||||
PlayerGamePlayController gamePlayController,
|
||||
SceneManager sceneManager,
|
||||
@@ -369,7 +379,7 @@ namespace Pal3.Camera
|
||||
return _currentAppliedDefaultTransformOption;
|
||||
}
|
||||
|
||||
public void ApplySceneSettings(ScnSceneInfo sceneInfo)
|
||||
private void ApplySceneSettings(ScnSceneInfo sceneInfo)
|
||||
{
|
||||
switch (sceneInfo.SceneType)
|
||||
{
|
||||
@@ -406,7 +416,7 @@ namespace Pal3.Camera
|
||||
_shouldResetVelocity = true;
|
||||
}
|
||||
|
||||
public void ApplyDefaultSettings(int option)
|
||||
private void ApplyDefaultSettings(int option)
|
||||
{
|
||||
Quaternion rotation;
|
||||
float distance = 688.0f / GameBoxInterpreter.GameBoxUnitToUnityUnit;
|
||||
@@ -692,16 +702,49 @@ namespace Pal3.Camera
|
||||
public void Execute(CameraSetYawCommand command)
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
RotateToOrbitPoint(command.Yaw);
|
||||
}
|
||||
|
||||
public void Execute(SceneLeavingCurrentSceneNotification command)
|
||||
{
|
||||
if (_sceneManager.GetCurrentScene() is not { } currentScene) return;
|
||||
|
||||
if (currentScene.GetSceneInfo().SceneType != ScnSceneType.StoryB)
|
||||
{
|
||||
var cameraTransform = _camera.transform;
|
||||
_cameraLastKnownSceneState.Add((
|
||||
currentScene.GetSceneInfo(),
|
||||
cameraTransform.position,
|
||||
cameraTransform.rotation,
|
||||
_cameraOffset));
|
||||
|
||||
if (_cameraLastKnownSceneState.Count > LAST_KNOWN_SCENE_STATE_LIST_MAX_LENGTH)
|
||||
{
|
||||
_cameraLastKnownSceneState.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ScenePreLoadingNotification notification)
|
||||
{
|
||||
_currentAppliedDefaultTransformOption = 0;
|
||||
ApplySceneSettings(notification.NewSceneInfo);
|
||||
}
|
||||
|
||||
// Apply the last known scene state if found in record.
|
||||
if (notification.NewSceneInfo.SceneType != ScnSceneType.StoryB)
|
||||
{
|
||||
if (_cameraLastKnownSceneState.Count > 0 && _cameraLastKnownSceneState.Any(_ =>
|
||||
_.sceneInfo.ModelEquals(notification.NewSceneInfo)))
|
||||
{
|
||||
(ScnSceneInfo _, Vector3 cameraPosition, Quaternion cameraRotation, Vector3 cameraOffset) =
|
||||
_cameraLastKnownSceneState.Last(_ => _.sceneInfo.ModelEquals(notification.NewSceneInfo));
|
||||
|
||||
_camera.transform.SetPositionAndRotation(cameraPosition, cameraRotation);
|
||||
_cameraOffset = cameraOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(CameraFocusOnActorCommand command)
|
||||
{
|
||||
if (command.ActorId == ActorConstants.PlayerActorVirtualID) return;
|
||||
@@ -721,5 +764,11 @@ namespace Pal3.Camera
|
||||
{
|
||||
if (command.NewState == GameState.Gameplay) _free = true;
|
||||
}
|
||||
|
||||
public void Execute(ResetGameStateCommand command)
|
||||
{
|
||||
_cameraLastKnownSceneState.Clear();
|
||||
_free = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2022, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Command.InternalCommands
|
||||
{
|
||||
public class SceneLeavingCurrentSceneNotification : ICommand
|
||||
{
|
||||
public SceneLeavingCurrentSceneNotification() { }
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 332a46f38a2c43759aecfba77b293112
|
||||
timeCreated: 1665352229
|
||||
@@ -35,7 +35,7 @@ namespace Pal3.Player
|
||||
#if PAL3
|
||||
ICommandExecutor<LongKuiSwitchModeCommand>,
|
||||
#endif
|
||||
ICommandExecutor<SceneLoadCommand>,
|
||||
ICommandExecutor<SceneLeavingCurrentSceneNotification>,
|
||||
ICommandExecutor<ScenePostLoadingNotification>,
|
||||
ICommandExecutor<ResetGameStateCommand>
|
||||
{
|
||||
@@ -64,11 +64,11 @@ namespace Pal3.Player
|
||||
private ActorActionController _playerActorActionController;
|
||||
private ActorMovementController _playerActorMovementController;
|
||||
|
||||
private const int POSITION_INFO_LIST_MAX_LENGTH = 2;
|
||||
private readonly List<(string scene,
|
||||
private const int LAST_KNOWN_SCENE_STATE_LIST_MAX_LENGTH = 2;
|
||||
private readonly List<(ScnSceneInfo sceneInfo,
|
||||
int actorNavIndex,
|
||||
Vector2Int actorTilePosition,
|
||||
Vector3 actorFacing)> _playerActorLastKnownPositionInfo = new ();
|
||||
Vector3 actorFacing)> _playerActorLastKnownSceneState = new ();
|
||||
|
||||
public void Init(GameStateManager gameStateManager,
|
||||
PlayerManager playerManager,
|
||||
@@ -668,6 +668,13 @@ namespace Pal3.Player
|
||||
new StopSfxPlayingAtGameObjectRequest(_playerActor,
|
||||
PLAYER_ACTOR_MOVEMENT_SFX_AUDIO_SOURCE_NAME,
|
||||
disposeSource: false));
|
||||
|
||||
// Just to make sure actor is activated
|
||||
if (_playerManager.IsPlayerInputEnabled() &&
|
||||
!_playerActorController.IsActive)
|
||||
{
|
||||
_playerActorController.IsActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(PlayerEnableInputCommand command)
|
||||
@@ -711,26 +718,10 @@ namespace Pal3.Player
|
||||
|
||||
_lastKnownPosition = currentScene.GetTilemap().GetWorldPosition(
|
||||
new Vector2Int(command.TileXPosition,command.TileZPosition), currentLayerIndex);
|
||||
|
||||
if (!_playerActorController.IsActive)
|
||||
{
|
||||
_playerActorController.IsActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetSceneNameHashKey(ScnSceneInfo sceneInfo)
|
||||
{
|
||||
#if PAL3
|
||||
return $"{sceneInfo.CityName}_{sceneInfo.Model}";
|
||||
#elif PAL3A
|
||||
return sceneInfo.Model.EndsWith("y", StringComparison.OrdinalIgnoreCase) ?
|
||||
$"{sceneInfo.CityName}_{sceneInfo.Model[..^1]}" :
|
||||
$"{sceneInfo.CityName}_{sceneInfo.Model}";
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Execute(SceneLoadCommand command)
|
||||
public void Execute(SceneLeavingCurrentSceneNotification command)
|
||||
{
|
||||
if (_sceneManager.GetCurrentScene() is not { } currentScene) return;
|
||||
|
||||
@@ -744,15 +735,15 @@ namespace Pal3.Player
|
||||
disposeSource: true));
|
||||
}
|
||||
|
||||
_playerActorLastKnownPositionInfo.Add((
|
||||
GetSceneNameHashKey(currentScene.GetSceneInfo()),
|
||||
_playerActorLastKnownSceneState.Add((
|
||||
currentScene.GetSceneInfo(),
|
||||
_playerActorMovementController.GetCurrentLayerIndex(),
|
||||
_playerActorMovementController.GetTilePosition(),
|
||||
_playerActor.transform.forward));
|
||||
|
||||
if (_playerActorLastKnownPositionInfo.Count > POSITION_INFO_LIST_MAX_LENGTH)
|
||||
if (_playerActorLastKnownSceneState.Count > LAST_KNOWN_SCENE_STATE_LIST_MAX_LENGTH)
|
||||
{
|
||||
_playerActorLastKnownPositionInfo.RemoveAt(0);
|
||||
_playerActorLastKnownSceneState.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -762,23 +753,19 @@ namespace Pal3.Player
|
||||
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ActorActivateCommand(playerActorId, 1));
|
||||
|
||||
if (_playerActorLastKnownPositionInfo.Count > 0 && _playerActorLastKnownPositionInfo.Any(_ => string.Equals(
|
||||
_.scene,
|
||||
GetSceneNameHashKey(notification.NewSceneInfo),
|
||||
StringComparison.OrdinalIgnoreCase)))
|
||||
if (_playerActorLastKnownSceneState.Count > 0 && _playerActorLastKnownSceneState.Any(_ =>
|
||||
_.sceneInfo.ModelEquals(notification.NewSceneInfo)))
|
||||
{
|
||||
(string scene, int actorNavIndex, Vector2Int actorTilePosition, Vector3 actorFacing) positionInfo = _playerActorLastKnownPositionInfo.Last(_ => string.Equals(
|
||||
_.scene,
|
||||
GetSceneNameHashKey(notification.NewSceneInfo),
|
||||
StringComparison.OrdinalIgnoreCase));
|
||||
(ScnSceneInfo _, int actorNavIndex, Vector2Int actorTilePosition, Vector3 actorFacing) =
|
||||
_playerActorLastKnownSceneState.Last(_ => _.sceneInfo.ModelEquals(notification.NewSceneInfo));
|
||||
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorSetNavLayerCommand(playerActorId, positionInfo.actorNavIndex));
|
||||
new ActorSetNavLayerCommand(playerActorId, actorNavIndex));
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorSetTilePositionCommand(playerActorId, positionInfo.actorTilePosition.x, positionInfo.actorTilePosition.y));
|
||||
|
||||
new ActorSetTilePositionCommand(playerActorId, actorTilePosition.x, actorTilePosition.y));
|
||||
|
||||
_sceneManager.GetCurrentScene()
|
||||
.GetActorGameObject((byte)playerActorId).transform.forward = positionInfo.actorFacing;
|
||||
.GetActorGameObject((byte)playerActorId).transform.forward = actorFacing;
|
||||
}
|
||||
|
||||
if (_playerManager.IsPlayerActorControlEnabled())
|
||||
@@ -798,7 +785,7 @@ namespace Pal3.Player
|
||||
|
||||
public void Execute(ResetGameStateCommand command)
|
||||
{
|
||||
_playerActorLastKnownPositionInfo.Clear();
|
||||
_playerActorLastKnownSceneState.Clear();
|
||||
|
||||
_currentMovementSfxAudioName = string.Empty;
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace Pal3.Scene
|
||||
{
|
||||
if (_currentScene != null)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new SceneLeavingCurrentSceneNotification());
|
||||
Object.Destroy(_currentScene);
|
||||
Object.Destroy(_currentSceneRoot);
|
||||
_currentScene = null;
|
||||
|
||||
@@ -69,21 +69,9 @@ namespace ResourceViewer
|
||||
_renderingRoot = new GameObject("Model");
|
||||
_renderingRoot.transform.SetParent(null);
|
||||
|
||||
Application.targetFrameRate = Application.platform switch
|
||||
{
|
||||
RuntimePlatform.WindowsEditor => 120,
|
||||
RuntimePlatform.WindowsPlayer => 120,
|
||||
RuntimePlatform.OSXEditor => 120,
|
||||
RuntimePlatform.OSXPlayer => 120,
|
||||
RuntimePlatform.LinuxEditor => 120,
|
||||
RuntimePlatform.LinuxPlayer => 120,
|
||||
RuntimePlatform.IPhonePlayer => 60,
|
||||
RuntimePlatform.Android => 60,
|
||||
_ => -1,
|
||||
};
|
||||
Application.targetFrameRate = Screen.currentResolution.refreshRate;
|
||||
|
||||
if (Application.platform == RuntimePlatform.IPhonePlayer ||
|
||||
Application.platform == RuntimePlatform.Android)
|
||||
if (Application.platform is RuntimePlatform.IPhonePlayer or RuntimePlatform.Android)
|
||||
{
|
||||
DebugLogManager.Instance.PopupEnabled = true;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ Shader "Pal3/Standard"
|
||||
color.a = alpha;
|
||||
}
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, color);
|
||||
//UNITY_APPLY_FOG(i.fogCoord, color);
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
|
||||
@@ -83,7 +83,7 @@ Shader "Pal3/StandardNoShadow"
|
||||
color.a = alpha;
|
||||
}
|
||||
|
||||
UNITY_APPLY_FOG(i.fogCoord, color);
|
||||
//UNITY_APPLY_FOG(i.fogCoord, color);
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
|
||||
@@ -134,7 +134,7 @@ PlayerSettings:
|
||||
16:10: 1
|
||||
16:9: 1
|
||||
Others: 1
|
||||
bundleVersion: 0.27
|
||||
bundleVersion: 0.28
|
||||
preloadedAssets: []
|
||||
metroInputSource: 0
|
||||
wsaTransparentSwapchain: 0
|
||||
|
||||
Reference in new issue
Block a user