mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-27 01:48:06 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4506397e73 | ||
|
|
89aba474ae | ||
|
|
94a3bc6466 | ||
|
|
8369ce4457 | ||
|
|
3ca369173a | ||
|
|
27e92ce148 | ||
|
|
5eb5574ff6 | ||
|
|
5e73768756 | ||
|
|
1c40f78179 | ||
|
|
3506623d43 | ||
|
|
6dcfa9acc0 | ||
|
|
f0efdfa67c | ||
|
|
ef2710f028 | ||
|
|
bd39ad5474 |
No files matched your search
@@ -4982,6 +4982,7 @@ MonoBehaviour:
|
||||
dialogueSelectionButtonPrefab: {fileID: 4172465472256067823, guid: a7a35ac194873f94d8d9f86a534fb73f, type: 3}
|
||||
captionImage: {fileID: 3071742581265337525}
|
||||
debugInfo: {fileID: 9135205958574637510}
|
||||
fpsCounter: {fileID: 887733067292281693}
|
||||
bigMapCanvasGroup: {fileID: 6994295648662812940}
|
||||
bigMapRegionButtonPrefab: {fileID: 799485479191424804, guid: 6cb716e1f5237d348a31b595966399f8, type: 3}
|
||||
bigMapBackground: {fileID: 8628713396278854032}
|
||||
@@ -5407,7 +5408,7 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2755888773251150947, guid: 3ef1d32c83f86744286e2067bc5f73e4, type: 3}
|
||||
propertyPath: m_Value
|
||||
value: 0
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2755888773251194751, guid: 3ef1d32c83f86744286e2067bc5f73e4, type: 3}
|
||||
propertyPath: m_Enabled
|
||||
|
||||
@@ -40,9 +40,19 @@ namespace Core.DataLoader
|
||||
{
|
||||
try
|
||||
{
|
||||
DownloadHandlerAudioClip audioClipHandler = (DownloadHandlerAudioClip)request.downloadHandler;
|
||||
|
||||
// Stream audio to avoid loading the entire AudioClip into memory at once,
|
||||
// which can cause frame drops and stuttering during gameplay.
|
||||
((DownloadHandlerAudioClip) request.downloadHandler).streamAudio = streamAudio;
|
||||
audioClipHandler.streamAudio = streamAudio;
|
||||
|
||||
if (!streamAudio)
|
||||
{
|
||||
// Compress audio to reduce memory usage,
|
||||
// which is recommended for small sfx audio clips.
|
||||
// StreamAudio must be false to compress audio.
|
||||
audioClipHandler.compressed = true;
|
||||
}
|
||||
|
||||
AudioClip audioClip = DownloadHandlerAudioClip.GetContent(request);
|
||||
onLoaded?.Invoke(audioClip);
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace Core.DataReader.Scn
|
||||
return string.Equals(CityName, cityName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private bool IsScene(string sceneName)
|
||||
public bool IsScene(string sceneName)
|
||||
{
|
||||
return string.Equals(SceneName, sceneName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,17 @@ namespace Core.DataReader
|
||||
throw new ArgumentException("Stream must be seekable", nameof(stream));
|
||||
}
|
||||
|
||||
var length = stream.Length;
|
||||
var data = new byte[length];
|
||||
_ = stream.Read(data, 0, (int)length);
|
||||
Length = stream.Length;
|
||||
|
||||
// If data is empty, set position to 0 and return
|
||||
if (Length == 0)
|
||||
{
|
||||
_position = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
var data = new byte[Length];
|
||||
_ = stream.Read(data, 0, (int)Length);
|
||||
|
||||
Init(data);
|
||||
}
|
||||
@@ -41,6 +49,14 @@ namespace Core.DataReader
|
||||
private void Init(byte[] data)
|
||||
{
|
||||
Length = data.Length;
|
||||
|
||||
// If data is empty, set position to 0 and return
|
||||
if (Length == 0)
|
||||
{
|
||||
_position = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
_handle = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||
fixed (byte* ptr = &data[0])
|
||||
{
|
||||
@@ -49,7 +65,9 @@ namespace Core.DataReader
|
||||
}
|
||||
}
|
||||
|
||||
public long Position => _dataPtr - _startPtr;
|
||||
private long? _position;
|
||||
public long Position => _position ?? _dataPtr - _startPtr;
|
||||
|
||||
public long Length { get; private set; }
|
||||
|
||||
public void Seek(long offset, SeekOrigin seekOrigin)
|
||||
@@ -212,7 +230,12 @@ namespace Core.DataReader
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
_handle.Free();
|
||||
|
||||
if (Length != 0)
|
||||
{
|
||||
_handle.Free();
|
||||
}
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f61b67e4060bb34f8cb9eda9a42619d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Core.Navigation
|
||||
{
|
||||
/*
|
||||
* Use integer to represent 8 directions
|
||||
*
|
||||
* 5 4 3
|
||||
* |
|
||||
* 6 -- -- 2
|
||||
* |
|
||||
* 7 0 1
|
||||
*
|
||||
*/
|
||||
|
||||
public enum Direction
|
||||
{
|
||||
South = 0,
|
||||
SouthEast = 1,
|
||||
East = 2,
|
||||
NorthEast = 3,
|
||||
North = 4,
|
||||
NorthWest = 5,
|
||||
West = 6,
|
||||
SouthWest = 7,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aaf07680771bcc24ab17a056b1c4aadd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+1
-29
@@ -3,36 +3,13 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.MetaData
|
||||
namespace Core.Navigation
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
/*
|
||||
* Use integer to represent 8 directions
|
||||
*
|
||||
* 5 4 3
|
||||
* |
|
||||
* 6 -- -- 2
|
||||
* |
|
||||
* 7 0 1
|
||||
*
|
||||
*/
|
||||
|
||||
public enum Direction
|
||||
{
|
||||
South = 0,
|
||||
SouthEast = 1,
|
||||
East = 2,
|
||||
NorthEast = 3,
|
||||
North = 4,
|
||||
NorthWest = 5,
|
||||
West = 6,
|
||||
SouthWest = 7,
|
||||
}
|
||||
|
||||
public static class DirectionUtils
|
||||
{
|
||||
public static IEnumerable<Direction> AllDirections => Enum.GetValues(typeof(Direction)).Cast<Direction>();
|
||||
@@ -69,9 +46,4 @@ namespace Pal3.MetaData
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class NavigationConstants
|
||||
{
|
||||
public const float NavTileSize = 12f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ae63e5dc80c88e43b8ea35c656ec7ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Core.Navigation
|
||||
{
|
||||
public enum MovementMode
|
||||
{
|
||||
File renamed without changes.
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Core.Navigation
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
File renamed without changes.
@@ -13,6 +13,8 @@ namespace Core.Renderer
|
||||
private MeshRenderer _meshRenderer;
|
||||
private MeshFilter _meshFilter;
|
||||
|
||||
private Material[] _materials;
|
||||
|
||||
public Mesh Render(ref Vector3[] vertices,
|
||||
ref int[] triangles,
|
||||
ref Vector3[] normals,
|
||||
@@ -23,6 +25,7 @@ namespace Core.Renderer
|
||||
{
|
||||
Dispose();
|
||||
|
||||
_materials = materials;
|
||||
_meshRenderer = gameObject.AddComponent<MeshRenderer>();
|
||||
_meshRenderer.sharedMaterials = materials;
|
||||
|
||||
@@ -73,6 +76,11 @@ namespace Core.Renderer
|
||||
return _meshFilter.sharedMesh.bounds;
|
||||
}
|
||||
|
||||
public Material[] GetMaterials()
|
||||
{
|
||||
return _materials;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Dispose();
|
||||
@@ -88,13 +96,10 @@ namespace Core.Renderer
|
||||
|
||||
if (_meshRenderer != null)
|
||||
{
|
||||
foreach (Material material in _meshRenderer.sharedMaterials)
|
||||
{
|
||||
Destroy(material);
|
||||
}
|
||||
|
||||
Destroy(_meshRenderer);
|
||||
}
|
||||
|
||||
_materials = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,14 @@ namespace Core.Services
|
||||
_services.Remove(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all registered services.
|
||||
/// </summary>
|
||||
public IEnumerable<object> GetAllRegisteredServices()
|
||||
{
|
||||
return _services.Values;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters all services.
|
||||
/// </summary>
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Editor
|
||||
BuildTargetGroup.Switch,
|
||||
BuildTargetGroup.GameCoreXboxOne,
|
||||
BuildTargetGroup.GameCoreXboxSeries,
|
||||
BuildTargetGroup.VisionOS,
|
||||
//BuildTargetGroup.VisionOS,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Editor
|
||||
NamedBuildTarget.tvOS,
|
||||
NamedBuildTarget.NintendoSwitch,
|
||||
NamedBuildTarget.WindowsStoreApps,
|
||||
NamedBuildTarget.VisionOS,
|
||||
//NamedBuildTarget.VisionOS,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Pal3.Actor
|
||||
{
|
||||
using Core.DataReader.Scn;
|
||||
using Core.GameBox;
|
||||
using Core.Navigation;
|
||||
using Data;
|
||||
using MetaData;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Pal3.Actor
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Controllers;
|
||||
using Data;
|
||||
using Dev;
|
||||
using MetaData;
|
||||
@@ -20,6 +21,9 @@ namespace Pal3.Actor
|
||||
Tilemap tilemap,
|
||||
bool isDropShadowEnabled,
|
||||
Color tintColor,
|
||||
float movementMaxYDifferential,
|
||||
float movementMaxYDifferentialCrossLayer,
|
||||
float movementMaxYDifferentialCrossPlatform,
|
||||
Func<int, int[], HashSet<Vector2Int>> getAllActiveActorBlockingTilePositions)
|
||||
{
|
||||
var actorGameObject = new GameObject($"Actor_{actor.Info.Id}_{actor.Info.Name}")
|
||||
@@ -63,7 +67,13 @@ namespace Pal3.Actor
|
||||
}
|
||||
|
||||
var movementController = actorGameObject.AddComponent<ActorMovementController>();
|
||||
movementController.Init(actor, tilemap, actionController, getAllActiveActorBlockingTilePositions);
|
||||
movementController.Init(actor,
|
||||
tilemap,
|
||||
actionController,
|
||||
movementMaxYDifferential,
|
||||
movementMaxYDifferentialCrossLayer,
|
||||
movementMaxYDifferentialCrossPlatform,
|
||||
getAllActiveActorBlockingTilePositions);
|
||||
|
||||
var actorController = actorGameObject.AddComponent<ActorController>();
|
||||
actorController.Init(actor, actionController, movementController);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9260c8ecdc555a84197706f7f99c4a7c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Pal3.Actor.Controllers
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
File renamed without changes.
+2
-1
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Pal3.Actor.Controllers
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -13,6 +13,7 @@ namespace Pal3.Actor
|
||||
using Core.Animation;
|
||||
using Core.DataReader.Scn;
|
||||
using Core.GameBox;
|
||||
using Core.Navigation;
|
||||
using Core.Services;
|
||||
using Input;
|
||||
using MetaData;
|
||||
File renamed without changes.
+25
-13
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Pal3.Actor.Controllers
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -16,6 +16,7 @@ namespace Pal3.Actor
|
||||
using Core.DataReader.Nav;
|
||||
using Core.DataReader.Scn;
|
||||
using Core.GameBox;
|
||||
using Core.Navigation;
|
||||
using Core.Utils;
|
||||
using MetaData;
|
||||
using Scene;
|
||||
@@ -58,9 +59,6 @@ namespace Pal3.Actor
|
||||
ICommandExecutor<ActorActivateCommand>,
|
||||
ICommandExecutor<ActorSetNavLayerCommand>
|
||||
{
|
||||
private const float MAX_Y_DIFFERENTIAL = 2.2f;
|
||||
private const float MAX_Y_DIFFERENTIAL_CROSS_LAYER = 2f;
|
||||
private const float MAX_Y_DIFFERENTIAL_CROSS_PLATFORM = 2f;
|
||||
private const float DEFAULT_ROTATION_SPEED = 20f;
|
||||
|
||||
private Actor _actor;
|
||||
@@ -76,15 +74,27 @@ namespace Pal3.Actor
|
||||
private readonly HashSet<ActiveColliderInfo> _activeColliders = new ();
|
||||
private readonly HashSet<ActiveStandingPlatformInfo> _activeStandingPlatforms = new ();
|
||||
|
||||
private float _movementMaxYDifferential;
|
||||
private float _movementMaxYDifferentialCrossLayer;
|
||||
private float _movementMaxYDifferentialCrossPlatform;
|
||||
|
||||
private Func<int, int[], HashSet<Vector2Int>> _getAllActiveActorBlockingTilePositions;
|
||||
|
||||
public void Init(Actor actor, Tilemap tilemap, ActorActionController actionController,
|
||||
public void Init(Actor actor,
|
||||
Tilemap tilemap,
|
||||
ActorActionController actionController,
|
||||
float movementMaxYDifferential,
|
||||
float movementMaxYDifferentialCrossLayer,
|
||||
float movementMaxYDifferentialCrossPlatform,
|
||||
Func<int, int[], HashSet<Vector2Int>> getAllActiveActorBlockingTilePositions)
|
||||
{
|
||||
_actor = actor;
|
||||
_tilemap = tilemap;
|
||||
_actionController = actionController;
|
||||
_currentLayerIndex = actor.Info.LayerIndex;
|
||||
_movementMaxYDifferential = movementMaxYDifferential;
|
||||
_movementMaxYDifferentialCrossLayer = movementMaxYDifferentialCrossLayer;
|
||||
_movementMaxYDifferentialCrossPlatform = movementMaxYDifferentialCrossPlatform;
|
||||
_getAllActiveActorBlockingTilePositions = getAllActiveActorBlockingTilePositions;
|
||||
|
||||
Vector3 initPosition = GameBoxInterpreter.ToUnityPosition(new Vector3(
|
||||
@@ -365,7 +375,7 @@ namespace Pal3.Actor
|
||||
// Move actor on to the platform if platform is higher than current position
|
||||
Vector3 currentPosition = transform.position;
|
||||
var targetYPosition = standingPlatformController.GetPlatformHeight();
|
||||
if (Mathf.Abs(currentPosition.y - targetYPosition) <= MAX_Y_DIFFERENTIAL_CROSS_PLATFORM &&
|
||||
if (Mathf.Abs(currentPosition.y - targetYPosition) <= _movementMaxYDifferentialCrossPlatform &&
|
||||
currentPosition.y < targetYPosition) // Don't move the actor if platform is lower
|
||||
{
|
||||
transform.position = new Vector3(currentPosition.x, targetYPosition, currentPosition.z);
|
||||
@@ -502,9 +512,9 @@ namespace Pal3.Actor
|
||||
|
||||
switch (ignoreObstacle)
|
||||
{
|
||||
case false when Mathf.Abs(newYPosition - newPosition.y) > MAX_Y_DIFFERENTIAL:
|
||||
case false when Mathf.Abs(newYPosition - newPosition.y) > _movementMaxYDifferential:
|
||||
return MovementResult.Blocked;
|
||||
case true when Mathf.Abs(newYPosition - newPosition.y) > MAX_Y_DIFFERENTIAL:
|
||||
case true when Mathf.Abs(newYPosition - newPosition.y) > _movementMaxYDifferential:
|
||||
newYPosition = currentPosition.y;
|
||||
break;
|
||||
}
|
||||
@@ -595,7 +605,7 @@ namespace Pal3.Actor
|
||||
// Make sure actor is on top of the platform
|
||||
if (Utility.IsPointWithinCollider(platformInfo.Platform.GetCollider(),
|
||||
new Vector3(newPosition.x, targetYPosition, newPosition.z), tolerance) &&
|
||||
Mathf.Abs(currentPosition.y - targetYPosition) <= MAX_Y_DIFFERENTIAL_CROSS_PLATFORM)
|
||||
Mathf.Abs(currentPosition.y - targetYPosition) <= _movementMaxYDifferentialCrossPlatform)
|
||||
{
|
||||
newYPosition = targetYPosition;
|
||||
isNewPositionValid = true;
|
||||
@@ -631,7 +641,7 @@ namespace Pal3.Actor
|
||||
{
|
||||
var yPositionAtNextLayer = GameBoxInterpreter.ToUnityYPosition(tileAtNextLayer.GameBoxYPosition);
|
||||
|
||||
if (Mathf.Abs(currentPosition.y - yPositionAtNextLayer) > MAX_Y_DIFFERENTIAL_CROSS_LAYER)
|
||||
if (Mathf.Abs(currentPosition.y - yPositionAtNextLayer) > _movementMaxYDifferentialCrossLayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -846,8 +856,7 @@ namespace Pal3.Actor
|
||||
|
||||
// Check if position at current layer exists, if not, auto switch
|
||||
// to next layer (if tile at next layer is valid).
|
||||
// If position at both layers are valid, switch to next layer.
|
||||
// If current layer is not walkable but next layer is walkable.
|
||||
// Also, switch to next layer if tile at current layer is obstacle.
|
||||
if (_tilemap.GetLayerCount() > 1)
|
||||
{
|
||||
bool isTileExistsInCurrentLayer = _tilemap.TryGetTile(tilePosition,
|
||||
@@ -860,7 +869,10 @@ namespace Pal3.Actor
|
||||
SetNavLayer((_currentLayerIndex + 1) % 2);
|
||||
}
|
||||
else if (isTileExistsInCurrentLayer && isTileExistsInNextLayer &&
|
||||
!tileAtCurrentLayer.IsWalkable() && tileAtNextLayer.IsWalkable())
|
||||
tileAtCurrentLayer.DistanceToNearestObstacle == 0 &&
|
||||
tileAtNextLayer.DistanceToNearestObstacle > 0)
|
||||
// DO NOT USE IsWalkable() to check if tile is obstacle, because it can be
|
||||
// overwritten by script (Ex: Tilemap.MarkFloorKindAsObstacle())
|
||||
{
|
||||
SetNavLayer((_currentLayerIndex + 1) % 2);
|
||||
}
|
||||
File renamed without changes.
+2
-1
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Pal3.Actor.Controllers
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -11,6 +11,7 @@ namespace Pal3.Actor
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.GameBox;
|
||||
using Core.Navigation;
|
||||
using Script.Waiter;
|
||||
using UnityEngine;
|
||||
|
||||
File renamed without changes.
+2
-1
@@ -5,11 +5,12 @@
|
||||
|
||||
#if PAL3
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Pal3.Actor.Controllers
|
||||
{
|
||||
using Command;
|
||||
using Command.SceCommands;
|
||||
using Core.GameBox;
|
||||
using Core.Navigation;
|
||||
using Core.Services;
|
||||
using MetaData;
|
||||
using Scene;
|
||||
File renamed without changes.
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
#if PAL3
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Pal3.Actor.Controllers
|
||||
{
|
||||
using Command;
|
||||
using Command.SceCommands;
|
||||
File renamed without changes.
+4
-5
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Pal3.Actor.Controllers
|
||||
{
|
||||
using System;
|
||||
using Command;
|
||||
@@ -16,7 +16,8 @@ namespace Pal3.Actor
|
||||
using Core.Extensions;
|
||||
using Core.Utils;
|
||||
using Data;
|
||||
using Renderer;
|
||||
using Rendering.Material;
|
||||
using Rendering.Renderer;
|
||||
using Script.Waiter;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -172,9 +173,7 @@ namespace Pal3.Actor
|
||||
_skeletalModelRenderer == null ||
|
||||
!_skeletalModelRenderer.IsVisible()) return;
|
||||
|
||||
_skeletalModelRenderer.PauseAnimation();
|
||||
|
||||
if (_autoStand && _skeletalModelRenderer.IsVisible())
|
||||
if (_skeletalModelRenderer.IsVisible())
|
||||
{
|
||||
PerformAction(_actor.GetIdleAction());
|
||||
}
|
||||
File renamed without changes.
+4
-4
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Actor
|
||||
namespace Pal3.Actor.Controllers
|
||||
{
|
||||
using System;
|
||||
using Command;
|
||||
@@ -18,7 +18,8 @@ namespace Pal3.Actor
|
||||
using Core.Utils;
|
||||
using Data;
|
||||
using MetaData;
|
||||
using Renderer;
|
||||
using Rendering.Material;
|
||||
using Rendering.Renderer;
|
||||
using Script.Waiter;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -250,10 +251,9 @@ namespace Pal3.Actor
|
||||
}
|
||||
else
|
||||
{
|
||||
_mv3ModelRenderer.PauseAnimation();
|
||||
_animationLoopPointWaiter?.CancelWait();
|
||||
|
||||
if (_autoStand && _mv3ModelRenderer.IsVisible())
|
||||
if (_mv3ModelRenderer.IsVisible())
|
||||
{
|
||||
PerformAction(_actor.GetIdleAction());
|
||||
}
|
||||
File renamed without changes.
@@ -24,7 +24,7 @@ namespace Pal3.Audio
|
||||
using State;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class AudioManager : MonoBehaviour,
|
||||
public sealed class AudioManager : IDisposable,
|
||||
ICommandExecutor<PlaySfxCommand>,
|
||||
ICommandExecutor<PlayMusicCommand>,
|
||||
ICommandExecutor<AttachSfxToGameObjectRequest>,
|
||||
@@ -36,11 +36,11 @@ namespace Pal3.Audio
|
||||
ICommandExecutor<ResetGameStateCommand>,
|
||||
ICommandExecutor<SettingChangedNotification>
|
||||
{
|
||||
private Camera _mainCamera;
|
||||
private AudioSource _musicPlayer;
|
||||
private GameResourceProvider _resourceProvider;
|
||||
private SceneManager _sceneManager;
|
||||
private GameSettings _gameSettings;
|
||||
private readonly Camera _mainCamera;
|
||||
private readonly AudioSource _musicPlayer;
|
||||
private readonly GameResourceProvider _resourceProvider;
|
||||
private readonly SceneManager _sceneManager;
|
||||
private readonly GameSettings _gameSettings;
|
||||
|
||||
private const string STOP_MUSIC_NAME = "NONE";
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Pal3.Audio
|
||||
|
||||
private CancellationTokenSource _sceneAudioCts = new ();
|
||||
|
||||
public void Init(Camera mainCamera,
|
||||
public AudioManager(Camera mainCamera,
|
||||
GameResourceProvider resourceProvider,
|
||||
SceneManager sceneManager,
|
||||
AudioSource musicSource,
|
||||
@@ -71,14 +71,11 @@ namespace Pal3.Audio
|
||||
|
||||
_musicVolume = _gameSettings.MusicVolume;
|
||||
_sfxVolume = _gameSettings.SfxVolume;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
@@ -276,7 +273,7 @@ namespace Pal3.Audio
|
||||
audioSource.Stop();
|
||||
}
|
||||
|
||||
Destroy(audioSourceParentTransform.gameObject);
|
||||
UnityEngine.Object.Destroy(audioSourceParentTransform.gameObject);
|
||||
}
|
||||
|
||||
_playingSfxSourceNames.Clear();
|
||||
@@ -321,7 +318,7 @@ namespace Pal3.Audio
|
||||
{
|
||||
case 0: // start playing sfx indefinitely for the given sfxName
|
||||
_playingSfxSourceNames.Add(sfxName);
|
||||
StartCoroutine(AttachSfxToGameObjectAndPlaySfxAsync(_mainCamera.gameObject,
|
||||
Pal3.Instance.StartCoroutine(AttachSfxToGameObjectAndPlaySfxAsync(_mainCamera.gameObject,
|
||||
_resourceProvider.GetSfxFilePath(sfxName),
|
||||
sfxName, // use sfx name as audio source name
|
||||
loopCount: -1, // loop indefinitely
|
||||
@@ -341,7 +338,7 @@ namespace Pal3.Audio
|
||||
_playingSfxSourceNames.Add(sfxName);
|
||||
var sfxFilePath = _resourceProvider.GetSfxFilePath(sfxName);
|
||||
CancellationToken cancellationToken = _sceneAudioCts.Token;
|
||||
StartCoroutine(AttachSfxToGameObjectAndPlaySfxAsync(_mainCamera.gameObject,
|
||||
Pal3.Instance.StartCoroutine(AttachSfxToGameObjectAndPlaySfxAsync(_mainCamera.gameObject,
|
||||
sfxFilePath,
|
||||
sfxName, // use sfx name as audio source name
|
||||
loopCount,
|
||||
@@ -362,7 +359,7 @@ namespace Pal3.Audio
|
||||
|
||||
var sfxFilePath = _resourceProvider.GetSfxFilePath(request.SfxName);
|
||||
CancellationToken cancellationToken = _sceneAudioCts.Token;
|
||||
StartCoroutine(StartWithDelayAsync(request.StartDelayInSeconds,
|
||||
Pal3.Instance.StartCoroutine(StartWithDelayAsync(request.StartDelayInSeconds,
|
||||
AttachSfxToGameObjectAndPlaySfxAsync(request.Parent,
|
||||
sfxFilePath,
|
||||
request.AudioSourceName,
|
||||
@@ -392,7 +389,7 @@ namespace Pal3.Audio
|
||||
|
||||
if (command.DisposeSource)
|
||||
{
|
||||
Destroy(audioSourceParent);
|
||||
UnityEngine.Object.Destroy(audioSourceParent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +415,7 @@ namespace Pal3.Audio
|
||||
_currentMusicClipName = command.MusicName;
|
||||
var musicFileVirtualPath = FileConstants.GetMusicFileVirtualPath(command.MusicName);
|
||||
var musicFileCachePath = _resourceProvider.GetMusicFilePathInCacheFolder(musicFileVirtualPath);
|
||||
StartCoroutine(PlayMusicAsync(command.MusicName,
|
||||
Pal3.Instance.StartCoroutine(PlayMusicAsync(command.MusicName,
|
||||
musicFileVirtualPath,
|
||||
musicFileCachePath,
|
||||
command.Loop == 0 ? -1 : command.Loop));
|
||||
@@ -435,7 +432,7 @@ namespace Pal3.Audio
|
||||
_currentMusicClipName = string.Empty;
|
||||
|
||||
ScnSceneInfo sceneInfo = _sceneManager.GetCurrentScene().GetSceneInfo();
|
||||
StartCoroutine(PlaySceneMusicAsync(sceneInfo.CityName, sceneInfo.SceneName));
|
||||
Pal3.Instance.StartCoroutine(PlaySceneMusicAsync(sceneInfo.CityName, sceneInfo.SceneName));
|
||||
}
|
||||
|
||||
public void Execute(ScenePreLoadingNotification command)
|
||||
@@ -449,7 +446,8 @@ namespace Pal3.Audio
|
||||
{
|
||||
if (string.IsNullOrEmpty(_currentScriptMusic))
|
||||
{
|
||||
StartCoroutine(PlaySceneMusicAsync(command.NewSceneInfo.CityName, command.NewSceneInfo.SceneName));
|
||||
Pal3.Instance.StartCoroutine(
|
||||
PlaySceneMusicAsync(command.NewSceneInfo.CityName, command.NewSceneInfo.SceneName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Pal3.Camera
|
||||
using UnityEngine.InputSystem.OnScreen;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public sealed class CameraManager : MonoBehaviour,
|
||||
public sealed class CameraManager : IDisposable,
|
||||
ICommandExecutor<CameraSetTransformCommand>,
|
||||
ICommandExecutor<CameraSetDefaultTransformCommand>,
|
||||
ICommandExecutor<CameraShakeEffectCommand>,
|
||||
@@ -65,8 +65,8 @@ namespace Pal3.Camera
|
||||
private const float CAMERA_SMOOTH_FOLLOW_TIME = 0.2f;
|
||||
private const float CAMERA_SMOOTH_FOLLOW_MAX_DISTANCE = 7f;
|
||||
|
||||
private Camera _camera;
|
||||
private Image _curtainImage;
|
||||
private readonly Camera _camera;
|
||||
private readonly Image _curtainImage;
|
||||
|
||||
private GameObject _lookAtGameObject;
|
||||
private Vector3 _lastLookAtPoint = Vector3.zero;
|
||||
@@ -81,14 +81,14 @@ namespace Pal3.Camera
|
||||
private bool _shouldResetVelocity = false;
|
||||
private int _currentAppliedDefaultTransformOption = 0;
|
||||
|
||||
private PlayerInputActions _inputActions;
|
||||
private PlayerGamePlayController _gamePlayController;
|
||||
private SceneManager _sceneManager;
|
||||
private GameStateManager _gameStateManager;
|
||||
private readonly PlayerInputActions _inputActions;
|
||||
private readonly PlayerGamePlayManager _gamePlayManager;
|
||||
private readonly SceneManager _sceneManager;
|
||||
private readonly GameStateManager _gameStateManager;
|
||||
|
||||
private RectTransform _joyStickRectTransform;
|
||||
private float _joyStickMovementRange;
|
||||
private bool _isTouchEnabled;
|
||||
private readonly RectTransform _joyStickRectTransform;
|
||||
private readonly float _joyStickMovementRange;
|
||||
private readonly bool _isTouchEnabled;
|
||||
|
||||
private bool _cameraAnimationInProgress;
|
||||
private CancellationTokenSource _asyncCameraAnimationCts = new ();
|
||||
@@ -102,8 +102,8 @@ namespace Pal3.Camera
|
||||
Quaternion cameraRotation,
|
||||
int transformOption)> _cameraLastKnownState = new ();
|
||||
|
||||
public void Init(PlayerInputActions inputActions,
|
||||
PlayerGamePlayController gamePlayController,
|
||||
public CameraManager(PlayerInputActions inputActions,
|
||||
PlayerGamePlayManager gamePlayManager,
|
||||
SceneManager sceneManager,
|
||||
GameStateManager gameStateManager,
|
||||
Camera mainCamera,
|
||||
@@ -111,7 +111,7 @@ namespace Pal3.Camera
|
||||
Image curtainImage)
|
||||
{
|
||||
_inputActions = Requires.IsNotNull(inputActions, nameof(inputActions));
|
||||
_gamePlayController = Requires.IsNotNull(gamePlayController, nameof(gamePlayController));
|
||||
_gamePlayManager = Requires.IsNotNull(gamePlayManager, nameof(gamePlayManager));
|
||||
_sceneManager = Requires.IsNotNull(sceneManager, nameof(sceneManager));
|
||||
_gameStateManager = Requires.IsNotNull(gameStateManager, nameof(gameStateManager));
|
||||
|
||||
@@ -126,19 +126,16 @@ namespace Pal3.Camera
|
||||
_joyStickMovementRange = onScreenStick.movementRange;
|
||||
var joyStickImage = onScreenStick.gameObject.GetComponent<Image>();
|
||||
_joyStickRectTransform = joyStickImage.rectTransform;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
public void LateUpdate(float deltaTime)
|
||||
{
|
||||
if (!_cameraFollowPlayer)
|
||||
{
|
||||
@@ -152,7 +149,7 @@ namespace Pal3.Camera
|
||||
{
|
||||
_lastLookAtPoint = _lookAtGameObject.transform.position;
|
||||
}
|
||||
else if (_gamePlayController.TryGetPlayerActorLastKnownPosition(out Vector3 playerActorPosition))
|
||||
else if (_gamePlayManager.TryGetPlayerActorLastKnownPosition(out Vector3 playerActorPosition))
|
||||
{
|
||||
_lastLookAtPoint = playerActorPosition;
|
||||
}
|
||||
@@ -191,24 +188,24 @@ namespace Pal3.Camera
|
||||
return;
|
||||
}
|
||||
|
||||
RotateCameraBasedOnUserInput();
|
||||
RotateCameraBasedOnUserInput(deltaTime);
|
||||
}
|
||||
|
||||
private void RotateCameraBasedOnUserInput()
|
||||
private void RotateCameraBasedOnUserInput(float deltaTime)
|
||||
{
|
||||
if (_inputActions.Gameplay.RotateCameraClockwise.inProgress)
|
||||
{
|
||||
RotateToOrbitPoint(Time.deltaTime * CAMERA_ROTATION_SPEED_KEY_PRESS);
|
||||
RotateToOrbitPoint(deltaTime * CAMERA_ROTATION_SPEED_KEY_PRESS);
|
||||
}
|
||||
else if (_inputActions.Gameplay.RotateCameraCounterClockwise.inProgress)
|
||||
{
|
||||
RotateToOrbitPoint(-Time.deltaTime * CAMERA_ROTATION_SPEED_KEY_PRESS);
|
||||
RotateToOrbitPoint(-deltaTime * CAMERA_ROTATION_SPEED_KEY_PRESS);
|
||||
}
|
||||
|
||||
var mouseScroll = _inputActions.Gameplay.OnScroll.ReadValue<float>();
|
||||
if (mouseScroll != 0)
|
||||
{
|
||||
RotateToOrbitPoint(mouseScroll * Time.deltaTime * CAMERA_ROTATION_SPEED_SCROLL);
|
||||
RotateToOrbitPoint(mouseScroll * deltaTime * CAMERA_ROTATION_SPEED_SCROLL);
|
||||
}
|
||||
|
||||
if (!_isTouchEnabled) return;
|
||||
@@ -220,7 +217,7 @@ namespace Pal3.Camera
|
||||
|
||||
if (IsTouchPositionOutsideVirtualJoyStickRange(startPosition))
|
||||
{
|
||||
RotateToOrbitPoint(touch0Delta * Time.deltaTime * CAMERA_ROTATION_SPEED_DRAG);
|
||||
RotateToOrbitPoint(touch0Delta * deltaTime * CAMERA_ROTATION_SPEED_DRAG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +228,7 @@ namespace Pal3.Camera
|
||||
|
||||
if (IsTouchPositionOutsideVirtualJoyStickRange(startPosition))
|
||||
{
|
||||
RotateToOrbitPoint(touch1Delta * Time.deltaTime * CAMERA_ROTATION_SPEED_DRAG);
|
||||
RotateToOrbitPoint(touch1Delta * deltaTime * CAMERA_ROTATION_SPEED_DRAG);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -489,7 +486,7 @@ namespace Pal3.Camera
|
||||
{
|
||||
if (!_asyncCameraAnimationCts.IsCancellationRequested) _asyncCameraAnimationCts.Cancel();
|
||||
|
||||
if (_gamePlayController.TryGetPlayerActorLastKnownPosition(out Vector3 playerActorPosition))
|
||||
if (_gamePlayManager.TryGetPlayerActorLastKnownPosition(out Vector3 playerActorPosition))
|
||||
{
|
||||
_lastLookAtPoint = playerActorPosition;
|
||||
}
|
||||
@@ -537,7 +534,7 @@ namespace Pal3.Camera
|
||||
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(ShakeAsync(command.Duration,
|
||||
Pal3.Instance.StartCoroutine(ShakeAsync(command.Duration,
|
||||
GameBoxInterpreter.ToUnityDistance(command.Amplitude),
|
||||
() => waiter.CancelWait()));
|
||||
}
|
||||
@@ -549,7 +546,7 @@ namespace Pal3.Camera
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(OrbitAsync(rotation,
|
||||
Pal3.Instance.StartCoroutine(OrbitAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
0f,
|
||||
@@ -569,7 +566,7 @@ namespace Pal3.Camera
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(RotateAsync(rotation,
|
||||
Pal3.Instance.StartCoroutine(RotateAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
() => waiter.CancelWait()));
|
||||
@@ -579,7 +576,7 @@ namespace Pal3.Camera
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(RotateAsync(rotation,
|
||||
Pal3.Instance.StartCoroutine(RotateAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
onFinished: null,
|
||||
@@ -594,7 +591,7 @@ namespace Pal3.Camera
|
||||
_cameraFadeAnimationCts = new CancellationTokenSource();
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(FadeAsync(true,
|
||||
Pal3.Instance.StartCoroutine(FadeAsync(true,
|
||||
FADE_ANIMATION_DURATION,
|
||||
Color.black,
|
||||
() => waiter.CancelWait(),
|
||||
@@ -607,7 +604,7 @@ namespace Pal3.Camera
|
||||
_cameraFadeAnimationCts = new CancellationTokenSource();
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(FadeAsync(true,
|
||||
Pal3.Instance.StartCoroutine(FadeAsync(true,
|
||||
FADE_ANIMATION_DURATION,
|
||||
Color.white,
|
||||
() => waiter.CancelWait(),
|
||||
@@ -620,7 +617,7 @@ namespace Pal3.Camera
|
||||
_cameraFadeAnimationCts = new CancellationTokenSource();
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(FadeAsync(false,
|
||||
Pal3.Instance.StartCoroutine(FadeAsync(false,
|
||||
FADE_ANIMATION_DURATION,
|
||||
Color.black,
|
||||
() => waiter.CancelWait(),
|
||||
@@ -633,7 +630,7 @@ namespace Pal3.Camera
|
||||
_cameraFadeAnimationCts = new CancellationTokenSource();
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
StartCoroutine(FadeAsync(false,
|
||||
Pal3.Instance.StartCoroutine(FadeAsync(false,
|
||||
FADE_ANIMATION_DURATION,
|
||||
Color.white,
|
||||
() => waiter.CancelWait(),
|
||||
@@ -653,7 +650,7 @@ namespace Pal3.Camera
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
var distance = GameBoxInterpreter.ToUnityDistance(command.GameBoxDistance);
|
||||
StartCoroutine(PushAsync(distance,
|
||||
Pal3.Instance.StartCoroutine(PushAsync(distance,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
() => waiter.CancelWait()));
|
||||
@@ -663,7 +660,7 @@ namespace Pal3.Camera
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
var distance = GameBoxInterpreter.ToUnityDistance(command.GameBoxDistance);
|
||||
StartCoroutine(PushAsync(distance,
|
||||
Pal3.Instance.StartCoroutine(PushAsync(distance,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
onFinished: null,
|
||||
@@ -688,7 +685,7 @@ namespace Pal3.Camera
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
StartCoroutine(MoveAsync(position,
|
||||
Pal3.Instance.StartCoroutine(MoveAsync(position,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
() => waiter.CancelWait()));
|
||||
@@ -701,7 +698,7 @@ namespace Pal3.Camera
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
StartCoroutine(MoveAsync(position,
|
||||
Pal3.Instance.StartCoroutine(MoveAsync(position,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
onFinished: null,
|
||||
@@ -816,7 +813,7 @@ namespace Pal3.Camera
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(OrbitAsync(rotation,
|
||||
Pal3.Instance.StartCoroutine(OrbitAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
distanceDelta,
|
||||
@@ -826,7 +823,7 @@ namespace Pal3.Camera
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(OrbitAsync(rotation,
|
||||
Pal3.Instance.StartCoroutine(OrbitAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
distanceDelta,
|
||||
@@ -848,7 +845,7 @@ namespace Pal3.Camera
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(OrbitAsync(rotation,
|
||||
Pal3.Instance.StartCoroutine(OrbitAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
distanceDelta,
|
||||
@@ -858,7 +855,7 @@ namespace Pal3.Camera
|
||||
{
|
||||
_asyncCameraAnimationCts = new CancellationTokenSource();
|
||||
Quaternion rotation = GameBoxInterpreter.ToUnityRotation(command.Pitch, command.Yaw, 0f);
|
||||
StartCoroutine(OrbitAsync(rotation,
|
||||
Pal3.Instance.StartCoroutine(OrbitAsync(rotation,
|
||||
command.Duration,
|
||||
(AnimationCurveType)command.CurveType,
|
||||
distanceDelta,
|
||||
@@ -883,7 +880,7 @@ namespace Pal3.Camera
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
StartCoroutine(MoveAsync(position,
|
||||
Pal3.Instance.StartCoroutine(MoveAsync(position,
|
||||
duration,
|
||||
AnimationCurveType.Sine,
|
||||
() => waiter.CancelWait()));
|
||||
@@ -895,7 +892,7 @@ namespace Pal3.Camera
|
||||
command.GameBoxXPosition,
|
||||
command.GameBoxYPosition,
|
||||
command.GameBoxZPosition));
|
||||
StartCoroutine(MoveAsync(position,
|
||||
Pal3.Instance.StartCoroutine(MoveAsync(position,
|
||||
duration,
|
||||
AnimationCurveType.Sine,
|
||||
onFinished: null,
|
||||
@@ -910,10 +907,10 @@ namespace Pal3.Camera
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
|
||||
if (_gamePlayController.TryGetPlayerActorLastKnownPosition(out Vector3 playerActorPosition))
|
||||
if (_gamePlayManager.TryGetPlayerActorLastKnownPosition(out Vector3 playerActorPosition))
|
||||
{
|
||||
Vector3 position = _cameraOffset + playerActorPosition;
|
||||
StartCoroutine(MoveAsync(position,
|
||||
Pal3.Instance.StartCoroutine(MoveAsync(position,
|
||||
command.Duration,
|
||||
AnimationCurveType.Sine,
|
||||
() => waiter.CancelWait()));
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Pal3.Data
|
||||
using Core.Services;
|
||||
using Core.Utils;
|
||||
using MetaData;
|
||||
using Renderer;
|
||||
using Rendering.Material;
|
||||
using Settings;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -36,7 +36,8 @@ namespace Pal3.Data
|
||||
/// Also manages the lifecycle of the resource it provides.
|
||||
/// </summary>
|
||||
public sealed class GameResourceProvider : IDisposable,
|
||||
ICommandExecutor<ScenePreLoadingNotification>
|
||||
ICommandExecutor<ScenePreLoadingNotification>,
|
||||
ICommandExecutor<SettingChangedNotification>
|
||||
{
|
||||
private const string CACHE_FOLDER_NAME = "CacheData";
|
||||
private const string MV3_ACTOR_CONFIG_HEADER = ";#MV3#";
|
||||
@@ -90,12 +91,28 @@ namespace Pal3.Data
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_textureCache?.DisposeAll();
|
||||
_spriteCache.Clear();
|
||||
_gameResourceFileCache.Clear();
|
||||
_audioClipCache.Clear();
|
||||
_vfxEffectPrefabCache.Clear();
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
|
||||
_textureCache?.DisposeAll();
|
||||
|
||||
foreach (Sprite sprite in _spriteCache.Values)
|
||||
{
|
||||
Object.Destroy(sprite);
|
||||
}
|
||||
_spriteCache.Clear();
|
||||
|
||||
foreach (AudioClip audioClip in _audioClipCache.Values)
|
||||
{
|
||||
Object.Destroy(audioClip);
|
||||
}
|
||||
_audioClipCache.Clear();
|
||||
|
||||
_vfxEffectPrefabCache.Clear();
|
||||
|
||||
_unlitMaterialFactory?.DeallocateMaterialPool();
|
||||
_litMaterialFactory?.DeallocateMaterialPool();
|
||||
|
||||
_gameResourceFileCache.Clear();
|
||||
}
|
||||
|
||||
public void UseTextureCache(TextureCache textureCache)
|
||||
@@ -447,7 +464,7 @@ namespace Pal3.Data
|
||||
|
||||
if (!Directory.Exists(videoFolder))
|
||||
{
|
||||
throw new Exception($"Video directory does not exists: {videoFolder}.");
|
||||
throw new DirectoryNotFoundException($"Video directory does not exists: {videoFolder}.");
|
||||
}
|
||||
|
||||
var supportedVideoFormats = UnitySupportedVideoFormats.GetSupportedVideoFormats(Application.platform);
|
||||
@@ -462,7 +479,7 @@ namespace Pal3.Data
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception($"Cannot find video file: {videoName} under path: {videoFolder}. " +
|
||||
throw new FileNotFoundException($"Cannot find video file: {videoName} under path: {videoFolder}. " +
|
||||
$"Supported video formats are: {string.Join(" ", supportedVideoFormats)}.");
|
||||
}
|
||||
|
||||
@@ -615,5 +632,23 @@ namespace Pal3.Data
|
||||
// clear all vfx prefabs in cache
|
||||
_vfxEffectPrefabCache.Clear();
|
||||
}
|
||||
|
||||
public void Execute(SettingChangedNotification command)
|
||||
{
|
||||
// Need to deallocate and reallocate material pool when switching between lit and unlit materials
|
||||
if (command.SettingName == nameof(_gameSettings.IsRealtimeLightingAndShadowsEnabled))
|
||||
{
|
||||
if (_gameSettings.IsRealtimeLightingAndShadowsEnabled)
|
||||
{
|
||||
_unlitMaterialFactory?.DeallocateMaterialPool();
|
||||
_litMaterialFactory?.AllocateMaterialPool();
|
||||
}
|
||||
else
|
||||
{
|
||||
_litMaterialFactory?.DeallocateMaterialPool();
|
||||
_unlitMaterialFactory?.AllocateMaterialPool();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ namespace Pal3.Dev
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public sealed class MainMenu : MonoBehaviour,
|
||||
public sealed class MainMenu : IDisposable,
|
||||
ICommandExecutor<ToggleMainMenuRequest>,
|
||||
ICommandExecutor<GameSwitchToMainMenuCommand>,
|
||||
ICommandExecutor<ScenePostLoadingNotification>,
|
||||
@@ -42,34 +42,34 @@ namespace Pal3.Dev
|
||||
{
|
||||
private const int SAVE_SLOT_COUNT = 5;
|
||||
|
||||
private GameSettings _gameSettings;
|
||||
private InputManager _inputManager;
|
||||
private EventSystem _eventSystem;
|
||||
private PlayerInputActions _playerInputActions;
|
||||
private ScriptManager _scriptManager;
|
||||
private TeamManager _teamManager;
|
||||
private GameStateManager _gameStateManager;
|
||||
private SceneManager _sceneManager;
|
||||
private SaveManager _saveManager;
|
||||
private InformationManager _informationManager;
|
||||
private MazeSkipper _mazeSkipper;
|
||||
private readonly GameSettings _gameSettings;
|
||||
private readonly InputManager _inputManager;
|
||||
private readonly EventSystem _eventSystem;
|
||||
private readonly PlayerInputActions _playerInputActions;
|
||||
private readonly ScriptManager _scriptManager;
|
||||
private readonly TeamManager _teamManager;
|
||||
private readonly GameStateManager _gameStateManager;
|
||||
private readonly SceneManager _sceneManager;
|
||||
private readonly SaveManager _saveManager;
|
||||
private readonly InformationManager _informationManager;
|
||||
private readonly MazeSkipper _mazeSkipper;
|
||||
|
||||
private CanvasGroup _mainMenuCanvasGroup;
|
||||
private GameObject _menuButtonPrefab;
|
||||
private RectTransform _backgroundTransform;
|
||||
private RectTransform _contentTransform;
|
||||
private GridLayoutGroup _contentGridLayoutGroup;
|
||||
private ScrollRect _contentScrollRect;
|
||||
private readonly CanvasGroup _mainMenuCanvasGroup;
|
||||
private readonly GameObject _menuButtonPrefab;
|
||||
private readonly RectTransform _backgroundTransform;
|
||||
private readonly RectTransform _contentTransform;
|
||||
private readonly GridLayoutGroup _contentGridLayoutGroup;
|
||||
private readonly ScrollRect _contentScrollRect;
|
||||
|
||||
private bool _isInInitView = true;
|
||||
private CancellationTokenSource _initViewCameraOrbitAnimationCts = new ();
|
||||
private Camera _mainCamera;
|
||||
private readonly Camera _mainCamera;
|
||||
|
||||
private readonly List<string> _deferredExecutionCommands = new();
|
||||
|
||||
private readonly List<GameObject> _menuItems = new();
|
||||
|
||||
public void Init(GameSettings gameSettings,
|
||||
public MainMenu(GameSettings gameSettings,
|
||||
InputManager inputManager,
|
||||
SceneManager sceneManager,
|
||||
GameStateManager gameStateManager,
|
||||
@@ -112,21 +112,18 @@ namespace Pal3.Dev
|
||||
_mainMenuCanvasGroup.interactable = false;
|
||||
|
||||
_playerInputActions.Gameplay.ToggleStorySelector.performed += ToggleMainMenuPerformed;
|
||||
_playerInputActions.Cutscene.ToggleStorySelector.performed += ToggleMainMenuPerformed;
|
||||
_playerInputActions.Cutscene.ExitCurrentShowingMenu.performed += HideMainMenuPerformed;
|
||||
}
|
||||
_playerInputActions.UI.ToggleStorySelector.performed += ToggleMainMenuPerformed;
|
||||
_playerInputActions.UI.ExitCurrentShowingMenu.performed += HideMainMenuPerformed;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
_playerInputActions.Gameplay.ToggleStorySelector.performed -= ToggleMainMenuPerformed;
|
||||
_playerInputActions.Cutscene.ToggleStorySelector.performed -= ToggleMainMenuPerformed;
|
||||
_playerInputActions.Cutscene.ExitCurrentShowingMenu.performed -= HideMainMenuPerformed;
|
||||
_playerInputActions.UI.ToggleStorySelector.performed -= ToggleMainMenuPerformed;
|
||||
_playerInputActions.UI.ExitCurrentShowingMenu.performed -= HideMainMenuPerformed;
|
||||
}
|
||||
|
||||
private void ToggleMainMenuPerformed(InputAction.CallbackContext _)
|
||||
@@ -141,7 +138,7 @@ namespace Pal3.Dev
|
||||
if (_mainMenuCanvasGroup.interactable)
|
||||
{
|
||||
HideMenu();
|
||||
_gameStateManager.GoToState(GameState.Gameplay);
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +149,7 @@ namespace Pal3.Dev
|
||||
if (_mainMenuCanvasGroup.interactable)
|
||||
{
|
||||
HideMenu();
|
||||
_gameStateManager.GoToState(GameState.Gameplay);
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
}
|
||||
else if (_gameStateManager.GetCurrentState() == GameState.Gameplay)
|
||||
{
|
||||
@@ -187,9 +184,9 @@ namespace Pal3.Dev
|
||||
_initViewCameraOrbitAnimationCts.Cancel();
|
||||
}
|
||||
_initViewCameraOrbitAnimationCts = new CancellationTokenSource();
|
||||
StartCoroutine(StartCameraOrbitAnimationAsync(_initViewCameraOrbitAnimationCts.Token));
|
||||
Pal3.Instance.StartCoroutine(StartCameraOrbitAnimationAsync(_initViewCameraOrbitAnimationCts.Token));
|
||||
|
||||
_gameStateManager.GoToState(GameState.Cutscene);
|
||||
_gameStateManager.TryGoToState(GameState.UI);
|
||||
}
|
||||
|
||||
private IEnumerator StartCameraOrbitAnimationAsync(CancellationToken cancellationToken)
|
||||
@@ -234,7 +231,7 @@ namespace Pal3.Dev
|
||||
|
||||
public void ShowMenu()
|
||||
{
|
||||
_gameStateManager.GoToState(GameState.Cutscene);
|
||||
_gameStateManager.TryGoToState(GameState.UI);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorStopActionAndStandCommand(ActorConstants.PlayerActorVirtualID));
|
||||
SetupMainMenuButtons();
|
||||
@@ -267,7 +264,7 @@ namespace Pal3.Dev
|
||||
CreateMenuButton("返回游戏", _ => delegate
|
||||
{
|
||||
HideMenu();
|
||||
_gameStateManager.GoToState(GameState.Gameplay);
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -306,13 +303,13 @@ namespace Pal3.Dev
|
||||
{
|
||||
_mazeSkipper.PortalToEntrance();
|
||||
HideMenu();
|
||||
_gameStateManager.GoToState(GameState.Gameplay);
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
});
|
||||
CreateMenuButton("迷宫出口或剧情点", _ => delegate
|
||||
{
|
||||
_mazeSkipper.PortalToExitOrNextStoryPoint();
|
||||
HideMenu();
|
||||
_gameStateManager.GoToState(GameState.Gameplay);
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -727,7 +724,7 @@ namespace Pal3.Dev
|
||||
|
||||
private void CreateMenuButton(string text, Func<TextMeshProUGUI, UnityAction> onSelection)
|
||||
{
|
||||
GameObject menuButtonGo = Instantiate(_menuButtonPrefab, _contentTransform);
|
||||
GameObject menuButtonGo = UnityEngine.Object.Instantiate(_menuButtonPrefab, _contentTransform);
|
||||
var buttonTextUI = menuButtonGo.GetComponentInChildren<TextMeshProUGUI>();
|
||||
buttonTextUI.text = text;
|
||||
var button = menuButtonGo.GetComponent<Button>();
|
||||
@@ -798,7 +795,7 @@ namespace Pal3.Dev
|
||||
foreach (GameObject item in _menuItems)
|
||||
{
|
||||
item.GetComponent<Button>()?.onClick.RemoveAllListeners();
|
||||
Destroy(item);
|
||||
UnityEngine.Object.Destroy(item);
|
||||
}
|
||||
_menuItems.Clear();
|
||||
}
|
||||
@@ -818,7 +815,7 @@ namespace Pal3.Dev
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new TaskOpenCommand(TaskConstants.InitTaskId));
|
||||
#endif
|
||||
|
||||
_gameStateManager.GoToState(GameState.Cutscene);
|
||||
_gameStateManager.TryGoToState(GameState.Cutscene);
|
||||
}
|
||||
|
||||
private void ExecuteCommands(string commands)
|
||||
@@ -910,7 +907,8 @@ namespace Pal3.Dev
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(ExecuteDeferredCommandsAfterSceneScriptFinishedAsync(command.SceneScriptId));
|
||||
Pal3.Instance.StartCoroutine(ExecuteDeferredCommandsAfterSceneScriptFinishedAsync(
|
||||
command.SceneScriptId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -932,13 +930,13 @@ namespace Pal3.Dev
|
||||
|
||||
public void Execute(GameStateChangedNotification command)
|
||||
{
|
||||
// If menu is still active, go to cutscene state
|
||||
// If menu is still active, go to UI state
|
||||
// When turn on/off real time lighting and shadow, the game will reload the scene
|
||||
// and run scene script again, so we need to check if the menu is still active
|
||||
// and set the game state to cutscene
|
||||
// and set the game state to UI
|
||||
if (_mainMenuCanvasGroup.interactable)
|
||||
{
|
||||
_gameStateManager.GoToState(GameState.Cutscene);
|
||||
_gameStateManager.TryGoToState(GameState.UI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,21 +7,20 @@ namespace Pal3.Effect
|
||||
{
|
||||
using System;
|
||||
using Actor;
|
||||
using Actor.Controllers;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.DataReader.Dat;
|
||||
using Core.DataReader.Data;
|
||||
using Core.GameBox;
|
||||
using Core.Utils;
|
||||
using Data;
|
||||
using MetaData;
|
||||
using Scene;
|
||||
using Script.Waiter;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
public sealed class EffectManager : MonoBehaviour, IDisposable,
|
||||
public sealed class EffectManager : IDisposable,
|
||||
ICommandExecutor<EffectPreLoadCommand>,
|
||||
ICommandExecutor<EffectAttachToActorCommand>,
|
||||
ICommandExecutor<EffectSetPositionCommand>,
|
||||
@@ -29,14 +28,14 @@ namespace Pal3.Effect
|
||||
ICommandExecutor<SceneLeavingCurrentSceneNotification>,
|
||||
ICommandExecutor<ResetGameStateCommand>
|
||||
{
|
||||
private GameResourceProvider _resourceProvider;
|
||||
private SceneManager _sceneManager;
|
||||
private readonly GameResourceProvider _resourceProvider;
|
||||
private readonly SceneManager _sceneManager;
|
||||
private ICommand _effectPositionCommand;
|
||||
|
||||
private const string EFFECT_LINKER_FILE_NAME = "efflinker.dat";
|
||||
private EffectLinkerFile _effectLinkerFile;
|
||||
|
||||
public void Init(GameResourceProvider resourceProvider,
|
||||
public EffectManager(GameResourceProvider resourceProvider,
|
||||
SceneManager sceneManager)
|
||||
{
|
||||
_resourceProvider = Requires.IsNotNull(resourceProvider, nameof(resourceProvider));
|
||||
@@ -44,20 +43,13 @@ namespace Pal3.Effect
|
||||
|
||||
_effectLinkerFile = _resourceProvider.GetGameResourceFile<EffectLinkerFile>(
|
||||
FileConstants.CombatDataFolderVirtualPath + EFFECT_LINKER_FILE_NAME);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
_effectPositionCommand = null;
|
||||
}
|
||||
|
||||
@@ -68,7 +60,7 @@ namespace Pal3.Effect
|
||||
// Even with a waiter, we need to make sure waiter's current execution mode is set
|
||||
// to synchronous otherwise the effect will be played before the pre-load is finished.
|
||||
#if PAL3
|
||||
StartCoroutine(_resourceProvider.PreLoadVfxEffectAsync(command.EffectGroupId));
|
||||
Pal3.Instance.StartCoroutine(_resourceProvider.PreLoadVfxEffectAsync(command.EffectGroupId));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -118,7 +110,7 @@ namespace Pal3.Effect
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
var vfx = (GameObject)Instantiate(vfxPrefab, parent, false);
|
||||
var vfx = (GameObject)Object.Instantiate(vfxPrefab, parent, false);
|
||||
vfx.name = "VFX_" + command.EffectGroupId;
|
||||
vfx.transform.localPosition += localPosition;
|
||||
}
|
||||
@@ -172,12 +164,12 @@ namespace Pal3.Effect
|
||||
|
||||
public void Execute(SceneLeavingCurrentSceneNotification command)
|
||||
{
|
||||
Dispose();
|
||||
_effectPositionCommand = null;
|
||||
}
|
||||
|
||||
public void Execute(ResetGameStateCommand command)
|
||||
{
|
||||
Dispose();
|
||||
_effectPositionCommand = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@ namespace Pal3.Effect
|
||||
using Core.Utils;
|
||||
using Data;
|
||||
using MetaData;
|
||||
using Renderer;
|
||||
using Rendering.Material;
|
||||
using Rendering.Renderer;
|
||||
using UnityEngine;
|
||||
|
||||
public class FireEffect : MonoBehaviour, IEffect
|
||||
@@ -40,7 +41,8 @@ namespace Pal3.Effect
|
||||
_sceneObjectRenderer = gameObject.AddComponent<PolyModelRenderer>();
|
||||
_sceneObjectRenderer.Render(polFile,
|
||||
textureProvider,
|
||||
materialFactory);
|
||||
materialFactory,
|
||||
isStaticObject: false);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(info.TexturePathFormat))
|
||||
|
||||
@@ -5,32 +5,32 @@
|
||||
|
||||
namespace Pal3.Effect.PostProcessing
|
||||
{
|
||||
using System;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.Utils;
|
||||
using Settings;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
public sealed class PostProcessManager : MonoBehaviour,
|
||||
public sealed class PostProcessManager : IDisposable,
|
||||
ICommandExecutor<EffectSetScreenEffectCommand>,
|
||||
ICommandExecutor<ResetGameStateCommand>,
|
||||
ICommandExecutor<SettingChangedNotification>
|
||||
{
|
||||
private PostProcessVolume _postProcessVolume;
|
||||
private PostProcessLayer _postProcessLayer;
|
||||
private GameSettings _gameSettings;
|
||||
private readonly PostProcessVolume _postProcessVolume;
|
||||
private readonly PostProcessLayer _postProcessLayer;
|
||||
private readonly GameSettings _gameSettings;
|
||||
|
||||
private Bloom _bloom;
|
||||
private AmbientOcclusion _ambientOcclusion;
|
||||
private ColorGrading _colorGrading;
|
||||
private Vignette _vignette;
|
||||
private Distortion _distortion;
|
||||
private readonly Bloom _bloom;
|
||||
private readonly AmbientOcclusion _ambientOcclusion;
|
||||
private readonly ColorGrading _colorGrading;
|
||||
private readonly Vignette _vignette;
|
||||
private readonly Distortion _distortion;
|
||||
|
||||
private int _currentAppliedEffectMode = -1;
|
||||
|
||||
public void Init(PostProcessVolume volume,
|
||||
public PostProcessManager(PostProcessVolume volume,
|
||||
PostProcessLayer postProcessLayer,
|
||||
GameSettings gameSettings)
|
||||
{
|
||||
@@ -57,6 +57,8 @@ namespace Pal3.Effect.PostProcessing
|
||||
}
|
||||
|
||||
TogglePostProcessLayerWhenNeeded();
|
||||
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void ToggleBloomBasedOnSetting()
|
||||
@@ -102,12 +104,7 @@ namespace Pal3.Effect.PostProcessing
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
|
||||
@@ -226,6 +226,19 @@ namespace Pal3.GamePlay
|
||||
{
|
||||
if (command.ActorId == ActorConstants.PlayerActorVirtualID)
|
||||
{
|
||||
// Fix a bug in PAL3 script
|
||||
// TODO: Implement a better solution to fix command at dispatching time
|
||||
#if PAL3
|
||||
if (command.TileXPosition == 289 &&
|
||||
command.TileYPosition == 21 &&
|
||||
command.Mode == 0)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorPathToCommand((int)_playerActor, 288, 20, command.Mode));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorPathToCommand((int)_playerActor, command.TileXPosition, command.TileYPosition, command.Mode));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,60 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.GamePlay
|
||||
{
|
||||
using System;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.DataReader.Scn;
|
||||
using MetaData;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public partial class PlayerGamePlayManager :
|
||||
ICommandExecutor<SwitchPlayerActorRequest>
|
||||
{
|
||||
public void Execute(SwitchPlayerActorRequest command)
|
||||
{
|
||||
if (_sceneManager.GetCurrentScene().GetSceneInfo().SceneType == ScnSceneType.Maze)
|
||||
{
|
||||
SwitchPlayerActorInCurrentTeam(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void SwitchToNextPlayerActorPerformed(InputAction.CallbackContext _)
|
||||
{
|
||||
SwitchPlayerActorInCurrentTeam(true);
|
||||
}
|
||||
|
||||
private void SwitchToPreviousPlayerActorPerformed(InputAction.CallbackContext _)
|
||||
{
|
||||
SwitchPlayerActorInCurrentTeam(false);
|
||||
}
|
||||
|
||||
private void SwitchPlayerActorInCurrentTeam(bool next)
|
||||
{
|
||||
if (!_playerActorManager.IsPlayerActorControlEnabled() ||
|
||||
!_playerActorManager.IsPlayerInputEnabled() ||
|
||||
_sceneManager.GetCurrentScene().GetSceneInfo().SceneType != ScnSceneType.Maze)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var actorsInTeam = _teamManager.GetActorsInTeam();
|
||||
if (actorsInTeam.Count <= 1) return; // Makes no sense to change player actor if there is only one actor in the team
|
||||
|
||||
var playerActorIdLength = Enum.GetNames(typeof(PlayerActorId)).Length;
|
||||
int targetPlayerActorId = _playerActor.Info.Id;
|
||||
|
||||
do
|
||||
{
|
||||
targetPlayerActorId = (targetPlayerActorId + playerActorIdLength + (next ? +1 : -1)) % playerActorIdLength;
|
||||
} while (!actorsInTeam.Contains((PlayerActorId) targetPlayerActorId));
|
||||
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ActorEnablePlayerControlCommand(targetPlayerActorId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3822202328afc74380116ad2e9a5247
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,147 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.GamePlay
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.GameBox;
|
||||
using Core.Renderer;
|
||||
using MetaData;
|
||||
using Scene;
|
||||
using Scene.SceneObjects;
|
||||
using Script.Waiter;
|
||||
using UnityEngine;
|
||||
|
||||
public partial class PlayerGamePlayManager :
|
||||
ICommandExecutor<ActorPerformClimbActionCommand>
|
||||
{
|
||||
public void Execute(ActorPerformClimbActionCommand command)
|
||||
{
|
||||
Scene scene = _sceneManager.GetCurrentScene();
|
||||
SceneObject climbableSceneObject = scene.GetSceneObject(command.ObjectId);
|
||||
GameObject climbableObject = climbableSceneObject.GetGameObject();
|
||||
if (climbableObject == null)
|
||||
{
|
||||
Debug.LogError($"[{nameof(PlayerGamePlayManager)}] Scene object not found or not activated yet: {command.ObjectId}.");
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 climbableObjectPosition = climbableObject.transform.position;
|
||||
Vector3 climbableObjectFacing = GameBoxInterpreter.ToUnityRotation(
|
||||
new Vector3(0f, climbableSceneObject.ObjectInfo.GameBoxYRotation, 0f)) * Vector3.forward;
|
||||
|
||||
Vector3 lowerPosition = climbableObjectFacing.normalized * 0.5f + climbableObjectPosition;
|
||||
Vector3 lowerStandingPosition = climbableObjectFacing.normalized * 1.5f + climbableObjectPosition;
|
||||
Vector3 upperPosition = -climbableObjectFacing.normalized * 0.5f + climbableObjectPosition;
|
||||
Vector3 upperStandingPosition = -climbableObjectFacing.normalized * 1.5f + climbableObjectPosition;
|
||||
|
||||
var currentPlayerLayer = _playerActorMovementController.GetCurrentLayerIndex();
|
||||
|
||||
var climbUp = (command.ClimbUp == 1);
|
||||
var climbableHeight = climbableObject.GetComponentInChildren<StaticMeshRenderer>()
|
||||
.GetRendererBounds().max.y / 2f; // Half is enough for the animation
|
||||
|
||||
Vector3 playerCurrentPosition = _playerActorGameObject.transform.position;
|
||||
if (command.ClimbUp == 1)
|
||||
{
|
||||
lowerPosition.y = playerCurrentPosition.y;
|
||||
lowerStandingPosition.y = playerCurrentPosition.y;
|
||||
upperPosition.y = playerCurrentPosition.y + climbableHeight;
|
||||
upperStandingPosition.y = playerCurrentPosition.y + climbableHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
lowerPosition.y = playerCurrentPosition.y - climbableHeight;
|
||||
lowerStandingPosition.y = playerCurrentPosition.y - climbableHeight;
|
||||
upperPosition.y = playerCurrentPosition.y;
|
||||
upperStandingPosition.y = playerCurrentPosition.y;
|
||||
}
|
||||
|
||||
var waiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
|
||||
var climbAnimationOnly = command.ClimbUp != -1;
|
||||
Pal3.Instance.StartCoroutine(PlayerActorMoveToClimbableObjectAndClimbAsync(climbableObject,
|
||||
climbUp,
|
||||
climbAnimationOnly,
|
||||
climbableHeight,
|
||||
lowerPosition,
|
||||
lowerStandingPosition,
|
||||
upperPosition,
|
||||
upperStandingPosition,
|
||||
currentPlayerLayer,
|
||||
currentPlayerLayer,
|
||||
() => waiter.CancelWait()));
|
||||
}
|
||||
|
||||
public IEnumerator PlayerActorMoveToClimbableObjectAndClimbAsync(
|
||||
GameObject climbableObject,
|
||||
bool climbUp,
|
||||
bool climbOnly,
|
||||
float climbableHeight,
|
||||
Vector3 lowerPosition,
|
||||
Vector3 lowerStandingPosition,
|
||||
Vector3 upperPosition,
|
||||
Vector3 upperStandingPosition,
|
||||
int lowerLayer,
|
||||
int upperLayer,
|
||||
Action onFinished = null)
|
||||
{
|
||||
yield return _playerActorMovementController
|
||||
.MoveDirectlyToAsync(climbUp ? lowerPosition : upperPosition, 0, true);
|
||||
|
||||
_playerActorActionController.PerformAction(climbUp ? ActorActionType.Climb : ActorActionType.ClimbDown);
|
||||
|
||||
Vector3 newPosition = new Vector3(lowerPosition.x, _playerActorGameObject.transform.position.y, lowerPosition.z);
|
||||
var objectRotationY = climbableObject.transform.rotation.eulerAngles.y;
|
||||
Quaternion newRotation = Quaternion.Euler(0f, objectRotationY + 180f, 0f);
|
||||
|
||||
_playerActorGameObject.transform.SetPositionAndRotation(newPosition, newRotation);
|
||||
|
||||
if (climbUp)
|
||||
{
|
||||
var currentHeight = 0f;
|
||||
while (currentHeight < climbableHeight)
|
||||
{
|
||||
var delta = Time.deltaTime * ActorConstants.PlayerActorClimbSpeed;
|
||||
currentHeight += delta;
|
||||
_playerActorGameObject.transform.position += new Vector3(0f, delta, 0f);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (!climbOnly)
|
||||
{
|
||||
_playerActorMovementController.SetNavLayer(upperLayer);
|
||||
yield return _playerActorMovementController.MoveDirectlyToAsync(upperStandingPosition, 0, true);
|
||||
_playerActorGameObject.transform.position = upperStandingPosition;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var currentHeight = climbableHeight;
|
||||
while (currentHeight > 0f)
|
||||
{
|
||||
var delta = Time.deltaTime * ActorConstants.PlayerActorClimbSpeed;
|
||||
currentHeight -= delta;
|
||||
_playerActorGameObject.transform.position -= new Vector3(0f, delta, 0f);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (!climbOnly)
|
||||
{
|
||||
_playerActorMovementController.SetNavLayer(lowerLayer);
|
||||
yield return _playerActorMovementController.MoveDirectlyToAsync(lowerStandingPosition, 0, true);
|
||||
_playerActorGameObject.transform.position = lowerStandingPosition;
|
||||
}
|
||||
}
|
||||
|
||||
onFinished?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9373576ee1894d44db3c4002224ae072
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,234 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.GamePlay
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Actor;
|
||||
using Actor.Controllers;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.DataReader.Scn;
|
||||
using MetaData;
|
||||
using Scene;
|
||||
using Scene.SceneObjects;
|
||||
using Script;
|
||||
using Script.Waiter;
|
||||
using State;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public partial class PlayerGamePlayManager :
|
||||
ICommandExecutor<PlayerInteractionRequest>,
|
||||
ICommandExecutor<PlayerInteractWithObjectCommand>
|
||||
{
|
||||
public void Execute(PlayerInteractWithObjectCommand command)
|
||||
{
|
||||
Scene currentScene = _sceneManager.GetCurrentScene();
|
||||
if (currentScene.GetAllActivatedSceneObjects().Contains(command.SceneObjectId))
|
||||
{
|
||||
Pal3.Instance.StartCoroutine(InteractWithSceneObjectAsync(
|
||||
currentScene.GetSceneObject(command.SceneObjectId), startedByPlayer: false));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"[{nameof(PlayerGamePlayManager)}] Scene object not found" +
|
||||
$" or not activated yet: {command.SceneObjectId}.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(PlayerInteractionRequest _)
|
||||
{
|
||||
if (IsPlayerActorInsideJumpableArea())
|
||||
{
|
||||
Pal3.Instance.StartCoroutine(JumpAsync());
|
||||
}
|
||||
else
|
||||
{
|
||||
InteractWithFacingInteractable();
|
||||
}
|
||||
}
|
||||
|
||||
private void InteractionPerformed(InputAction.CallbackContext _)
|
||||
{
|
||||
if (!_playerActorManager.IsPlayerActorControlEnabled() ||
|
||||
!_playerActorManager.IsPlayerInputEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsPlayerActorInsideJumpableArea())
|
||||
{
|
||||
Pal3.Instance.StartCoroutine(JumpAsync());
|
||||
}
|
||||
else
|
||||
{
|
||||
InteractWithFacingInteractable();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interact with the nearby interactable object by the player actor facing direction.
|
||||
/// </summary>
|
||||
private void InteractWithFacingInteractable()
|
||||
{
|
||||
Vector3 actorFacingDirection = _playerActorMovementController.transform.forward;
|
||||
Vector3 actorCenterPosition = _playerActorActionController.GetRendererBounds().center;
|
||||
var currentLayerIndex = _playerActorMovementController.GetCurrentLayerIndex();
|
||||
|
||||
float nearestInteractableFacingAngle = 181f;
|
||||
IEnumerator interactionRoutine = null;
|
||||
|
||||
foreach (var sceneObjectId in
|
||||
_sceneManager.GetCurrentScene().GetAllActivatedSceneObjects())
|
||||
{
|
||||
SceneObject sceneObject = _sceneManager.GetCurrentScene().GetSceneObject(sceneObjectId);
|
||||
|
||||
Vector3 closetPointOnObject = sceneObject.GetRendererBounds().ClosestPoint(actorCenterPosition);
|
||||
float distanceToActor = Vector3.Distance(actorCenterPosition, closetPointOnObject);
|
||||
Vector3 actorToObjectFacing = closetPointOnObject - actorCenterPosition;
|
||||
float facingAngle = Vector2.Angle(
|
||||
new Vector2(actorFacingDirection.x, actorFacingDirection.z),
|
||||
new Vector2(actorToObjectFacing.x, actorToObjectFacing.z));
|
||||
|
||||
if (sceneObject.IsDirectlyInteractable(distanceToActor) &&
|
||||
facingAngle < nearestInteractableFacingAngle)
|
||||
{
|
||||
//Debug.DrawLine(actorCenterPosition, closetPointOnObject, Color.white, 1000);
|
||||
nearestInteractableFacingAngle = facingAngle;
|
||||
interactionRoutine = InteractWithSceneObjectAsync(sceneObject, startedByPlayer: true);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var actorInfo in
|
||||
_sceneManager.GetCurrentScene().GetAllActorGameObjects())
|
||||
{
|
||||
var actorController = actorInfo.Value.GetComponent<ActorController>();
|
||||
var actorActionController = actorInfo.Value.GetComponent<ActorActionController>();
|
||||
var actorMovementController = actorInfo.Value.GetComponent<ActorMovementController>();
|
||||
|
||||
if (actorMovementController.GetCurrentLayerIndex() != currentLayerIndex ||
|
||||
actorInfo.Key == (int)_playerActorManager.GetPlayerActor() ||
|
||||
!actorController.IsActive) continue;
|
||||
|
||||
Vector3 targetActorCenterPosition = actorActionController.GetRendererBounds().center;
|
||||
var distance = Vector3.Distance(actorCenterPosition,targetActorCenterPosition);
|
||||
Vector3 actorToActorFacing = targetActorCenterPosition - actorCenterPosition;
|
||||
float facingAngle = Vector2.Angle(
|
||||
new Vector2(actorFacingDirection.x, actorFacingDirection.z),
|
||||
new Vector2(actorToActorFacing.x, actorToActorFacing.z));
|
||||
|
||||
if (actorController.IsDirectlyInteractable(distance) &&
|
||||
facingAngle < nearestInteractableFacingAngle)
|
||||
{
|
||||
//Debug.DrawLine(actorCenterPosition, targetActorCenterPosition, Color.white, 1000);
|
||||
nearestInteractableFacingAngle = facingAngle;
|
||||
interactionRoutine = InteractWithActorAsync(actorInfo.Key, actorInfo.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (interactionRoutine != null)
|
||||
{
|
||||
Pal3.Instance.StartCoroutine(interactionRoutine);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator InteractWithSceneObjectAsync(SceneObject sceneObject, bool startedByPlayer)
|
||||
{
|
||||
var correlationId = Guid.NewGuid();
|
||||
var requiresStateChange = sceneObject.ShouldGoToCutsceneWhenInteractionStarted();
|
||||
|
||||
if (requiresStateChange)
|
||||
{
|
||||
_gameStateManager.TryGoToState(GameState.Cutscene);
|
||||
_gameStateManager.AddGamePlayStateLocker(correlationId);
|
||||
}
|
||||
|
||||
yield return sceneObject.InteractAsync(new InteractionContext
|
||||
{
|
||||
CorrelationId = correlationId,
|
||||
InitObjectId = sceneObject.ObjectInfo.Id,
|
||||
PlayerActorGameObject = _playerActorGameObject,
|
||||
CurrentScene = _sceneManager.GetCurrentScene(),
|
||||
StartedByPlayer = startedByPlayer,
|
||||
});
|
||||
|
||||
if (requiresStateChange)
|
||||
{
|
||||
_gameStateManager.RemoveGamePlayStateLocker(correlationId);
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator InteractWithActorAsync(int actorId, GameObject actorGameObject)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new GameStateChangeRequest(GameState.Cutscene));
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorStopActionAndStandCommand(ActorConstants.PlayerActorVirtualID));
|
||||
|
||||
Actor targetActor = _sceneManager.GetCurrentScene().GetActor(actorId);
|
||||
Quaternion rotationBeforeInteraction = actorGameObject.transform.rotation;
|
||||
|
||||
var actorController = actorGameObject.GetComponent<ActorController>();
|
||||
var movementController = actorGameObject.GetComponent<ActorMovementController>();
|
||||
|
||||
// Pause current path follow movement of the interacting actor
|
||||
if (actorController != null &&
|
||||
movementController != null &&
|
||||
actorController.GetCurrentBehaviour() == ScnActorBehaviour.PathFollow)
|
||||
{
|
||||
movementController.PauseMovement();
|
||||
}
|
||||
|
||||
// Look at the target actor
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorLookAtActorCommand(_playerActor.Info.Id, targetActor.Info.Id));
|
||||
|
||||
bool shouldResetFacingAfterInteraction = false;
|
||||
|
||||
// Only let target actor look at player actor when NoTurn is set to false
|
||||
// and InitBehaviour is not set to Hold
|
||||
if (targetActor.Info.NoTurn == 0 && targetActor.Info.InitBehaviour != ScnActorBehaviour.Hold)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorLookAtActorCommand(targetActor.Info.Id, _playerActor.Info.Id));
|
||||
shouldResetFacingAfterInteraction = true;
|
||||
}
|
||||
|
||||
// Resume animation of the target actor if it is set to hold and loop action is set to 0
|
||||
if (targetActor.Info.InitBehaviour == ScnActorBehaviour.Hold &&
|
||||
targetActor.Info.LoopAction == 0)
|
||||
{
|
||||
var actionController = actorGameObject.GetComponent<ActorActionController>();
|
||||
// PerformAction internally checks if the target actor is already performing the action
|
||||
actionController.PerformAction(actionController.GetCurrentAction(), false, 1);
|
||||
}
|
||||
|
||||
// Run dialogue script
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ScriptRunCommand((int)targetActor.Info.ScriptId));
|
||||
|
||||
// Wait until the dialogue script is finished
|
||||
yield return new WaitUntilScriptFinished(PalScriptType.Scene, targetActor.Info.ScriptId);
|
||||
|
||||
// Resume current path follow movement of the interacting actor
|
||||
if (actorController != null &&
|
||||
movementController != null &&
|
||||
actorController.GetCurrentBehaviour() == ScnActorBehaviour.PathFollow)
|
||||
{
|
||||
movementController.ResumeMovement();
|
||||
}
|
||||
|
||||
// Reset facing rotation of the interacting actor if needed
|
||||
if (shouldResetFacingAfterInteraction && actorGameObject != null)
|
||||
{
|
||||
actorGameObject.transform.rotation = rotationBeforeInteraction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d408f988e08d644c8124b5b6b735f83
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,224 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.GamePlay
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Core.Animation;
|
||||
using Core.DataReader.Nav;
|
||||
using Core.GameBox;
|
||||
using Core.Renderer;
|
||||
using MetaData;
|
||||
using Scene;
|
||||
using State;
|
||||
using UnityEngine;
|
||||
|
||||
public partial class PlayerGamePlayManager
|
||||
{
|
||||
private const float MIN_JUMP_DISTANCE = 1.2f;
|
||||
private const float MAX_JUMP_DISTANCE = 8f;
|
||||
private const float MAX_JUMP_Y_DIFFERENTIAL = 3.5f;
|
||||
private const float JUMP_HEIGHT = 6f;
|
||||
|
||||
private int _jumpableAreaEnterCount;
|
||||
|
||||
private GameObject _jumpIndicatorGameObject;
|
||||
private AnimatedBillboardRenderer _jumpIndicatorRenderer;
|
||||
|
||||
private void JumpToTapPosition()
|
||||
{
|
||||
if (!_lastInputTapPosition.HasValue) return;
|
||||
|
||||
Ray ray = _camera.ScreenPointToRay(_lastInputTapPosition.Value);
|
||||
|
||||
if (!Physics.Raycast(ray, out RaycastHit hit)) return;
|
||||
|
||||
if (_sceneManager.GetCurrentScene()
|
||||
.GetMeshColliders().Any(_ => _.Value == hit.collider))
|
||||
{
|
||||
Pal3.Instance.StartCoroutine(JumpAsync(hit.point));
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayerActorEnteredJumpableArea()
|
||||
{
|
||||
if (_jumpIndicatorGameObject == null)
|
||||
{
|
||||
var sprites = _resourceProvider.GetJumpIndicatorSprites();
|
||||
|
||||
_jumpIndicatorGameObject = new GameObject($"JumpIndicator");
|
||||
_jumpIndicatorGameObject.transform.SetParent(_playerActorGameObject.transform, false);
|
||||
_jumpIndicatorGameObject.transform.localScale = new Vector3(3f, 3f, 3f);
|
||||
_jumpIndicatorGameObject.transform.localPosition = new Vector3(0f,
|
||||
_playerActorActionController.GetActorHeight() + 1f, 0f);
|
||||
|
||||
_jumpIndicatorRenderer = _jumpIndicatorGameObject.AddComponent<AnimatedBillboardRenderer>();
|
||||
_jumpIndicatorRenderer.Init(sprites, 4);
|
||||
}
|
||||
|
||||
if (_jumpableAreaEnterCount == 0)
|
||||
{
|
||||
_jumpIndicatorRenderer.StartAnimation(-1);
|
||||
}
|
||||
|
||||
_jumpableAreaEnterCount++;
|
||||
}
|
||||
|
||||
public void PlayerActorExitedJumpableArea()
|
||||
{
|
||||
_jumpableAreaEnterCount--;
|
||||
|
||||
if (_jumpableAreaEnterCount == 0 && _jumpIndicatorRenderer != null)
|
||||
{
|
||||
_jumpIndicatorRenderer.StopAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsPlayerActorInsideJumpableArea()
|
||||
{
|
||||
return _jumpableAreaEnterCount > 0;
|
||||
}
|
||||
|
||||
private void ResetAndDisposeJumpIndicators()
|
||||
{
|
||||
_jumpableAreaEnterCount = 0;
|
||||
|
||||
if (_jumpIndicatorRenderer != null)
|
||||
{
|
||||
_jumpIndicatorRenderer.StopAnimation();
|
||||
UnityEngine.Object.Destroy(_jumpIndicatorRenderer);
|
||||
_jumpIndicatorRenderer = null;
|
||||
}
|
||||
|
||||
if (_jumpIndicatorGameObject != null)
|
||||
{
|
||||
UnityEngine.Object.Destroy(_jumpIndicatorGameObject);
|
||||
_jumpIndicatorGameObject = null;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator JumpAsync(Vector3? jumpTargetPosition = null)
|
||||
{
|
||||
_gameStateManager.TryGoToState(GameState.Cutscene);
|
||||
_playerActorMovementController.CancelMovement();
|
||||
|
||||
Vector3 currentPosition = _playerActorMovementController.GetWorldPosition();
|
||||
|
||||
Scene currentScene = _sceneManager.GetCurrentScene();
|
||||
Tilemap tilemap = currentScene.GetTilemap();
|
||||
|
||||
bool IsPositionCanJumpTo(Vector3 position, int layerIndex, out float yPosition, out int distanceToObstacle)
|
||||
{
|
||||
Vector2Int tilePosition = tilemap.GetTilePosition(position, layerIndex);
|
||||
|
||||
if (tilemap.TryGetTile(position, layerIndex, out NavTile tile) &&
|
||||
tile.IsWalkable())
|
||||
{
|
||||
distanceToObstacle = tile.DistanceToNearestObstacle;
|
||||
yPosition = GameBoxInterpreter.ToUnityYPosition(tile.GameBoxYPosition);
|
||||
|
||||
if (Mathf.Abs(yPosition - currentPosition.y) > MAX_JUMP_Y_DIFFERENTIAL) return false;
|
||||
|
||||
if (currentScene.IsPositionInsideJumpableArea(layerIndex, tilePosition))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#if PAL3
|
||||
// Special case for PAL3 M15-B1
|
||||
if (_sceneManager.GetCurrentScene().GetSceneInfo().Is("m15", "b1"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
yPosition = 0f;
|
||||
distanceToObstacle = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 jumpDirection = _playerActorGameObject.transform.forward;
|
||||
|
||||
if (jumpTargetPosition != null)
|
||||
{
|
||||
jumpDirection = jumpTargetPosition.Value - _playerActorGameObject.transform.position;
|
||||
jumpDirection.y = 0f;
|
||||
jumpDirection.Normalize();
|
||||
_playerActorGameObject.transform.forward = jumpDirection;
|
||||
}
|
||||
|
||||
var validJumpTargetPositions = new List<(Vector3 position, int layerIndex, int distanceToObstacle)>();
|
||||
|
||||
for (float i = MIN_JUMP_DISTANCE; i <= MAX_JUMP_DISTANCE; i += 0.1f)
|
||||
{
|
||||
Vector3 targetPosition = currentPosition + jumpDirection * i;
|
||||
|
||||
for (var j = 0; j < tilemap.GetLayerCount(); j++)
|
||||
{
|
||||
if (IsPositionCanJumpTo(targetPosition, j,
|
||||
out float yPosition, out int distanceToObstacle))
|
||||
{
|
||||
Vector3 position = targetPosition;
|
||||
position.y = yPosition;
|
||||
validJumpTargetPositions.Add((position, j, distanceToObstacle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var currentLayer = _playerActorMovementController.GetCurrentLayerIndex();
|
||||
var jumpTargetLayer = currentLayer;
|
||||
if (validJumpTargetPositions.Count > 0)
|
||||
{
|
||||
// If there are valid jump target positions in different layers,
|
||||
// only pick positions in the other layer
|
||||
if (validJumpTargetPositions.Any(_ => _.layerIndex != currentLayer))
|
||||
{
|
||||
validJumpTargetPositions = validJumpTargetPositions.Where(_ => _.layerIndex != currentLayer).ToList();
|
||||
}
|
||||
|
||||
// Pick a position that is farthest from obstacles
|
||||
int maxDistanceToObstacle = validJumpTargetPositions.Max(_ => _.distanceToObstacle);
|
||||
var bestPosition = validJumpTargetPositions
|
||||
.First(_ => _.distanceToObstacle == maxDistanceToObstacle);
|
||||
jumpTargetPosition = bestPosition.position;
|
||||
jumpTargetLayer = bestPosition.layerIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
jumpTargetPosition = currentPosition;
|
||||
}
|
||||
|
||||
_playerActorActionController.PerformAction(ActorConstants.ActionToNameMap[ActorActionType.Jump],
|
||||
overwrite: true, loopCount: 1);
|
||||
yield return new WaitForSeconds(0.7f);
|
||||
|
||||
var xzOffset = Vector2.Distance(
|
||||
new Vector2(jumpTargetPosition.Value.x, jumpTargetPosition.Value.z),
|
||||
new Vector2(currentPosition.x, currentPosition.z));
|
||||
var startingYPosition = currentPosition.y;
|
||||
var yOffset = jumpTargetPosition.Value.y - currentPosition.y;
|
||||
|
||||
yield return CoreAnimation.EnumerateValueAsync(0f, 1f, 1.1f, AnimationCurveType.Sine,
|
||||
value =>
|
||||
{
|
||||
Vector3 calculatedPosition = currentPosition + jumpDirection * (xzOffset * value);
|
||||
calculatedPosition.y = startingYPosition + (0.5f - MathF.Abs(value - 0.5f)) * JUMP_HEIGHT + yOffset * value;
|
||||
_playerActorGameObject.transform.position = calculatedPosition;
|
||||
});
|
||||
yield return new WaitForSeconds(0.7f);
|
||||
|
||||
_playerActorMovementController.SetNavLayer(jumpTargetLayer);
|
||||
|
||||
PlayerActorTilePositionChanged(jumpTargetLayer,
|
||||
tilemap.GetTilePosition(jumpTargetPosition.Value, jumpTargetLayer), false);
|
||||
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9dcc05fc2830c441b0e4e26a21ca33b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,260 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.GamePlay
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Actor.Controllers;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Core.DataReader.Nav;
|
||||
using Core.Navigation;
|
||||
using MetaData;
|
||||
using Scene;
|
||||
using Scene.SceneObjects.Common;
|
||||
using UnityEngine;
|
||||
|
||||
public partial class PlayerGamePlayManager
|
||||
{
|
||||
private const float PLAYER_ACTOR_MOVEMENT_SFX_WALK_VOLUME = 0.6f;
|
||||
private const float PLAYER_ACTOR_MOVEMENT_SFX_RUN_VOLUME = 1.0f;
|
||||
|
||||
private void ReadInputAndMovePlayerIfNeeded()
|
||||
{
|
||||
var movement = _inputActions.Gameplay.Movement.ReadValue<Vector2>();
|
||||
if (movement.magnitude <= 0.01f) return;
|
||||
|
||||
MovementMode movementMode = movement.magnitude < 0.7f ? MovementMode.Walk : MovementMode.Run;
|
||||
ActorActionType movementAction = movementMode == MovementMode.Walk ? ActorActionType.Walk : ActorActionType.Run;
|
||||
_playerActorMovementController.CancelMovement();
|
||||
Transform cameraTransform = _camera.transform;
|
||||
Vector2 normalizedDirection = movement.normalized;
|
||||
Vector3 inputDirection = cameraTransform.forward * normalizedDirection.y +
|
||||
cameraTransform.right * normalizedDirection.x;
|
||||
MovementResult result = PlayerActorMoveTowards(inputDirection, movementMode);
|
||||
_playerActorActionController.PerformAction(result == MovementResult.Blocked
|
||||
? ActorActionType.Stand
|
||||
: movementAction);
|
||||
}
|
||||
|
||||
private void PortalToTapPosition()
|
||||
{
|
||||
if (!_lastInputTapPosition.HasValue) return;
|
||||
|
||||
Ray ray = _camera.ScreenPointToRay(_lastInputTapPosition.Value);
|
||||
|
||||
if (!Physics.Raycast(ray, out RaycastHit hit)) return;
|
||||
|
||||
int layerIndex;
|
||||
bool isPositionOnStandingPlatform;
|
||||
|
||||
if (hit.collider.gameObject.GetComponent<StandingPlatformController>() is { } standingPlatformController)
|
||||
{
|
||||
layerIndex = standingPlatformController.LayerIndex;
|
||||
isPositionOnStandingPlatform = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var meshColliders = _sceneManager.GetCurrentScene()
|
||||
.GetMeshColliders();
|
||||
|
||||
if (meshColliders.Any(_ => _.Value == hit.collider))
|
||||
{
|
||||
layerIndex = meshColliders.First(_ => _.Value == hit.collider).Key;
|
||||
isPositionOnStandingPlatform = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Raycast hit a collider that is not a mesh collider or a standing platform
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_playerActorMovementController.PortalToPosition(hit.point, layerIndex, isPositionOnStandingPlatform);
|
||||
}
|
||||
|
||||
// Raycast caches to avoid GC
|
||||
private readonly RaycastHit[] _raycastHits = new RaycastHit[4];
|
||||
private readonly Dictionary<int, (Vector3 point, bool isPlatform)> _tapPoints = new ();
|
||||
private void MoveToTapPosition(bool isDoubleTap)
|
||||
{
|
||||
if (!_lastInputTapPosition.HasValue) return;
|
||||
|
||||
Scene currentScene = _sceneManager.GetCurrentScene();
|
||||
var meshColliders = currentScene.GetMeshColliders();
|
||||
|
||||
Ray ray = _camera.ScreenPointToRay(_lastInputTapPosition.Value);
|
||||
|
||||
var hitCount = Physics.RaycastNonAlloc(ray, _raycastHits, 500f);
|
||||
if (hitCount == 0) return;
|
||||
|
||||
Tilemap tilemap = currentScene.GetTilemap();
|
||||
|
||||
_tapPoints.Clear();
|
||||
for (var i = 0; i < hitCount; i++)
|
||||
{
|
||||
RaycastHit hit = _raycastHits[i];
|
||||
|
||||
if (hit.collider.gameObject.GetComponent<StandingPlatformController>() is { }
|
||||
standingPlatformController)
|
||||
{
|
||||
_tapPoints[standingPlatformController.LayerIndex] = (hit.point, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
var layerIndex = meshColliders.FirstOrDefault(_ => _.Value == hit.collider).Key;
|
||||
|
||||
if (!tilemap.TryGetTile(hit.point, layerIndex, out NavTile _))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector3 cameraPosition = _camera.transform.position;
|
||||
var distanceToCamera = Vector3.Distance(cameraPosition, hit.point);
|
||||
|
||||
if (_tapPoints.ContainsKey(layerIndex))
|
||||
{
|
||||
var existingDistance = Vector3.Distance(cameraPosition, _tapPoints[layerIndex].point);
|
||||
if (distanceToCamera < existingDistance)
|
||||
{
|
||||
_tapPoints[layerIndex] = (hit.point, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_tapPoints[layerIndex] = (hit.point, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (_tapPoints.Count > 0)
|
||||
{
|
||||
_playerActorMovementController.MoveToTapPoint(_tapPoints, isDoubleTap);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjust some degrees to the inputDirection to prevent player actor
|
||||
/// from hitting into the wall and gets blocked.
|
||||
/// This process is purely for improving the gameplay experience.
|
||||
/// </summary>
|
||||
/// <param name="inputDirection">User input direction in game space</param>
|
||||
/// <param name="movementMode">Player actor movement mode</param>
|
||||
/// <returns>MovementResult</returns>
|
||||
private MovementResult PlayerActorMoveTowards(Vector3 inputDirection, MovementMode movementMode)
|
||||
{
|
||||
Vector3 playerActorPosition = _playerActorGameObject.transform.position;
|
||||
MovementResult result = _playerActorMovementController.MoveTowards(
|
||||
playerActorPosition + inputDirection, movementMode);
|
||||
|
||||
if (result != MovementResult.Blocked) return result;
|
||||
|
||||
if (_playerActorMovementController.IsDuringCollision()) return result;
|
||||
|
||||
// Don't adjust direction if player actor is inside jumpable area
|
||||
if (IsPlayerActorInsideJumpableArea()) return result;
|
||||
|
||||
// Try change direction a little bit to see if it works
|
||||
for (var degrees = 2; degrees <= 80; degrees+= 2)
|
||||
{
|
||||
// + degrees
|
||||
{
|
||||
Vector3 newDirection = Quaternion.Euler(0f, degrees, 0f) * inputDirection;
|
||||
result = _playerActorMovementController.MoveTowards(
|
||||
playerActorPosition + newDirection, movementMode);
|
||||
if (result != MovementResult.Blocked) return result;
|
||||
}
|
||||
// - degrees
|
||||
{
|
||||
Vector3 newDirection = Quaternion.Euler(0f, -degrees, 0f) * inputDirection;
|
||||
result = _playerActorMovementController.MoveTowards(
|
||||
playerActorPosition + newDirection, movementMode);
|
||||
if (result != MovementResult.Blocked) return result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetMovementSfxName(ActorActionType movementAction)
|
||||
{
|
||||
if (movementAction is not (ActorActionType.Walk or ActorActionType.Run)) return string.Empty;
|
||||
|
||||
#if PAL3
|
||||
var sfxPrefix = movementAction == ActorActionType.Walk ?
|
||||
AudioConstants.MainActorWalkSfxNamePrefix : AudioConstants.MainActorRunSfxNamePrefix;
|
||||
|
||||
Tilemap tileMap = _sceneManager.GetCurrentScene().GetTilemap();
|
||||
if ((_lastKnownPosition.HasValue && _lastKnownLayerIndex.HasValue) &&
|
||||
tileMap.TryGetTile(_lastKnownPosition.Value, _lastKnownLayerIndex.Value, out NavTile tile))
|
||||
{
|
||||
return tile.FloorKind switch
|
||||
{
|
||||
NavFloorKind.Grass => sfxPrefix + 'b',
|
||||
NavFloorKind.Snow => sfxPrefix + 'c',
|
||||
NavFloorKind.Sand => sfxPrefix + 'd',
|
||||
_ => sfxPrefix + 'a'
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return sfxPrefix + 'a';
|
||||
}
|
||||
#elif PAL3A
|
||||
if (movementAction == ActorActionType.Walk)
|
||||
{
|
||||
return AudioConstants.MainActorWalkSfxName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _playerActor.Info.Id == (byte)PlayerActorId.WangPengXu ?
|
||||
AudioConstants.WangPengXuFlySfxName : AudioConstants.MainActorRunSfxName;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void UpdatePlayerActorMovementSfx(string playerActorAction)
|
||||
{
|
||||
var newMovementSfxAudioFileName = string.Empty;
|
||||
ActorActionType actionType = ActorActionType.Walk;
|
||||
|
||||
if (string.Equals(playerActorAction, ActorConstants.ActionToNameMap[ActorActionType.Walk]))
|
||||
{
|
||||
newMovementSfxAudioFileName = GetMovementSfxName(ActorActionType.Walk);
|
||||
actionType = ActorActionType.Walk;
|
||||
}
|
||||
else if (string.Equals(playerActorAction, ActorConstants.ActionToNameMap[ActorActionType.Run]))
|
||||
{
|
||||
newMovementSfxAudioFileName = GetMovementSfxName(ActorActionType.Run);
|
||||
actionType = ActorActionType.Run;
|
||||
}
|
||||
|
||||
if (string.Equals(_currentMovementSfxAudioName, newMovementSfxAudioFileName)) return;
|
||||
|
||||
_currentMovementSfxAudioName = newMovementSfxAudioFileName;
|
||||
|
||||
if (string.IsNullOrEmpty(_currentMovementSfxAudioName))
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new StopSfxPlayingAtGameObjectRequest(_playerActorGameObject,
|
||||
AudioConstants.PlayerActorMovementSfxAudioSourceName,
|
||||
disposeSource: false));
|
||||
}
|
||||
else
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new AttachSfxToGameObjectRequest(_playerActorGameObject,
|
||||
newMovementSfxAudioFileName,
|
||||
AudioConstants.PlayerActorMovementSfxAudioSourceName,
|
||||
loopCount: -1,
|
||||
actionType == ActorActionType.Walk
|
||||
? PLAYER_ACTOR_MOVEMENT_SFX_WALK_VOLUME
|
||||
: PLAYER_ACTOR_MOVEMENT_SFX_RUN_VOLUME,
|
||||
startDelayInSeconds: 0f,
|
||||
interval: 0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1f00335891b5c64e8664b2686da4f09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,485 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.GamePlay
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Actor;
|
||||
using Actor.Controllers;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.DataReader.Scn;
|
||||
using Core.Utils;
|
||||
using Data;
|
||||
using GameSystem;
|
||||
using Input;
|
||||
using MetaData;
|
||||
using Scene;
|
||||
using Scene.SceneObjects;
|
||||
using State;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public partial class PlayerGamePlayManager : IDisposable,
|
||||
ICommandExecutor<ActorEnablePlayerControlCommand>,
|
||||
ICommandExecutor<ActorSetTilePositionCommand>,
|
||||
ICommandExecutor<PlayerEnableInputCommand>,
|
||||
#if PAL3
|
||||
ICommandExecutor<LongKuiSwitchModeCommand>,
|
||||
#endif
|
||||
ICommandExecutor<SceneLeavingCurrentSceneNotification>,
|
||||
ICommandExecutor<ScenePostLoadingNotification>,
|
||||
ICommandExecutor<PlayerActorLookAtSceneObjectCommand>,
|
||||
ICommandExecutor<ResetGameStateCommand>
|
||||
{
|
||||
private readonly GameResourceProvider _resourceProvider;
|
||||
private readonly GameStateManager _gameStateManager;
|
||||
private readonly PlayerActorManager _playerActorManager;
|
||||
private readonly TeamManager _teamManager;
|
||||
private readonly PlayerInputActions _inputActions;
|
||||
private readonly SceneManager _sceneManager;
|
||||
private readonly Camera _camera;
|
||||
|
||||
private string _currentMovementSfxAudioName = string.Empty;
|
||||
|
||||
private Vector2? _lastInputTapPosition;
|
||||
private Vector3? _lastKnownPosition;
|
||||
private Vector2Int? _lastKnownTilePosition;
|
||||
private int? _lastKnownLayerIndex;
|
||||
private bool _isTilePositionPendingNotify;
|
||||
|
||||
private string _lastKnownPlayerActorAction = string.Empty;
|
||||
|
||||
#if PAL3
|
||||
private int _longKuiLastKnownMode = 0;
|
||||
#endif
|
||||
|
||||
private Actor _playerActor;
|
||||
private GameObject _playerActorGameObject;
|
||||
private ActorController _playerActorController;
|
||||
private ActorActionController _playerActorActionController;
|
||||
private ActorMovementController _playerActorMovementController;
|
||||
|
||||
private const int LAST_KNOWN_SCENE_STATE_LIST_MAX_LENGTH = 2;
|
||||
private readonly List<(ScnSceneInfo sceneInfo,
|
||||
int actorNavIndex,
|
||||
Vector2Int actorTilePosition,
|
||||
Vector3 actorFacing)> _playerActorLastKnownSceneState = new ();
|
||||
|
||||
public PlayerGamePlayManager(GameResourceProvider resourceProvider,
|
||||
GameStateManager gameStateManager,
|
||||
PlayerActorManager playerActorManager,
|
||||
TeamManager teamManager,
|
||||
PlayerInputActions inputActions,
|
||||
SceneManager sceneManager,
|
||||
Camera mainCamera)
|
||||
{
|
||||
_resourceProvider = Requires.IsNotNull(resourceProvider, nameof(resourceProvider));
|
||||
_gameStateManager = Requires.IsNotNull(gameStateManager, nameof(gameStateManager));
|
||||
_playerActorManager = Requires.IsNotNull(playerActorManager, nameof(playerActorManager));
|
||||
_teamManager = Requires.IsNotNull(teamManager, nameof(teamManager));
|
||||
_inputActions = Requires.IsNotNull(inputActions, nameof(inputActions));
|
||||
_sceneManager = Requires.IsNotNull(sceneManager, nameof(sceneManager));
|
||||
_camera = Requires.IsNotNull(mainCamera, nameof(mainCamera));
|
||||
|
||||
_inputActions.Gameplay.OnTap.performed += OnTapPerformed;
|
||||
_inputActions.Gameplay.OnMove.performed += OnMovePerformed;
|
||||
_inputActions.Gameplay.OnDoubleTap.performed += OnDoubleTapPerformed;
|
||||
_inputActions.Gameplay.PortalTo.performed += PortalToPerformed;
|
||||
_inputActions.Gameplay.Interact.performed += InteractionPerformed;
|
||||
_inputActions.Gameplay.Movement.canceled += MovementCanceled;
|
||||
_inputActions.Gameplay.SwitchToPreviousPlayerActor.performed += SwitchToPreviousPlayerActorPerformed;
|
||||
_inputActions.Gameplay.SwitchToNextPlayerActor.performed += SwitchToNextPlayerActorPerformed;
|
||||
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_inputActions.Gameplay.OnTap.performed -= OnTapPerformed;
|
||||
_inputActions.Gameplay.OnMove.performed -= OnMovePerformed;
|
||||
_inputActions.Gameplay.OnDoubleTap.performed -= OnDoubleTapPerformed;
|
||||
_inputActions.Gameplay.PortalTo.performed -= PortalToPerformed;
|
||||
_inputActions.Gameplay.Interact.performed -= InteractionPerformed;
|
||||
_inputActions.Gameplay.Movement.canceled -= MovementCanceled;
|
||||
_inputActions.Gameplay.SwitchToPreviousPlayerActor.performed -= SwitchToPreviousPlayerActorPerformed;
|
||||
_inputActions.Gameplay.SwitchToNextPlayerActor.performed -= SwitchToNextPlayerActorPerformed;
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
if (_playerActorGameObject == null) return;
|
||||
|
||||
var isPlayerInControl = false;
|
||||
|
||||
if (_gameStateManager.GetCurrentState() == GameState.Gameplay &&
|
||||
_playerActorManager.IsPlayerInputEnabled() &&
|
||||
_playerActorManager.IsPlayerActorControlEnabled())
|
||||
{
|
||||
isPlayerInControl = true;
|
||||
ReadInputAndMovePlayerIfNeeded();
|
||||
}
|
||||
|
||||
var shouldUpdatePlayerActorMovementSfx = false;
|
||||
|
||||
Vector3 position = _playerActorGameObject.transform.position;
|
||||
var layerIndex = _playerActorMovementController.GetCurrentLayerIndex();
|
||||
|
||||
if (!(position == _lastKnownPosition && layerIndex == _lastKnownLayerIndex))
|
||||
{
|
||||
_lastKnownPosition = position;
|
||||
Vector2Int tilePosition = _playerActorMovementController.GetTilePosition();
|
||||
if (!(tilePosition == _lastKnownTilePosition && layerIndex == _lastKnownLayerIndex))
|
||||
{
|
||||
shouldUpdatePlayerActorMovementSfx = true;
|
||||
_lastKnownTilePosition = tilePosition;
|
||||
PlayerActorTilePositionChanged(layerIndex, tilePosition, !isPlayerInControl);
|
||||
}
|
||||
else if (_isTilePositionPendingNotify)
|
||||
{
|
||||
PlayerActorTilePositionChanged(layerIndex, tilePosition, !isPlayerInControl);
|
||||
_isTilePositionPendingNotify = false;
|
||||
}
|
||||
}
|
||||
|
||||
_lastKnownLayerIndex = layerIndex;
|
||||
|
||||
var currentAction = _playerActorActionController.GetCurrentAction();
|
||||
if (currentAction != _lastKnownPlayerActorAction)
|
||||
{
|
||||
_lastKnownPlayerActorAction = currentAction;
|
||||
shouldUpdatePlayerActorMovementSfx = true;
|
||||
}
|
||||
|
||||
if (shouldUpdatePlayerActorMovementSfx)
|
||||
{
|
||||
UpdatePlayerActorMovementSfx(_lastKnownPlayerActorAction);
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayerActorTilePositionChanged(int layerIndex, Vector2Int tilePosition, bool movedByScript)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new PlayerActorTilePositionUpdatedNotification(tilePosition, layerIndex, movedByScript));
|
||||
}
|
||||
|
||||
public bool TryGetPlayerActorLastKnownPosition(out Vector3 position)
|
||||
{
|
||||
if (_lastKnownPosition.HasValue)
|
||||
{
|
||||
position = _lastKnownPosition.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
position = Vector3.zero;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void MovementCanceled(InputAction.CallbackContext _)
|
||||
{
|
||||
_playerActorActionController.PerformAction(ActorActionType.Stand);
|
||||
}
|
||||
|
||||
private void OnTapPerformed(InputAction.CallbackContext _)
|
||||
{
|
||||
if (!_playerActorManager.IsPlayerActorControlEnabled() ||
|
||||
!_playerActorManager.IsPlayerInputEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTapPosition(false);
|
||||
}
|
||||
|
||||
private void OnDoubleTapPerformed(InputAction.CallbackContext _)
|
||||
{
|
||||
if (!_playerActorManager.IsPlayerActorControlEnabled() ||
|
||||
!_playerActorManager.IsPlayerInputEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTapPosition(true);
|
||||
}
|
||||
|
||||
private void PortalToPerformed(InputAction.CallbackContext _)
|
||||
{
|
||||
if (!_playerActorManager.IsPlayerActorControlEnabled() ||
|
||||
!_playerActorManager.IsPlayerInputEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Keyboard.current.leftCtrlKey.isPressed)
|
||||
{
|
||||
PortalToTapPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsPlayerActorInsideJumpableArea())
|
||||
{
|
||||
JumpToTapPosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMovePerformed(InputAction.CallbackContext ctx)
|
||||
{
|
||||
if (!_playerActorManager.IsPlayerActorControlEnabled() ||
|
||||
!_playerActorManager.IsPlayerInputEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lastInputTapPosition = ctx.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
public void Execute(PlayerActorLookAtSceneObjectCommand command)
|
||||
{
|
||||
Transform actorTransform = _playerActorGameObject.transform;
|
||||
SceneObject sceneObject = _sceneManager.GetCurrentScene().GetSceneObject(command.SceneObjectId);
|
||||
|
||||
if (sceneObject?.GetGameObject() is { } sceneObjectGameObject)
|
||||
{
|
||||
Vector3 objectPosition = sceneObjectGameObject.transform.position;
|
||||
|
||||
actorTransform.LookAt(new Vector3(
|
||||
objectPosition.x,
|
||||
actorTransform.position.y,
|
||||
objectPosition.z));
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ActorEnablePlayerControlCommand command)
|
||||
{
|
||||
if (command.ActorId == ActorConstants.PlayerActorVirtualID) return;
|
||||
|
||||
// Check if actor is player actor.
|
||||
if (!Enum.IsDefined(typeof(PlayerActorId), command.ActorId))
|
||||
{
|
||||
Debug.LogError($"[{nameof(PlayerGamePlayManager)}] Cannot enable player control for actor " +
|
||||
$"{command.ActorId} since actor is not a player actor.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop & dispose current player actor movement sfx
|
||||
if (_playerActorGameObject != null)
|
||||
{
|
||||
_currentMovementSfxAudioName = string.Empty;
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new StopSfxPlayingAtGameObjectRequest(_playerActorGameObject,
|
||||
AudioConstants.PlayerActorMovementSfxAudioSourceName,
|
||||
disposeSource: true));
|
||||
}
|
||||
|
||||
// Reset & dispose current player actor's jump indicators
|
||||
int jumpableAreaEnterCount = _jumpableAreaEnterCount;
|
||||
ResetAndDisposeJumpIndicators();
|
||||
|
||||
Vector3? lastActivePlayerActorPosition = null;
|
||||
Quaternion? lastActivePlayerActorRotation = null;
|
||||
int? lastActivePlayerActorNavLayerIndex = null;
|
||||
|
||||
// Deactivate current player actor
|
||||
if (_playerActorGameObject != null &&
|
||||
_playerActor.Info.Id != command.ActorId &&
|
||||
_playerActorController != null &&
|
||||
_playerActorController.IsActive)
|
||||
{
|
||||
lastActivePlayerActorNavLayerIndex = _playerActorMovementController.GetCurrentLayerIndex();
|
||||
_playerActorGameObject.transform.GetPositionAndRotation(out Vector3 currentPosition, out Quaternion currentRotation);
|
||||
lastActivePlayerActorPosition = currentPosition;
|
||||
lastActivePlayerActorRotation = currentRotation;
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ActorActivateCommand(_playerActor.Info.Id, 0));
|
||||
}
|
||||
|
||||
// Set target actor as player actor
|
||||
_playerActor = _sceneManager.GetCurrentScene().GetActor(command.ActorId);
|
||||
_playerActorGameObject = _sceneManager.GetCurrentScene().GetActorGameObject(command.ActorId);
|
||||
_playerActorController = _playerActorGameObject.GetComponent<ActorController>();
|
||||
_playerActorActionController = _playerActorGameObject.GetComponent<ActorActionController>();
|
||||
_playerActorMovementController = _playerActorGameObject.GetComponent<ActorMovementController>();
|
||||
|
||||
#if PAL3
|
||||
// LongKui should stay blue form when player control is enabled
|
||||
if (command.ActorId == (int)PlayerActorId.LongKui)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new LongKuiSwitchModeCommand(0));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Just to make sure the new actor is activated
|
||||
if (!_playerActorController.IsActive)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ActorActivateCommand(_playerActor.Info.Id, 1));
|
||||
|
||||
// Inherent nav layer index
|
||||
if (lastActivePlayerActorNavLayerIndex.HasValue)
|
||||
{
|
||||
_playerActorMovementController.SetNavLayer(lastActivePlayerActorNavLayerIndex.Value);
|
||||
}
|
||||
// Inherent position
|
||||
if (lastActivePlayerActorPosition.HasValue)
|
||||
{
|
||||
_playerActorGameObject.transform.position = lastActivePlayerActorPosition.Value;
|
||||
}
|
||||
// Inherent rotation
|
||||
if (lastActivePlayerActorRotation.HasValue)
|
||||
{
|
||||
_playerActorGameObject.transform.rotation = lastActivePlayerActorRotation.Value;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset states
|
||||
_lastKnownPosition = null;
|
||||
_lastKnownTilePosition = null;
|
||||
_lastKnownPlayerActorAction = string.Empty;
|
||||
|
||||
// Inherent jumpable state
|
||||
if (jumpableAreaEnterCount > 0)
|
||||
{
|
||||
PlayerActorEnteredJumpableArea();
|
||||
// Inherent jumpable area enter count
|
||||
_jumpableAreaEnterCount = jumpableAreaEnterCount;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(PlayerEnableInputCommand command)
|
||||
{
|
||||
if (command.Enable == 0)
|
||||
{
|
||||
if (_playerActorMovementController != null)
|
||||
{
|
||||
_playerActorMovementController.CancelMovement();
|
||||
}
|
||||
|
||||
if (_playerActorActionController != null &&
|
||||
!string.IsNullOrEmpty(_playerActorActionController.GetCurrentAction()) &&
|
||||
!string.Equals(ActorConstants.ActionToNameMap[ActorActionType.Stand],
|
||||
_playerActorActionController.GetCurrentAction(),
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_playerActorActionController.PerformAction(ActorActionType.Stand);
|
||||
}
|
||||
|
||||
_lastKnownPosition = null;
|
||||
_lastKnownTilePosition = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ActorSetTilePositionCommand command)
|
||||
{
|
||||
if (command.ActorId == ActorConstants.PlayerActorVirtualID ||
|
||||
(_playerActor != null && _playerActor.Info.Id == command.ActorId))
|
||||
{
|
||||
_isTilePositionPendingNotify = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(SceneLeavingCurrentSceneNotification command)
|
||||
{
|
||||
if (_sceneManager.GetCurrentScene() is not { } currentScene) return;
|
||||
|
||||
// Stop current player actor movement sfx
|
||||
if (_playerActorGameObject != null)
|
||||
{
|
||||
_currentMovementSfxAudioName = string.Empty;
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new StopSfxPlayingAtGameObjectRequest(_playerActorGameObject,
|
||||
AudioConstants.PlayerActorMovementSfxAudioSourceName,
|
||||
disposeSource: true));
|
||||
}
|
||||
|
||||
// Remove game play indicators
|
||||
ResetAndDisposeJumpIndicators();
|
||||
|
||||
_playerActorLastKnownSceneState.Add((
|
||||
currentScene.GetSceneInfo(),
|
||||
_playerActorMovementController.GetCurrentLayerIndex(),
|
||||
_playerActorMovementController.GetTilePosition(),
|
||||
_playerActorGameObject.transform.forward));
|
||||
|
||||
if (_playerActorLastKnownSceneState.Count > LAST_KNOWN_SCENE_STATE_LIST_MAX_LENGTH)
|
||||
{
|
||||
_playerActorLastKnownSceneState.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ScenePostLoadingNotification notification)
|
||||
{
|
||||
var playerActorId = (int)_playerActorManager.GetPlayerActor();
|
||||
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ActorActivateCommand(playerActorId, 1));
|
||||
|
||||
if (_playerActorLastKnownSceneState.Count > 0 && _playerActorLastKnownSceneState.Any(_ =>
|
||||
_.sceneInfo.ModelEquals(notification.NewSceneInfo)))
|
||||
{
|
||||
(ScnSceneInfo _, int actorNavIndex, Vector2Int actorTilePosition, Vector3 actorFacing) =
|
||||
_playerActorLastKnownSceneState.Last(_ => _.sceneInfo.ModelEquals(notification.NewSceneInfo));
|
||||
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorSetNavLayerCommand(playerActorId, actorNavIndex));
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorSetTilePositionCommand(playerActorId, actorTilePosition.x, actorTilePosition.y));
|
||||
|
||||
_sceneManager.GetCurrentScene()
|
||||
.GetActorGameObject(playerActorId).transform.forward = actorFacing;
|
||||
}
|
||||
|
||||
if (_playerActorManager.IsPlayerActorControlEnabled())
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ActorEnablePlayerControlCommand(playerActorId));
|
||||
}
|
||||
|
||||
if (_playerActorManager.IsPlayerInputEnabled())
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new PlayerEnableInputCommand(1));
|
||||
}
|
||||
|
||||
#if PAL3
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new LongKuiSwitchModeCommand(_longKuiLastKnownMode));
|
||||
#endif
|
||||
|
||||
_isTilePositionPendingNotify = true;
|
||||
}
|
||||
|
||||
public void Execute(ResetGameStateCommand command)
|
||||
{
|
||||
ResetAndDisposeJumpIndicators();
|
||||
|
||||
_playerActorLastKnownSceneState.Clear();
|
||||
|
||||
_currentMovementSfxAudioName = string.Empty;
|
||||
|
||||
_lastInputTapPosition = null;
|
||||
_lastKnownPosition = null;
|
||||
_lastKnownTilePosition = null;
|
||||
_lastKnownLayerIndex = null;
|
||||
_lastKnownPlayerActorAction = string.Empty;
|
||||
_isTilePositionPendingNotify = false;
|
||||
|
||||
#if PAL3
|
||||
_longKuiLastKnownMode = 0;
|
||||
#endif
|
||||
|
||||
_playerActor = null;
|
||||
_playerActorGameObject = null;
|
||||
_playerActorController = null;
|
||||
_playerActorActionController = null;
|
||||
_playerActorMovementController = null;
|
||||
}
|
||||
|
||||
#if PAL3
|
||||
public void Execute(LongKuiSwitchModeCommand command)
|
||||
{
|
||||
_longKuiLastKnownMode = command.Mode;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -20,7 +20,7 @@ namespace Pal3
|
||||
using Core.Services;
|
||||
using Data;
|
||||
using MetaData;
|
||||
using Renderer;
|
||||
using Rendering.Material;
|
||||
using Settings;
|
||||
using SimpleFileBrowser;
|
||||
using TMPro;
|
||||
@@ -39,7 +39,7 @@ namespace Pal3
|
||||
[SerializeField] private TextMeshProUGUI loadingText;
|
||||
|
||||
// Optional materials that are used in the game but not open sourced
|
||||
private Material _toonDefaultMaterial;
|
||||
private Material _toonOpaqueMaterial;
|
||||
private Material _toonTransparentMaterial;
|
||||
|
||||
private IEnumerator Start()
|
||||
@@ -47,12 +47,12 @@ namespace Pal3
|
||||
loadingText.text = "正在加载游戏数据...";
|
||||
yield return null; // Wait for next frame to make sure the text is updated
|
||||
|
||||
ResourceRequest toonDefaultMaterialLoadRequest = Resources.LoadAsync<Material>("Materials/ToonDefault");
|
||||
yield return toonDefaultMaterialLoadRequest;
|
||||
ResourceRequest toonOpaqueMaterialLoadRequest = Resources.LoadAsync<Material>("Materials/ToonDefault");
|
||||
yield return toonOpaqueMaterialLoadRequest;
|
||||
|
||||
if (toonDefaultMaterialLoadRequest.asset != null)
|
||||
if (toonOpaqueMaterialLoadRequest.asset != null)
|
||||
{
|
||||
_toonDefaultMaterial = toonDefaultMaterialLoadRequest.asset as Material;
|
||||
_toonOpaqueMaterial = toonOpaqueMaterialLoadRequest.asset as Material;
|
||||
}
|
||||
|
||||
ResourceRequest toonTransparentMaterialLoadRequest = Resources.LoadAsync<Material>("Materials/ToonTransparent");
|
||||
@@ -76,7 +76,7 @@ namespace Pal3
|
||||
ServiceLocator.Instance.Register<Crc32Hash>(crcHash);
|
||||
|
||||
// If toon materials are not present, it's an open source build
|
||||
bool isOpenSourceVersion = _toonDefaultMaterial == null || _toonTransparentMaterial == null;
|
||||
bool isOpenSourceVersion = _toonOpaqueMaterial == null || _toonTransparentMaterial == null;
|
||||
|
||||
// Init settings store
|
||||
ITransactionalKeyValueStore settingsStore = new PlayerPrefsStore();
|
||||
@@ -165,18 +165,31 @@ namespace Pal3
|
||||
}
|
||||
}
|
||||
|
||||
loadingText.text = "正在初始化游戏资源...";
|
||||
yield return null; // Wait for next frame to make sure the text is updated
|
||||
|
||||
// Init TextureLoaderFactory
|
||||
TextureLoaderFactory textureLoaderFactory = new ();
|
||||
ServiceLocator.Instance.Register<ITextureLoaderFactory>(textureLoaderFactory);
|
||||
|
||||
// Init material factories
|
||||
IMaterialFactory unlitMaterialFactory = new UnlitMaterialFactory();
|
||||
IMaterialFactory litMaterialFactory = null;
|
||||
|
||||
IMaterialFactory litMaterialFactory = null;
|
||||
// Only create litMaterialFactory when toon materials are present
|
||||
if (_toonDefaultMaterial != null && _toonTransparentMaterial != null)
|
||||
if (_toonOpaqueMaterial != null && _toonTransparentMaterial != null)
|
||||
{
|
||||
litMaterialFactory = new LitMaterialFactory(_toonDefaultMaterial, _toonTransparentMaterial);
|
||||
litMaterialFactory = new LitMaterialFactory(_toonOpaqueMaterial, _toonTransparentMaterial);
|
||||
}
|
||||
|
||||
// Pre-allocate material pool, since it is very costly to create new materials at runtime
|
||||
if (!isOpenSourceVersion && gameSettings.IsRealtimeLightingAndShadowsEnabled && litMaterialFactory != null)
|
||||
{
|
||||
litMaterialFactory.AllocateMaterialPool();
|
||||
}
|
||||
else
|
||||
{
|
||||
unlitMaterialFactory.AllocateMaterialPool();
|
||||
}
|
||||
|
||||
// Init Game resource provider
|
||||
@@ -189,6 +202,9 @@ namespace Pal3
|
||||
|
||||
Debug.Log($"[{nameof(GameResourceInitializer)}] Game resources initialized.");
|
||||
|
||||
loadingText.text = "正在启动游戏...";
|
||||
yield return null; // Wait for next frame to make sure the text is updated
|
||||
|
||||
// Instantiate starting component
|
||||
GameObject startingGameObject = Instantiate(startingComponent, null);
|
||||
startingGameObject.name = startingComponent.name;
|
||||
|
||||
@@ -26,24 +26,24 @@ namespace Pal3.GameSystem
|
||||
using UnityEngine.InputSystem.DualShock;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public sealed class BigMapManager : MonoBehaviour,
|
||||
public sealed class BigMapManager : IDisposable,
|
||||
ICommandExecutor<BigMapEnableRegionCommand>,
|
||||
ICommandExecutor<ResetGameStateCommand>,
|
||||
ICommandExecutor<GameSwitchRenderingStateCommand>,
|
||||
ICommandExecutor<GameSwitchToMainMenuCommand>,
|
||||
ICommandExecutor<ToggleBigMapRequest>
|
||||
{
|
||||
private EventSystem _eventSystem;
|
||||
private GameStateManager _gameStateManager;
|
||||
private InputManager _inputManager;
|
||||
private PlayerInputActions _playerInputActions;
|
||||
private ScriptManager _scriptManager;
|
||||
private SceneManager _sceneManager;
|
||||
private CanvasGroup _bigMapCanvas;
|
||||
private GridLayoutGroup _bigMapCanvasGridLayoutGroup;
|
||||
private GameObject _bigMapRegionButtonPrefab;
|
||||
private RectTransform _bigMapBackgroundTransform;
|
||||
private CanvasGroup _bigMapBackgroundCanvasGroup;
|
||||
private readonly EventSystem _eventSystem;
|
||||
private readonly GameStateManager _gameStateManager;
|
||||
private readonly InputManager _inputManager;
|
||||
private readonly PlayerInputActions _playerInputActions;
|
||||
private readonly ScriptManager _scriptManager;
|
||||
private readonly SceneManager _sceneManager;
|
||||
private readonly CanvasGroup _bigMapCanvas;
|
||||
private readonly GridLayoutGroup _bigMapCanvasGridLayoutGroup;
|
||||
private readonly GameObject _bigMapRegionButtonPrefab;
|
||||
private readonly RectTransform _bigMapBackgroundTransform;
|
||||
private readonly CanvasGroup _bigMapBackgroundCanvasGroup;
|
||||
|
||||
private bool _isVisible;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Pal3.GameSystem
|
||||
private readonly List<GameObject> _selectionButtons = new();
|
||||
private readonly Dictionary<int, int> _regionEnablementInfo = new ();
|
||||
|
||||
public void Init(EventSystem eventSystem,
|
||||
public BigMapManager(EventSystem eventSystem,
|
||||
GameStateManager gameStateManager,
|
||||
SceneManager sceneManager,
|
||||
InputManager inputManager,
|
||||
@@ -82,21 +82,18 @@ namespace Pal3.GameSystem
|
||||
_isVisible = false;
|
||||
|
||||
_playerInputActions.Gameplay.ToggleBigMap.performed += ToggleBigMapOnPerformed;
|
||||
_playerInputActions.Cutscene.ToggleBigMap.performed += ToggleBigMapOnPerformed;
|
||||
_playerInputActions.Cutscene.ExitCurrentShowingMenu.performed += HideBigMapOnPerformed;
|
||||
}
|
||||
_playerInputActions.UI.ToggleBigMap.performed += ToggleBigMapOnPerformed;
|
||||
_playerInputActions.UI.ExitCurrentShowingMenu.performed += HideBigMapOnPerformed;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
_playerInputActions.Gameplay.ToggleBigMap.performed -= ToggleBigMapOnPerformed;
|
||||
_playerInputActions.Cutscene.ToggleBigMap.performed -= ToggleBigMapOnPerformed;
|
||||
_playerInputActions.Cutscene.ExitCurrentShowingMenu.performed -= HideBigMapOnPerformed;
|
||||
_playerInputActions.UI.ToggleBigMap.performed -= ToggleBigMapOnPerformed;
|
||||
_playerInputActions.UI.ExitCurrentShowingMenu.performed -= HideBigMapOnPerformed;
|
||||
}
|
||||
|
||||
private void ToggleBigMapOnPerformed(InputAction.CallbackContext _)
|
||||
@@ -109,7 +106,7 @@ namespace Pal3.GameSystem
|
||||
if (_isVisible)
|
||||
{
|
||||
Hide();
|
||||
_gameStateManager.GoToState(GameState.Gameplay);
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +127,7 @@ namespace Pal3.GameSystem
|
||||
if (_isVisible)
|
||||
{
|
||||
Hide();
|
||||
_gameStateManager.GoToState(GameState.Gameplay);
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
}
|
||||
else if (_gameStateManager.GetCurrentState() == GameState.Gameplay)
|
||||
{
|
||||
@@ -142,7 +139,7 @@ namespace Pal3.GameSystem
|
||||
}
|
||||
}
|
||||
|
||||
public void Show()
|
||||
private void Show()
|
||||
{
|
||||
if (_regionEnablementInfo.Count == 0)
|
||||
{
|
||||
@@ -150,7 +147,7 @@ namespace Pal3.GameSystem
|
||||
return;
|
||||
}
|
||||
|
||||
_gameStateManager.GoToState(GameState.Cutscene);
|
||||
_gameStateManager.TryGoToState(GameState.UI);
|
||||
// Scene script can execute GameSwitchRenderingStateCommand to toggle BigMap
|
||||
// After the script finishes, the state will be reset to Gameplay. Thus we need to
|
||||
// block the state change.
|
||||
@@ -159,7 +156,8 @@ namespace Pal3.GameSystem
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorStopActionAndStandCommand(ActorConstants.PlayerActorVirtualID));
|
||||
|
||||
GameObject exitButtonObj = Instantiate(_bigMapRegionButtonPrefab, _bigMapCanvas.transform);
|
||||
GameObject exitButtonObj = UnityEngine.Object.Instantiate(_bigMapRegionButtonPrefab,
|
||||
_bigMapCanvas.transform);
|
||||
var exitButtonTextUI = exitButtonObj.GetComponentInChildren<TextMeshProUGUI>();
|
||||
exitButtonTextUI.text = "关闭";
|
||||
var exitButton = exitButtonObj.GetComponent<Button>();
|
||||
@@ -170,7 +168,8 @@ namespace Pal3.GameSystem
|
||||
for (var i = 0; i < BigMapConstants.BigMapRegions.Length; i++)
|
||||
{
|
||||
if (!_regionEnablementInfo.ContainsKey(i) || _regionEnablementInfo[i] != 2) continue;
|
||||
GameObject selectionButton = Instantiate(_bigMapRegionButtonPrefab, _bigMapCanvas.transform);
|
||||
GameObject selectionButton = UnityEngine.Object.Instantiate(_bigMapRegionButtonPrefab,
|
||||
_bigMapCanvas.transform);
|
||||
var buttonTextUI = selectionButton.GetComponentInChildren<TextMeshProUGUI>();
|
||||
buttonTextUI.text = BigMapConstants.BigMapRegions[i];
|
||||
var buttonIndex = i;
|
||||
@@ -240,10 +239,10 @@ namespace Pal3.GameSystem
|
||||
_scriptManager.AddScript((uint)(100 + buttonIndex), true);
|
||||
}
|
||||
Hide();
|
||||
_gameStateManager.GoToState(GameState.Gameplay);
|
||||
_gameStateManager.TryGoToState(GameState.Gameplay);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
private void Hide()
|
||||
{
|
||||
_bigMapCanvas.alpha = 0f;
|
||||
_bigMapCanvas.interactable = false;
|
||||
@@ -253,7 +252,7 @@ namespace Pal3.GameSystem
|
||||
foreach (GameObject button in _selectionButtons)
|
||||
{
|
||||
button.GetComponent<Button>().onClick.RemoveAllListeners();
|
||||
Destroy(button);
|
||||
UnityEngine.Object.Destroy(button);
|
||||
}
|
||||
_selectionButtons.Clear();
|
||||
_gameStateManager.RemoveGamePlayStateLocker(_stateLockerGuid);
|
||||
@@ -271,7 +270,7 @@ namespace Pal3.GameSystem
|
||||
|
||||
public void Execute(GameSwitchRenderingStateCommand command)
|
||||
{
|
||||
if (command.State == 13)
|
||||
if ((RenderingState)command.State == RenderingState.BigMap)
|
||||
{
|
||||
Show();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Pal3.GameSystem
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public sealed class CaptionRenderer : MonoBehaviour,
|
||||
public sealed class CaptionRenderer : IDisposable,
|
||||
#if PAL3A
|
||||
ICommandExecutor<UIDisplayNextCaptionCommand>,
|
||||
#endif
|
||||
@@ -27,14 +27,14 @@ namespace Pal3.GameSystem
|
||||
{
|
||||
private const float CAPTION_ANIMATION_DURATION = 10f;
|
||||
|
||||
private GameResourceProvider _gameResourceProvider;
|
||||
private PlayerInputActions _playerInputActions;
|
||||
private Image _captionImage;
|
||||
private readonly GameResourceProvider _gameResourceProvider;
|
||||
private readonly PlayerInputActions _playerInputActions;
|
||||
private readonly Image _captionImage;
|
||||
|
||||
private WaitUntilCanceled _skipCaptionWaiter;
|
||||
private bool _skipCaptionRequested;
|
||||
|
||||
public void Init(GameResourceProvider gameResourceProvider,
|
||||
public CaptionRenderer(GameResourceProvider gameResourceProvider,
|
||||
PlayerInputActions playerInputActions,
|
||||
Image captionImage)
|
||||
{
|
||||
@@ -44,14 +44,11 @@ namespace Pal3.GameSystem
|
||||
|
||||
_captionImage.preserveAspect = true;
|
||||
_playerInputActions.Cutscene.Continue.performed += CutsceneContinueOnPerformed;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
_playerInputActions.Cutscene.Continue.performed -= CutsceneContinueOnPerformed;
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
@@ -65,7 +62,8 @@ namespace Pal3.GameSystem
|
||||
private IEnumerator AnimateCaptionAsync(string textureName)
|
||||
{
|
||||
_skipCaptionWaiter = new WaitUntilCanceled();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(_skipCaptionWaiter));
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ScriptRunnerAddWaiterRequest(_skipCaptionWaiter));
|
||||
|
||||
Texture2D texture = _gameResourceProvider.GetCaptionTexture(textureName);
|
||||
var sprite = Sprite.Create(texture,
|
||||
@@ -75,8 +73,8 @@ namespace Pal3.GameSystem
|
||||
_captionImage.sprite = sprite;
|
||||
_captionImage.color = Color.clear;
|
||||
|
||||
yield return CoreAnimation.EnumerateValueAsync(0, 1, CAPTION_ANIMATION_DURATION, AnimationCurveType.Linear,
|
||||
alpha =>
|
||||
yield return CoreAnimation.EnumerateValueAsync(0, 1, CAPTION_ANIMATION_DURATION,
|
||||
AnimationCurveType.Linear, alpha =>
|
||||
{
|
||||
_captionImage.color = new Color(1f, 1f, 1f, alpha);
|
||||
});
|
||||
@@ -85,8 +83,8 @@ namespace Pal3.GameSystem
|
||||
yield return new WaitUntil(() => _skipCaptionRequested);
|
||||
|
||||
_captionImage.color = Color.clear;
|
||||
Destroy(texture);
|
||||
Destroy(sprite);
|
||||
UnityEngine.Object.Destroy(texture);
|
||||
UnityEngine.Object.Destroy(sprite);
|
||||
|
||||
_skipCaptionWaiter.CancelWait();
|
||||
_skipCaptionWaiter = null;
|
||||
@@ -94,13 +92,13 @@ namespace Pal3.GameSystem
|
||||
|
||||
public void Execute(UIDisplayCaptionCommand command)
|
||||
{
|
||||
StartCoroutine(AnimateCaptionAsync(command.TextureName));
|
||||
Pal3.Instance.StartCoroutine(AnimateCaptionAsync(command.TextureName));
|
||||
}
|
||||
|
||||
#if PAL3A
|
||||
public void Execute(UIDisplayNextCaptionCommand command)
|
||||
{
|
||||
StartCoroutine(AnimateCaptionAsync(command.TextureName));
|
||||
Pal3.Instance.StartCoroutine(AnimateCaptionAsync(command.TextureName));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Pal3.GameSystem
|
||||
using UnityEngine.UI;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
public sealed class DialogueManager : MonoBehaviour,
|
||||
public sealed class DialogueManager : IDisposable,
|
||||
ICommandExecutor<DialogueRenderActorAvatarCommand>,
|
||||
ICommandExecutor<DialogueRenderTextCommand>,
|
||||
ICommandExecutor<DialogueAddSelectionsCommand>,
|
||||
@@ -45,24 +45,24 @@ namespace Pal3.GameSystem
|
||||
|
||||
private const string INFORMATION_TEXT_COLOR_HEX = "#ffff05";
|
||||
|
||||
private GameResourceProvider _resourceProvider;
|
||||
private GameStateManager _gameStateManager;
|
||||
private SceneManager _sceneManager;
|
||||
private InputManager _inputManager;
|
||||
private PlayerInputActions _inputActions;
|
||||
private readonly GameResourceProvider _resourceProvider;
|
||||
private readonly GameStateManager _gameStateManager;
|
||||
private readonly SceneManager _sceneManager;
|
||||
private readonly InputManager _inputManager;
|
||||
private readonly PlayerInputActions _inputActions;
|
||||
|
||||
private EventSystem _eventSystem;
|
||||
private CanvasGroup _dialogueCanvasGroup;
|
||||
private Canvas _dialogueSelectionButtonsCanvas;
|
||||
private GameObject _dialogueSelectionButtonPrefab;
|
||||
private Image _dialogueBackgroundImage;
|
||||
private RoundedFrostedGlassImage _backgroundFrostedGlassImage;
|
||||
private readonly EventSystem _eventSystem;
|
||||
private readonly CanvasGroup _dialogueCanvasGroup;
|
||||
private readonly Canvas _dialogueSelectionButtonsCanvas;
|
||||
private readonly GameObject _dialogueSelectionButtonPrefab;
|
||||
private readonly Image _dialogueBackgroundImage;
|
||||
private readonly RoundedFrostedGlassImage _backgroundFrostedGlassImage;
|
||||
|
||||
private Image _avatarImageLeft;
|
||||
private Image _avatarImageRight;
|
||||
private TextMeshProUGUI _dialogueTextLeft;
|
||||
private TextMeshProUGUI _dialogueTextRight;
|
||||
private TextMeshProUGUI _dialogueTextDefault;
|
||||
private readonly Image _avatarImageLeft;
|
||||
private readonly Image _avatarImageRight;
|
||||
private readonly TextMeshProUGUI _dialogueTextLeft;
|
||||
private readonly TextMeshProUGUI _dialogueTextRight;
|
||||
private readonly TextMeshProUGUI _dialogueTextDefault;
|
||||
|
||||
private Texture2D _avatarTexture;
|
||||
private bool _isDialoguePresenting;
|
||||
@@ -78,7 +78,7 @@ namespace Pal3.GameSystem
|
||||
private DialogueRenderActorAvatarCommand _lastAvatarCommand;
|
||||
private readonly Queue<IEnumerator> _dialogueRenderQueue = new();
|
||||
|
||||
public void Init(GameResourceProvider resourceProvider,
|
||||
public DialogueManager(GameResourceProvider resourceProvider,
|
||||
GameStateManager gameStateManager,
|
||||
SceneManager sceneManager,
|
||||
InputManager inputManager,
|
||||
@@ -121,14 +121,11 @@ namespace Pal3.GameSystem
|
||||
|
||||
_inputActions = inputManager.GetPlayerInputActions();
|
||||
_inputActions.Cutscene.Continue.performed += SkipDialoguePerformed;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
_inputActions.Cutscene.Continue.performed -= SkipDialoguePerformed;
|
||||
@@ -180,12 +177,12 @@ namespace Pal3.GameSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
if (!_isDialoguePresenting && _dialogueRenderQueue.Count > 0)
|
||||
{
|
||||
_isDialoguePresenting = true;
|
||||
StartCoroutine(_dialogueRenderQueue.Dequeue());
|
||||
Pal3.Instance.StartCoroutine(_dialogueRenderQueue.Dequeue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +288,7 @@ namespace Pal3.GameSystem
|
||||
_flashingAnimationCts.Cancel();
|
||||
}
|
||||
_flashingAnimationCts = new CancellationTokenSource();
|
||||
StartCoroutine(PlayDialogueBackgroundFlashingAnimationAsync(
|
||||
Pal3.Instance.StartCoroutine(PlayDialogueBackgroundFlashingAnimationAsync(
|
||||
duration: LIMIT_TIME_DIALOGUE_PLAYER_MAX_REACTION_TIME_IN_SECONDS,
|
||||
_flashingAnimationCts.Token));
|
||||
}
|
||||
@@ -301,14 +298,14 @@ namespace Pal3.GameSystem
|
||||
{
|
||||
IEnumerator renderDialogue = RenderDialogueTextWithAnimationAsync(dialogueTextUI, dialogue);
|
||||
|
||||
StartCoroutine(renderDialogue);
|
||||
Pal3.Instance.StartCoroutine(renderDialogue);
|
||||
|
||||
yield return SkipDialogueRequestedAsync();
|
||||
|
||||
if (_isDialogueRenderingAnimationInProgress)
|
||||
{
|
||||
_isDialogueRenderingAnimationInProgress = false;
|
||||
StopCoroutine(renderDialogue);
|
||||
Pal3.Instance.StopCoroutine(renderDialogue);
|
||||
dialogueTextUI.text = dialogue;
|
||||
yield return SkipDialogueRequestedAsync();
|
||||
}
|
||||
@@ -416,7 +413,7 @@ namespace Pal3.GameSystem
|
||||
foreach (GameObject button in _selectionButtons)
|
||||
{
|
||||
button.GetComponentInChildren<Button>().onClick.RemoveAllListeners();
|
||||
Destroy(button);
|
||||
UnityEngine.Object.Destroy(button);
|
||||
}
|
||||
_selectionButtons.Clear();
|
||||
}
|
||||
@@ -565,7 +562,7 @@ namespace Pal3.GameSystem
|
||||
|
||||
public void Execute(DialogueAddSelectionsCommand command)
|
||||
{
|
||||
_gameStateManager.GoToState(GameState.MenuShowing);
|
||||
_gameStateManager.TryGoToState(GameState.UI);
|
||||
|
||||
WaitUntilCanceled waiter = new ();
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new ScriptRunnerAddWaiterRequest(waiter));
|
||||
@@ -573,7 +570,7 @@ namespace Pal3.GameSystem
|
||||
Transform canvasTransform = _dialogueSelectionButtonsCanvas.transform;
|
||||
for (var i = 0; i < command.Selections.Count; i++)
|
||||
{
|
||||
GameObject selectionButton = Instantiate(_dialogueSelectionButtonPrefab, canvasTransform);
|
||||
GameObject selectionButton = UnityEngine.Object.Instantiate(_dialogueSelectionButtonPrefab, canvasTransform);
|
||||
var buttonTextUI = selectionButton.GetComponentInChildren<TextMeshProUGUI>();
|
||||
buttonTextUI.text = GetSelectionDisplayText(command.Selections[i]);
|
||||
var buttonIndex = i;
|
||||
|
||||
@@ -14,31 +14,26 @@ namespace Pal3.GameSystem
|
||||
using Scene;
|
||||
using Script;
|
||||
using State;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class HotelManager : MonoBehaviour,
|
||||
public sealed class HotelManager : IDisposable,
|
||||
ICommandExecutor<UIShowHotelMenuCommand>
|
||||
{
|
||||
private ScriptManager _scriptManager;
|
||||
private SceneManager _sceneManager;
|
||||
private readonly ScriptManager _scriptManager;
|
||||
private readonly SceneManager _sceneManager;
|
||||
|
||||
public void Init(ScriptManager scriptManager, SceneManager sceneManager)
|
||||
public HotelManager(ScriptManager scriptManager, SceneManager sceneManager)
|
||||
{
|
||||
_scriptManager = Requires.IsNotNull(scriptManager, nameof(scriptManager));
|
||||
_sceneManager = Requires.IsNotNull(sceneManager, nameof(sceneManager));
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
|
||||
public void Rest(string sceneFileName, string sceneName, uint afterRestTalkScript)
|
||||
private void Rest(string sceneFileName, string sceneName, uint afterRestTalkScript)
|
||||
{
|
||||
_sceneManager.LoadScene(sceneFileName, sceneName);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new GameStateChangeRequest(GameState.Cutscene));
|
||||
|
||||
@@ -17,9 +17,9 @@ namespace Pal3.GameSystem
|
||||
using State;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
|
||||
[RequireComponent(typeof(FpsCounter))]
|
||||
public sealed class InformationManager : MonoBehaviour,
|
||||
public sealed class InformationManager : IDisposable,
|
||||
ICommandExecutor<UIDisplayNoteCommand>,
|
||||
ICommandExecutor<UIShowDealerMenuCommand>,
|
||||
ICommandExecutor<SceneLeavingCurrentSceneNotification>,
|
||||
@@ -29,28 +29,33 @@ namespace Pal3.GameSystem
|
||||
private const float NOTE_LAST_TIME_IN_SECONDS = 2.5f;
|
||||
private const float NOTE_DISAPPEAR_ANIMATION_TIME_IN_SECONDS = 1f;
|
||||
|
||||
private GameSettings _gameSettings;
|
||||
private CanvasGroup _noteCanvasGroup;
|
||||
private TextMeshProUGUI _noteText;
|
||||
private Coroutine _noteAnimation;
|
||||
private TextMeshProUGUI _debugInfo;
|
||||
private readonly GameSettings _gameSettings;
|
||||
private readonly CanvasGroup _noteCanvasGroup;
|
||||
private readonly TextMeshProUGUI _noteText;
|
||||
private readonly TextMeshProUGUI _debugInfo;
|
||||
|
||||
private FpsCounter _fpsCounter;
|
||||
private string _debugInfoStringFormat;
|
||||
private readonly FpsCounter _fpsCounter;
|
||||
private readonly string _debugInfoStringFormat;
|
||||
|
||||
private Coroutine _noteAnimation;
|
||||
|
||||
private double _heapSizeLastQueryTime;
|
||||
private float _heapSize;
|
||||
private float _totalAllocatedMemorySize;
|
||||
private float _totalReservedMemorySize;
|
||||
|
||||
private bool _isNoteShowingEnabled = true;
|
||||
|
||||
private string _defaultText;
|
||||
private readonly string _defaultText;
|
||||
|
||||
public void Init(GameSettings gameSettings,
|
||||
public InformationManager(GameSettings gameSettings,
|
||||
FpsCounter fpsCounter,
|
||||
CanvasGroup noteCanvasGroup,
|
||||
TextMeshProUGUI noteText,
|
||||
TextMeshProUGUI debugInfo)
|
||||
{
|
||||
_gameSettings = Requires.IsNotNull(gameSettings, nameof(gameSettings));
|
||||
_fpsCounter = Requires.IsNotNull(fpsCounter, nameof(fpsCounter));
|
||||
_noteCanvasGroup = Requires.IsNotNull(noteCanvasGroup, nameof(noteCanvasGroup));
|
||||
_noteText = Requires.IsNotNull(noteText, nameof(noteText));
|
||||
_debugInfo = Requires.IsNotNull(debugInfo, nameof(debugInfo));
|
||||
@@ -65,7 +70,7 @@ namespace Pal3.GameSystem
|
||||
const string scriptingBackend = "Mono";
|
||||
#endif
|
||||
|
||||
_defaultText = $"{GameConstants.ContactInfo} v{Application.version} {GameConstants.TestingType} (Unity {Application.unityVersion} {scriptingBackend})\n";
|
||||
_defaultText = $"{GameConstants.ContactInfo} v{Application.version} {GameConstants.TestingType} ({Application.platform}-{scriptingBackend})\n";
|
||||
_debugInfo.SetText(_defaultText);
|
||||
|
||||
#if UNITY_2022_1_OR_NEWER
|
||||
@@ -76,28 +81,23 @@ namespace Pal3.GameSystem
|
||||
|
||||
var deviceInfo =
|
||||
$"Device: {SystemInfo.deviceModel.Trim()} OS: {SystemInfo.operatingSystem.Trim()}\n" +
|
||||
$"CPU: {SystemInfo.processorType.Trim()} ({SystemInfo.processorCount} vCores)\n" +
|
||||
$"GPU: {SystemInfo.graphicsDeviceName.Trim()} ({SystemInfo.graphicsDeviceType})\n" +
|
||||
$"RAM: {SystemInfo.systemMemorySize / 1024f:0.0} GB VRAM: {SystemInfo.graphicsMemorySize / 1024f:0.0} GB\n";
|
||||
$"CPU: {SystemInfo.processorType.Trim()} ({SystemInfo.processorCount} vCores) RAM: {SystemInfo.systemMemorySize / 1024f:0.0} GB\n" +
|
||||
$"GPU: {SystemInfo.graphicsDeviceName.Trim()} ({SystemInfo.graphicsDeviceType}) VRAM: {SystemInfo.graphicsMemorySize / 1024f:0.0} GB\n";
|
||||
|
||||
_debugInfoStringFormat = _defaultText + deviceInfo +
|
||||
"Heap size: {0:0.00} MB\n" + "{3:0.} fps ({1}x{2}, " + refreshRate + "Hz)";
|
||||
"Heap: {0:0.} MB Allocated: {1:0.} MB Reserved: {2:0.} MB\n" +
|
||||
"{3:0.} fps ({4}x{5}, " + refreshRate + "Hz)";
|
||||
|
||||
_fpsCounter = GetComponent<FpsCounter>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
if (_noteAnimation != null) StopCoroutine(_noteAnimation);
|
||||
if (_noteAnimation != null) Pal3.Instance.StopCoroutine(_noteAnimation);
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
if (!_gameSettings.IsDebugInfoEnabled) return;
|
||||
|
||||
@@ -105,13 +105,17 @@ namespace Pal3.GameSystem
|
||||
if (currentTime - _heapSizeLastQueryTime > 5f)
|
||||
{
|
||||
_heapSize = GC.GetTotalMemory(false) / (1024f * 1024f);
|
||||
_totalAllocatedMemorySize = Profiler.GetTotalAllocatedMemoryLong() / (1024f * 1024f);
|
||||
_totalReservedMemorySize = Profiler.GetTotalReservedMemoryLong() / (1024f * 1024f);
|
||||
_heapSizeLastQueryTime = currentTime;
|
||||
}
|
||||
_debugInfo.SetText(_debugInfoStringFormat,
|
||||
_heapSize,
|
||||
_totalAllocatedMemorySize,
|
||||
_totalReservedMemorySize,
|
||||
Mathf.Ceil(_fpsCounter.GetFps()),
|
||||
Screen.width,
|
||||
Screen.height,
|
||||
Mathf.Ceil(_fpsCounter.GetFps()));
|
||||
Screen.height);
|
||||
}
|
||||
|
||||
private IEnumerator AnimateNoteUIAsync()
|
||||
@@ -141,7 +145,7 @@ namespace Pal3.GameSystem
|
||||
var currentText = _noteText.text;
|
||||
if (_noteAnimation != null)
|
||||
{
|
||||
StopCoroutine(_noteAnimation);
|
||||
Pal3.Instance.StopCoroutine(_noteAnimation);
|
||||
}
|
||||
|
||||
if (!string.Equals(currentText, command.Note) &&
|
||||
@@ -155,14 +159,14 @@ namespace Pal3.GameSystem
|
||||
_noteText.text = command.Note;
|
||||
}
|
||||
|
||||
_noteAnimation = StartCoroutine(AnimateNoteUIAsync());
|
||||
_noteAnimation = Pal3.Instance.StartCoroutine(AnimateNoteUIAsync());
|
||||
}
|
||||
|
||||
public void Execute(SceneLeavingCurrentSceneNotification command)
|
||||
{
|
||||
if (_noteAnimation != null)
|
||||
{
|
||||
StopCoroutine(_noteAnimation);
|
||||
Pal3.Instance.StopCoroutine(_noteAnimation);
|
||||
}
|
||||
_noteCanvasGroup.alpha = 0f;
|
||||
_noteText.text = string.Empty;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Pal3.GameSystem
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public sealed class MiniMapManager : MonoBehaviour,
|
||||
public sealed class MiniMapManager : IDisposable,
|
||||
ICommandExecutor<PlayerActorTilePositionUpdatedNotification>,
|
||||
ICommandExecutor<SceneLeavingCurrentSceneNotification>,
|
||||
ICommandExecutor<ScenePostLoadingNotification>,
|
||||
@@ -25,22 +25,22 @@ namespace Pal3.GameSystem
|
||||
{
|
||||
private const float MINIMAP_SCALE = 2.5f;
|
||||
|
||||
private Camera _mainCamera;
|
||||
private SceneManager _sceneManager;
|
||||
private readonly Camera _mainCamera;
|
||||
private readonly SceneManager _sceneManager;
|
||||
|
||||
private CanvasGroup _miniMapCanvasGroup;
|
||||
private RectTransform _miniMapRectTransform;
|
||||
private float _miniMapWidth;
|
||||
private Image _miniMapImage;
|
||||
private readonly CanvasGroup _miniMapCanvasGroup;
|
||||
private readonly RectTransform _miniMapRectTransform;
|
||||
private readonly float _miniMapWidth;
|
||||
private readonly Image _miniMapImage;
|
||||
|
||||
private Texture2D[] _miniMapTextures;
|
||||
private Sprite[] _miniMapSprites;
|
||||
|
||||
private Tilemap _currentTilemap;
|
||||
private int _currentLayerIndex = -1;
|
||||
private GameState _currentGameState = GameState.MenuShowing;
|
||||
private GameState _currentGameState = GameState.UI;
|
||||
|
||||
public void Init(Camera mainCamera,
|
||||
public MiniMapManager(Camera mainCamera,
|
||||
SceneManager sceneManager,
|
||||
CanvasGroup miniMapCanvasGroup,
|
||||
Image miniMapImage)
|
||||
@@ -54,20 +54,17 @@ namespace Pal3.GameSystem
|
||||
_miniMapRectTransform = Requires.IsNotNull(_miniMapCanvasGroup.GetComponent<RectTransform>(), nameof(miniMapImage));
|
||||
_miniMapWidth = _miniMapRectTransform.rect.width;
|
||||
_miniMapCanvasGroup.alpha = 0f;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
public void Dispose()
|
||||
{
|
||||
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
|
||||
Dispose();
|
||||
DisposeCurrentMapAndReset();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
public void LateUpdate(float deltaTime)
|
||||
{
|
||||
_miniMapRectTransform.localRotation = Quaternion.Euler(0, 0, _mainCamera.transform.eulerAngles.y + 180f);
|
||||
}
|
||||
@@ -160,15 +157,15 @@ namespace Pal3.GameSystem
|
||||
_currentLayerIndex = -1;
|
||||
}
|
||||
|
||||
private void Dispose()
|
||||
private void DisposeCurrentMapAndReset()
|
||||
{
|
||||
_miniMapCanvasGroup.alpha = 0f;
|
||||
|
||||
if (_miniMapSprites != null)
|
||||
{
|
||||
foreach (var sprite in _miniMapSprites)
|
||||
foreach (Sprite sprite in _miniMapSprites)
|
||||
{
|
||||
Destroy(sprite);
|
||||
UnityEngine.Object.Destroy(sprite);
|
||||
}
|
||||
|
||||
_miniMapSprites = null;
|
||||
@@ -176,9 +173,9 @@ namespace Pal3.GameSystem
|
||||
|
||||
if (_miniMapTextures != null)
|
||||
{
|
||||
foreach (var texture in _miniMapTextures)
|
||||
foreach (Texture2D texture in _miniMapTextures)
|
||||
{
|
||||
Destroy(texture);
|
||||
UnityEngine.Object.Destroy(texture);
|
||||
}
|
||||
|
||||
_miniMapTextures = null;
|
||||
@@ -191,7 +188,7 @@ namespace Pal3.GameSystem
|
||||
|
||||
public void Execute(SceneLeavingCurrentSceneNotification command)
|
||||
{
|
||||
Dispose();
|
||||
DisposeCurrentMapAndReset();
|
||||
}
|
||||
|
||||
public void Execute(GameStateChangedNotification command)
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Pal3.GameSystem
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Actor;
|
||||
using Actor.Controllers;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Pal3.Input
|
||||
_playerInputActions = Requires.IsNotNull(playerInputActions, nameof(playerInputActions));
|
||||
|
||||
// Goto initial state
|
||||
SwitchCurrentActionMap(GameState.MenuShowing);
|
||||
SwitchCurrentActionMap(GameState.UI);
|
||||
|
||||
InputSystem.onActionChange += OnInputActionChange;
|
||||
}
|
||||
@@ -63,10 +63,12 @@ namespace Pal3.Input
|
||||
|
||||
InputActionMap inputActionMap = state switch
|
||||
{
|
||||
GameState.MenuShowing => _playerInputActions.UI.Get(),
|
||||
GameState.UI => _playerInputActions.UI.Get(),
|
||||
GameState.Gameplay => _playerInputActions.Gameplay.Get(),
|
||||
GameState.Cutscene => _playerInputActions.Cutscene.Get(),
|
||||
GameState.VideoPlaying => _playerInputActions.VideoPlaying.Get(),
|
||||
GameState.Combat => _playerInputActions.Combat.Get(),
|
||||
GameState.Debug => _playerInputActions.Debug.Get(),
|
||||
_ => null
|
||||
};
|
||||
|
||||
|
||||
@@ -570,33 +570,6 @@ namespace Pal3.Input
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
},
|
||||
{
|
||||
""name"": ""ToggleBigMap"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""5e633979-d23a-4bd2-994f-038c922e0a25"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
},
|
||||
{
|
||||
""name"": ""ToggleStorySelector"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""a7a425ae-d24d-45f9-a11d-54d0f876a1d0"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
},
|
||||
{
|
||||
""name"": ""ExitCurrentShowingMenu"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""f4c71292-8ed0-4ea2-9f78-bf137d63f607"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
}
|
||||
],
|
||||
""bindings"": [
|
||||
@@ -643,83 +616,6 @@ namespace Pal3.Input
|
||||
""action"": ""Continue"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""a3c5f1bf-a6f8-4719-84c7-c923788b4819"",
|
||||
""path"": ""<Keyboard>/u"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleStorySelector"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""90a640cc-40a5-4494-9dc1-d1cf85674620"",
|
||||
""path"": ""<Gamepad>/select"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleStorySelector"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""30885317-9959-46c4-a930-1a29c0e33b47"",
|
||||
""path"": ""<Keyboard>/escape"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleStorySelector"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""6404737e-bf57-43a9-83a5-3fa155e78c1b"",
|
||||
""path"": ""<Keyboard>/m"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleBigMap"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""390ac655-d64d-48e5-9bbc-69a2f3938770"",
|
||||
""path"": ""<Gamepad>/start"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleBigMap"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""9a0e1e31-3aac-4131-8cc6-f1a87d113db6"",
|
||||
""path"": ""<Keyboard>/escape"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ExitCurrentShowingMenu"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""046969fe-1445-429a-b8ca-1a687dbdd20d"",
|
||||
""path"": ""<Gamepad>/buttonEast"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ExitCurrentShowingMenu"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -866,6 +762,33 @@ namespace Pal3.Input
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
},
|
||||
{
|
||||
""name"": ""ToggleBigMap"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""c0eb7e88-5de5-45e8-b93a-d5a669cb1e87"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
},
|
||||
{
|
||||
""name"": ""ToggleStorySelector"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""ac2e00e5-0cba-4594-96e0-b8a39e97c5f7"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
},
|
||||
{
|
||||
""name"": ""ExitCurrentShowingMenu"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""37efe51b-ffd5-4283-b253-65611750e358"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
}
|
||||
],
|
||||
""bindings"": [
|
||||
@@ -1242,8 +1165,97 @@ namespace Pal3.Input
|
||||
""action"": ""TrackedDeviceOrientation"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""6d9749bf-4ff4-4c1c-b3b8-8fd519c213aa"",
|
||||
""path"": ""<Keyboard>/m"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleBigMap"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""b2fa38b5-fad5-4477-a7f1-815554cea62d"",
|
||||
""path"": ""<Gamepad>/start"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleBigMap"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""6e85d718-ef17-47b9-a6a8-9d4a19174180"",
|
||||
""path"": ""<Keyboard>/u"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleStorySelector"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""5c73bf36-9883-4a4a-b981-18615f0a9230"",
|
||||
""path"": ""<Gamepad>/select"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleStorySelector"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""6956fcc8-e046-47f7-a9f3-6b9ca0030f2e"",
|
||||
""path"": ""<Keyboard>/escape"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ToggleStorySelector"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""637d83eb-8f9f-4077-b91c-4b1ca0f7890b"",
|
||||
""path"": ""<Keyboard>/escape"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ExitCurrentShowingMenu"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""6817bb0f-608a-42c7-a862-8c96c956dd15"",
|
||||
""path"": ""<Gamepad>/buttonEast"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""ExitCurrentShowingMenu"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
""name"": ""Debug"",
|
||||
""id"": ""76cd9d4b-6f9c-4f58-a69b-859c0b6d3c6b"",
|
||||
""actions"": [],
|
||||
""bindings"": []
|
||||
},
|
||||
{
|
||||
""name"": ""Combat"",
|
||||
""id"": ""49ab487c-79cc-4f76-9e0f-872d16db5f30"",
|
||||
""actions"": [],
|
||||
""bindings"": []
|
||||
}
|
||||
],
|
||||
""controlSchemes"": []
|
||||
@@ -1271,9 +1283,6 @@ namespace Pal3.Input
|
||||
// Cutscene
|
||||
m_Cutscene = asset.FindActionMap("Cutscene", throwIfNotFound: true);
|
||||
m_Cutscene_Continue = m_Cutscene.FindAction("Continue", throwIfNotFound: true);
|
||||
m_Cutscene_ToggleBigMap = m_Cutscene.FindAction("ToggleBigMap", throwIfNotFound: true);
|
||||
m_Cutscene_ToggleStorySelector = m_Cutscene.FindAction("ToggleStorySelector", throwIfNotFound: true);
|
||||
m_Cutscene_ExitCurrentShowingMenu = m_Cutscene.FindAction("ExitCurrentShowingMenu", throwIfNotFound: true);
|
||||
// VideoPlaying
|
||||
m_VideoPlaying = asset.FindActionMap("VideoPlaying", throwIfNotFound: true);
|
||||
m_VideoPlaying_SkipVideo = m_VideoPlaying.FindAction("SkipVideo", throwIfNotFound: true);
|
||||
@@ -1289,6 +1298,13 @@ namespace Pal3.Input
|
||||
m_UI_RightClick = m_UI.FindAction("RightClick", throwIfNotFound: true);
|
||||
m_UI_TrackedDevicePosition = m_UI.FindAction("TrackedDevicePosition", throwIfNotFound: true);
|
||||
m_UI_TrackedDeviceOrientation = m_UI.FindAction("TrackedDeviceOrientation", throwIfNotFound: true);
|
||||
m_UI_ToggleBigMap = m_UI.FindAction("ToggleBigMap", throwIfNotFound: true);
|
||||
m_UI_ToggleStorySelector = m_UI.FindAction("ToggleStorySelector", throwIfNotFound: true);
|
||||
m_UI_ExitCurrentShowingMenu = m_UI.FindAction("ExitCurrentShowingMenu", throwIfNotFound: true);
|
||||
// Debug
|
||||
m_Debug = asset.FindActionMap("Debug", throwIfNotFound: true);
|
||||
// Combat
|
||||
m_Combat = asset.FindActionMap("Combat", throwIfNotFound: true);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -1533,17 +1549,11 @@ namespace Pal3.Input
|
||||
private readonly InputActionMap m_Cutscene;
|
||||
private List<ICutsceneActions> m_CutsceneActionsCallbackInterfaces = new List<ICutsceneActions>();
|
||||
private readonly InputAction m_Cutscene_Continue;
|
||||
private readonly InputAction m_Cutscene_ToggleBigMap;
|
||||
private readonly InputAction m_Cutscene_ToggleStorySelector;
|
||||
private readonly InputAction m_Cutscene_ExitCurrentShowingMenu;
|
||||
public struct CutsceneActions
|
||||
{
|
||||
private @PlayerInputActions m_Wrapper;
|
||||
public CutsceneActions(@PlayerInputActions wrapper) { m_Wrapper = wrapper; }
|
||||
public InputAction @Continue => m_Wrapper.m_Cutscene_Continue;
|
||||
public InputAction @ToggleBigMap => m_Wrapper.m_Cutscene_ToggleBigMap;
|
||||
public InputAction @ToggleStorySelector => m_Wrapper.m_Cutscene_ToggleStorySelector;
|
||||
public InputAction @ExitCurrentShowingMenu => m_Wrapper.m_Cutscene_ExitCurrentShowingMenu;
|
||||
public InputActionMap Get() { return m_Wrapper.m_Cutscene; }
|
||||
public void Enable() { Get().Enable(); }
|
||||
public void Disable() { Get().Disable(); }
|
||||
@@ -1556,15 +1566,6 @@ namespace Pal3.Input
|
||||
@Continue.started += instance.OnContinue;
|
||||
@Continue.performed += instance.OnContinue;
|
||||
@Continue.canceled += instance.OnContinue;
|
||||
@ToggleBigMap.started += instance.OnToggleBigMap;
|
||||
@ToggleBigMap.performed += instance.OnToggleBigMap;
|
||||
@ToggleBigMap.canceled += instance.OnToggleBigMap;
|
||||
@ToggleStorySelector.started += instance.OnToggleStorySelector;
|
||||
@ToggleStorySelector.performed += instance.OnToggleStorySelector;
|
||||
@ToggleStorySelector.canceled += instance.OnToggleStorySelector;
|
||||
@ExitCurrentShowingMenu.started += instance.OnExitCurrentShowingMenu;
|
||||
@ExitCurrentShowingMenu.performed += instance.OnExitCurrentShowingMenu;
|
||||
@ExitCurrentShowingMenu.canceled += instance.OnExitCurrentShowingMenu;
|
||||
}
|
||||
|
||||
private void UnregisterCallbacks(ICutsceneActions instance)
|
||||
@@ -1572,15 +1573,6 @@ namespace Pal3.Input
|
||||
@Continue.started -= instance.OnContinue;
|
||||
@Continue.performed -= instance.OnContinue;
|
||||
@Continue.canceled -= instance.OnContinue;
|
||||
@ToggleBigMap.started -= instance.OnToggleBigMap;
|
||||
@ToggleBigMap.performed -= instance.OnToggleBigMap;
|
||||
@ToggleBigMap.canceled -= instance.OnToggleBigMap;
|
||||
@ToggleStorySelector.started -= instance.OnToggleStorySelector;
|
||||
@ToggleStorySelector.performed -= instance.OnToggleStorySelector;
|
||||
@ToggleStorySelector.canceled -= instance.OnToggleStorySelector;
|
||||
@ExitCurrentShowingMenu.started -= instance.OnExitCurrentShowingMenu;
|
||||
@ExitCurrentShowingMenu.performed -= instance.OnExitCurrentShowingMenu;
|
||||
@ExitCurrentShowingMenu.canceled -= instance.OnExitCurrentShowingMenu;
|
||||
}
|
||||
|
||||
public void RemoveCallbacks(ICutsceneActions instance)
|
||||
@@ -1658,6 +1650,9 @@ namespace Pal3.Input
|
||||
private readonly InputAction m_UI_RightClick;
|
||||
private readonly InputAction m_UI_TrackedDevicePosition;
|
||||
private readonly InputAction m_UI_TrackedDeviceOrientation;
|
||||
private readonly InputAction m_UI_ToggleBigMap;
|
||||
private readonly InputAction m_UI_ToggleStorySelector;
|
||||
private readonly InputAction m_UI_ExitCurrentShowingMenu;
|
||||
public struct UIActions
|
||||
{
|
||||
private @PlayerInputActions m_Wrapper;
|
||||
@@ -1672,6 +1667,9 @@ namespace Pal3.Input
|
||||
public InputAction @RightClick => m_Wrapper.m_UI_RightClick;
|
||||
public InputAction @TrackedDevicePosition => m_Wrapper.m_UI_TrackedDevicePosition;
|
||||
public InputAction @TrackedDeviceOrientation => m_Wrapper.m_UI_TrackedDeviceOrientation;
|
||||
public InputAction @ToggleBigMap => m_Wrapper.m_UI_ToggleBigMap;
|
||||
public InputAction @ToggleStorySelector => m_Wrapper.m_UI_ToggleStorySelector;
|
||||
public InputAction @ExitCurrentShowingMenu => m_Wrapper.m_UI_ExitCurrentShowingMenu;
|
||||
public InputActionMap Get() { return m_Wrapper.m_UI; }
|
||||
public void Enable() { Get().Enable(); }
|
||||
public void Disable() { Get().Disable(); }
|
||||
@@ -1711,6 +1709,15 @@ namespace Pal3.Input
|
||||
@TrackedDeviceOrientation.started += instance.OnTrackedDeviceOrientation;
|
||||
@TrackedDeviceOrientation.performed += instance.OnTrackedDeviceOrientation;
|
||||
@TrackedDeviceOrientation.canceled += instance.OnTrackedDeviceOrientation;
|
||||
@ToggleBigMap.started += instance.OnToggleBigMap;
|
||||
@ToggleBigMap.performed += instance.OnToggleBigMap;
|
||||
@ToggleBigMap.canceled += instance.OnToggleBigMap;
|
||||
@ToggleStorySelector.started += instance.OnToggleStorySelector;
|
||||
@ToggleStorySelector.performed += instance.OnToggleStorySelector;
|
||||
@ToggleStorySelector.canceled += instance.OnToggleStorySelector;
|
||||
@ExitCurrentShowingMenu.started += instance.OnExitCurrentShowingMenu;
|
||||
@ExitCurrentShowingMenu.performed += instance.OnExitCurrentShowingMenu;
|
||||
@ExitCurrentShowingMenu.canceled += instance.OnExitCurrentShowingMenu;
|
||||
}
|
||||
|
||||
private void UnregisterCallbacks(IUIActions instance)
|
||||
@@ -1745,6 +1752,15 @@ namespace Pal3.Input
|
||||
@TrackedDeviceOrientation.started -= instance.OnTrackedDeviceOrientation;
|
||||
@TrackedDeviceOrientation.performed -= instance.OnTrackedDeviceOrientation;
|
||||
@TrackedDeviceOrientation.canceled -= instance.OnTrackedDeviceOrientation;
|
||||
@ToggleBigMap.started -= instance.OnToggleBigMap;
|
||||
@ToggleBigMap.performed -= instance.OnToggleBigMap;
|
||||
@ToggleBigMap.canceled -= instance.OnToggleBigMap;
|
||||
@ToggleStorySelector.started -= instance.OnToggleStorySelector;
|
||||
@ToggleStorySelector.performed -= instance.OnToggleStorySelector;
|
||||
@ToggleStorySelector.canceled -= instance.OnToggleStorySelector;
|
||||
@ExitCurrentShowingMenu.started -= instance.OnExitCurrentShowingMenu;
|
||||
@ExitCurrentShowingMenu.performed -= instance.OnExitCurrentShowingMenu;
|
||||
@ExitCurrentShowingMenu.canceled -= instance.OnExitCurrentShowingMenu;
|
||||
}
|
||||
|
||||
public void RemoveCallbacks(IUIActions instance)
|
||||
@@ -1762,6 +1778,82 @@ namespace Pal3.Input
|
||||
}
|
||||
}
|
||||
public UIActions @UI => new UIActions(this);
|
||||
|
||||
// Debug
|
||||
private readonly InputActionMap m_Debug;
|
||||
private List<IDebugActions> m_DebugActionsCallbackInterfaces = new List<IDebugActions>();
|
||||
public struct DebugActions
|
||||
{
|
||||
private @PlayerInputActions m_Wrapper;
|
||||
public DebugActions(@PlayerInputActions wrapper) { m_Wrapper = wrapper; }
|
||||
public InputActionMap Get() { return m_Wrapper.m_Debug; }
|
||||
public void Enable() { Get().Enable(); }
|
||||
public void Disable() { Get().Disable(); }
|
||||
public bool enabled => Get().enabled;
|
||||
public static implicit operator InputActionMap(DebugActions set) { return set.Get(); }
|
||||
public void AddCallbacks(IDebugActions instance)
|
||||
{
|
||||
if (instance == null || m_Wrapper.m_DebugActionsCallbackInterfaces.Contains(instance)) return;
|
||||
m_Wrapper.m_DebugActionsCallbackInterfaces.Add(instance);
|
||||
}
|
||||
|
||||
private void UnregisterCallbacks(IDebugActions instance)
|
||||
{
|
||||
}
|
||||
|
||||
public void RemoveCallbacks(IDebugActions instance)
|
||||
{
|
||||
if (m_Wrapper.m_DebugActionsCallbackInterfaces.Remove(instance))
|
||||
UnregisterCallbacks(instance);
|
||||
}
|
||||
|
||||
public void SetCallbacks(IDebugActions instance)
|
||||
{
|
||||
foreach (var item in m_Wrapper.m_DebugActionsCallbackInterfaces)
|
||||
UnregisterCallbacks(item);
|
||||
m_Wrapper.m_DebugActionsCallbackInterfaces.Clear();
|
||||
AddCallbacks(instance);
|
||||
}
|
||||
}
|
||||
public DebugActions @Debug => new DebugActions(this);
|
||||
|
||||
// Combat
|
||||
private readonly InputActionMap m_Combat;
|
||||
private List<ICombatActions> m_CombatActionsCallbackInterfaces = new List<ICombatActions>();
|
||||
public struct CombatActions
|
||||
{
|
||||
private @PlayerInputActions m_Wrapper;
|
||||
public CombatActions(@PlayerInputActions wrapper) { m_Wrapper = wrapper; }
|
||||
public InputActionMap Get() { return m_Wrapper.m_Combat; }
|
||||
public void Enable() { Get().Enable(); }
|
||||
public void Disable() { Get().Disable(); }
|
||||
public bool enabled => Get().enabled;
|
||||
public static implicit operator InputActionMap(CombatActions set) { return set.Get(); }
|
||||
public void AddCallbacks(ICombatActions instance)
|
||||
{
|
||||
if (instance == null || m_Wrapper.m_CombatActionsCallbackInterfaces.Contains(instance)) return;
|
||||
m_Wrapper.m_CombatActionsCallbackInterfaces.Add(instance);
|
||||
}
|
||||
|
||||
private void UnregisterCallbacks(ICombatActions instance)
|
||||
{
|
||||
}
|
||||
|
||||
public void RemoveCallbacks(ICombatActions instance)
|
||||
{
|
||||
if (m_Wrapper.m_CombatActionsCallbackInterfaces.Remove(instance))
|
||||
UnregisterCallbacks(instance);
|
||||
}
|
||||
|
||||
public void SetCallbacks(ICombatActions instance)
|
||||
{
|
||||
foreach (var item in m_Wrapper.m_CombatActionsCallbackInterfaces)
|
||||
UnregisterCallbacks(item);
|
||||
m_Wrapper.m_CombatActionsCallbackInterfaces.Clear();
|
||||
AddCallbacks(instance);
|
||||
}
|
||||
}
|
||||
public CombatActions @Combat => new CombatActions(this);
|
||||
public interface IGameplayActions
|
||||
{
|
||||
void OnMovement(InputAction.CallbackContext context);
|
||||
@@ -1786,9 +1878,6 @@ namespace Pal3.Input
|
||||
public interface ICutsceneActions
|
||||
{
|
||||
void OnContinue(InputAction.CallbackContext context);
|
||||
void OnToggleBigMap(InputAction.CallbackContext context);
|
||||
void OnToggleStorySelector(InputAction.CallbackContext context);
|
||||
void OnExitCurrentShowingMenu(InputAction.CallbackContext context);
|
||||
}
|
||||
public interface IVideoPlayingActions
|
||||
{
|
||||
@@ -1806,6 +1895,15 @@ namespace Pal3.Input
|
||||
void OnRightClick(InputAction.CallbackContext context);
|
||||
void OnTrackedDevicePosition(InputAction.CallbackContext context);
|
||||
void OnTrackedDeviceOrientation(InputAction.CallbackContext context);
|
||||
void OnToggleBigMap(InputAction.CallbackContext context);
|
||||
void OnToggleStorySelector(InputAction.CallbackContext context);
|
||||
void OnExitCurrentShowingMenu(InputAction.CallbackContext context);
|
||||
}
|
||||
public interface IDebugActions
|
||||
{
|
||||
}
|
||||
public interface ICombatActions
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -546,33 +546,6 @@
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "ToggleBigMap",
|
||||
"type": "Button",
|
||||
"id": "5e633979-d23a-4bd2-994f-038c922e0a25",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "ToggleStorySelector",
|
||||
"type": "Button",
|
||||
"id": "a7a425ae-d24d-45f9-a11d-54d0f876a1d0",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "ExitCurrentShowingMenu",
|
||||
"type": "Button",
|
||||
"id": "f4c71292-8ed0-4ea2-9f78-bf137d63f607",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
@@ -619,83 +592,6 @@
|
||||
"action": "Continue",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "a3c5f1bf-a6f8-4719-84c7-c923788b4819",
|
||||
"path": "<Keyboard>/u",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleStorySelector",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "90a640cc-40a5-4494-9dc1-d1cf85674620",
|
||||
"path": "<Gamepad>/select",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleStorySelector",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "30885317-9959-46c4-a930-1a29c0e33b47",
|
||||
"path": "<Keyboard>/escape",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleStorySelector",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "6404737e-bf57-43a9-83a5-3fa155e78c1b",
|
||||
"path": "<Keyboard>/m",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleBigMap",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "390ac655-d64d-48e5-9bbc-69a2f3938770",
|
||||
"path": "<Gamepad>/start",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleBigMap",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "9a0e1e31-3aac-4131-8cc6-f1a87d113db6",
|
||||
"path": "<Keyboard>/escape",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ExitCurrentShowingMenu",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "046969fe-1445-429a-b8ca-1a687dbdd20d",
|
||||
"path": "<Gamepad>/buttonEast",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ExitCurrentShowingMenu",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -842,6 +738,33 @@
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "ToggleBigMap",
|
||||
"type": "Button",
|
||||
"id": "c0eb7e88-5de5-45e8-b93a-d5a669cb1e87",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "ToggleStorySelector",
|
||||
"type": "Button",
|
||||
"id": "ac2e00e5-0cba-4594-96e0-b8a39e97c5f7",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
},
|
||||
{
|
||||
"name": "ExitCurrentShowingMenu",
|
||||
"type": "Button",
|
||||
"id": "37efe51b-ffd5-4283-b253-65611750e358",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
@@ -1218,8 +1141,97 @@
|
||||
"action": "TrackedDeviceOrientation",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "6d9749bf-4ff4-4c1c-b3b8-8fd519c213aa",
|
||||
"path": "<Keyboard>/m",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleBigMap",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "b2fa38b5-fad5-4477-a7f1-815554cea62d",
|
||||
"path": "<Gamepad>/start",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleBigMap",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "6e85d718-ef17-47b9-a6a8-9d4a19174180",
|
||||
"path": "<Keyboard>/u",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleStorySelector",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "5c73bf36-9883-4a4a-b981-18615f0a9230",
|
||||
"path": "<Gamepad>/select",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleStorySelector",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "6956fcc8-e046-47f7-a9f3-6b9ca0030f2e",
|
||||
"path": "<Keyboard>/escape",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ToggleStorySelector",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "637d83eb-8f9f-4077-b91c-4b1ca0f7890b",
|
||||
"path": "<Keyboard>/escape",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ExitCurrentShowingMenu",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "6817bb0f-608a-42c7-a862-8c96c956dd15",
|
||||
"path": "<Gamepad>/buttonEast",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "ExitCurrentShowingMenu",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Debug",
|
||||
"id": "76cd9d4b-6f9c-4f58-a69b-859c0b6d3c6b",
|
||||
"actions": [],
|
||||
"bindings": []
|
||||
},
|
||||
{
|
||||
"name": "Combat",
|
||||
"id": "49ab487c-79cc-4f76-9e0f-872d16db5f30",
|
||||
"actions": [],
|
||||
"bindings": []
|
||||
}
|
||||
],
|
||||
"controlSchemes": []
|
||||
|
||||
@@ -5,33 +5,23 @@
|
||||
|
||||
namespace Pal3.MetaData
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public static class AudioConstants
|
||||
{
|
||||
public const string PlayerActorMovementSfxAudioSourceName = "PlayerActorMovementSfx";
|
||||
|
||||
public static readonly HashSet<string> PlayerActorMovementSfxAudioFileNames = new ()
|
||||
{
|
||||
#if PAL3
|
||||
"we021a.wav",
|
||||
"we021b.wav",
|
||||
"we021c.wav",
|
||||
"we021d.wav",
|
||||
"we022a.wav",
|
||||
"we022b.wav",
|
||||
"we022c.wav",
|
||||
"we022d.wav",
|
||||
#elif PAL3A
|
||||
"WE007.WAV",
|
||||
"WE008.WAV"
|
||||
#endif
|
||||
};
|
||||
|
||||
#if PAL3
|
||||
public const string ThemeMusicName = "PI01";
|
||||
#elif PAL3A
|
||||
public const string ThemeMusicName = "P01";
|
||||
#endif
|
||||
|
||||
#if PAL3
|
||||
public const string MainActorWalkSfxNamePrefix = "we021";
|
||||
public const string MainActorRunSfxNamePrefix = "we022";
|
||||
#elif PAL3A
|
||||
public const string MainActorWalkSfxName = "WE007";
|
||||
public const string MainActorRunSfxName= "WE008";
|
||||
public const string WangPengXuFlySfxName = "WE045";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5608b8799894c0e99618df0dbe9ae55
|
||||
timeCreated: 1642920639
|
||||
@@ -0,0 +1,15 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.MetaData
|
||||
{
|
||||
// OG game rendering state constants
|
||||
public enum RenderingState
|
||||
{
|
||||
Gameplay = 0, // 游戏
|
||||
BigMap = 13, // 大地图
|
||||
MonsterCatalogue = 17, // 降妖谱
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f225bf17492d67047bae2645baeb6055
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+120
-161
@@ -7,14 +7,14 @@ namespace Pal3
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Actor;
|
||||
using Actor.Controllers;
|
||||
using Audio;
|
||||
using Camera;
|
||||
using Command;
|
||||
using Command.SceCommands;
|
||||
using Core.DataLoader;
|
||||
using Core.DataReader.Scn;
|
||||
using Core.FileSystem;
|
||||
using Core.Services;
|
||||
@@ -87,6 +87,7 @@ namespace Pal3
|
||||
|
||||
// Debug
|
||||
[SerializeField] private TextMeshProUGUI debugInfo;
|
||||
[SerializeField] private FpsCounter fpsCounter;
|
||||
|
||||
// BigMap
|
||||
[SerializeField] private CanvasGroup bigMapCanvasGroup;
|
||||
@@ -120,7 +121,7 @@ namespace Pal3
|
||||
// Global texture cache store
|
||||
private readonly TextureCache _textureCache = new ();
|
||||
|
||||
// Core game systems
|
||||
// Core game systems amd components
|
||||
private GameSettings _gameSettings;
|
||||
private ICpkFileSystem _fileSystem;
|
||||
private GameResourceProvider _gameResourceProvider;
|
||||
@@ -139,11 +140,9 @@ namespace Pal3
|
||||
private DialogueManager _dialogueManager;
|
||||
private PostProcessManager _postProcessManager;
|
||||
private EffectManager _effectManager;
|
||||
|
||||
// Game components
|
||||
private MiniMapManager _miniMapManager;
|
||||
private TouchControlUIManager _touchControlUIManager;
|
||||
private PlayerGamePlayController _playerGamePlayController;
|
||||
private PlayerGamePlayManager _playerGamePlayManager;
|
||||
private TeamManager _teamManager;
|
||||
private HotelManager _hotelManager;
|
||||
private InformationManager _informationManager;
|
||||
@@ -152,6 +151,7 @@ namespace Pal3
|
||||
private CaptionRenderer _captionRenderer;
|
||||
private CursorManager _cursorManager;
|
||||
private SaveManager _saveManager;
|
||||
private RenderingSettingsManager _renderingSettingsManager;
|
||||
|
||||
#if PAL3 // PAL3 specific components
|
||||
private AppraisalsMiniGame _appraisalsMiniGame;
|
||||
@@ -165,13 +165,12 @@ namespace Pal3
|
||||
private TaskManager _taskManager;
|
||||
#endif
|
||||
|
||||
// Utility components
|
||||
private RenderingSettingsManager _renderingSettingsManager;
|
||||
|
||||
// Dev tools
|
||||
private MazeSkipper _mazeSkipper;
|
||||
private MainMenu _mainMenu;
|
||||
|
||||
private IEnumerable<object> _allRegisteredServices;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Debug.Log($"[{nameof(Pal3)}] Game setup and initialization started...");
|
||||
@@ -183,31 +182,79 @@ namespace Pal3
|
||||
|
||||
_fileSystemCacheManager = new FileSystemCacheManager(_fileSystem);
|
||||
ServiceLocator.Instance.Register(_fileSystemCacheManager);
|
||||
|
||||
_inputActions = new PlayerInputActions();
|
||||
ServiceLocator.Instance.Register(_inputActions);
|
||||
|
||||
_inputManager= new InputManager(_inputActions);
|
||||
ServiceLocator.Instance.Register(_inputManager);
|
||||
|
||||
_scriptManager = new ScriptManager(_gameResourceProvider);
|
||||
ServiceLocator.Instance.Register(_scriptManager);
|
||||
|
||||
_gameStateManager = new GameStateManager(_inputManager, _scriptManager);
|
||||
ServiceLocator.Instance.Register(_gameStateManager);
|
||||
|
||||
_sceneStateManager = new SceneStateManager();
|
||||
ServiceLocator.Instance.Register(_sceneStateManager);
|
||||
|
||||
_sceneManager = new SceneManager(_gameResourceProvider,
|
||||
_sceneStateManager, _scriptManager, _gameSettings, mainCamera);
|
||||
ServiceLocator.Instance.Register(_sceneManager);
|
||||
|
||||
_playerActorManager = new PlayerActorManager();
|
||||
ServiceLocator.Instance.Register(_playerActorManager);
|
||||
|
||||
_inventoryManager = new InventoryManager(_gameResourceProvider);
|
||||
ServiceLocator.Instance.Register(_inventoryManager);
|
||||
|
||||
_teamManager = new TeamManager(_playerActorManager, _sceneManager);
|
||||
ServiceLocator.Instance.Register(_teamManager);
|
||||
|
||||
_touchControlUIManager = new TouchControlUIManager(_sceneManager,
|
||||
touchControlUI, interactionButton, multiFunctionButton, mainMenuButton);
|
||||
ServiceLocator.Instance.Register(_touchControlUIManager);
|
||||
|
||||
_favorManager = new FavorManager();
|
||||
ServiceLocator.Instance.Register(_favorManager);
|
||||
|
||||
_videoManager = new VideoManager(_gameResourceProvider,
|
||||
_gameStateManager, _inputActions, videoPlayerCanvas, videoPlayer);
|
||||
ServiceLocator.Instance.Register(_videoManager);
|
||||
|
||||
_audioManager = new AudioManager(mainCamera,
|
||||
_gameResourceProvider, _sceneManager, musicSource, _gameSettings);
|
||||
ServiceLocator.Instance.Register(_audioManager);
|
||||
|
||||
_captionRenderer = new CaptionRenderer(_gameResourceProvider, _inputActions, captionImage);
|
||||
ServiceLocator.Instance.Register(_captionRenderer);
|
||||
|
||||
_hotelManager = new HotelManager(_scriptManager, _sceneManager);
|
||||
ServiceLocator.Instance.Register(_hotelManager);
|
||||
|
||||
_bigMapManager = new BigMapManager(eventSystem,
|
||||
_gameStateManager, _sceneManager, _inputManager, _scriptManager,
|
||||
bigMapCanvasGroup, bigMapRegionButtonPrefab, bigMapBackground);
|
||||
ServiceLocator.Instance.Register(_bigMapManager);
|
||||
|
||||
_postProcessManager = new PostProcessManager(postProcessVolume,
|
||||
postProcessLayer, _gameSettings);
|
||||
ServiceLocator.Instance.Register(_postProcessManager);
|
||||
|
||||
_effectManager = new EffectManager(_gameResourceProvider, _sceneManager);
|
||||
ServiceLocator.Instance.Register(_effectManager);
|
||||
|
||||
_mazeSkipper = new MazeSkipper(_sceneManager);
|
||||
ServiceLocator.Instance.Register(_mazeSkipper);
|
||||
|
||||
_renderingSettingsManager = new RenderingSettingsManager(_gameSettings);
|
||||
ServiceLocator.Instance.Register(_renderingSettingsManager);
|
||||
|
||||
#if UNITY_STANDALONE || UNITY_EDITOR
|
||||
_cursorManager = new CursorManager(_gameResourceProvider);
|
||||
ServiceLocator.Instance.Register(_cursorManager);
|
||||
#endif
|
||||
|
||||
#if PAL3
|
||||
_appraisalsMiniGame = new AppraisalsMiniGame();
|
||||
ServiceLocator.Instance.Register(_appraisalsMiniGame);
|
||||
@@ -228,31 +275,17 @@ namespace Pal3
|
||||
ServiceLocator.Instance.Register(_taskManager);
|
||||
#endif
|
||||
|
||||
_videoManager = gameObject.AddComponent<VideoManager>();
|
||||
_videoManager.Init(_gameResourceProvider,
|
||||
_gameStateManager,
|
||||
_inputActions,
|
||||
videoPlayerCanvas,
|
||||
videoPlayer);
|
||||
ServiceLocator.Instance.Register(_videoManager);
|
||||
|
||||
_captionRenderer = gameObject.AddComponent<CaptionRenderer>();
|
||||
_captionRenderer.Init(_gameResourceProvider, _inputActions, captionImage);
|
||||
ServiceLocator.Instance.Register(_captionRenderer);
|
||||
|
||||
_playerGamePlayController = gameObject.AddComponent<PlayerGamePlayController>();
|
||||
_playerGamePlayController.Init(_gameResourceProvider,
|
||||
_playerGamePlayManager = new PlayerGamePlayManager(_gameResourceProvider,
|
||||
_gameStateManager,
|
||||
_playerActorManager,
|
||||
_teamManager,
|
||||
_inputActions,
|
||||
_sceneManager,
|
||||
mainCamera);
|
||||
ServiceLocator.Instance.Register(_playerGamePlayController);
|
||||
ServiceLocator.Instance.Register(_playerGamePlayManager);
|
||||
|
||||
_cameraManager = gameObject.AddComponent<CameraManager>();
|
||||
_cameraManager.Init(_inputActions,
|
||||
_playerGamePlayController,
|
||||
_cameraManager = new CameraManager(_inputActions,
|
||||
_playerGamePlayManager,
|
||||
_sceneManager,
|
||||
_gameStateManager,
|
||||
mainCamera,
|
||||
@@ -260,24 +293,15 @@ namespace Pal3
|
||||
curtainImage);
|
||||
ServiceLocator.Instance.Register(_cameraManager);
|
||||
|
||||
_audioManager = gameObject.AddComponent<AudioManager>();
|
||||
_audioManager.Init(mainCamera,
|
||||
_gameResourceProvider,
|
||||
_sceneManager,
|
||||
musicSource,
|
||||
_gameSettings);
|
||||
ServiceLocator.Instance.Register(_audioManager);
|
||||
|
||||
_informationManager = gameObject.AddComponent<InformationManager>();
|
||||
_informationManager.Init(_gameSettings, noteCanvasGroup, noteText, debugInfo);
|
||||
ServiceLocator.Instance.Register(_informationManager);
|
||||
|
||||
_miniMapManager = gameObject.AddComponent<MiniMapManager>();
|
||||
_miniMapManager.Init(mainCamera, _sceneManager, miniMapCanvasGroup, miniMapImage);
|
||||
_miniMapManager = new MiniMapManager(mainCamera,
|
||||
_sceneManager, miniMapCanvasGroup, miniMapImage);
|
||||
ServiceLocator.Instance.Register(_miniMapManager);
|
||||
|
||||
_dialogueManager = gameObject.AddComponent<DialogueManager>();
|
||||
_dialogueManager.Init(_gameResourceProvider,
|
||||
_informationManager = new InformationManager(_gameSettings,
|
||||
fpsCounter, noteCanvasGroup, noteText, debugInfo);
|
||||
ServiceLocator.Instance.Register(_informationManager);
|
||||
|
||||
_dialogueManager = new DialogueManager(_gameResourceProvider,
|
||||
_gameStateManager,
|
||||
_sceneManager,
|
||||
_inputManager,
|
||||
@@ -293,77 +317,23 @@ namespace Pal3
|
||||
dialogueSelectionButtonPrefab);
|
||||
ServiceLocator.Instance.Register(_dialogueManager);
|
||||
|
||||
#if UNITY_STANDALONE || UNITY_EDITOR
|
||||
_cursorManager = gameObject.AddComponent<CursorManager>();
|
||||
_cursorManager.Init(_gameResourceProvider);
|
||||
ServiceLocator.Instance.Register(_cursorManager);
|
||||
#endif
|
||||
|
||||
_hotelManager = gameObject.AddComponent<HotelManager>();
|
||||
_hotelManager.Init(_scriptManager, _sceneManager);
|
||||
ServiceLocator.Instance.Register(_hotelManager);
|
||||
|
||||
_bigMapManager = gameObject.AddComponent<BigMapManager>();
|
||||
_bigMapManager.Init(eventSystem,
|
||||
_gameStateManager,
|
||||
_sceneManager,
|
||||
_inputManager,
|
||||
_scriptManager,
|
||||
bigMapCanvasGroup,
|
||||
bigMapRegionButtonPrefab,
|
||||
bigMapBackground);
|
||||
ServiceLocator.Instance.Register(_bigMapManager);
|
||||
|
||||
_postProcessManager = gameObject.AddComponent<PostProcessManager>();
|
||||
_postProcessManager.Init(postProcessVolume, postProcessLayer, _gameSettings);
|
||||
ServiceLocator.Instance.Register(_postProcessManager);
|
||||
|
||||
_effectManager = gameObject.AddComponent<EffectManager>();
|
||||
_effectManager.Init(_gameResourceProvider, _sceneManager);
|
||||
ServiceLocator.Instance.Register(_effectManager);
|
||||
|
||||
_saveManager = new SaveManager(_sceneManager,
|
||||
_playerActorManager,
|
||||
_teamManager,
|
||||
_inventoryManager,
|
||||
_sceneStateManager,
|
||||
_bigMapManager,
|
||||
_scriptManager,
|
||||
_favorManager,
|
||||
_saveManager = new SaveManager(_sceneManager, _playerActorManager,
|
||||
_teamManager, _inventoryManager, _sceneStateManager,
|
||||
_bigMapManager, _scriptManager, _favorManager,
|
||||
#if PAL3A
|
||||
_taskManager,
|
||||
#endif
|
||||
_cameraManager,
|
||||
_audioManager,
|
||||
_postProcessManager);
|
||||
_cameraManager, _audioManager, _postProcessManager);
|
||||
ServiceLocator.Instance.Register(_saveManager);
|
||||
|
||||
_mazeSkipper = new MazeSkipper(_sceneManager);
|
||||
ServiceLocator.Instance.Register(_mazeSkipper);
|
||||
|
||||
_mainMenu = gameObject.AddComponent<MainMenu>();
|
||||
_mainMenu.Init(
|
||||
_gameSettings,
|
||||
_inputManager,
|
||||
_sceneManager,
|
||||
_gameStateManager,
|
||||
_scriptManager,
|
||||
_teamManager,
|
||||
_saveManager,
|
||||
_informationManager,
|
||||
_mazeSkipper,
|
||||
mainMenuCanvasGroup,
|
||||
menuButtonPrefab,
|
||||
contentScrollRect,
|
||||
backgroundTransform,
|
||||
contentTransform,
|
||||
eventSystem,
|
||||
mainCamera);
|
||||
_mainMenu = new MainMenu(_gameSettings, _inputManager, _sceneManager,
|
||||
_gameStateManager, _scriptManager, _teamManager,
|
||||
_saveManager,_informationManager, _mazeSkipper,
|
||||
mainMenuCanvasGroup, menuButtonPrefab, contentScrollRect,
|
||||
backgroundTransform, contentTransform, eventSystem, mainCamera);
|
||||
ServiceLocator.Instance.Register(_mainMenu);
|
||||
|
||||
_renderingSettingsManager = gameObject.AddComponent<RenderingSettingsManager>();
|
||||
_renderingSettingsManager.Init(_gameSettings);
|
||||
ServiceLocator.Instance.Register(_renderingSettingsManager);
|
||||
_allRegisteredServices = ServiceLocator.Instance.GetAllRegisteredServices();
|
||||
|
||||
DebugLogManager.Instance.OnLogWindowShown += OnDebugWindowShown;
|
||||
DebugLogManager.Instance.OnLogWindowHidden += OnDebugWindowHidden;
|
||||
@@ -432,8 +402,12 @@ namespace Pal3
|
||||
|
||||
void OnAnyKeyOrTouchTriggered()
|
||||
{
|
||||
if (!Application.isPlaying) return;
|
||||
|
||||
InputSystem.onEvent -= OnInputEvent; // Only listen to the first touch event.
|
||||
Destroy(logoImage.sprite.texture);
|
||||
Destroy(logoImage.sprite);
|
||||
Destroy(logoImage);
|
||||
Destroy(logoCanvas);
|
||||
StartCoroutine(ShowMainMenuAfterLogoAsync());
|
||||
}
|
||||
@@ -467,58 +441,52 @@ namespace Pal3
|
||||
});
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
/// <summary>
|
||||
/// Main game loop.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
_gameSettings.Dispose();
|
||||
_gameResourceProvider.Dispose();
|
||||
_fileSystemCacheManager.Dispose();
|
||||
_inputManager.Dispose();
|
||||
_inputActions.Dispose();
|
||||
_gameStateManager.Dispose();
|
||||
_sceneStateManager.Dispose();
|
||||
_scriptManager.Dispose();
|
||||
_playerActorManager.Dispose();
|
||||
_inventoryManager.Dispose();
|
||||
_teamManager.Dispose();
|
||||
_sceneManager.Dispose();
|
||||
_touchControlUIManager.Dispose();
|
||||
_favorManager.Dispose();
|
||||
_saveManager.Dispose();
|
||||
var deltaTime = Time.deltaTime;
|
||||
|
||||
#if PAL3
|
||||
_appraisalsMiniGame.Dispose();
|
||||
_sailingMiniGame.Dispose();
|
||||
_hideFightMiniGame.Dispose();
|
||||
_encampMiniGame.Dispose();
|
||||
_skiMiniGame.Dispose();
|
||||
_swatAFlyMiniGame.Dispose();
|
||||
_caveExperienceMiniGame.Dispose();
|
||||
#elif PAL3A
|
||||
_taskManager.Dispose();
|
||||
#endif
|
||||
|
||||
Destroy(_videoManager);
|
||||
Destroy(_playerGamePlayController);
|
||||
Destroy(_cameraManager);
|
||||
Destroy(_audioManager);
|
||||
Destroy(_informationManager);
|
||||
Destroy(_miniMapManager);
|
||||
Destroy(_dialogueManager);
|
||||
Destroy(_hotelManager);
|
||||
Destroy(_bigMapManager);
|
||||
Destroy(_captionRenderer);
|
||||
Destroy(_postProcessManager);
|
||||
Destroy(_effectManager);
|
||||
Destroy(_mainMenu);
|
||||
Destroy(_renderingSettingsManager);
|
||||
|
||||
if (_cursorManager != null)
|
||||
GameState currentState = _gameStateManager.GetCurrentState();
|
||||
if (currentState != GameState.VideoPlaying)
|
||||
{
|
||||
Destroy(_cursorManager);
|
||||
_scriptManager.Update(deltaTime);
|
||||
_playerGamePlayManager.Update(deltaTime);
|
||||
_dialogueManager.Update(deltaTime);
|
||||
}
|
||||
|
||||
_informationManager.Update(deltaTime);
|
||||
_renderingSettingsManager.Update(deltaTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main game late update loop.
|
||||
/// </summary>
|
||||
private void LateUpdate()
|
||||
{
|
||||
var deltaTime = Time.deltaTime;
|
||||
|
||||
GameState currentState = _gameStateManager.GetCurrentState();
|
||||
if (currentState != GameState.VideoPlaying)
|
||||
{
|
||||
_cameraManager.LateUpdate(deltaTime);
|
||||
_miniMapManager.LateUpdate(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
DebugLogManager.Instance.OnLogWindowShown -= OnDebugWindowShown;
|
||||
DebugLogManager.Instance.OnLogWindowHidden -= OnDebugWindowHidden;
|
||||
|
||||
foreach (IDisposable service in _allRegisteredServices.Where(s => s is IDisposable))
|
||||
{
|
||||
Debug.Log($"[{nameof(Pal3)}] Disposing service {service.GetType().Name}.");
|
||||
service.Dispose();
|
||||
}
|
||||
|
||||
Debug.Log($"[{nameof(Pal3)}] Game exited.");
|
||||
}
|
||||
|
||||
private void OnDebugWindowShown()
|
||||
@@ -546,15 +514,6 @@ namespace Pal3
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
GameState currentState = _gameStateManager.GetCurrentState();
|
||||
if (currentState is GameState.Cutscene or GameState.Gameplay)
|
||||
{
|
||||
_scriptManager.Update(Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrintCurrentGameStateInCommandsForm()
|
||||
{
|
||||
var commands = _saveManager.ConvertCurrentGameStateToCommands(SaveLevel.Minimal);
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
{
|
||||
using Core.GameBox;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Lit material factory for generating materials
|
||||
/// to be used when lighting and shadow are enabled
|
||||
/// </summary>
|
||||
public class LitMaterialFactory : MaterialFactoryBase, IMaterialFactory
|
||||
{
|
||||
// Toon material uniforms
|
||||
private static readonly int BlendSrcFactorPropertyId = Shader.PropertyToID("_BlendSrcFactor");
|
||||
private static readonly int BlendDstFactorPropertyId = Shader.PropertyToID("_BlendDstFactor");
|
||||
private static readonly int CutoutPropertyId = Shader.PropertyToID("_Cutout");
|
||||
private static readonly int LightIntensityPropertyId = Shader.PropertyToID("_LightIntensity");
|
||||
private static readonly int OpacityPropertyId = Shader.PropertyToID("_Opacity");
|
||||
private static readonly int EnvironmentalLightingIntensityPropertyId = Shader.PropertyToID("_EnvironmentalLightingIntensity");
|
||||
|
||||
private readonly Material _toonDefaultMaterial;
|
||||
private readonly Material _toonTransparentMaterial;
|
||||
private readonly Shader _toonDefaultShader;
|
||||
private readonly Shader _toonTransparentShader;
|
||||
|
||||
public LitMaterialFactory(
|
||||
Material toonDefaultMaterial,
|
||||
Material toonTransparentMaterial)
|
||||
{
|
||||
_toonDefaultMaterial = toonDefaultMaterial;
|
||||
_toonTransparentMaterial = toonTransparentMaterial;
|
||||
|
||||
_toonDefaultShader = toonDefaultMaterial.shader;
|
||||
_toonTransparentShader = toonTransparentMaterial.shader;
|
||||
}
|
||||
|
||||
public MaterialShaderType ShaderType { get; } = MaterialShaderType.Lit;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Material[] CreateStandardMaterials(
|
||||
RendererType rendererType,
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
Material[] materials = null;
|
||||
|
||||
if (blendFlag is GameBoxBlendFlag.AlphaBlend or GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
#if PAL3
|
||||
// These are the texture/materials that have to be transparent in the game
|
||||
// m23-3-05.tga => transparent doom like structure in PAL3 scene M23-3
|
||||
// Q08QN10-05.tga => transparent coffin in PAL3 scene Q08-QN10
|
||||
// TODO: Add more if needed
|
||||
bool useTransparentMaterial = mainTexture.name is "m23-3-05.tga" or "Q08QN10-05.tga" ||
|
||||
blendFlag == GameBoxBlendFlag.InvertColorBlend;
|
||||
#elif PAL3A
|
||||
bool useTransparentMaterial = blendFlag == GameBoxBlendFlag.InvertColorBlend;
|
||||
#endif
|
||||
|
||||
materials = new Material[1];
|
||||
materials[0] = useTransparentMaterial
|
||||
? CreateBaseTransparentMaterial(mainTexture)
|
||||
: CreateBaseOpaqueMaterial(mainTexture);
|
||||
|
||||
if (!useTransparentMaterial)
|
||||
{
|
||||
materials[0].SetFloat(CutoutPropertyId, 0.3f);
|
||||
}
|
||||
|
||||
if (blendFlag == GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
materials[0].SetInt(BlendSrcFactorPropertyId, (int)BlendMode.SrcAlpha);
|
||||
materials[0].SetInt(BlendDstFactorPropertyId, (int)BlendMode.One);
|
||||
}
|
||||
}
|
||||
else if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
materials = new Material[1];
|
||||
materials[0] = CreateBaseOpaqueMaterial(mainTexture);
|
||||
}
|
||||
|
||||
if (materials != null && rendererType == RendererType.Mv3)
|
||||
{
|
||||
// This is to make the shadow on actor lighter
|
||||
materials[0].SetFloat(LightIntensityPropertyId, -0.5f);
|
||||
}
|
||||
|
||||
return materials;
|
||||
}
|
||||
|
||||
public void UpdateMaterial(Material material, Texture2D newMainTexture, GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
material.mainTexture = newMainTexture;
|
||||
|
||||
if (blendFlag is GameBoxBlendFlag.AlphaBlend or GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
material.SetFloat(CutoutPropertyId, 0.3f);
|
||||
}
|
||||
else if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
material.SetFloat(CutoutPropertyId, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Material CreateWaterMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
float opacity,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
opacity = 1.0f;
|
||||
}
|
||||
|
||||
// This is a tweak to make the water surface look better
|
||||
// when lit materials are used
|
||||
opacity = opacity < 0.8f ? 0.8f : opacity;
|
||||
|
||||
// No need to use transparent material if alpha is close to 1
|
||||
bool useTransparentMaterial = opacity < 0.9f;
|
||||
|
||||
if (useTransparentMaterial)
|
||||
{
|
||||
Material material = CreateBaseTransparentMaterial(mainTexture);
|
||||
material.SetFloat(OpacityPropertyId, opacity);
|
||||
material.SetFloat(EnvironmentalLightingIntensityPropertyId, 0.3f);
|
||||
return material;
|
||||
}
|
||||
else
|
||||
{
|
||||
Material material = CreateBaseOpaqueMaterial(mainTexture);
|
||||
material.SetFloat(EnvironmentalLightingIntensityPropertyId, 0.5f);
|
||||
return material;
|
||||
}
|
||||
}
|
||||
|
||||
private Material CreateBaseTransparentMaterial((string name, Texture2D texture) mainTexture)
|
||||
{
|
||||
Material material = new Material(_toonTransparentShader);
|
||||
material.CopyPropertiesFromMaterial(_toonTransparentMaterial);
|
||||
material.mainTexture = mainTexture.texture;
|
||||
return material;
|
||||
}
|
||||
|
||||
private Material CreateBaseOpaqueMaterial((string name, Texture2D texture) mainTexture)
|
||||
{
|
||||
Material material = new Material(_toonDefaultShader);
|
||||
material.CopyPropertiesFromMaterial(_toonDefaultMaterial);
|
||||
material.mainTexture = mainTexture.texture;
|
||||
return material;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
{
|
||||
using Core.GameBox;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Unlit material factory for generating materials that have similar
|
||||
/// look and feel as the original game
|
||||
/// </summary>
|
||||
public class UnlitMaterialFactory : MaterialFactoryBase, IMaterialFactory
|
||||
{
|
||||
// Pal3 unlit shaders
|
||||
private const string OPAQUE_SHADER_PATH = "Pal3/Opaque";
|
||||
private const string TRANSPARENT_SHADER_PATH = "Pal3/Transparent";
|
||||
private const string TRANSPARENT_OPAQUE_PART_SHADER_PATH = "Pal3/TransparentOpaquePart";
|
||||
private const string WATER_SHADER_PATH = "Pal3/Water";
|
||||
|
||||
// Water material uniforms
|
||||
private static readonly int WaterMainTexPropId = Shader.PropertyToID("_MainTex");
|
||||
private static readonly int WaterShadowTexPropId = Shader.PropertyToID("_ShadowTex");
|
||||
private static readonly int WaterAlphaPropId = Shader.PropertyToID("_Alpha");
|
||||
private static readonly int WaterHasShadowTexPropId = Shader.PropertyToID("_HasShadowTex");
|
||||
|
||||
// Standard material uniforms for Pal3 unlit shaders
|
||||
private static readonly int BlendSrcFactorPropertyId = Shader.PropertyToID("_BlendSrcFactor");
|
||||
private static readonly int BlendDstFactorPropertyId = Shader.PropertyToID("_BlendDstFactor");
|
||||
private static readonly int MainTexturePropertyId = Shader.PropertyToID("_MainTex");
|
||||
private static readonly int TintColorPropertyId = Shader.PropertyToID("_TintColor");
|
||||
private static readonly int TransparentThresholdPropertyId = Shader.PropertyToID("_Threshold");
|
||||
private static readonly int HasShadowTexturePropertyId = Shader.PropertyToID("_HasShadowTex");
|
||||
private static readonly int ShadowTexturePropertyId = Shader.PropertyToID("_ShadowTex");
|
||||
|
||||
private const float DEFAULT_TRANSPARENT_THRESHOLD = 0.9f;
|
||||
|
||||
public MaterialShaderType ShaderType { get; } = MaterialShaderType.Unlit;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Material CreateWaterMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
float opacity,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
var material = new Material(GetShader(WATER_SHADER_PATH));
|
||||
material.SetTexture(WaterMainTexPropId,mainTexture.texture);
|
||||
material.SetFloat(WaterAlphaPropId, opacity);
|
||||
if (shadowTexture.texture != null)
|
||||
{
|
||||
material.SetFloat(WaterHasShadowTexPropId, 1.0f);
|
||||
material.SetTexture(WaterShadowTexPropId, shadowTexture.texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.SetFloat(WaterHasShadowTexPropId, 0.5f);
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Material[] CreateStandardMaterials(
|
||||
RendererType rendererType,
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
Material[] materials = null;
|
||||
|
||||
float transparentThreshold = DEFAULT_TRANSPARENT_THRESHOLD;
|
||||
|
||||
if (shadowTexture.texture == null && rendererType == RendererType.Pol)
|
||||
{
|
||||
transparentThreshold = 1.0f;
|
||||
}
|
||||
|
||||
if (blendFlag is GameBoxBlendFlag.AlphaBlend or GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
materials = new Material[2];
|
||||
materials[0] = CreateTransparentOpaquePartMaterial(mainTexture,
|
||||
shadowTexture,
|
||||
tintColor,
|
||||
transparentThreshold);
|
||||
materials[1] = CreateTransparentMaterial(mainTexture,
|
||||
shadowTexture,
|
||||
tintColor,
|
||||
transparentThreshold);
|
||||
|
||||
BlendMode srcFactor;
|
||||
BlendMode destFactor;
|
||||
|
||||
if (blendFlag == GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
srcFactor = BlendMode.SrcAlpha;
|
||||
destFactor = BlendMode.One;
|
||||
}
|
||||
else
|
||||
{
|
||||
srcFactor = BlendMode.SrcAlpha;
|
||||
destFactor = BlendMode.OneMinusSrcAlpha;
|
||||
}
|
||||
|
||||
materials[1].SetInt(BlendSrcFactorPropertyId, (int)srcFactor);
|
||||
materials[1].SetInt(BlendDstFactorPropertyId, (int)destFactor);
|
||||
}
|
||||
else if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
materials = new Material[1];
|
||||
materials[0] = CreateOpaqueMaterial(mainTexture, shadowTexture, tintColor);
|
||||
}
|
||||
|
||||
return materials;
|
||||
}
|
||||
|
||||
public void UpdateMaterial(Material material,
|
||||
Texture2D newMainTexture,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
material.mainTexture = newMainTexture;
|
||||
|
||||
if (blendFlag is GameBoxBlendFlag.AlphaBlend or GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
material.SetFloat(TransparentThresholdPropertyId, DEFAULT_TRANSPARENT_THRESHOLD);
|
||||
}
|
||||
else if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
material.SetFloat(TransparentThresholdPropertyId, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
private Material CreateTransparentMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor,
|
||||
float transparentThreshold)
|
||||
{
|
||||
var material = new Material(GetShader(TRANSPARENT_SHADER_PATH));
|
||||
material.SetTexture(MainTexturePropertyId, mainTexture.texture);
|
||||
material.SetColor(TintColorPropertyId, tintColor);
|
||||
material.SetFloat(TransparentThresholdPropertyId, transparentThreshold);
|
||||
|
||||
// shadow texture
|
||||
material.SetFloat(HasShadowTexturePropertyId, 0.0f);
|
||||
if (shadowTexture.texture != null)
|
||||
{
|
||||
material.SetFloat(HasShadowTexturePropertyId, 1.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, shadowTexture.texture);
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
private Material CreateTransparentOpaquePartMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor,
|
||||
float transparentThreshold)
|
||||
{
|
||||
Material material = new Material(GetShader(TRANSPARENT_OPAQUE_PART_SHADER_PATH));
|
||||
material.SetTexture(MainTexturePropertyId, mainTexture.texture);
|
||||
material.SetColor(TintColorPropertyId, tintColor);
|
||||
material.SetFloat(TransparentThresholdPropertyId, transparentThreshold);
|
||||
|
||||
// shadow
|
||||
material.SetFloat(HasShadowTexturePropertyId, 0.0f);
|
||||
if (shadowTexture.texture != null)
|
||||
{
|
||||
material.SetFloat(HasShadowTexturePropertyId, 1.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, shadowTexture.texture);
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
private Material CreateOpaqueMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor)
|
||||
{
|
||||
Material material = new Material(GetShader(OPAQUE_SHADER_PATH));
|
||||
material.SetTexture(MainTexturePropertyId, mainTexture.texture);
|
||||
material.SetColor(TintColorPropertyId, tintColor);
|
||||
|
||||
// shadow
|
||||
material.SetFloat(HasShadowTexturePropertyId, 0.0f);
|
||||
if (shadowTexture.texture != null)
|
||||
{
|
||||
material.SetFloat(HasShadowTexturePropertyId, 1.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, shadowTexture.texture);
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0609d6afd87fc544b9484decc3b2a4f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+17
-1
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
namespace Pal3.Rendering.Material
|
||||
{
|
||||
using Core.GameBox;
|
||||
using UnityEngine;
|
||||
@@ -70,5 +70,21 @@ namespace Pal3.Renderer
|
||||
public void UpdateMaterial(Material material,
|
||||
Texture2D newMainTexture,
|
||||
GameBoxBlendFlag blendFlag);
|
||||
|
||||
/// <summary>
|
||||
/// Allocate a pool of materials.
|
||||
/// </summary>
|
||||
public void AllocateMaterialPool();
|
||||
|
||||
/// <summary>
|
||||
/// Deallocate the material pool.
|
||||
/// </summary>
|
||||
public void DeallocateMaterialPool();
|
||||
|
||||
/// <summary>
|
||||
/// Return materials to the pool.
|
||||
/// </summary>
|
||||
/// <param name="materials">Materials to return</param>
|
||||
public void ReturnToPool(Material[] materials);
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,310 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Rendering.Material
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Core.GameBox;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using Debug = UnityEngine.Debug;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
/// <summary>
|
||||
/// Lit material factory for generating materials
|
||||
/// to be used when lighting and shadow are enabled
|
||||
/// </summary>
|
||||
public class LitMaterialFactory : MaterialFactoryBase, IMaterialFactory
|
||||
{
|
||||
// Toon material uniforms
|
||||
private static readonly int BlendSrcFactorPropertyId = Shader.PropertyToID("_BlendSrcFactor");
|
||||
private static readonly int BlendDstFactorPropertyId = Shader.PropertyToID("_BlendDstFactor");
|
||||
private static readonly int CutoutPropertyId = Shader.PropertyToID("_Cutout");
|
||||
private static readonly int LightIntensityPropertyId = Shader.PropertyToID("_LightIntensity");
|
||||
private static readonly int OpacityPropertyId = Shader.PropertyToID("_Opacity");
|
||||
private static readonly int EnvironmentalLightingIntensityPropertyId = Shader.PropertyToID("_EnvironmentalLightingIntensity");
|
||||
|
||||
private readonly Material _toonOpaqueMaterial;
|
||||
private readonly Material _toonTransparentMaterial;
|
||||
|
||||
private const string OPAQUE_MATERIAL_SHADER_NAME = "RealToon/Version 5/Default/Default";
|
||||
private const string TRANSPARENT_MATERIAL_SHADER_NAME = "RealToon/Version 5/Default/Fade Transparency";
|
||||
|
||||
private const int OPAQUE_MATERIAL_POOL_SIZE = 3500;
|
||||
private const int TRANSPARENT_MATERIAL_POOL_SIZE = 500;
|
||||
|
||||
private readonly Stack<Material> _opaqueMaterialPool = new (OPAQUE_MATERIAL_POOL_SIZE);
|
||||
private readonly Stack<Material> _transparentMaterialPool = new (TRANSPARENT_MATERIAL_POOL_SIZE);
|
||||
|
||||
private readonly float _opaqueMaterialCutoutPropertyDefaultValue;
|
||||
private readonly float _opaqueMaterialLightIntensityPropertyDefaultValue;
|
||||
private readonly float _opaqueMaterialEnvironmentalLightingIntensityPropertyDefaultValue;
|
||||
|
||||
private readonly int _transparentMaterialBlendSrcFactorPropertyDefaultValue;
|
||||
private readonly int _transparentMaterialBlendDstFactorPropertyDefaultValue;
|
||||
private readonly float _transparentMaterialOpacityPropertyDefaultValue;
|
||||
private readonly float _transparentMaterialLightIntensityPropertyDefaultValue;
|
||||
private readonly float _transparentMaterialEnvironmentalLightingIntensityPropertyDefaultValue;
|
||||
|
||||
private bool _isMaterialPoolAllocated = false;
|
||||
|
||||
public LitMaterialFactory(
|
||||
Material toonOpaqueMaterial,
|
||||
Material toonTransparentMaterial)
|
||||
{
|
||||
_toonOpaqueMaterial = toonOpaqueMaterial;
|
||||
_toonTransparentMaterial = toonTransparentMaterial;
|
||||
|
||||
_opaqueMaterialCutoutPropertyDefaultValue =
|
||||
_toonOpaqueMaterial.GetFloat(CutoutPropertyId);
|
||||
_opaqueMaterialLightIntensityPropertyDefaultValue =
|
||||
_toonOpaqueMaterial.GetFloat(LightIntensityPropertyId);
|
||||
_opaqueMaterialEnvironmentalLightingIntensityPropertyDefaultValue =
|
||||
_toonOpaqueMaterial.GetFloat(EnvironmentalLightingIntensityPropertyId);
|
||||
|
||||
_transparentMaterialBlendSrcFactorPropertyDefaultValue =
|
||||
_toonTransparentMaterial.GetInt(BlendSrcFactorPropertyId);
|
||||
_transparentMaterialBlendDstFactorPropertyDefaultValue =
|
||||
_toonTransparentMaterial.GetInt(BlendDstFactorPropertyId);
|
||||
_transparentMaterialOpacityPropertyDefaultValue = _toonTransparentMaterial.GetFloat(OpacityPropertyId);
|
||||
_transparentMaterialLightIntensityPropertyDefaultValue =
|
||||
_toonTransparentMaterial.GetFloat(LightIntensityPropertyId);
|
||||
_transparentMaterialEnvironmentalLightingIntensityPropertyDefaultValue =
|
||||
_toonTransparentMaterial.GetFloat(EnvironmentalLightingIntensityPropertyId);
|
||||
}
|
||||
|
||||
public void AllocateMaterialPool()
|
||||
{
|
||||
if (_isMaterialPoolAllocated) return;
|
||||
|
||||
var timer = new Stopwatch();
|
||||
timer.Start();
|
||||
|
||||
for (var i = 0; i < OPAQUE_MATERIAL_POOL_SIZE; i++)
|
||||
{
|
||||
_opaqueMaterialPool.Push(new Material(_toonOpaqueMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0; i < TRANSPARENT_MATERIAL_POOL_SIZE; i++)
|
||||
{
|
||||
_transparentMaterialPool.Push(new Material(_toonTransparentMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
});
|
||||
}
|
||||
|
||||
_isMaterialPoolAllocated = true;
|
||||
|
||||
timer.Stop();
|
||||
Debug.Log($"[{nameof(LitMaterialFactory)}] Material pool allocated in {timer.ElapsedMilliseconds} ms.");
|
||||
}
|
||||
|
||||
public void DeallocateMaterialPool()
|
||||
{
|
||||
var timer = new Stopwatch();
|
||||
timer.Start();
|
||||
|
||||
while (_opaqueMaterialPool.Count > 0)
|
||||
{
|
||||
Object.Destroy(_opaqueMaterialPool.Pop());
|
||||
}
|
||||
|
||||
while (_transparentMaterialPool.Count > 0)
|
||||
{
|
||||
Object.Destroy(_transparentMaterialPool.Pop());
|
||||
}
|
||||
|
||||
_isMaterialPoolAllocated = false;
|
||||
|
||||
timer.Stop();
|
||||
Debug.Log($"[{nameof(LitMaterialFactory)}] Material pool de-allocated in {timer.ElapsedMilliseconds} ms.");
|
||||
}
|
||||
|
||||
public MaterialShaderType ShaderType => MaterialShaderType.Lit;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Material[] CreateStandardMaterials(
|
||||
RendererType rendererType,
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
Material[] materials = null;
|
||||
|
||||
if (blendFlag is GameBoxBlendFlag.AlphaBlend or GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
#if PAL3
|
||||
// These are the texture/materials that have to be transparent in the game
|
||||
// m23-3-05.tga => transparent doom like structure in PAL3 scene M23-3
|
||||
// Q08QN10-05.tga => transparent coffin in PAL3 scene Q08-QN10
|
||||
// m25-2-05.tga => transparent roof in PAL3 scene M25-2
|
||||
// TODO: Add more if needed, by default we use opaque material
|
||||
bool useTransparentMaterial = blendFlag == GameBoxBlendFlag.InvertColorBlend ||
|
||||
mainTexture.name.Equals("m23-3-05.tga", StringComparison.OrdinalIgnoreCase) ||
|
||||
mainTexture.name.Equals("Q08QN10-05.tga", StringComparison.OrdinalIgnoreCase) ||
|
||||
mainTexture.name.Equals("m25-2-05.tga", StringComparison.OrdinalIgnoreCase);
|
||||
#elif PAL3A
|
||||
bool useTransparentMaterial = blendFlag == GameBoxBlendFlag.InvertColorBlend;
|
||||
#endif
|
||||
|
||||
// For CVD renderer, we always use transparent material if blendFlag is
|
||||
// InvertColorBlend or AlphaBlend
|
||||
if (rendererType == RendererType.Cvd) useTransparentMaterial = true;
|
||||
|
||||
materials = new Material[1];
|
||||
materials[0] = useTransparentMaterial
|
||||
? CreateBaseTransparentMaterial(mainTexture)
|
||||
: CreateBaseOpaqueMaterial(mainTexture);
|
||||
|
||||
if (!useTransparentMaterial)
|
||||
{
|
||||
materials[0].SetFloat(CutoutPropertyId, 0.3f);
|
||||
}
|
||||
|
||||
if (blendFlag == GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
materials[0].SetInt(BlendSrcFactorPropertyId, (int)BlendMode.SrcAlpha);
|
||||
materials[0].SetInt(BlendDstFactorPropertyId, (int)BlendMode.One);
|
||||
}
|
||||
}
|
||||
else if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
materials = new Material[1];
|
||||
materials[0] = CreateBaseOpaqueMaterial(mainTexture);
|
||||
}
|
||||
|
||||
if (materials != null && rendererType == RendererType.Mv3)
|
||||
{
|
||||
// This is to make the shadow on actor lighter
|
||||
materials[0].SetFloat(LightIntensityPropertyId, -0.5f);
|
||||
}
|
||||
|
||||
return materials;
|
||||
}
|
||||
|
||||
public void UpdateMaterial(Material material, Texture2D newMainTexture, GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
material.mainTexture = newMainTexture;
|
||||
|
||||
if (blendFlag is GameBoxBlendFlag.AlphaBlend or GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
material.SetFloat(CutoutPropertyId, 0.3f);
|
||||
}
|
||||
else if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
material.SetFloat(CutoutPropertyId, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Material CreateWaterMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
float opacity,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
opacity = 1.0f;
|
||||
}
|
||||
|
||||
// This is a tweak to make the water surface look better
|
||||
// when lit materials are used
|
||||
opacity = opacity < 0.8f ? 0.8f : opacity;
|
||||
|
||||
// No need to use transparent material if alpha is close to 1
|
||||
bool useTransparentMaterial = opacity < 0.9f;
|
||||
|
||||
if (useTransparentMaterial)
|
||||
{
|
||||
Material material = CreateBaseTransparentMaterial(mainTexture);
|
||||
material.SetFloat(OpacityPropertyId, opacity);
|
||||
material.SetFloat(EnvironmentalLightingIntensityPropertyId, 0.3f);
|
||||
return material;
|
||||
}
|
||||
else
|
||||
{
|
||||
Material material = CreateBaseOpaqueMaterial(mainTexture);
|
||||
material.SetFloat(EnvironmentalLightingIntensityPropertyId, 0.5f);
|
||||
return material;
|
||||
}
|
||||
}
|
||||
|
||||
private Material CreateBaseTransparentMaterial((string name, Texture2D texture) mainTexture)
|
||||
{
|
||||
if (_transparentMaterialPool.Count > 0)
|
||||
{
|
||||
Material material = _transparentMaterialPool.Pop();
|
||||
// Reset material properties
|
||||
material.SetInt(BlendSrcFactorPropertyId,
|
||||
_transparentMaterialBlendSrcFactorPropertyDefaultValue);
|
||||
material.SetInt(BlendDstFactorPropertyId,
|
||||
_transparentMaterialBlendDstFactorPropertyDefaultValue);
|
||||
material.SetFloat(OpacityPropertyId,
|
||||
_transparentMaterialOpacityPropertyDefaultValue);
|
||||
material.SetFloat(LightIntensityPropertyId,
|
||||
_transparentMaterialLightIntensityPropertyDefaultValue);
|
||||
material.SetFloat(EnvironmentalLightingIntensityPropertyId,
|
||||
_transparentMaterialEnvironmentalLightingIntensityPropertyDefaultValue);
|
||||
material.mainTexture = mainTexture.texture;
|
||||
return material;
|
||||
}
|
||||
|
||||
// In case we run out of transparent materials
|
||||
return new Material(_toonTransparentMaterial)
|
||||
{
|
||||
mainTexture = mainTexture.texture,
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
};
|
||||
}
|
||||
|
||||
private Material CreateBaseOpaqueMaterial((string name, Texture2D texture) mainTexture)
|
||||
{
|
||||
if (_opaqueMaterialPool.Count > 0)
|
||||
{
|
||||
Material material = _opaqueMaterialPool.Pop();
|
||||
// Reset material properties
|
||||
material.SetFloat(CutoutPropertyId,
|
||||
_opaqueMaterialCutoutPropertyDefaultValue);
|
||||
material.SetFloat(LightIntensityPropertyId,
|
||||
_opaqueMaterialLightIntensityPropertyDefaultValue);
|
||||
material.SetFloat(EnvironmentalLightingIntensityPropertyId,
|
||||
_opaqueMaterialEnvironmentalLightingIntensityPropertyDefaultValue);
|
||||
material.mainTexture = mainTexture.texture;
|
||||
return material;
|
||||
}
|
||||
|
||||
// In case we run out of opaque materials
|
||||
return new Material(_toonOpaqueMaterial)
|
||||
{
|
||||
mainTexture = mainTexture.texture,
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
};
|
||||
}
|
||||
|
||||
protected override void ReturnToPool(Material material)
|
||||
{
|
||||
switch (material.shader.name)
|
||||
{
|
||||
case TRANSPARENT_MATERIAL_SHADER_NAME:
|
||||
material.mainTexture = null;
|
||||
_transparentMaterialPool.Push(material);
|
||||
break;
|
||||
case OPAQUE_MATERIAL_SHADER_NAME:
|
||||
material.mainTexture = null;
|
||||
_opaqueMaterialPool.Push(material);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+13
-1
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
namespace Pal3.Rendering.Material
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -42,5 +42,17 @@ namespace Pal3.Renderer
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
public void ReturnToPool(Material[] materials)
|
||||
{
|
||||
if (materials == null) return;
|
||||
|
||||
foreach (Material material in materials)
|
||||
{
|
||||
ReturnToPool(material);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ReturnToPool(Material material) { }
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,392 @@
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Rendering.Material
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Core.GameBox;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
/// <summary>
|
||||
/// Unlit material factory for generating materials that have similar
|
||||
/// look and feel as the original game
|
||||
/// </summary>
|
||||
public class UnlitMaterialFactory : MaterialFactoryBase, IMaterialFactory
|
||||
{
|
||||
// Pal3 unlit shaders
|
||||
private const string OPAQUE_SHADER_PATH = "Pal3/Opaque";
|
||||
private const string TRANSPARENT_SHADER_PATH = "Pal3/Transparent";
|
||||
private const string TRANSPARENT_OPAQUE_PART_SHADER_PATH = "Pal3/TransparentOpaquePart";
|
||||
private const string WATER_SHADER_PATH = "Pal3/Water";
|
||||
|
||||
private const string OPAQUE_SHADER_NAME = "Pal3/Opaque";
|
||||
private const string TRANSPARENT_SHADER_NAME = "Pal3/Transparent";
|
||||
private const string TRANSPARENT_OPAQUE_PART_SHADER_NAME = "Pal3/TransparentOpaquePart";
|
||||
private const string WATER_SHADER_NAME = "Pal3/Water";
|
||||
|
||||
// Water material uniforms
|
||||
private static readonly int WaterAlphaPropId = Shader.PropertyToID("_Alpha");
|
||||
private static readonly int WaterHasShadowTexPropId = Shader.PropertyToID("_HasShadowTex");
|
||||
|
||||
// Standard material uniforms for Pal3 unlit shaders
|
||||
private static readonly int BlendSrcFactorPropertyId = Shader.PropertyToID("_BlendSrcFactor");
|
||||
private static readonly int BlendDstFactorPropertyId = Shader.PropertyToID("_BlendDstFactor");
|
||||
private static readonly int TintColorPropertyId = Shader.PropertyToID("_TintColor");
|
||||
private static readonly int TransparentThresholdPropertyId = Shader.PropertyToID("_Threshold");
|
||||
private static readonly int HasShadowTexturePropertyId = Shader.PropertyToID("_HasShadowTex");
|
||||
private static readonly int ShadowTexturePropertyId = Shader.PropertyToID("_ShadowTex");
|
||||
|
||||
private const float DEFAULT_TRANSPARENT_THRESHOLD = 0.9f;
|
||||
|
||||
public MaterialShaderType ShaderType => MaterialShaderType.Unlit;
|
||||
|
||||
private readonly Material _waterMaterial;
|
||||
private readonly Material _transparentMaterial;
|
||||
private readonly Material _transparentOpaquePartMaterial;
|
||||
private readonly Material _opaqueMaterial;
|
||||
|
||||
private const int WATER_MATERIAL_POOL_SIZE = 100;
|
||||
private const int TRANSPARENT_MATERIAL_POOL_SIZE = 1500;
|
||||
private const int TRANSPARENT_OPAQUE_PART_MATERIAL_POOL_SIZE = 1500;
|
||||
private const int OPAQUE_MATERIAL_POOL_SIZE = 2000;
|
||||
|
||||
private readonly Stack<Material> _waterMaterialPool = new (WATER_MATERIAL_POOL_SIZE);
|
||||
private readonly Stack<Material> _transparentMaterialPool = new (TRANSPARENT_MATERIAL_POOL_SIZE);
|
||||
private readonly Stack<Material> _transparentOpaquePartMaterialPool = new (TRANSPARENT_OPAQUE_PART_MATERIAL_POOL_SIZE);
|
||||
private readonly Stack<Material> _opaqueMaterialPool = new (OPAQUE_MATERIAL_POOL_SIZE);
|
||||
|
||||
private bool _isMaterialPoolAllocated = false;
|
||||
|
||||
public UnlitMaterialFactory()
|
||||
{
|
||||
_waterMaterial = new Material(GetShader(WATER_SHADER_PATH));
|
||||
_transparentMaterial = new Material(GetShader(TRANSPARENT_SHADER_PATH));
|
||||
_transparentOpaquePartMaterial = new Material(GetShader(TRANSPARENT_OPAQUE_PART_SHADER_PATH));
|
||||
_opaqueMaterial = new Material(GetShader(OPAQUE_SHADER_PATH));
|
||||
}
|
||||
|
||||
public void AllocateMaterialPool()
|
||||
{
|
||||
if (_isMaterialPoolAllocated) return;
|
||||
|
||||
var timer = new Stopwatch();
|
||||
timer.Start();
|
||||
|
||||
for (var i = 0; i < WATER_MATERIAL_POOL_SIZE; i++)
|
||||
{
|
||||
_waterMaterialPool.Push(new Material(_waterMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0; i < TRANSPARENT_MATERIAL_POOL_SIZE; i++)
|
||||
{
|
||||
_transparentMaterialPool.Push(new Material(_transparentMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0; i < TRANSPARENT_OPAQUE_PART_MATERIAL_POOL_SIZE; i++)
|
||||
{
|
||||
_transparentOpaquePartMaterialPool.Push(new Material(_transparentOpaquePartMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0; i < OPAQUE_MATERIAL_POOL_SIZE; i++)
|
||||
{
|
||||
_opaqueMaterialPool.Push(new Material(_opaqueMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
});
|
||||
}
|
||||
|
||||
timer.Stop();
|
||||
Debug.Log($"[{nameof(UnlitMaterialFactory)}] Material pool allocated in {timer.ElapsedMilliseconds} ms.");
|
||||
}
|
||||
|
||||
public void DeallocateMaterialPool()
|
||||
{
|
||||
var timer = new Stopwatch();
|
||||
timer.Start();
|
||||
|
||||
while (_waterMaterialPool.Count > 0)
|
||||
{
|
||||
Object.Destroy(_waterMaterialPool.Pop());
|
||||
}
|
||||
|
||||
while (_transparentMaterialPool.Count > 0)
|
||||
{
|
||||
Object.Destroy(_transparentMaterialPool.Pop());
|
||||
}
|
||||
|
||||
while (_transparentOpaquePartMaterialPool.Count > 0)
|
||||
{
|
||||
Object.Destroy(_transparentOpaquePartMaterialPool.Pop());
|
||||
}
|
||||
|
||||
while (_opaqueMaterialPool.Count > 0)
|
||||
{
|
||||
Object.Destroy(_opaqueMaterialPool.Pop());
|
||||
}
|
||||
|
||||
_isMaterialPoolAllocated = false;
|
||||
|
||||
timer.Stop();
|
||||
Debug.Log($"[{nameof(LitMaterialFactory)}] Material pool de-allocated in {timer.ElapsedMilliseconds} ms.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Material[] CreateStandardMaterials(
|
||||
RendererType rendererType,
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
Material[] materials = null;
|
||||
|
||||
float transparentThreshold = DEFAULT_TRANSPARENT_THRESHOLD;
|
||||
|
||||
if (shadowTexture.texture == null && rendererType == RendererType.Pol)
|
||||
{
|
||||
transparentThreshold = 1.0f;
|
||||
}
|
||||
|
||||
if (blendFlag is GameBoxBlendFlag.AlphaBlend or GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
materials = new Material[2];
|
||||
materials[0] = CreateTransparentOpaquePartMaterial(mainTexture,
|
||||
shadowTexture,
|
||||
tintColor,
|
||||
transparentThreshold);
|
||||
materials[1] = CreateTransparentMaterial(mainTexture,
|
||||
shadowTexture,
|
||||
tintColor,
|
||||
transparentThreshold);
|
||||
|
||||
BlendMode srcFactor;
|
||||
BlendMode destFactor;
|
||||
|
||||
if (blendFlag == GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
srcFactor = BlendMode.SrcAlpha;
|
||||
destFactor = BlendMode.One;
|
||||
}
|
||||
else
|
||||
{
|
||||
srcFactor = BlendMode.SrcAlpha;
|
||||
destFactor = BlendMode.OneMinusSrcAlpha;
|
||||
}
|
||||
|
||||
materials[1].SetInt(BlendSrcFactorPropertyId, (int)srcFactor);
|
||||
materials[1].SetInt(BlendDstFactorPropertyId, (int)destFactor);
|
||||
}
|
||||
else if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
materials = new Material[1];
|
||||
materials[0] = CreateOpaqueMaterial(mainTexture, shadowTexture, tintColor);
|
||||
}
|
||||
|
||||
return materials;
|
||||
}
|
||||
|
||||
public void UpdateMaterial(Material material,
|
||||
Texture2D newMainTexture,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
material.mainTexture = newMainTexture;
|
||||
|
||||
if (blendFlag is GameBoxBlendFlag.AlphaBlend or GameBoxBlendFlag.InvertColorBlend)
|
||||
{
|
||||
material.SetFloat(TransparentThresholdPropertyId, DEFAULT_TRANSPARENT_THRESHOLD);
|
||||
}
|
||||
else if (blendFlag == GameBoxBlendFlag.Opaque)
|
||||
{
|
||||
material.SetFloat(TransparentThresholdPropertyId, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Material CreateWaterMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
float opacity,
|
||||
GameBoxBlendFlag blendFlag)
|
||||
{
|
||||
Material material;
|
||||
if (_waterMaterialPool.Count > 0)
|
||||
{
|
||||
material = _waterMaterialPool.Pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
material = new Material(_waterMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
};
|
||||
}
|
||||
|
||||
material.mainTexture = mainTexture.texture;
|
||||
material.SetFloat(WaterAlphaPropId, opacity);
|
||||
|
||||
if (shadowTexture.texture != null)
|
||||
{
|
||||
material.SetFloat(WaterHasShadowTexPropId, 1.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, shadowTexture.texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.SetFloat(WaterHasShadowTexPropId, 0.5f);
|
||||
material.SetTexture(ShadowTexturePropertyId, null);
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
private Material CreateTransparentMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor,
|
||||
float transparentThreshold)
|
||||
{
|
||||
Material material;
|
||||
if (_transparentMaterialPool.Count > 0)
|
||||
{
|
||||
material = _transparentMaterialPool.Pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
material = new Material(_transparentMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
};
|
||||
}
|
||||
|
||||
material.mainTexture = mainTexture.texture;
|
||||
material.SetColor(TintColorPropertyId, tintColor);
|
||||
material.SetFloat(TransparentThresholdPropertyId, transparentThreshold);
|
||||
|
||||
if (shadowTexture.texture != null)
|
||||
{
|
||||
material.SetFloat(HasShadowTexturePropertyId, 1.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, shadowTexture.texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.SetFloat(HasShadowTexturePropertyId, 0.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, null);
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
private Material CreateTransparentOpaquePartMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor,
|
||||
float transparentThreshold)
|
||||
{
|
||||
Material material;
|
||||
if (_transparentOpaquePartMaterialPool.Count > 0)
|
||||
{
|
||||
material = _transparentOpaquePartMaterialPool.Pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
material = new Material(_transparentOpaquePartMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
};
|
||||
}
|
||||
|
||||
material.mainTexture = mainTexture.texture;
|
||||
material.SetColor(TintColorPropertyId, tintColor);
|
||||
material.SetFloat(TransparentThresholdPropertyId, transparentThreshold);
|
||||
|
||||
if (shadowTexture.texture != null)
|
||||
{
|
||||
material.SetFloat(HasShadowTexturePropertyId, 1.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, shadowTexture.texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.SetFloat(HasShadowTexturePropertyId, 0.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, null);
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
private Material CreateOpaqueMaterial(
|
||||
(string name, Texture2D texture) mainTexture,
|
||||
(string name, Texture2D texture) shadowTexture,
|
||||
Color tintColor)
|
||||
{
|
||||
Material material;
|
||||
if (_opaqueMaterialPool.Count > 0)
|
||||
{
|
||||
material = _opaqueMaterialPool.Pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
material = new Material(_opaqueMaterial)
|
||||
{
|
||||
hideFlags = HideFlags.HideAndDontSave
|
||||
};
|
||||
}
|
||||
|
||||
material.mainTexture = mainTexture.texture;
|
||||
material.SetColor(TintColorPropertyId, tintColor);
|
||||
|
||||
if (shadowTexture.texture != null)
|
||||
{
|
||||
material.SetFloat(HasShadowTexturePropertyId, 1.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, shadowTexture.texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.SetFloat(HasShadowTexturePropertyId, 0.0f);
|
||||
material.SetTexture(ShadowTexturePropertyId, null);
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
protected override void ReturnToPool(Material material)
|
||||
{
|
||||
switch (material.shader.name)
|
||||
{
|
||||
case WATER_SHADER_NAME:
|
||||
material.mainTexture = null;
|
||||
material.SetTexture(ShadowTexturePropertyId, null);
|
||||
_waterMaterialPool.Push(material);
|
||||
break;
|
||||
case TRANSPARENT_SHADER_NAME:
|
||||
material.mainTexture = null;
|
||||
material.SetTexture(ShadowTexturePropertyId, null);
|
||||
_transparentMaterialPool.Push(material);
|
||||
break;
|
||||
case TRANSPARENT_OPAQUE_PART_SHADER_NAME:
|
||||
material.mainTexture = null;
|
||||
material.SetTexture(ShadowTexturePropertyId, null);
|
||||
_transparentOpaquePartMaterialPool.Push(material);
|
||||
break;
|
||||
case OPAQUE_SHADER_NAME:
|
||||
material.mainTexture = null;
|
||||
material.SetTexture(ShadowTexturePropertyId, null);
|
||||
_opaqueMaterialPool.Push(material);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+1
-1
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
namespace Pal3.Rendering
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
File renamed without changes.
+2
-1
@@ -3,9 +3,10 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
namespace Pal3.Rendering
|
||||
{
|
||||
using Core.Renderer;
|
||||
using Rendering;
|
||||
using UnityEngine;
|
||||
|
||||
public class RenderMeshComponent
|
||||
File renamed without changes.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a8204fb1460dc2479eb7692c396c23b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+9
-7
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
namespace Pal3.Rendering.Renderer
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -14,6 +14,7 @@ namespace Pal3.Renderer
|
||||
using Core.Renderer;
|
||||
using Core.Utils;
|
||||
using Dev;
|
||||
using Material;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -30,12 +31,15 @@ namespace Pal3.Renderer
|
||||
private float _animationDuration;
|
||||
private CancellationTokenSource _animationCts = new ();
|
||||
|
||||
private IMaterialFactory _materialFactory;
|
||||
|
||||
public void Init(CvdFile cvdFile,
|
||||
ITextureResourceProvider textureProvider,
|
||||
IMaterialFactory materialFactory,
|
||||
Color? tintColor = default,
|
||||
float initTime = 0f)
|
||||
{
|
||||
_materialFactory = materialFactory;
|
||||
_animationDuration = cvdFile.AnimationDuration;
|
||||
_tintColor = tintColor ?? Color.white;
|
||||
_currentTime = initTime;
|
||||
@@ -55,7 +59,6 @@ namespace Pal3.Renderer
|
||||
hashKey,
|
||||
cvdFile.RootNodes[i],
|
||||
_textureCache,
|
||||
materialFactory,
|
||||
root);
|
||||
}
|
||||
|
||||
@@ -193,7 +196,6 @@ namespace Pal3.Renderer
|
||||
string meshName,
|
||||
CvdGeometryNode node,
|
||||
Dictionary<string, Texture2D> textureCache,
|
||||
IMaterialFactory materialFactory,
|
||||
GameObject parent)
|
||||
{
|
||||
var meshObject = new GameObject(meshName);
|
||||
@@ -246,7 +248,7 @@ namespace Pal3.Renderer
|
||||
materialInfoPresenter.material = meshSection.Material;
|
||||
#endif
|
||||
|
||||
Material[] materials = materialFactory.CreateStandardMaterials(
|
||||
Material[] materials = _materialFactory.CreateStandardMaterials(
|
||||
RendererType.Cvd,
|
||||
(textureName, textureCache[textureName]),
|
||||
shadowTexture: (null, null), // CVD models don't have shadow textures
|
||||
@@ -287,7 +289,6 @@ namespace Pal3.Renderer
|
||||
childMeshName,
|
||||
node.Children[i],
|
||||
textureCache,
|
||||
materialFactory,
|
||||
meshObject);
|
||||
}
|
||||
}
|
||||
@@ -353,8 +354,8 @@ namespace Pal3.Renderer
|
||||
influence,
|
||||
frameMatrix);
|
||||
|
||||
renderMeshComponent.Mesh.vertices = meshDataBuffer.VertexBuffer;
|
||||
renderMeshComponent.Mesh.uv = meshDataBuffer.UvBuffer;
|
||||
renderMeshComponent.Mesh.SetVertices(meshDataBuffer.VertexBuffer);
|
||||
renderMeshComponent.Mesh.SetUVs(0, meshDataBuffer.UvBuffer);
|
||||
renderMeshComponent.Mesh.RecalculateBounds();
|
||||
}
|
||||
}
|
||||
@@ -578,6 +579,7 @@ namespace Pal3.Renderer
|
||||
|
||||
foreach (StaticMeshRenderer meshRenderer in GetComponentsInChildren<StaticMeshRenderer>())
|
||||
{
|
||||
_materialFactory.ReturnToPool(meshRenderer.GetMaterials());
|
||||
Destroy(meshRenderer.gameObject);
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+52
-37
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
namespace Pal3.Rendering.Renderer
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -15,6 +15,8 @@ namespace Pal3.Renderer
|
||||
using Core.Renderer;
|
||||
using Core.Utils;
|
||||
using Dev;
|
||||
using Material;
|
||||
using Rendering;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -125,6 +127,7 @@ namespace Pal3.Renderer
|
||||
tagNodeRenderer.Render(tagNodePolFile,
|
||||
tagNodeTextureProvider,
|
||||
_materialFactory,
|
||||
isStaticObject: false,
|
||||
tagNodeTintColor);
|
||||
|
||||
_tagNodes[i].transform.SetParent(transform, true);
|
||||
@@ -253,42 +256,6 @@ namespace Pal3.Renderer
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
PauseAnimation();
|
||||
|
||||
if (_renderMeshComponents != null)
|
||||
{
|
||||
foreach (RenderMeshComponent renderMeshComponent in _renderMeshComponents)
|
||||
{
|
||||
Destroy(renderMeshComponent.Mesh);
|
||||
Destroy(renderMeshComponent.MeshRenderer);
|
||||
}
|
||||
|
||||
_renderMeshComponents = null;
|
||||
}
|
||||
|
||||
if (_meshObjects != null)
|
||||
{
|
||||
foreach (GameObject meshObject in _meshObjects)
|
||||
{
|
||||
Destroy(meshObject);
|
||||
}
|
||||
|
||||
_meshObjects = null;
|
||||
}
|
||||
|
||||
if (_tagNodes != null)
|
||||
{
|
||||
foreach (GameObject tagNode in _tagNodes)
|
||||
{
|
||||
Destroy(tagNode);
|
||||
}
|
||||
|
||||
_tagNodes = null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsVisible()
|
||||
{
|
||||
return _meshObjects != null;
|
||||
@@ -486,5 +453,53 @@ namespace Pal3.Renderer
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
PauseAnimation();
|
||||
|
||||
if (_renderMeshComponents != null)
|
||||
{
|
||||
foreach (RenderMeshComponent renderMeshComponent in _renderMeshComponents)
|
||||
{
|
||||
var materials = renderMeshComponent.MeshRenderer.GetMaterials();
|
||||
if (materials != null)
|
||||
{
|
||||
#if PAL3A
|
||||
// Revert tiling fix before returning to pool
|
||||
foreach (Material material in materials)
|
||||
{
|
||||
material.mainTextureScale = Vector2.one;
|
||||
}
|
||||
#endif
|
||||
_materialFactory.ReturnToPool(materials);
|
||||
}
|
||||
Destroy(renderMeshComponent.Mesh);
|
||||
Destroy(renderMeshComponent.MeshRenderer);
|
||||
}
|
||||
|
||||
_renderMeshComponents = null;
|
||||
}
|
||||
|
||||
if (_meshObjects != null)
|
||||
{
|
||||
foreach (GameObject meshObject in _meshObjects)
|
||||
{
|
||||
Destroy(meshObject);
|
||||
}
|
||||
|
||||
_meshObjects = null;
|
||||
}
|
||||
|
||||
if (_tagNodes != null)
|
||||
{
|
||||
foreach (GameObject tagNode in _tagNodes)
|
||||
{
|
||||
Destroy(tagNode);
|
||||
}
|
||||
|
||||
_tagNodes = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+10
-2
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
namespace Pal3.Rendering.Renderer
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -13,6 +13,7 @@ namespace Pal3.Renderer
|
||||
using Core.GameBox;
|
||||
using Core.Renderer;
|
||||
using Dev;
|
||||
using Material;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
@@ -32,6 +33,7 @@ namespace Pal3.Renderer
|
||||
private readonly List<Coroutine> _waterAnimations = new ();
|
||||
private Dictionary<string, Texture2D> _textureCache = new ();
|
||||
|
||||
private bool _isStaticObject;
|
||||
private Color _tintColor;
|
||||
private bool _isWaterSurfaceOpaque;
|
||||
|
||||
@@ -40,11 +42,13 @@ namespace Pal3.Renderer
|
||||
public void Render(PolFile polFile,
|
||||
ITextureResourceProvider textureProvider,
|
||||
IMaterialFactory materialFactory,
|
||||
bool isStaticObject,
|
||||
Color? tintColor = default,
|
||||
bool isWaterSurfaceOpaque = default)
|
||||
{
|
||||
_textureProvider = textureProvider;
|
||||
_materialFactory = materialFactory;
|
||||
_isStaticObject = isStaticObject;
|
||||
_tintColor = tintColor ?? Color.white;
|
||||
_isWaterSurfaceOpaque = isWaterSurfaceOpaque;
|
||||
_textureCache = BuildTextureCache(polFile, textureProvider);
|
||||
@@ -148,7 +152,10 @@ namespace Pal3.Renderer
|
||||
return;
|
||||
}
|
||||
|
||||
var meshObject = new GameObject(meshNode.Name);
|
||||
GameObject meshObject = new (meshNode.Name)
|
||||
{
|
||||
isStatic = _isStaticObject
|
||||
};
|
||||
|
||||
// Attach BlendFlag and GameBoxMaterial to the GameObject for better debuggability
|
||||
#if UNITY_EDITOR
|
||||
@@ -271,6 +278,7 @@ namespace Pal3.Renderer
|
||||
|
||||
foreach (StaticMeshRenderer meshRenderer in GetComponentsInChildren<StaticMeshRenderer>())
|
||||
{
|
||||
_materialFactory.ReturnToPool(meshRenderer.GetMaterials());
|
||||
Destroy(meshRenderer.gameObject);
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+8
-5
@@ -3,20 +3,22 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
namespace Pal3.Rendering.Renderer
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Core.DataReader.Msh;
|
||||
using Core.DataReader.Mov;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Core.DataReader.Msh;
|
||||
using Core.DataReader.Mov;
|
||||
using Core.DataLoader;
|
||||
using Core.DataReader.Mtl;
|
||||
using Core.GameBox;
|
||||
using Core.Renderer;
|
||||
using Core.Utils;
|
||||
using Material;
|
||||
using Rendering;
|
||||
using UnityEngine;
|
||||
|
||||
internal class Bone
|
||||
{
|
||||
@@ -207,7 +209,7 @@ namespace Pal3.Renderer
|
||||
{
|
||||
if (_renderMeshComponents == null) return false;
|
||||
|
||||
foreach (var renderMeshComponent in _renderMeshComponents)
|
||||
foreach (RenderMeshComponent renderMeshComponent in _renderMeshComponents)
|
||||
{
|
||||
if (renderMeshComponent.MeshRenderer.IsVisible()) return true;
|
||||
}
|
||||
@@ -461,6 +463,7 @@ namespace Pal3.Renderer
|
||||
{
|
||||
foreach (RenderMeshComponent renderMeshComponent in _renderMeshComponents)
|
||||
{
|
||||
_materialFactory.ReturnToPool(renderMeshComponent.MeshRenderer.GetMaterials());
|
||||
Destroy(renderMeshComponent.Mesh);
|
||||
Destroy(renderMeshComponent.MeshRenderer);
|
||||
}
|
||||
File renamed without changes.
+1
-1
@@ -3,7 +3,7 @@
|
||||
// See LICENSE file in the project root for license information.
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Pal3.Renderer
|
||||
namespace Pal3.Rendering
|
||||
{
|
||||
public enum RendererType
|
||||
{
|
||||
File renamed without changes.
@@ -10,18 +10,21 @@ namespace Pal3.Scene
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Actor;
|
||||
using Actor.Controllers;
|
||||
using Command;
|
||||
using Command.InternalCommands;
|
||||
using Command.SceCommands;
|
||||
using Core.Animation;
|
||||
using Core.DataReader.Scn;
|
||||
using Core.GameBox;
|
||||
using Core.Navigation;
|
||||
using Core.Renderer;
|
||||
using Core.Utils;
|
||||
using Data;
|
||||
using Effect;
|
||||
using MetaData;
|
||||
using Renderer;
|
||||
using Rendering.Material;
|
||||
using Rendering.Renderer;
|
||||
using SceneObjects;
|
||||
using State;
|
||||
using UnityEngine;
|
||||
@@ -240,13 +243,18 @@ namespace Pal3.Scene
|
||||
private void RenderMesh()
|
||||
{
|
||||
// Render mesh
|
||||
_mesh = new GameObject($"Mesh_{ScnFile.SceneInfo.CityName}_{ScnFile.SceneInfo.SceneName}");
|
||||
_mesh = new GameObject($"Mesh_{ScnFile.SceneInfo.CityName}_{ScnFile.SceneInfo.SceneName}")
|
||||
{
|
||||
isStatic = true // Scene mesh is static
|
||||
};
|
||||
|
||||
var polyMeshRenderer = _mesh.AddComponent<PolyModelRenderer>();
|
||||
_mesh.transform.SetParent(_parent.transform, false);
|
||||
|
||||
polyMeshRenderer.Render(ScenePolyMesh.PolFile,
|
||||
ScenePolyMesh.TextureProvider,
|
||||
_materialFactory,
|
||||
isStaticObject: true, // Scene mesh is static
|
||||
Color.white,
|
||||
IsWaterSurfaceOpaque());
|
||||
|
||||
@@ -348,19 +356,19 @@ namespace Pal3.Scene
|
||||
_mainLight.color = IsNightScene() ?
|
||||
new Color(60f / 255f, 80f / 255f, 170f / 255f) :
|
||||
new Color(220f / 255f, 210f / 255f, 200f / 255f);
|
||||
_mainLight.intensity = (IsNightScene() || ScnFile.SceneInfo.SceneType == ScnSceneType.InDoor) ? 0.75f : 1f;
|
||||
_mainLight.intensity = (IsNightScene() || ScnFile.SceneInfo.SceneType == ScnSceneType.InDoor) ? 0.75f : 0.9f;
|
||||
#elif PAL3A
|
||||
_mainLight.color = IsNightScene() ?
|
||||
new Color(60f / 255f, 80f / 255f, 170f / 255f) :
|
||||
new Color(200f / 255f, 200f / 255f, 200f / 255f);
|
||||
_mainLight.intensity = (IsNightScene() || ScnFile.SceneInfo.SceneType == ScnSceneType.InDoor) ? 0.65f : 1f;
|
||||
_mainLight.intensity = (IsNightScene() || ScnFile.SceneInfo.SceneType == ScnSceneType.InDoor) ? 0.65f : 0.9f;
|
||||
#endif
|
||||
|
||||
// Ambient light
|
||||
RenderSettings.ambientIntensity = 1f;
|
||||
RenderSettings.ambientLight = IsNightScene() ?
|
||||
new Color( 90f/ 255f, 100f / 255f, 130f / 255f) :
|
||||
new Color(200f / 255f, 200f / 255f, 180f / 255f);
|
||||
new Color(180f / 255f, 180f / 255f, 160f / 255f);
|
||||
|
||||
// Apply lighting override
|
||||
var key = (ScnFile.SceneInfo.CityName.ToLower(), ScnFile.SceneInfo.SceneName.ToLower());
|
||||
@@ -489,6 +497,9 @@ namespace Pal3.Scene
|
||||
tileMap,
|
||||
isDropShadowEnabled: !_isLightingEnabled,
|
||||
tintColor,
|
||||
ActorMovementMaxYDifferential,
|
||||
ActorMovementMaxYDifferentialCrossLayer,
|
||||
ActorMovementMaxYDifferentialCrossPlatform,
|
||||
GetAllActiveActorBlockingTilePositions);
|
||||
actorGameObject.transform.SetParent(_parent.transform, false);
|
||||
_actorObjects[actor.Info.Id] = actorGameObject;
|
||||
@@ -518,7 +529,7 @@ namespace Pal3.Scene
|
||||
{
|
||||
var actorMovementController = actor.GetComponent<ActorMovementController>();
|
||||
if (actorMovementController.GetCurrentLayerIndex() != layerIndex) continue;
|
||||
Vector2Int tilePosition = _tilemap.GetTilePosition(actorMovementController.GetWorldPosition(), layerIndex);
|
||||
Vector2Int tilePosition = actorMovementController.GetTilePosition();
|
||||
actorTiles.Add(tilePosition);
|
||||
}
|
||||
}
|
||||
@@ -526,6 +537,8 @@ namespace Pal3.Scene
|
||||
var obstacles = new HashSet<Vector2Int>();
|
||||
foreach (Vector2Int actorTile in actorTiles)
|
||||
{
|
||||
if (!_tilemap.IsTilePositionInsideTileMap(actorTile, layerIndex)) continue;
|
||||
|
||||
obstacles.Add(actorTile);
|
||||
|
||||
// Mark 8 tiles right next to the actor tile as obstacles
|
||||
|
||||
Loaded 100 of 141 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user