Compare commits

...
13 Commits
Author SHA1 Message Date
Jiaqi Liu db11847130 v0.66 2023-07-30 03:58:14 -07:00
Jiaqi Liu d88f737375 Code refactoring 2023-07-30 03:36:57 -07:00
Jiaqi Liu d1a7de0229 Fix a bug that might be caused by a delayed destroy 2023-07-30 02:55:42 -07:00
Jiaqi Liu 78e9692abc Upgrade dependencies 2023-07-29 14:55:58 -07:00
Jiaqi Liu 836463c795 Smoothen skeletal animation with interpolation 2023-07-29 02:07:26 -07:00
Jiaqi Liu 630166880f Fix: Use Slerp for quaternion Interpolation 2023-07-29 02:06:59 -07:00
Jiaqi Liu 421ee12a82 Properly implement logic to read mtl file and handle GB Material 2023-07-28 19:52:03 -07:00
Jiaqi Liu 4dd3992a32 v0.65 2023-07-27 22:12:51 -07:00
Jiaqi Liu 5fab0d867e Implement skeletal animation logic (#17)
Properly implements SkeletalModelRenderer + SkeletalAnimationActorActionController
2023-07-27 21:48:39 -07:00
Jiaqi Liu a1801f59f5 Upgrade Unity version 2023-07-20 20:41:22 -07:00
Jiaqi Liu 3f467944ce Fix a bug where actor might spawn at wrong Y position 2023-07-06 00:28:33 -07:00
Jiaqi Liu b1add2a940 Minor refactoring 2023-07-05 23:58:27 -07:00
Jiaqi Liu 3e8f350740 Upgrade packages 2023-07-01 23:34:41 -07:00
83 changed files with 1088 additions and 470 deletions

No files matched your search

+4 -1
View File
@@ -83,4 +83,7 @@ crashlytics-build.properties
/Assets/Resources/Prefabs/VFX/PAL3A/*.meta
# Materials that are using 3rd party assets
/Assets/Resources/Materials/
/Assets/Resources/Materials/
# VS Conde config file
.vsconfig
@@ -134,7 +134,7 @@ namespace Core.Animation
var timePast = 0f;
while (timePast < duration && target != null && !cancellationToken.IsCancellationRequested)
{
Quaternion rotation = Quaternion.Lerp(startRotation, toRotation,
Quaternion rotation = Quaternion.Slerp(startRotation, toRotation,
GetInterpolationRatio(timePast / duration, curveType));
Vector3 direction = (rotation * Vector3.forward).normalized;
@@ -167,7 +167,7 @@ namespace Core.Animation
var timePast = 0f;
while (timePast < duration && target != null && !cancellationToken.IsCancellationRequested)
{
Quaternion rotation = Quaternion.Lerp(startRotation, toRotation,
Quaternion rotation = Quaternion.Slerp(startRotation, toRotation,
GetInterpolationRatio(timePast / duration, curveType));
target.rotation = rotation;
@@ -154,7 +154,6 @@ namespace Core.DataReader.Cvd
public int[] Triangles;
public GameBoxBlendFlag BlendFlag;
public GameBoxMaterial Material;
public string TextureName;
public float[] AnimationTimeKeys;
public GameBoxMaterial[] AnimationMaterials;
}
@@ -413,19 +413,18 @@ namespace Core.DataReader.Cvd
int codepage)
#endif
{
var blendFlag = (GameBoxBlendFlag)reader.ReadByte();
GameBoxBlendFlag blendFlag = (GameBoxBlendFlag)reader.ReadByte();
var material = new GameBoxMaterial()
GameBoxMaterial material = new ()
{
Diffuse = Utility.ToColor32(reader.ReadBytes(4)),
Ambient = Utility.ToColor32(reader.ReadBytes(4)),
Specular = Utility.ToColor32(reader.ReadBytes(4)),
Emissive = Utility.ToColor32(reader.ReadBytes(4)),
Power = reader.ReadSingle()
SpecularPower = reader.ReadSingle(),
TextureFileNames = new [] { reader.ReadString(64, codepage) }
};
var textureName = reader.ReadString(64, codepage);
var numberOfIndices = reader.ReadInt32();
var indices = new (ushort x, ushort y, ushort z)[numberOfIndices];
@@ -458,7 +457,7 @@ namespace Core.DataReader.Cvd
Ambient = Utility.ToColor(reader.ReadSingleArray(4)),
Specular = Utility.ToColor(reader.ReadSingleArray(4)),
Emissive = Utility.ToColor(reader.ReadSingleArray(4)),
Power = reader.ReadSingle()
SpecularPower = reader.ReadSingle()
};
}
}
@@ -486,7 +485,6 @@ namespace Core.DataReader.Cvd
{
BlendFlag = blendFlag,
Material = material,
TextureName = textureName,
FrameVertices = frameVertices,
Triangles = triangles.ToArray(),
AnimationTimeKeys = animationTimeKeys,
@@ -501,18 +499,18 @@ namespace Core.DataReader.Cvd
var triangles = new List<int>();
var index = 0;
for (var j = 0; j < allIndices.Length; j++)
for (var i = 0; i < allIndices.Length; i++)
{
var indices = new[]
{
allIndices[j].x,
allIndices[j].y,
allIndices[j].z
allIndices[i].x,
allIndices[i].y,
allIndices[i].z
};
for (var k = 0; k < 3; k++)
for (var j = 0; j < 3; j++)
{
indexBuffer.Add(indices[k]);
indexBuffer.Add(indices[j]);
triangles.Add(index++);
}
}
@@ -86,7 +86,7 @@ namespace Core.DataReader.Mov
{
return new MovAnimationEvent()
{
Tick = GameBoxInterpreter.GameBoxSecondsToTick(reader.ReadSingle()),
Tick = GameBoxInterpreter.SecondsToTick(reader.ReadSingle()),
Name = reader.ReadString(16, codepage)
};
}
@@ -110,7 +110,7 @@ namespace Core.DataReader.Mov
{
animationKeyFrames[i] = new MovAnimationKeyFrame()
{
Tick = GameBoxInterpreter.GameBoxSecondsToTick(reader.ReadSingle()),
Tick = GameBoxInterpreter.SecondsToTick(reader.ReadSingle()),
Translation = GameBoxInterpreter.ToUnityPosition(reader.ReadVector3()),
Rotation = GameBoxInterpreter.MovQuaternionToUnityQuaternion(new GameBoxQuaternion()
{
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5f50098c0cef46349314b7f36bc59136
timeCreated: 1690567483
@@ -0,0 +1,19 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Core.DataReader.Mtl
{
using GameBox;
public sealed class MtlFile
{
public GameBoxMaterial[] Materials { get; }
public MtlFile(GameBoxMaterial[] materials)
{
Materials = materials;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f167ffdd8daf4bcfb2b50ee3e3e7bc8b
timeCreated: 1690567491
@@ -0,0 +1,76 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
#define USE_UNSAFE_BINARY_READER
namespace Core.DataReader.Mtl
{
using System.Collections.Generic;
using System.IO;
using Extensions;
using GameBox;
using Utils;
public sealed class MtlFileReader : IFileReader<MtlFile>
{
private readonly int _codepage;
public MtlFileReader(int codepage)
{
_codepage = codepage;
}
public MtlFile Read(byte[] data)
{
#if USE_UNSAFE_BINARY_READER
using var reader = new UnsafeBinaryReader(data);
#else
using var stream = new MemoryStream(data);
using var reader = new BinaryReader(stream);
#endif
var header = reader.ReadChars(4);
var headerStr = new string(header[..^1]);
if (headerStr != "mtl")
{
throw new InvalidDataException("Invalid MTL(.mtl) file: header != mtl");
}
var version = reader.ReadInt32();
if (version != 100)
{
throw new InvalidDataException("Invalid MTL(.mtl) file: version != 100");
}
int numberOfMaterials = reader.ReadInt32();
var materials = new GameBoxMaterial[numberOfMaterials];
for (var i = 0; i < numberOfMaterials; i++)
{
materials[i] = new GameBoxMaterial
{
Diffuse = Utility.ToColor(reader.ReadSingleArray(4)),
Ambient = Utility.ToColor(reader.ReadSingleArray(4)),
Specular = Utility.ToColor(reader.ReadSingleArray(4)),
Emissive = Utility.ToColor(reader.ReadSingleArray(4)),
SpecularPower = reader.ReadSingle(),
};
List<string> textureNames = new ();
for (var j = 0; j < 4; j++)
{
int textureNameLength = reader.ReadInt32();
if (textureNameLength == 0) continue;
textureNames.Add(reader.ReadString(textureNameLength, _codepage));
}
materials[i].TextureFileNames = textureNames.ToArray();
}
return new MtlFile(materials);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 16ec8deffba245bcb6808f8ad26677c7
timeCreated: 1690567511
+4 -10
View File
@@ -56,12 +56,6 @@ namespace Core.DataReader.Mv3
public Mv3Vert[] Vertices;
}
public struct Mv3Material
{
public GameBoxMaterial Material;
public string[] TextureNames;
}
public struct Mv3Mesh
{
public string Name; // 64 chars max
@@ -87,20 +81,20 @@ namespace Core.DataReader.Mv3
public uint Duration { get; }
public Mv3AnimationEvent[] AnimationEvents { get; }
public Mv3TagNode[] TagNodes { get; }
public Mv3Material[] Materials { get; }
public Mv3Mesh[] Meshes { get; }
public GameBoxMaterial[] Materials { get; }
public Mv3File(uint duration,
Mv3AnimationEvent[] animationEvents,
Mv3TagNode[] tagNodes,
Mv3Material[] materials,
Mv3Mesh[] meshes)
Mv3Mesh[] meshes,
GameBoxMaterial[] materials)
{
Duration = duration;
AnimationEvents = animationEvents;
TagNodes = tagNodes;
Materials = materials;
Meshes = meshes;
Materials = materials;
}
}
}
@@ -70,7 +70,7 @@ namespace Core.DataReader.Mv3
tagNodes[i] = ReadTagNode(reader, _codepage);
}
var materials = new Mv3Material[numberOfMaterials];
var materials = new GameBoxMaterial[numberOfMaterials];
for (var i = 0; i < numberOfMaterials; i++)
{
materials[i] = ReadMaterial(reader, _codepage);
@@ -85,8 +85,8 @@ namespace Core.DataReader.Mv3
return new Mv3File(duration,
animationEvents,
tagNodes,
materials,
meshes);
meshes,
materials);
}
#if USE_UNSAFE_BINARY_READER
@@ -306,34 +306,30 @@ namespace Core.DataReader.Mv3
}
#if USE_UNSAFE_BINARY_READER
private static Mv3Material ReadMaterial(UnsafeBinaryReader reader, int codepage)
private static GameBoxMaterial ReadMaterial(UnsafeBinaryReader reader, int codepage)
#else
private static Mv3Material ReadMaterial(BinaryReader reader, int codepage)
private static GameBoxMaterial ReadMaterial(BinaryReader reader, int codepage)
#endif
{
var material = new GameBoxMaterial()
GameBoxMaterial material = new ()
{
Diffuse = Utility.ToColor(reader.ReadSingleArray(4)),
Ambient = Utility.ToColor(reader.ReadSingleArray(4)),
Specular = Utility.ToColor(reader.ReadSingleArray(4)),
Emissive = Utility.ToColor(reader.ReadSingleArray(4)),
Power = reader.ReadSingle()
SpecularPower = reader.ReadSingle()
};
var textureNames = new List<string>();
List<string> textureNames = new ();
for (var i = 0; i < 4; i++)
{
string textureName;
var length = reader.ReadInt32();
if (length is < 0 or > 255)
{
throw new InvalidDataException($"Invalid length of material name: {length}");
}
if (length == 0)
{
if (i > 0) continue;
textureName = string.Empty; // Use default white texture?
textureName = string.Empty; // Use default white texture
}
else
{
@@ -343,11 +339,9 @@ namespace Core.DataReader.Mv3
textureNames.Add(textureName);
}
return new Mv3Material()
{
Material = material,
TextureNames = textureNames.ToArray(),
};
material.TextureFileNames = textureNames.ToArray();
return material;
}
}
}
@@ -45,7 +45,6 @@ namespace Core.DataReader.Pol
{
public GameBoxBlendFlag BlendFlag;
public GameBoxMaterial Material;
public string[] TextureNames;
public uint VertStart;
public uint VertEnd;
public int[] Triangles;
@@ -241,20 +241,20 @@ namespace Core.DataReader.Pol
private static PolTexture ReadTextureInfo(BinaryReader reader, int version, int codepage)
#endif
{
var blendFlag = (GameBoxBlendFlag)reader.ReadUInt32();
GameBoxBlendFlag blendFlag = (GameBoxBlendFlag)reader.ReadUInt32();
var material = new GameBoxMaterial()
GameBoxMaterial material = new ()
{
Diffuse = Utility.ToColor(reader.ReadSingleArray(4)),
Ambient = Utility.ToColor(reader.ReadSingleArray(4)),
Specular = Utility.ToColor(reader.ReadSingleArray(4)),
Emissive = Utility.ToColor(reader.ReadSingleArray(4)),
Power = reader.ReadSingle()
SpecularPower = reader.ReadSingle()
};
// Hack fix
if (material.Power < 0) material.Power = 0;
else if (material.Power > 128) material.Power = 128;
if (material.SpecularPower < 0) material.SpecularPower = 0;
else if (material.SpecularPower > 128) material.SpecularPower = 128;
var numberOfTextures = reader.ReadInt32();
var textureNames = new string[numberOfTextures];
@@ -265,6 +265,8 @@ namespace Core.DataReader.Pol
textureNames[i] = textureName;
}
material.TextureFileNames = textureNames;
_ = reader.ReadInt32();
var vertStart = reader.ReadUInt32();
var vertEnd = reader.ReadUInt32();
@@ -285,7 +287,6 @@ namespace Core.DataReader.Pol
{
BlendFlag = blendFlag,
Material = material,
TextureNames = textureNames,
VertStart = vertStart,
VertEnd = vertEnd,
Triangles = triangles
@@ -203,16 +203,15 @@ namespace Core.GameBox
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint GameBoxSecondsToTick(float seconds)
public static uint SecondsToTick(float seconds)
{
return (uint)(seconds * GameBoxTicksPerSecond);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float TickToGameBoxSeconds(uint tick)
public static float TickToSeconds(uint tick)
{
return (float)tick / GameBoxTicksPerSecond;
}
}
}
@@ -10,11 +10,12 @@ namespace Core.GameBox
[System.Serializable]
public struct GameBoxMaterial
{
public Color32 Diffuse;
public Color32 Ambient;
public Color32 Specular;
public Color32 Emissive;
public float Power;
public Color Diffuse;
public Color Ambient;
public Color Specular;
public Color Emissive;
public float SpecularPower;
public string[] TextureFileNames;
}
// To meet opengl, use this order instead:
@@ -62,18 +62,11 @@ namespace Core.Utils
{
return platform switch
{
RuntimePlatform.WindowsPlayer => WindowsSupportedVideoFormats,
RuntimePlatform.WindowsEditor => WindowsSupportedVideoFormats,
RuntimePlatform.OSXPlayer => MacOSSupportedVideoFormats,
RuntimePlatform.OSXEditor => MacOSSupportedVideoFormats,
RuntimePlatform.LinuxPlayer => LinuxSupportedVideoFormats,
RuntimePlatform.LinuxEditor => LinuxSupportedVideoFormats,
RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsEditor => WindowsSupportedVideoFormats,
RuntimePlatform.OSXPlayer or RuntimePlatform.OSXEditor => MacOSSupportedVideoFormats,
RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxEditor => LinuxSupportedVideoFormats,
RuntimePlatform.IPhonePlayer => iOSSupportedVideoFormats,
RuntimePlatform.Android => AndroidSupportedVideoFormats,
_ => new HashSet<string> {".mp4" }
};
}
@@ -140,16 +140,19 @@ namespace Pal3.Actor
if (_shadow != null)
{
Destroy(_shadow);
_shadow = null;
}
if (_rigidbody != null)
{
Destroy(_rigidbody);
_rigidbody = null;
}
if (_collider != null)
{
Destroy(_collider);
_collider = null;
}
}
+28 -9
View File
@@ -14,8 +14,8 @@ namespace Pal3.Actor
public enum ActorAnimationType
{
Mv3 = 0,
Mov
Vertex = 0, // .mv3 animation
Skeletal = 1, // .msh + .mov animation
}
public abstract class ActorBase
@@ -47,20 +47,21 @@ namespace Pal3.Actor
ActorActionConfig defaultConfig = _resourceProvider.GetActorActionConfig(actorActionConfigFolder + $"{name}.ini");
// Add default config if it is MV3 animated
if (defaultConfig is Mv3ActionConfig mv3Config)
{
AddActorConfig(mv3Config);
AnimationType = ActorAnimationType.Mv3;
AnimationType = ActorAnimationType.Vertex;
return;
}
// Add default config if it is MOV
// Add default config if it is MOV animated
if (defaultConfig is MovActionConfig)
{
AddActorConfig(defaultConfig);
}
// For MOV animation actor, additional action config files are defined as
// For MOV animated skeletal actor, additional action config files are defined as
// 01.ini, 02.ini ...up tp 09.ini
for (var i = 0; i <= 9; i++)
{
@@ -71,7 +72,7 @@ namespace Pal3.Actor
}
}
AnimationType = ActorAnimationType.Mov;
AnimationType = ActorAnimationType.Skeletal;
}
private void AddActorConfig(ActorActionConfig config)
@@ -118,14 +119,14 @@ namespace Pal3.Actor
public string GetMeshFilePath(string actionName)
{
if (AnimationType != ActorAnimationType.Mov)
if (AnimationType != ActorAnimationType.Skeletal)
{
throw new InvalidOperationException("Mesh file path is only available for MOV animation type.");
throw new InvalidOperationException("Msh file path is only available for skeletal animation type.");
}
if (!_actionNameToMeshFileNameMap.TryGetValue(actionName, out var meshFileName))
{
throw new ArgumentException($"Mesh file name not found for action name {actionName}");
throw new ArgumentException($"Msh file name not found for action name {actionName}");
}
char separator = CpkConstants.DirectorySeparator;
@@ -133,5 +134,23 @@ namespace Pal3.Actor
$"{FileConstants.ActorFolderName}{separator}{_actorName}{separator}" +
$"{meshFileName}";
}
public string GetMaterialFilePath(string actionName)
{
if (AnimationType != ActorAnimationType.Skeletal)
{
throw new InvalidOperationException("Mtl file path is only available for skeletal animation type.");
}
if (!_actionNameToMaterialFileNameMap.TryGetValue(actionName, out var mtlFileName))
{
throw new ArgumentException($"Mtl file name not found for action name {actionName}");
}
char separator = CpkConstants.DirectorySeparator;
return $"{FileConstants.BaseDataCpkPathInfo.cpkName}{separator}" +
$"{FileConstants.ActorFolderName}{separator}{_actorName}{separator}" +
$"{mtlFileName}";
}
}
}
+19 -10
View File
@@ -40,17 +40,26 @@ namespace Pal3.Actor
#endif
ActorActionController actionController;
if (actor.AnimationType == ActorAnimationType.Mv3)
switch (actor.AnimationType)
{
Mv3ActorActionController mv3ActionController = actorGameObject.AddComponent<Mv3ActorActionController>();
mv3ActionController.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled, tintColor);
actionController = mv3ActionController;
}
else
{
MovActorActionController movActionController = actorGameObject.AddComponent<MovActorActionController>();
movActionController.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled, tintColor);
actionController = movActionController;
case ActorAnimationType.Vertex:
{
VertexAnimationActorActionController vertexActionController =
actorGameObject.AddComponent<VertexAnimationActorActionController>();
vertexActionController.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled, tintColor);
actionController = vertexActionController;
break;
}
case ActorAnimationType.Skeletal:
{
SkeletalAnimationActorActionController skeletalActionController =
actorGameObject.AddComponent<SkeletalAnimationActorActionController>();
skeletalActionController.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled, tintColor);
actionController = skeletalActionController;
break;
}
default:
throw new NotSupportedException($"Unsupported actor animation type: {actor.AnimationType}");
}
var movementController = actorGameObject.AddComponent<ActorMovementController>();
@@ -92,16 +92,19 @@ namespace Pal3.Actor
actor.Info.GameBoxYPosition,
actor.Info.GameBoxZPosition));
// Setup actor's initial position
if (actor.Info.InitBehaviour != ScnActorBehaviour.Hold &&
_tilemap.TryGetTile(initPosition, _currentLayerIndex, out NavTile tile))
{
if (tile.IsWalkable())
// If the actor is initially placed on a walkable tile, snap to the tile
// Same for the case when actor is configured to not facing the player actor during dialogue
if (tile.IsWalkable() || actor.Info.NoTurn == 1)
{
transform.position = new Vector3(initPosition.x,
GameBoxInterpreter.ToUnityYPosition(tile.GameBoxYPosition),
initPosition.z);
}
else
else // This is to handle the case where the actor is initially placed on a non-walkable tile
{
Vector2Int tilePosition = _tilemap.GetTilePosition(initPosition, _currentLayerIndex);
// Snap to the nearest adjacent tile if exists
@@ -1,224 +0,0 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Pal3.Actor
{
using System;
using Command;
using Command.InternalCommands;
using Command.SceCommands;
using Core.DataLoader;
using Core.DataReader.Mov;
using Core.DataReader.Msh;
using Core.Utils;
using Data;
using MetaData;
using Renderer;
using Script.Waiter;
using UnityEngine;
public class MovActorActionController : ActorActionController,
ICommandExecutor<ActorAutoStandCommand>,
ICommandExecutor<ActorStopActionCommand>
{
private GameResourceProvider _resourceProvider;
private IMaterialFactory _materialFactory;
private Actor _actor;
private Color _tintColor;
private bool _autoStand = true;
// private MovModelRenderer _movAnimationRenderer;
// private WaitUntilCanceled _animationLoopPointWaiter;
private Bounds _rendererBounds;
private Bounds _meshBounds;
public void Init(GameResourceProvider resourceProvider,
Actor actor,
bool hasColliderAndRigidBody,
bool isDropShadowEnabled,
Color tintColor)
{
base.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled);
_resourceProvider = resourceProvider;
_actor = actor;
_tintColor = tintColor;
_materialFactory = resourceProvider.GetMaterialFactory();
}
private void OnEnable()
{
CommandExecutorRegistry<ICommand>.Instance.Register(this);
}
private void OnDisable()
{
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
DeActivate();
base.DeActivate();
}
public override void PerformAction(string actionName,
bool overwrite = false,
int loopCount = -1,
WaitUntilCanceled waiter = null)
{
if (!overwrite && string.Equals(GetCurrentAction(), actionName, StringComparison.OrdinalIgnoreCase))
{
return;
}
if (!_actor.HasAction(actionName))
{
Debug.LogError($"Action {actionName} not found for actor {_actor.Info.Name}.");
waiter?.CancelWait();
return;
}
Debug.LogWarning($"Actor {_actor.Info.Name} is performing bone action {actionName}.");
MovFile movFile;
MshFile mshFile;
ITextureResourceProvider textureProvider;
try
{
string movFilePath = _actor.GetActionFilePath(actionName);
movFile = _resourceProvider.GetGameResourceFile<MovFile>(movFilePath);
textureProvider = _resourceProvider.CreateTextureResourceProvider(
Utility.GetRelativeDirectoryPath(movFilePath));
string mshFilePath = _actor.GetMeshFilePath(actionName);
mshFile = _resourceProvider.GetGameResourceFile<MshFile>(mshFilePath);
}
catch (Exception ex)
{
Debug.LogError(ex);
waiter?.CancelWait();
return;
}
DisposeCurrentAction();
// _animationLoopPointWaiter = waiter;
// _movAnimationRenderer = gameObject.GetOrAddComponent<MovModelRenderer>();
//
// ActorActionType actionType = ActorConstants.ActionNames
// .FirstOrDefault(_ => string.Equals(_.Value, actionName, StringComparison.OrdinalIgnoreCase)).Key;
//
// if (movFile.TagNodes is {Length: > 0} && _actor.GetWeaponName() is {} weaponName &&
// ActorConstants.ActionNameToWeaponArmTypeMap[actionType] != WeaponArmType.None)
// {
// var separator = CpkConstants.DirectorySeparator;
//
// var weaponPath = $"{FileConstants.BaseDataCpkPathInfo.cpkName}{separator}" +
// $"{FileConstants.WeaponFolderName}{separator}{weaponName}{separator}{weaponName}.pol";
//
// (PolFile polFile, ITextureResourceProvider weaponTextureProvider) = _resourceProvider.GetPol(weaponPath);
// _movAnimationRenderer.Init(movFile,
// _materialFactory,
// textureProvider,
// _tintColor,
// polFile,
// weaponTextureProvider);
// }
// else
// {
// _movAnimationRenderer.Init(movFile,
// _materialFactory,
// textureProvider,
// _tintColor);
// }
//
// _movAnimationRenderer.AnimationLoopPointReached += AnimationLoopPointReached;
// _movAnimationRenderer.StartAnimation(loopCount);
//
// _rendererBounds = _movAnimationRenderer.GetRendererBounds();
// _meshBounds = _movAnimationRenderer.GetMeshBounds();
base.PerformAction(actionName, overwrite, loopCount, waiter);
}
// public override float GetActorHeight()
// {
// if (_movAnimationRenderer == null || !_movAnimationRenderer.IsVisible())
// {
// return _meshBounds.size.y;
// }
//
// return _movAnimationRenderer.GetMeshBounds().size.y;
// }
//
// public override Bounds GetRendererBounds()
// {
// return (_movAnimationRenderer == null || !_movAnimationRenderer.IsVisible()) ? _rendererBounds :
// _movAnimationRenderer.GetRendererBounds();
// }
//
// public override Bounds GetMeshBounds()
// {
// return (_movAnimationRenderer == null || !_movAnimationRenderer.IsVisible()) ? _meshBounds :
// _movAnimationRenderer.GetMeshBounds();
// }
internal override void DisposeCurrentAction()
{
// _animationLoopPointWaiter?.CancelWait();
//
// if (_movAnimationRenderer != null)
// {
// _movAnimationRenderer.AnimationLoopPointReached -= AnimationLoopPointReached;
// _movAnimationRenderer.DisposeAnimation();
// }
base.DisposeCurrentAction();
}
internal override void DeActivate()
{
DisposeCurrentAction();
// if (_movAnimationRenderer != null)
// {
// Destroy(_movAnimationRenderer);
// }
base.DeActivate();
}
public void Execute(ActorAutoStandCommand command)
{
if (command.ActorId == _actor.Info.Id) _autoStand = (command.AutoStand == 1);
}
public void Execute(ActorStopActionCommand command)
{
// if (command.ActorId != _actor.Info.Id ||
// _movAnimationRenderer == null ||
// !_movAnimationRenderer.IsVisible()) return;
//
// if (_movAnimationRenderer.IsActionInHoldState())
// {
// _animationLoopPointWaiter?.CancelWait();
// _animationLoopPointWaiter = new WaitUntilCanceled();
// CommandDispatcher<ICommand>.Instance.Dispatch(
// new ScriptRunnerAddWaiterRequest(_animationLoopPointWaiter));
//
// _movAnimationRenderer.ResumeAction();
// }
// else
// {
// _movAnimationRenderer.PauseAnimation();
// _animationLoopPointWaiter?.CancelWait();
//
// if (_autoStand && _movAnimationRenderer.IsVisible())
// {
// PerformAction(_actor.GetIdleAction());
// }
// }
}
}
}
@@ -0,0 +1,182 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Pal3.Actor
{
using System;
using Command;
using Command.SceCommands;
using Core.DataLoader;
using Core.DataReader.Mov;
using Core.DataReader.Msh;
using Core.DataReader.Mtl;
using Core.Extensions;
using Core.Utils;
using Data;
using Renderer;
using Script.Waiter;
using UnityEngine;
public class SkeletalAnimationActorActionController : ActorActionController,
ICommandExecutor<ActorAutoStandCommand>,
ICommandExecutor<ActorStopActionCommand>
{
private GameResourceProvider _resourceProvider;
private IMaterialFactory _materialFactory;
private Actor _actor;
private Color _tintColor;
private bool _autoStand = true;
private SkeletalModelRenderer _skeletalModelRenderer;
private Bounds _rendererBounds;
private Bounds _meshBounds;
public void Init(GameResourceProvider resourceProvider,
Actor actor,
bool hasColliderAndRigidBody,
bool isDropShadowEnabled,
Color tintColor)
{
base.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled);
_resourceProvider = resourceProvider;
_actor = actor;
_tintColor = tintColor;
_materialFactory = resourceProvider.GetMaterialFactory();
}
private void OnEnable()
{
CommandExecutorRegistry<ICommand>.Instance.Register(this);
}
private void OnDisable()
{
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
DeActivate();
base.DeActivate();
}
public override void PerformAction(string actionName,
bool overwrite = false,
int loopCount = -1,
WaitUntilCanceled waiter = null)
{
if (!overwrite && string.Equals(GetCurrentAction(), actionName, StringComparison.OrdinalIgnoreCase))
{
return;
}
if (!_actor.HasAction(actionName))
{
Debug.LogError($"Action {actionName} not found for actor {_actor.Info.Name}.");
waiter?.CancelWait();
return;
}
MshFile mshFile;
MtlFile mtlFile;
MovFile movFile;
ITextureResourceProvider textureProvider;
try
{
string mshFilePath = _actor.GetMeshFilePath(actionName);
mshFile = _resourceProvider.GetGameResourceFile<MshFile>(mshFilePath);
string mtlFilePath = _actor.GetMaterialFilePath(actionName);
mtlFile = _resourceProvider.GetGameResourceFile<MtlFile>(mtlFilePath);
string movFilePath = _actor.GetActionFilePath(actionName);
movFile = _resourceProvider.GetGameResourceFile<MovFile>(movFilePath);
textureProvider = _resourceProvider.CreateTextureResourceProvider(
Utility.GetRelativeDirectoryPath(movFilePath));
}
catch (Exception ex)
{
Debug.LogError(ex);
waiter?.CancelWait();
return;
}
DisposeCurrentAction();
_skeletalModelRenderer = gameObject.GetOrAddComponent<SkeletalModelRenderer>();
_skeletalModelRenderer.Init(mshFile,
mtlFile,
_materialFactory,
textureProvider,
_tintColor);
_skeletalModelRenderer.StartAnimation(movFile, loopCount);
_rendererBounds = _skeletalModelRenderer.GetRendererBounds();
_meshBounds = _skeletalModelRenderer.GetMeshBounds();
base.PerformAction(actionName, overwrite, loopCount, waiter);
}
public override float GetActorHeight()
{
if (_skeletalModelRenderer == null || !_skeletalModelRenderer.IsVisible())
{
return _meshBounds.size.y;
}
return _skeletalModelRenderer.GetMeshBounds().size.y;
}
public override Bounds GetRendererBounds()
{
return (_skeletalModelRenderer == null || !_skeletalModelRenderer.IsVisible()) ? _rendererBounds :
_skeletalModelRenderer.GetRendererBounds();
}
public override Bounds GetMeshBounds()
{
return (_skeletalModelRenderer == null || !_skeletalModelRenderer.IsVisible()) ? _meshBounds :
_skeletalModelRenderer.GetMeshBounds();
}
internal override void DisposeCurrentAction()
{
if (_skeletalModelRenderer != null)
{
_skeletalModelRenderer.Dispose();
_skeletalModelRenderer = null;
}
base.DisposeCurrentAction();
}
internal override void DeActivate()
{
DisposeCurrentAction();
base.DeActivate();
}
public void Execute(ActorAutoStandCommand command)
{
if (command.ActorId == _actor.Info.Id) _autoStand = (command.AutoStand == 1);
}
public void Execute(ActorStopActionCommand command)
{
if (command.ActorId != _actor.Info.Id ||
_skeletalModelRenderer == null ||
!_skeletalModelRenderer.IsVisible()) return;
_skeletalModelRenderer.PauseAnimation();
if (_autoStand && _skeletalModelRenderer.IsVisible())
{
PerformAction(_actor.GetIdleAction());
}
}
}
}
@@ -22,7 +22,7 @@ namespace Pal3.Actor
using Script.Waiter;
using UnityEngine;
public class Mv3ActorActionController : ActorActionController,
public class VertexAnimationActorActionController : ActorActionController,
ICommandExecutor<ActorAutoStandCommand>,
ICommandExecutor<ActorStopActionCommand>,
ICommandExecutor<ActorChangeTextureCommand>
@@ -34,7 +34,7 @@ namespace Pal3.Actor
private bool _autoStand = true;
private Mv3ModelRenderer _mv3AnimationRenderer;
private Mv3ModelRenderer _mv3ModelRenderer;
private WaitUntilCanceled _animationLoopPointWaiter;
private Bounds _rendererBounds;
@@ -124,7 +124,7 @@ namespace Pal3.Actor
DisposeCurrentAction();
_animationLoopPointWaiter = waiter;
_mv3AnimationRenderer = gameObject.GetOrAddComponent<Mv3ModelRenderer>();
_mv3ModelRenderer = gameObject.GetOrAddComponent<Mv3ModelRenderer>();
ActorActionType? actionType = ActorConstants.NameToActionMap.ContainsKey(actionName.ToLower()) ?
ActorConstants.NameToActionMap[actionName.ToLower()] : null;
@@ -142,7 +142,7 @@ namespace Pal3.Actor
PolFile polFile = _resourceProvider.GetGameResourceFile<PolFile>(weaponPath);
ITextureResourceProvider weaponTextureProvider = _resourceProvider.CreateTextureResourceProvider(
Utility.GetRelativeDirectoryPath(weaponPath));
_mv3AnimationRenderer.Init(mv3File,
_mv3ModelRenderer.Init(mv3File,
_materialFactory,
textureProvider,
_tintColor,
@@ -151,49 +151,49 @@ namespace Pal3.Actor
}
else
{
_mv3AnimationRenderer.Init(mv3File,
_mv3ModelRenderer.Init(mv3File,
_materialFactory,
textureProvider,
_tintColor);
}
_mv3AnimationRenderer.AnimationLoopPointReached += AnimationLoopPointReached;
_mv3AnimationRenderer.StartAnimation(loopCount);
_mv3ModelRenderer.AnimationLoopPointReached += AnimationLoopPointReached;
_mv3ModelRenderer.StartAnimation(loopCount);
_rendererBounds = _mv3AnimationRenderer.GetRendererBounds();
_meshBounds = _mv3AnimationRenderer.GetMeshBounds();
_rendererBounds = _mv3ModelRenderer.GetRendererBounds();
_meshBounds = _mv3ModelRenderer.GetMeshBounds();
base.PerformAction(actionName, overwrite, loopCount, waiter);
}
public override void PauseAnimation()
{
if (_mv3AnimationRenderer != null)
if (_mv3ModelRenderer != null)
{
_mv3AnimationRenderer.PauseAnimation();
_mv3ModelRenderer.PauseAnimation();
}
}
public override float GetActorHeight()
{
if (_mv3AnimationRenderer == null || !_mv3AnimationRenderer.IsVisible())
if (_mv3ModelRenderer == null || !_mv3ModelRenderer.IsVisible())
{
return _meshBounds.size.y;
}
return _mv3AnimationRenderer.GetMeshBounds().size.y;
return _mv3ModelRenderer.GetMeshBounds().size.y;
}
public override Bounds GetRendererBounds()
{
return (_mv3AnimationRenderer == null || !_mv3AnimationRenderer.IsVisible()) ? _rendererBounds :
_mv3AnimationRenderer.GetRendererBounds();
return (_mv3ModelRenderer == null || !_mv3ModelRenderer.IsVisible()) ? _rendererBounds :
_mv3ModelRenderer.GetRendererBounds();
}
public override Bounds GetMeshBounds()
{
return (_mv3AnimationRenderer == null || !_mv3AnimationRenderer.IsVisible()) ? _meshBounds :
_mv3AnimationRenderer.GetMeshBounds();
return (_mv3ModelRenderer == null || !_mv3ModelRenderer.IsVisible()) ? _meshBounds :
_mv3ModelRenderer.GetMeshBounds();
}
private void AnimationLoopPointReached(object _, int loopCount)
@@ -203,10 +203,10 @@ namespace Pal3.Actor
_animationLoopPointWaiter?.CancelWait();
}
if (_autoStand && _mv3AnimationRenderer.IsVisible())
if (_autoStand && _mv3ModelRenderer.IsVisible())
{
if (loopCount is 0 ||
(loopCount is -2 && !_mv3AnimationRenderer.IsActionInHoldState()))
(loopCount is -2 && !_mv3ModelRenderer.IsActionInHoldState()))
{
PerformAction(_actor.GetIdleAction());
}
@@ -217,10 +217,11 @@ namespace Pal3.Actor
{
_animationLoopPointWaiter?.CancelWait();
if (_mv3AnimationRenderer != null)
if (_mv3ModelRenderer != null)
{
_mv3AnimationRenderer.AnimationLoopPointReached -= AnimationLoopPointReached;
_mv3AnimationRenderer.Dispose();
_mv3ModelRenderer.AnimationLoopPointReached -= AnimationLoopPointReached;
_mv3ModelRenderer.Dispose();
_mv3ModelRenderer = null;
}
base.DisposeCurrentAction();
@@ -229,12 +230,6 @@ namespace Pal3.Actor
internal override void DeActivate()
{
DisposeCurrentAction();
if (_mv3AnimationRenderer != null)
{
Destroy(_mv3AnimationRenderer);
}
base.DeActivate();
}
@@ -246,23 +241,23 @@ namespace Pal3.Actor
public void Execute(ActorStopActionCommand command)
{
if (command.ActorId != _actor.Info.Id ||
_mv3AnimationRenderer == null ||
!_mv3AnimationRenderer.IsVisible()) return;
_mv3ModelRenderer == null ||
!_mv3ModelRenderer.IsVisible()) return;
if (_mv3AnimationRenderer.IsActionInHoldState())
if (_mv3ModelRenderer.IsActionInHoldState())
{
_animationLoopPointWaiter?.CancelWait();
_animationLoopPointWaiter = new WaitUntilCanceled();
CommandDispatcher<ICommand>.Instance.Dispatch(
new ScriptRunnerAddWaiterRequest(_animationLoopPointWaiter));
_mv3AnimationRenderer.ResumeAction();
_mv3ModelRenderer.ResumeAction();
}
else
{
_mv3AnimationRenderer.PauseAnimation();
_mv3ModelRenderer.PauseAnimation();
_animationLoopPointWaiter?.CancelWait();
if (_autoStand && _mv3AnimationRenderer.IsVisible())
if (_autoStand && _mv3ModelRenderer.IsVisible())
{
PerformAction(_actor.GetIdleAction());
}
@@ -272,7 +267,7 @@ namespace Pal3.Actor
public void Execute(ActorChangeTextureCommand command)
{
if (_actor.Info.Id != command.ActorId) return;
_mv3AnimationRenderer.ChangeTexture(command.TextureName);
_mv3ModelRenderer.ChangeTexture(command.TextureName);
}
}
}
+2 -9
View File
@@ -138,7 +138,7 @@ namespace Pal3.Audio
}
_currentMusicClipName = musicName;
var musicFileVirtualPath = GetMusicFileVirtualPath(musicName);
var musicFileVirtualPath = _resourceProvider.GetMusicFileVirtualPath(musicName);
var musicFileCachePath = _resourceProvider.GetMp3FilePathInCacheFolder(musicFileVirtualPath);
yield return PlayMusicAsync(musicName, musicFileVirtualPath, musicFileCachePath, -1);
@@ -257,13 +257,6 @@ namespace Pal3.Audio
}
}
private string GetMusicFileVirtualPath(string musicName)
{
var separator = CpkConstants.DirectorySeparator;
return $"{FileConstants.MusicCpkPathInfo.cpkName}{separator}" +
$"{FileConstants.MusicCpkPathInfo.relativePath}{separator}{musicName}.mp3";
}
public IEnumerator PlayMusicAsync(string musicName,
string musicFileVirtualPath,
string musicFileCachePath,
@@ -447,7 +440,7 @@ namespace Pal3.Audio
_currentScriptMusic = command.MusicName;
_currentMusicClipName = command.MusicName;
var musicFileVirtualPath = GetMusicFileVirtualPath(command.MusicName);
var musicFileVirtualPath = _resourceProvider.GetMusicFileVirtualPath(command.MusicName);
var musicFileCachePath = _resourceProvider.GetMp3FilePathInCacheFolder(musicFileVirtualPath);
StartCoroutine(PlayMusicAsync(command.MusicName,
musicFileVirtualPath,
@@ -22,6 +22,8 @@ namespace Pal3.Data
using Core.DataReader.Ini;
using Core.DataReader.Lgt;
using Core.DataReader.Mov;
using Core.DataReader.Msh;
using Core.DataReader.Mtl;
using Core.DataReader.Mv3;
using Core.DataReader.Nav;
using Core.DataReader.Pol;
@@ -136,18 +138,18 @@ namespace Pal3.Data
new TextureProvider(_fileSystem, _textureLoaderFactory, relativeDirectoryPath);
}
public T GetGameResourceFile<T>(string filePath, bool useCache = true)
public T GetGameResourceFile<T>(string fileVirtualPath, bool useCache = true)
{
filePath = filePath.ToLower();
fileVirtualPath = fileVirtualPath.ToLower();
if (useCache &&
_gameResourceFileCache.ContainsKey(typeof(T)) &&
_gameResourceFileCache[typeof(T)].ContainsKey(filePath))
_gameResourceFileCache[typeof(T)].ContainsKey(fileVirtualPath))
{
return (T)_gameResourceFileCache[typeof(T)][filePath];
return (T)_gameResourceFileCache[typeof(T)][fileVirtualPath];
}
T file = GetGameResourceFileReader<T>().Read(_fileSystem.ReadAllBytes(filePath));
T file = GetGameResourceFileReader<T>().Read(_fileSystem.ReadAllBytes(fileVirtualPath));
if (useCache)
{
@@ -156,17 +158,12 @@ namespace Pal3.Data
{
_gameResourceFileCache[typeof(T)] = new Dictionary<string, object>();
}
_gameResourceFileCache[typeof(T)][filePath] = file;
_gameResourceFileCache[typeof(T)][fileVirtualPath] = file;
}
return file;
}
public LgtFile GetLgt(string lgtFilePath)
{
return GetGameResourceFileReader<LgtFile>().Read(_fileSystem.ReadAllBytes(lgtFilePath));
}
public NavFile GetNav(string sceneFileName, string sceneName)
{
#if PAL3
@@ -285,6 +282,13 @@ namespace Pal3.Data
return sfxFilePath;
}
public string GetMusicFileVirtualPath(string musicName)
{
var separator = CpkConstants.DirectorySeparator;
return $"{FileConstants.MusicCpkPathInfo.cpkName}{separator}" +
$"{FileConstants.MusicCpkPathInfo.relativePath}{separator}{musicName}.mp3";
}
public IEnumerator LoadAudioClipAsync(string filePath,
AudioType audioType,
bool streamAudio,
@@ -650,54 +654,60 @@ namespace Pal3.Data
if (!newCityName.Equals(_currentCityName, StringComparison.OrdinalIgnoreCase))
{
// Clean up cache after exiting current scene block
_textureCache?.DisposeAll();
foreach (Sprite sprite in _spriteCache.Values)
{
Object.Destroy(sprite);
}
_spriteCache.Clear();
if (_gameResourceFileCache.ContainsKey(typeof(PolFile)))
{
_gameResourceFileCache[typeof(PolFile)]?.Clear();
}
if (_gameResourceFileCache.ContainsKey(typeof(CvdFile)))
{
_gameResourceFileCache[typeof(CvdFile)]?.Clear();
}
if (_gameResourceFileCache.ContainsKey(typeof(MovFile)))
{
_gameResourceFileCache[typeof(MovFile)]?.Clear();
}
if (_gameResourceFileCache.ContainsKey(typeof(Mv3File)))
{
var mv3FileCache = _gameResourceFileCache[typeof(Mv3File)];
// Dispose non-main actor mv3 files
// All main actor names start with "1"
var mainActorMv3 = $"{FileConstants.ActorFolderName}{PathSeparator}1".ToLower();
var mv3FilesToDispose = mv3FileCache.Keys
.Where(mv3FilePath => !mv3FilePath.Contains(mainActorMv3))
.ToArray();
foreach (var mv3File in mv3FilesToDispose)
{
mv3FileCache.Remove(mv3File);
}
}
// clear all vfx prefabs in cache
_vfxEffectPrefabCache.Clear();
DisposeTemporaryInMemoryGameResources();
_currentCityName = newCityName;
}
// Unloads assets that are not used (textures etc.)
Resources.UnloadUnusedAssets();
}
/// <summary>
/// Dispose temporary in-memory resources that are only used in current scene block.
/// </summary>
private void DisposeTemporaryInMemoryGameResources()
{
// Clean up texture cache after exiting current scene block
_textureCache?.DisposeAll();
// Clean up sprite cache after exiting current scene block
foreach (Sprite sprite in _spriteCache.Values)
{
Object.Destroy(sprite);
}
_spriteCache.Clear();
// Dispose in-memory game resource files
foreach (var fileCache in _gameResourceFileCache)
{
if (fileCache.Key == typeof(Mv3File))
{
// Dispose non-main actor mv3 files
// All main actor names start with "1"
var mainActorMv3 = $"{FileConstants.ActorFolderName}{PathSeparator}1".ToLower();
var mv3FilesToDispose = fileCache.Value.Keys
.Where(mv3FilePath => !mv3FilePath.Contains(mainActorMv3))
.ToArray();
foreach (var mv3File in mv3FilesToDispose)
{
fileCache.Value.Remove(mv3File);
}
}
else if (fileCache.Key == typeof(GdbFile) ||
fileCache.Key == typeof(Mv3ActionConfig) ||
fileCache.Key == typeof(MovActionConfig))
{
// These files are used/cached across scenes
// Do not dispose them since they will be used in next scene block
}
else // Dispose all other files during scene block transition
{
fileCache.Value.Clear();
}
}
// clear all vfx prefabs in cache
_vfxEffectPrefabCache.Clear();
}
}
}
@@ -15,6 +15,5 @@ namespace Pal3.Dev
{
[SerializeField] public GameBoxBlendFlag blendFlag;
[SerializeField] public GameBoxMaterial material;
[SerializeField] public string[] textureNames;
}
}
@@ -21,6 +21,7 @@ namespace Pal3
using Core.DataReader.Lgt;
using Core.DataReader.Mov;
using Core.DataReader.Msh;
using Core.DataReader.Mtl;
using Core.DataReader.Mv3;
using Core.DataReader.Nav;
using Core.DataReader.Pol;
@@ -163,6 +164,7 @@ namespace Pal3
ServiceLocator.Instance.Register<IFileReader<Mv3File>>(new Mv3FileReader(codepage));
ServiceLocator.Instance.Register<IFileReader<MovFile>>(new MovFileReader(codepage));
ServiceLocator.Instance.Register<IFileReader<MshFile>>(new MshFileReader(codepage));
ServiceLocator.Instance.Register<IFileReader<MtlFile>>(new MtlFileReader(codepage));
ServiceLocator.Instance.Register<IFileReader<PolFile>>(new PolFileReader(codepage));
ServiceLocator.Instance.Register<IFileReader<GdbFile>>(new GdbFileReader(codepage));
ServiceLocator.Instance.Register<IFileReader<LgtFile>>(new LgtFileReader());
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
// version 1.5.1
// version 1.6.1
// from Assets/Scripts/Pal3/Input/PlayerInputActions.inputactions
//
// Changes to this file may cause incorrect behavior and will be lost if
@@ -140,10 +140,11 @@ namespace Pal3.Renderer
{
foreach (CvdMeshSection meshSection in node.Mesh.MeshSections)
{
if (string.IsNullOrEmpty(meshSection.TextureName)) continue;
if (textureCache.ContainsKey(meshSection.TextureName)) continue;
Texture2D texture2D = textureProvider.GetTexture(meshSection.TextureName);
if (texture2D != null) textureCache[meshSection.TextureName] = texture2D;
string textureName = meshSection.Material.TextureFileNames[0];
if (string.IsNullOrEmpty(textureName)) continue;
if (textureCache.ContainsKey(textureName)) continue;
Texture2D texture2D = textureProvider.GetTexture(textureName);
if (texture2D != null) textureCache[textureName] = texture2D;
}
}
@@ -232,8 +233,9 @@ namespace Pal3.Renderer
influence,
frameMatrix);
if (string.IsNullOrEmpty(meshSection.TextureName) ||
!textureCache.ContainsKey(meshSection.TextureName)) continue;
string textureName = meshSection.Material.TextureFileNames[0];
if (string.IsNullOrEmpty(textureName) || !textureCache.ContainsKey(textureName)) continue;
var meshSectionObject = new GameObject($"{sectionHashKey}");
@@ -242,12 +244,11 @@ namespace Pal3.Renderer
var materialInfoPresenter = meshObject.AddComponent<MaterialInfoPresenter>();
materialInfoPresenter.blendFlag = meshSection.BlendFlag;
materialInfoPresenter.material = meshSection.Material;
materialInfoPresenter.textureNames = new[] {meshSection.TextureName};
#endif
Material[] materials = materialFactory.CreateStandardMaterials(
RendererType.Cvd,
(meshSection.TextureName, textureCache[meshSection.TextureName]),
(textureName, textureCache[textureName]),
shadowTexture: (null, null), // CVD models don't have shadow textures
_tintColor,
meshSection.BlendFlag);
@@ -528,7 +529,7 @@ namespace Pal3.Renderer
CvdAnimationScaleKeyFrame fromKeyFrame = nodeScaleInfo[startIndex];
CvdAnimationScaleKeyFrame toKeyFrame = nodeScaleInfo[endIndex];
float influence = (time - fromKeyFrame.Time) / (toKeyFrame.Time - fromKeyFrame.Time);
Quaternion calculatedRotation = Quaternion.Lerp(fromKeyFrame.Rotation, toKeyFrame.Rotation, influence);
Quaternion calculatedRotation = Quaternion.Slerp(fromKeyFrame.Rotation, toKeyFrame.Rotation, influence);
Vector3 calculatedScale = Vector3.Lerp(fromKeyFrame.Scale, toKeyFrame.Scale, influence);
return (calculatedScale, calculatedRotation);
}
@@ -558,7 +559,7 @@ namespace Pal3.Renderer
CvdAnimationRotationKeyFrame fromKeyFrame = nodeRotationInfo[startIndex];
CvdAnimationRotationKeyFrame toKeyFrame = nodeRotationInfo[endIndex];
float influence = (time - fromKeyFrame.Time) / (toKeyFrame.Time - fromKeyFrame.Time);
return Quaternion.Lerp(fromKeyFrame.Rotation, toKeyFrame.Rotation, influence);
return Quaternion.Slerp(fromKeyFrame.Rotation, toKeyFrame.Rotation, influence);
}
public void StopCurrentAnimation()
@@ -26,7 +26,6 @@ namespace Pal3.Renderer
private const string MV3_ANIMATION_HOLD_EVENT_NAME = "hold";
private const string MV3_MODEL_DEFAULT_TEXTURE_EXTENSION = ".tga";
private const float TIME_TO_TICK_SCALE = 5000f;
private ITextureResourceProvider _textureProvider;
private IMaterialFactory _materialFactory;
@@ -104,7 +103,7 @@ namespace Pal3.Renderer
{
Mv3Mesh mesh = mv3File.Meshes[i];
var materialId = mesh.Attributes[0].MaterialId;
Mv3Material material = mv3File.Materials[materialId];
GameBoxMaterial material = mv3File.Materials[materialId];
InitSubMeshes(i, ref mesh, ref material);
}
@@ -137,11 +136,11 @@ namespace Pal3.Renderer
private void InitSubMeshes(int index,
ref Mv3Mesh mv3Mesh,
ref Mv3Material material)
ref GameBoxMaterial material)
{
var textureName = material.TextureNames[0];
var textureName = material.TextureFileNames[0];
_gbMaterials[index] = material.Material;
_gbMaterials[index] = material;
_textures[index] = _textureProvider.GetTexture(textureName, out var hasAlphaChannel);
_textureHasAlphaChannel[index]= hasAlphaChannel;
_animationName[index] = mv3Mesh.Name;
@@ -166,7 +165,6 @@ namespace Pal3.Renderer
GameBoxBlendFlag.AlphaBlend :
GameBoxBlendFlag.Opaque;
materialInfoPresenter.material = _gbMaterials[index];
materialInfoPresenter.textureNames = material.TextureNames;
#endif
var meshRenderer = _meshObjects[index].AddComponent<StaticMeshRenderer>();
@@ -219,7 +217,7 @@ namespace Pal3.Renderer
{
if (_renderMeshComponents == null)
{
throw new Exception("Animation not initialized.");
throw new Exception("Animation model not initialized.");
}
PauseAnimation();
@@ -406,8 +404,7 @@ namespace Pal3.Renderer
while (!cancellationToken.IsCancellationRequested)
{
var tick = ((Time.timeSinceLevelLoad - startTime) * TIME_TO_TICK_SCALE
+ startTick);
uint tick = GameBoxInterpreter.SecondsToTick(Time.timeSinceLevelLoad - startTime) + startTick;
if (tick >= endTick)
{
@@ -421,12 +418,12 @@ namespace Pal3.Renderer
var frameTicks = _frameTicks[i];
var currentFrameIndex = Utility.GetFloorIndex(frameTicks, (uint) tick);
var currentFrameIndex = Utility.GetFloorIndex(frameTicks, tick);
var currentFrameTick = _frameTicks[i][currentFrameIndex];
var nextFrameIndex = currentFrameIndex < frameTicks.Length - 1 ? currentFrameIndex + 1 : 0;
var nextFrameTick = nextFrameIndex == 0 ? endTick : _frameTicks[i][nextFrameIndex];
var influence = (tick - currentFrameTick) / (nextFrameTick - currentFrameTick);
var influence = (float)(tick - currentFrameTick) / (nextFrameTick - currentFrameTick);
var vertices = meshComponent.MeshDataBuffer.VertexBuffer;
for (var j = 0; j < vertices.Length; j++)
@@ -452,11 +449,11 @@ namespace Pal3.Renderer
var nextFrameIndex = currentFrameIndex < frameTicks.Length - 1 ? currentFrameIndex + 1 : 0;
var nextFrameTick = nextFrameIndex == 0 ? endTick : _tagNodeFrameTicks[i][nextFrameIndex];
var influence = (tick - currentFrameTick) / (nextFrameTick - currentFrameTick);
var influence = (float)(tick - currentFrameTick) / (nextFrameTick - currentFrameTick);
Vector3 position = Vector3.Lerp(_tagNodesInfo[i].TagFrames[currentFrameIndex].Position,
_tagNodesInfo[i].TagFrames[nextFrameIndex].Position, influence);
Quaternion rotation = Quaternion.Lerp(_tagNodesInfo[i].TagFrames[currentFrameIndex].Rotation,
Quaternion rotation = Quaternion.Slerp(_tagNodesInfo[i].TagFrames[currentFrameIndex].Rotation,
_tagNodesInfo[i].TagFrames[nextFrameIndex].Rotation, influence);
_tagNodes[i].transform.localPosition = position;
@@ -95,7 +95,7 @@ namespace Pal3.Renderer
{
foreach (PolTexture texture in mesh.Textures)
{
foreach (var textureName in texture.TextureNames)
foreach (var textureName in texture.Material.TextureFileNames)
{
if (string.IsNullOrEmpty(textureName)) continue;
if (textureCache.ContainsKey(textureName)) continue;
@@ -128,7 +128,7 @@ namespace Pal3.Renderer
for (var i = 0; i < mesh.Textures.Length; i++)
{
var textures = new List<(string name, Texture2D texture)>();
foreach (var textureName in mesh.Textures[i].TextureNames)
foreach (var textureName in mesh.Textures[i].Material.TextureFileNames)
{
if (string.IsNullOrEmpty(textureName))
{
@@ -155,7 +155,6 @@ namespace Pal3.Renderer
var materialInfoPresenter = meshObject.AddComponent<MaterialInfoPresenter>();
materialInfoPresenter.blendFlag = mesh.Textures[i].BlendFlag;
materialInfoPresenter.material = mesh.Textures[i].Material;
materialInfoPresenter.textureNames = mesh.Textures[i].TextureNames;
#endif
var meshRenderer = meshObject.AddComponent<StaticMeshRenderer>();
+1 -1
View File
@@ -10,6 +10,6 @@ namespace Pal3.Renderer
Cvd,
Pol,
Mv3,
Mov,
Msh,
}
}
@@ -0,0 +1,486 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Pal3.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.DataLoader;
using Core.DataReader.Mtl;
using Core.GameBox;
using Core.Renderer;
using Core.Utils;
internal class Bone
{
public string Name { get; }
public GameObject GameObject { get; }
public BoneNode BoneNode { get; }
public Matrix4x4 BindPoseModelToBoneSpace { get; set; }
public Matrix4x4 CurrentPoseToModelMatrix { get; set; }
public MovBoneAnimationTrack? AnimationTrack { get; private set; }
public uint[] FrameTicks { get; private set; }
public Bone(string name, GameObject gameObject, BoneNode boneNode)
{
Name = name;
GameObject = gameObject;
BoneNode = boneNode;
BindPoseModelToBoneSpace = Matrix4x4.identity;
CurrentPoseToModelMatrix = Matrix4x4.identity;
}
public bool IsRoot()
{
return BoneNode.ParentId == -1;
}
public void SetAnimationTrack(MovBoneAnimationTrack track)
{
AnimationTrack = track;
FrameTicks = new uint[track.KeyFrames.Length];
for (var i = 0; i < track.KeyFrames.Length; i++)
{
FrameTicks[i] = track.KeyFrames[i].Tick;
}
}
public void DisposeAnimationTrack()
{
AnimationTrack = null;
FrameTicks = null;
CurrentPoseToModelMatrix = Matrix4x4.identity;
}
}
/// <summary>
/// Skeletal animation model renderer
/// MSH(.msh) + MOV(.mov)
/// </summary>
public class SkeletalModelRenderer : MonoBehaviour, IDisposable
{
private IMaterialFactory _materialFactory;
private Material[][] _materials;
private MshFile _mshFile;
private MovFile _movFile;
private (string textureName, Texture2D texture) _mainTexture;
private Texture2D _texture;
private Color _tintColor;
private readonly Dictionary<int, Bone> _bones = new ();
private GameObject _rootBoneObject;
private GameObject[] _meshObjects;
private RenderMeshComponent[] _renderMeshComponents;
private Coroutine _animation;
private CancellationTokenSource _animationCts;
private readonly Dictionary<int, List<int>> _indexBuffer = new();
private readonly Dictionary<int, Vector3[]> _vertexBuffer = new();
public void Init(MshFile mshFile,
MtlFile mtlFile,
IMaterialFactory materialFactory,
ITextureResourceProvider textureProvider,
Color? tintColor = default)
{
Dispose();
_mshFile = mshFile;
_materialFactory = materialFactory;
_tintColor = tintColor ?? Color.white;
// All .mtl files in PAL3 contain only one material,
// and there is only one texture in the material
// so we only need to load the first texture from the
// first material to use as the main texture for the whole model
string textureName = mtlFile.Materials[0].TextureFileNames[0];
_mainTexture = (mtlFile.Materials[0].TextureFileNames[0], textureProvider.GetTexture(textureName));
SetupBone(_mshFile.RootBoneNode, parentBone: null);
RenderMesh();
}
public void StartAnimation(MovFile movFile, int loopCount = -1)
{
if (_renderMeshComponents == null)
{
throw new Exception("Animation model not initialized.");
}
PauseAnimation();
SetupAnimationTrack(movFile);
_animationCts = new CancellationTokenSource();
_animation = StartCoroutine(PlayAnimationInternalAsync(loopCount,
_animationCts.Token));
}
public void PauseAnimation()
{
if (_animation != null)
{
_animationCts.Cancel();
StopCoroutine(_animation);
_animation = null;
}
}
private void SetupAnimationTrack(MovFile movFile)
{
// Reset all existing bone animation tracks
foreach (Bone bone in _bones.Values)
{
bone.DisposeAnimationTrack();
}
_movFile = movFile;
// Bind animation tracks from mov file
foreach (MovBoneAnimationTrack track in _movFile.BoneAnimationTracks)
{
if (_bones.TryGetValue(track.BoneId, out Bone bonne))
{
bonne.SetAnimationTrack(track);
}
}
}
private IEnumerator PlayAnimationInternalAsync(int loopCount,
CancellationToken cancellationToken)
{
if (loopCount == -1) // Infinite loop until cancelled
{
while (!cancellationToken.IsCancellationRequested)
{
yield return PlayOneTimeAnimationInternalAsync(cancellationToken);
}
}
else if (loopCount > 0)
{
while (!cancellationToken.IsCancellationRequested && --loopCount >= 0)
{
yield return PlayOneTimeAnimationInternalAsync(cancellationToken);
}
}
}
private IEnumerator PlayOneTimeAnimationInternalAsync(CancellationToken cancellationToken)
{
var startTime = Time.timeSinceLevelLoad;
while (!cancellationToken.IsCancellationRequested)
{
uint tick = GameBoxInterpreter.SecondsToTick(Time.timeSinceLevelLoad - startTime);
if (tick >= _movFile.Duration)
{
yield break;
}
UpdateBone(_bones[0], tick);
UpdateSkinning();
yield return null;
}
}
private void UpdateBone(Bone bone, uint tick)
{
GameObject boneGo = bone.GameObject;
MovBoneAnimationTrack? track = bone.AnimationTrack;
BoneNode boneNode = bone.BoneNode;
if (track != null)
{
int currentFrameIndex = Utility.GetFloorIndex(bone.FrameTicks, tick);
uint currentFrameTick = bone.FrameTicks[currentFrameIndex];
var nextFrameIndex = currentFrameIndex < bone.FrameTicks.Length - 1 ? currentFrameIndex + 1 : 0;
uint nextFrameTick = nextFrameIndex == 0 ? _movFile.Duration : bone.FrameTicks[nextFrameIndex];
var influence = (float)(tick - currentFrameTick) / (nextFrameTick - currentFrameTick);
Vector3 localPosition = Vector3.Lerp(
track.Value.KeyFrames[currentFrameIndex].Translation,
track.Value.KeyFrames[nextFrameIndex].Translation,
influence);
Quaternion localRotation = Quaternion.Slerp(
track.Value.KeyFrames[currentFrameIndex].Rotation,
track.Value.KeyFrames[nextFrameIndex].Rotation,
influence);
boneGo.transform.localPosition = localPosition;
boneGo.transform.localRotation = localRotation;
Matrix4x4 curPoseToModelMatrix = Matrix4x4.Translate(localPosition) * Matrix4x4.Rotate(localRotation);
if (!bone.IsRoot())
{
curPoseToModelMatrix = _bones[boneNode.ParentId].CurrentPoseToModelMatrix * curPoseToModelMatrix;
}
bone.CurrentPoseToModelMatrix = curPoseToModelMatrix;
}
// Update children
for (var i = 0; i < boneNode.Children.Length; i++)
{
Bone childBone = _bones[boneNode.Children[i].Id];
UpdateBone(childBone, tick);
}
}
private void UpdateSkinning()
{
for (int subMeshIndex = 0; subMeshIndex < _renderMeshComponents.Length; subMeshIndex++)
{
MshMesh subMesh = _mshFile.SubMeshes[subMeshIndex];
Mesh mesh = _renderMeshComponents[subMeshIndex].Mesh;
mesh.SetVertices(BuildVerticesWithCurrentSkeleton(subMesh, subMeshIndex));
mesh.RecalculateBounds();
}
}
private void SetupBone(BoneNode boneNode, Bone parentBone)
{
GameObject boneGo = new GameObject($"{boneNode.Id}_{boneNode.Name}_{boneNode.Type}");
boneGo.transform.SetParent(parentBone == null ? gameObject.transform : parentBone.GameObject.transform);
boneGo.transform.localPosition = boneNode.Translation;
boneGo.transform.localRotation = boneNode.Rotation;
Bone bone = new (boneNode.Name, boneGo, boneNode);
if (parentBone == null)
{
_rootBoneObject = boneGo;
}
else
{
_bones.Add(boneNode.Id, bone);
Matrix4x4 translationMatrix = Matrix4x4.Translate(boneNode.Translation);
Matrix4x4 rotationMatrix = Matrix4x4.Rotate(boneNode.Rotation);
bone.BindPoseModelToBoneSpace = Matrix4x4.Inverse(rotationMatrix)
* Matrix4x4.Inverse(translationMatrix)
* parentBone.BindPoseModelToBoneSpace;
}
// Render child bones
foreach (BoneNode subBone in boneNode.Children)
{
SetupBone(subBone, bone);
}
}
private void RenderMesh()
{
if (_mshFile.SubMeshes.Length == 0) return;
_renderMeshComponents = new RenderMeshComponent[_mshFile.SubMeshes.Length];
_meshObjects = new GameObject[_mshFile.SubMeshes.Length];
for (var i = 0; i < _mshFile.SubMeshes.Length; i++)
{
MshMesh subMesh = _mshFile.SubMeshes[i];
RenderSubMesh(subMesh, i);
}
}
private void RenderSubMesh(MshMesh subMesh, int subMeshIndex)
{
_meshObjects[subMeshIndex] = new GameObject($"SubMesh_{subMeshIndex}");
_meshObjects[subMeshIndex].transform.SetParent(gameObject.transform, false);
List<Vector3> vertices = new List<Vector3>();
List<int> triangles = new List<int>();
Vector3[] normals = null;
List<Vector2> uvs = new List<Vector2>();
_indexBuffer[subMeshIndex] = new List<int>();
_vertexBuffer[subMeshIndex] = new Vector3[subMesh.Vertices.Length];
var index = 0;
foreach (PhyFace phyFace in subMesh.Faces)
{
for (var i = 0; i < phyFace.Indices.Length; i++)
{
_indexBuffer[subMeshIndex].Add(phyFace.Indices[i]);
uvs.Add(new Vector2(phyFace.U[i, 0], phyFace.V[i, 0]));
triangles.Add(index++);
}
}
GameBoxInterpreter.ToUnityTriangles(triangles);
for (var i = 0; i < _indexBuffer[subMeshIndex].Count; i++)
{
vertices.Add(subMesh.Vertices[_indexBuffer[subMeshIndex][i]].Position);
}
Material[] materials = _materialFactory.CreateStandardMaterials(
RendererType.Msh,
_mainTexture,
default,
_tintColor,
GameBoxBlendFlag.Opaque);
Vector3[] verts = vertices.ToArray();
int[] tris = triangles.ToArray();
Vector2[] uvs1 = uvs.ToArray();
Vector2[] uvs2 = null;
var meshRenderer = _meshObjects[subMeshIndex].AddComponent<StaticMeshRenderer>();
Mesh renderMesh = meshRenderer.Render(
ref verts,
ref tris,
ref normals,
ref uvs1,
ref uvs2,
ref materials,
true);
renderMesh.RecalculateNormals();
renderMesh.RecalculateTangents();
renderMesh.RecalculateBounds();
_renderMeshComponents[subMeshIndex] = new RenderMeshComponent
{
Mesh = renderMesh,
MeshRenderer = meshRenderer,
MeshDataBuffer = new MeshDataBuffer()
{
VertexBuffer = verts
}
};
}
private Vector3[] BuildVerticesWithCurrentSkeleton(MshMesh subMesh, int subMeshIndex)
{
for (var i = 0; i < subMesh.Vertices.Length; i++)
{
PhyVertex vert = subMesh.Vertices[i];
int boneId = vert.BoneIds[0];
Bone bone = _bones[boneId];
Vector4 originalPosition = new Vector4(vert.Position.x, vert.Position.y, vert.Position.z, 1.0f);
Vector4 currentPosition = bone.CurrentPoseToModelMatrix * bone.BindPoseModelToBoneSpace * originalPosition;
_vertexBuffer[subMeshIndex][i] = new Vector3(
currentPosition.x / currentPosition.w,
currentPosition.y / currentPosition.w,
currentPosition.z / currentPosition.w);
}
Vector3[] vertices = _renderMeshComponents[subMeshIndex].Mesh.vertices;
for (var i = 0; i < _indexBuffer[subMeshIndex].Count; i++)
{
vertices[i] = _vertexBuffer[subMeshIndex][_indexBuffer[subMeshIndex][i]];
}
return vertices;
}
public Bounds GetRendererBounds()
{
if (_renderMeshComponents.Length == 0)
{
return new Bounds(transform.position, Vector3.one);
}
Bounds bounds = _renderMeshComponents[0].MeshRenderer.GetRendererBounds();
for (var i = 1; i < _renderMeshComponents.Length; i++)
{
bounds.Encapsulate(_renderMeshComponents[i].MeshRenderer.GetRendererBounds());
}
return bounds;
}
public Bounds GetMeshBounds()
{
if (_renderMeshComponents.Length == 0)
{
return new Bounds(Vector3.zero, Vector3.one);
}
Bounds bounds = _renderMeshComponents[0].MeshRenderer.GetMeshBounds();
for (var i = 1; i < _renderMeshComponents.Length; i++)
{
bounds.Encapsulate(_renderMeshComponents[i].MeshRenderer.GetMeshBounds());
}
return bounds;
}
public bool IsVisible()
{
return _meshObjects != null;
}
private void OnDisable()
{
Dispose();
}
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 (_bones != null)
{
foreach (Bone bone in _bones.Values)
{
Destroy(bone.GameObject);
}
_bones.Clear();
}
if (_rootBoneObject != null)
{
Destroy(_rootBoneObject);
_rootBoneObject = null;
}
_indexBuffer.Clear();
_vertexBuffer.Clear();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ebe885a4d2b24f37a437c3c479c9291c
timeCreated: 1690401815
+1 -1
View File
@@ -110,7 +110,7 @@ namespace Pal3.Scene
// information to be used for lighting, so we are not using it for now.
// if (_resourceProvider.FileExists(sceneMetadataFilePrefix + ".lgt"))
// {
// LgtFile = _resourceProvider.GetLgt(sceneMetadataFilePrefix + ".lgt");
// LgtFile = _resourceProvider.GetGameResourceFile<LgtFile>(sceneMetadataFilePrefix + ".lgt");
// }
}
+6 -1
View File
@@ -113,9 +113,14 @@ namespace Pal3.Scene
{
CommandDispatcher<ICommand>.Instance.Dispatch(new SceneLeavingCurrentSceneNotification());
Object.Destroy(_currentScene);
Object.Destroy(_currentSceneRoot);
_currentScene = null;
}
if (_currentSceneRoot != null)
{
Object.Destroy(_currentSceneRoot);
_currentSceneRoot = null;
}
}
public void Execute(SceneLoadCommand command)
@@ -103,6 +103,7 @@ namespace Pal3.Scene.SceneObjects
{
_triggerController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_triggerController);
_triggerController = null;
}
base.Deactivate();
@@ -112,11 +112,13 @@ namespace Pal3.Scene.SceneObjects
_triggerController.OnPlayerActorEntered -= OnPlayerActorEntered;
_triggerController.OnPlayerActorExited -= OnPlayerActorExited;
Object.Destroy(_triggerController);
_triggerController = null;
}
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -43,6 +43,7 @@ namespace Pal3.Scene.SceneObjects.Common
if (_collider != null)
{
Destroy(_collider);
_collider = null;
}
}
@@ -69,6 +69,7 @@ namespace Pal3.Scene.SceneObjects.Common
if (_collider != null)
{
Destroy(_collider);
_collider = null;
}
}
}
@@ -80,6 +80,7 @@ namespace Pal3.Scene.SceneObjects.Common
if (_collider != null)
{
Destroy(_collider);
_collider = null;
}
}
}
@@ -75,6 +75,7 @@ namespace Pal3.Scene.SceneObjects
if (_platformController != null)
{
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -149,6 +149,7 @@ namespace Pal3.Scene.SceneObjects
_platformController.OnPlayerActorEntered -= OnPlayerActorEntered;
_platformController.OnPlayerActorExited -= OnPlayerActorExited;
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -55,6 +55,7 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -100,6 +100,7 @@ namespace Pal3.Scene.SceneObjects
{
_triggerController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_triggerController);
_triggerController = null;
}
base.Deactivate();
@@ -120,6 +120,7 @@ namespace Pal3.Scene.SceneObjects
{
_platformController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -89,12 +89,14 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
if (_triggerController != null)
{
_triggerController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_triggerController);
_triggerController = null;
}
base.Deactivate();
@@ -80,6 +80,7 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -117,6 +117,7 @@ namespace Pal3.Scene.SceneObjects
{
_platformController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -56,6 +56,7 @@ namespace Pal3.Scene.SceneObjects
_triggerController.OnPlayerActorEntered -= OnPlayerActorEntered;
_triggerController.OnPlayerActorExited -= OnPlayerActorExited;
Object.Destroy(_triggerController);
_triggerController = null;
}
base.Deactivate();
@@ -168,11 +168,13 @@ namespace Pal3.Scene.SceneObjects
if (_platformController != null)
{
Object.Destroy(_platformController);
_platformController = null;
}
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -225,6 +225,7 @@ namespace Pal3.Scene.SceneObjects
{
_platformController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -92,6 +92,7 @@ namespace Pal3.Scene.SceneObjects
if (_platformController != null)
{
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -130,6 +130,7 @@ namespace Pal3.Scene.SceneObjects
{
_platformController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -114,6 +114,7 @@ namespace Pal3.Scene.SceneObjects
{
_triggerController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_triggerController);
_triggerController = null;
}
base.Deactivate();
@@ -391,6 +391,7 @@ namespace Pal3.Scene.SceneObjects
{
_triggerController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_triggerController);
_triggerController = null;
}
if (_standingPlatformController != null)
@@ -75,6 +75,7 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -57,6 +57,7 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -130,11 +130,13 @@ namespace Pal3.Scene.SceneObjects
if (_platformController != null)
{
Object.Destroy(_platformController);
_platformController = null;
}
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -91,6 +91,7 @@ namespace Pal3.Scene.SceneObjects
if (_platformController != null)
{
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -83,16 +83,19 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
if (_subObjectMeshCollider != null)
{
Object.Destroy(_subObjectMeshCollider);
_subObjectMeshCollider = null;
}
if (_subObjectGameObject != null)
{
Object.Destroy(_subObjectGameObject);
_subObjectGameObject = null;
}
base.Deactivate();
@@ -281,6 +281,7 @@ namespace Pal3.Scene.SceneObjects
if (_sceneObjectGameObject != null)
{
Object.Destroy(_sceneObjectGameObject);
_sceneObjectGameObject = null;
}
}
@@ -66,6 +66,7 @@ namespace Pal3.Scene.SceneObjects
if (_standingPlatformController != null)
{
Object.Destroy(_standingPlatformController);
_standingPlatformController = null;
}
base.Deactivate();
@@ -113,6 +113,7 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -113,6 +113,7 @@ namespace Pal3.Scene.SceneObjects
private void OnDisable()
{
Destroy(_effectComponent);
_effectComponent = null;
}
}
}
@@ -89,6 +89,7 @@ namespace Pal3.Scene.SceneObjects
if (_platformController != null)
{
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -124,6 +124,8 @@ namespace Pal3.Scene.SceneObjects
_interactionIndicatorRenderer.Dispose();
Object.Destroy(_interactionIndicatorRenderer);
Object.Destroy(_interactionIndicatorGameObject);
_interactionIndicatorRenderer = null;
_interactionIndicatorGameObject = null;
}
if (ctx.StartedByPlayer &&
@@ -204,11 +206,13 @@ namespace Pal3.Scene.SceneObjects
{
_interactionIndicatorRenderer.Dispose();
Object.Destroy(_interactionIndicatorRenderer);
_interactionIndicatorRenderer = null;
}
if (_interactionIndicatorGameObject != null)
{
Object.Destroy(_interactionIndicatorGameObject);
_interactionIndicatorGameObject = null;
}
base.Deactivate();
@@ -85,6 +85,7 @@ namespace Pal3.Scene.SceneObjects
if (_platformController != null)
{
Object.Destroy(_platformController);
_platformController = null;
}
base.Deactivate();
@@ -104,6 +104,7 @@ namespace Pal3.Scene.SceneObjects
if (_standingPlatformController != null)
{
Object.Destroy(_standingPlatformController);
_standingPlatformController = null;
}
base.Deactivate();
@@ -146,6 +146,7 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -159,6 +159,7 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
@@ -95,6 +95,7 @@ namespace Pal3.Scene.SceneObjects
{
_triggerController.OnPlayerActorEntered -= OnPlayerActorEntered;
Object.Destroy(_triggerController);
_triggerController = null;
}
base.Deactivate();
@@ -99,6 +99,7 @@ namespace Pal3.Scene.SceneObjects
if (ObjectInfo.Parameters[0] == 1 && _meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
}
@@ -143,6 +144,7 @@ namespace Pal3.Scene.SceneObjects
if (_meshCollider != null)
{
Object.Destroy(_meshCollider);
_meshCollider = null;
}
base.Deactivate();
+1 -1
View File
@@ -21,7 +21,7 @@ namespace Pal3.UI
public void Init(GameResourceProvider gameResourceProvider)
{
gameResourceProvider = Requires.IsNotNull(gameResourceProvider, nameof(gameResourceProvider));
Requires.IsNotNull(gameResourceProvider, nameof(gameResourceProvider));
_cursorTextureNormal = gameResourceProvider.GetCursorTexture();
Cursor.SetCursor(_cursorTextureNormal, Vector2.zero, CursorMode.Auto);
}
@@ -48,8 +48,8 @@ namespace Pal3.UI
private void OnDestroy()
{
Destroy(_material);
image = null;
_material = null;
image = null;
}
private void OnRectTransformDimensionsChange()
@@ -16,6 +16,8 @@ namespace ResourceViewer
using Core.DataReader.Cpk;
using Core.DataReader.Cvd;
using Core.DataReader.Gdb;
using Core.DataReader.Mov;
using Core.DataReader.Msh;
using Core.DataReader.Mv3;
using Core.DataReader.Pol;
using Core.DataReader.Sce;
+4 -4
View File
@@ -6,14 +6,14 @@
"com.unity.ide.rider": "3.0.24",
"com.unity.ide.visualstudio": "2.0.18",
"com.unity.ide.vscode": "1.2.5",
"com.unity.inputsystem": "1.6.1",
"com.unity.inputsystem": "1.6.3",
"com.unity.memoryprofiler": "1.0.0",
"com.unity.postprocessing": "3.2.2",
"com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.7.4",
"com.unity.toolchain.macos-x86_64-linux-x86_64": "2.0.4",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.4",
"com.unity.timeline": "1.7.5",
"com.unity.toolchain.macos-x86_64-linux-x86_64": "2.0.6",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.6",
"com.unity.ugui": "1.0.0",
"com.unity.visualscripting": "1.8.0",
"com.unity.modules.ai": "1.0.0",
+11 -11
View File
@@ -70,7 +70,7 @@
"url": "https://packages.unity.com"
},
"com.unity.inputsystem": {
"version": "1.6.1",
"version": "1.6.3",
"depth": 0,
"source": "registry",
"dependencies": {
@@ -111,18 +111,18 @@
"url": "https://packages.unity.com"
},
"com.unity.sysroot": {
"version": "2.0.5",
"version": "2.0.7",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.sysroot.linux-x86_64": {
"version": "2.0.4",
"version": "2.0.6",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.sysroot": "2.0.5"
"com.unity.sysroot": "2.0.7"
},
"url": "https://packages.unity.com"
},
@@ -157,7 +157,7 @@
"url": "https://packages.unity.com"
},
"com.unity.timeline": {
"version": "1.7.4",
"version": "1.7.5",
"depth": 0,
"source": "registry",
"dependencies": {
@@ -169,22 +169,22 @@
"url": "https://packages.unity.com"
},
"com.unity.toolchain.macos-x86_64-linux-x86_64": {
"version": "2.0.4",
"version": "2.0.6",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.sysroot": "2.0.5",
"com.unity.sysroot.linux-x86_64": "2.0.4"
"com.unity.sysroot": "2.0.7",
"com.unity.sysroot.linux-x86_64": "2.0.6"
},
"url": "https://packages.unity.com"
},
"com.unity.toolchain.win-x86_64-linux-x86_64": {
"version": "2.0.4",
"version": "2.0.6",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.sysroot": "2.0.5",
"com.unity.sysroot.linux-x86_64": "2.0.4"
"com.unity.sysroot": "2.0.7",
"com.unity.sysroot.linux-x86_64": "2.0.6"
},
"url": "https://packages.unity.com"
},
+7 -5
View File
@@ -133,7 +133,7 @@ PlayerSettings:
vulkanEnableLateAcquireNextImage: 0
vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0
bundleVersion: 0.64
bundleVersion: 0.66
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
@@ -160,6 +160,7 @@ PlayerSettings:
buildNumber:
Bratwurst: 0
Standalone: 0
VisionOS: 0
iPhone: 0
tvOS: 0
overrideDefaultApplicationIdentifier: 1
@@ -184,8 +185,8 @@ PlayerSettings:
tvOSSdkVersion: 0
tvOSRequireExtendedGameController: 0
tvOSTargetOSVersionString: 12.0
bratwurstSdkVersion: 0
bratwurstTargetOSVersionString: 16.4
VisionOSSdkVersion: 0
VisionOSTargetOSVersionString: 1.0
uIPrerenderedIcon: 0
uIRequiresPersistentWiFi: 0
uIRequiresFullScreen: 1
@@ -233,10 +234,10 @@ PlayerSettings:
appleDeveloperTeamID: 4997CKN8MT
iOSManualSigningProvisioningProfileID:
tvOSManualSigningProvisioningProfileID:
bratwurstManualSigningProvisioningProfileID:
VisionOSManualSigningProvisioningProfileID:
iOSManualSigningProvisioningProfileType: 0
tvOSManualSigningProvisioningProfileType: 0
bratwurstManualSigningProvisioningProfileType: 0
VisionOSManualSigningProvisioningProfileType: 0
appleEnableAutomaticSigning: 0
iOSRequireARKit: 0
iOSAutomaticallyDetectAndAddCapabilities: 1
@@ -919,6 +920,7 @@ PlayerSettings:
QNX: UNITY_POST_PROCESSING_STACK_V2
Stadia: UNITY_POST_PROCESSING_STACK_V2
Standalone: PAL3;UNITY_POST_PROCESSING_STACK_V2
VisionOS: UNITY_POST_PROCESSING_STACK_V2
WebGL: UNITY_POST_PROCESSING_STACK_V2
Windows Store Apps: UNITY_POST_PROCESSING_STACK_V2
XboxOne: UNITY_POST_PROCESSING_STACK_V2
+2 -2
View File
@@ -1,2 +1,2 @@
m_EditorVersion: 2022.3.4f1
m_EditorVersionWithRevision: 2022.3.4f1 (35713cd46cd7)
m_EditorVersion: 2022.3.5f1
m_EditorVersionWithRevision: 2022.3.5f1 (9674261d40ee)