More abstractions and bug fixes

This commit is contained in:
Jiaqi Liu committed 2023-10-11 20:49:46 -07:00
1 parent b380075ee3
commit 1a03b20e0e
136 files changed
+872 -485

No files matched your search

@@ -1,38 +0,0 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Abstraction
{
using System;
public interface IGameEntity : IManagedObject
{
public string Name { get; set; }
public bool IsStatic { get; set; }
public ITransform Transform { get; }
public void SetParent(IGameEntity parent, bool worldPositionStays);
public T AddComponent<T>() where T : class;
public object AddComponent(Type type);
public T GetComponent<T>() where T : class;
public T GetComponentInChildren<T>() where T : class;
public T[] GetComponentsInChildren<T>() where T : class;
public T GetOrAddComponent<T>() where T : class;
public void SetLayer(int layerIndex);
public IGameEntity FindChild(string name);
public void Destroy();
}
}
@@ -1,14 +0,0 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Abstraction
{
public interface IManagedObject
{
public object NativeObject { get; }
public bool IsNativeObjectDisposed { get; }
}
}
@@ -1,45 +0,0 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Abstraction
{
using Quaternion = UnityEngine.Quaternion;
using Vector3 = UnityEngine.Vector3;
public interface ITransform : IManagedObject
{
public Vector3 Position { get; set; }
public Vector3 LocalPosition { get; set; }
public Quaternion Rotation { get; set; }
public Quaternion LocalRotation { get; set; }
public Vector3 LocalScale { get; set; }
public Vector3 Forward { get; set; }
public Vector3 Right { get; set; }
public Vector3 Up { get; set; }
public Vector3 EulerAngles { get; set; }
public void Translate(Vector3 translation);
public void GetPositionAndRotation(out Vector3 position, out Quaternion rotation);
public void SetPositionAndRotation(Vector3 position, Quaternion rotation);
public void GetLocalPositionAndRotation(out Vector3 position, out Quaternion rotation);
public void SetLocalPositionAndRotation(Vector3 position, Quaternion rotation);
public void LookAt(Vector3 target);
public void RotateAround(Vector3 centerPoint, Vector3 axis, float angle);
}
}
@@ -8,7 +8,7 @@ namespace Engine.Animation
using System;
using System.Collections;
using System.Threading;
using Abstraction;
using Core.Abstraction;
using Pal3.Core.Utilities;
using Services;
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9ef6c3bf5b624020a27bfc25b422e590
timeCreated: 1697047338
@@ -0,0 +1,96 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Core.Abstraction
{
using System;
/// <summary>
/// Represents a game entity that can be added to the game world.
/// </summary>
public interface IGameEntity : IManagedObject
{
/// <summary>
/// Gets or sets the name of the game entity.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the game entity is static.
/// </summary>
public bool IsStatic { get; set; }
/// <summary>
/// Gets or sets the layer of the game entity.
/// </summary>
public int Layer { get; set; }
/// <summary>
/// Gets the transform of the game entity.
/// </summary>
public ITransform Transform { get; }
/// <summary>
/// Sets the parent of the game entity.
/// </summary>
/// <param name="parent">The parent game entity.</param>
/// <param name="worldPositionStays">Whether to keep the world position of the game entity.</param>
public void SetParent(IGameEntity parent, bool worldPositionStays);
/// <summary>
/// Adds a component of the specified type to the game entity.
/// </summary>
/// <typeparam name="T">The type of the component to add.</typeparam>
/// <returns>The added component.</returns>
public T AddComponent<T>() where T : class;
/// <summary>
/// Adds a component of the specified type to the game entity.
/// </summary>
/// <param name="type">The type of the component to add.</param>
/// <returns>The added component.</returns>
public object AddComponent(Type type);
/// <summary>
/// Gets the component of the specified type from the game entity.
/// </summary>
/// <typeparam name="T">The type of the component to get.</typeparam>
/// <returns>The component of the specified type.</returns>
public T GetComponent<T>() where T : class;
/// <summary>
/// Gets the component of the specified type from the children of the game entity.
/// </summary>
/// <typeparam name="T">The type of the component to get.</typeparam>
/// <returns>The component of the specified type.</returns>
public T GetComponentInChildren<T>() where T : class;
/// <summary>
/// Gets all the components of the specified type from the children of the game entity.
/// </summary>
/// <typeparam name="T">The type of the components to get.</typeparam>
/// <returns>All the components of the specified type.</returns>
public T[] GetComponentsInChildren<T>() where T : class;
/// <summary>
/// Gets the component of the specified type from the game entity, or adds it if it doesn't exist.
/// </summary>
/// <typeparam name="T">The type of the component to get or add.</typeparam>
/// <returns>The component of the specified type.</returns>
public T GetOrAddComponent<T>() where T : class;
/// <summary>
/// Finds the child game entity with the specified name.
/// </summary>
/// <param name="name">The name of the child game entity.</param>
/// <returns>The child game entity with the specified name.</returns>
public IGameEntity FindChild(string name);
/// <summary>
/// Destroys the game entity.
/// </summary>
public void Destroy();
}
}
@@ -0,0 +1,23 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Core.Abstraction
{
/// <summary>
/// Interface for managed objects that wrap native objects.
/// </summary>
public interface IManagedObject
{
/// <summary>
/// Gets the underlying native object.
/// </summary>
object NativeObject { get; }
/// <summary>
/// Gets a value indicating whether the underlying native object has been disposed.
/// </summary>
bool IsNativeObjectDisposed { get; }
}
}
@@ -0,0 +1,109 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Core.Abstraction
{
using Quaternion = UnityEngine.Quaternion;
using Vector3 = UnityEngine.Vector3;
/// <summary>
/// Interface for a transform object, which represents the position, rotation, and scale of a game object.
/// </summary>
public interface ITransform : IManagedObject
{
/// <summary>
/// The position of the transform in world space.
/// </summary>
public Vector3 Position { get; set; }
/// <summary>
/// The position of the transform relative to the parent transform.
/// </summary>
public Vector3 LocalPosition { get; set; }
/// <summary>
/// The rotation of the transform in world space.
/// </summary>
public Quaternion Rotation { get; set; }
/// <summary>
/// The rotation of the transform relative to the parent transform.
/// </summary>
public Quaternion LocalRotation { get; set; }
/// <summary>
/// The scale of the transform relative to the parent transform.
/// </summary>
public Vector3 LocalScale { get; set; }
/// <summary>
/// The forward direction of the transform in world space.
/// </summary>
public Vector3 Forward { get; set; }
/// <summary>
/// The right direction of the transform in world space.
/// </summary>
public Vector3 Right { get; set; }
/// <summary>
/// The up direction of the transform in world space.
/// </summary>
public Vector3 Up { get; set; }
/// <summary>
/// The rotation of the transform expressed as euler angles.
/// </summary>
public Vector3 EulerAngles { get; set; }
/// <summary>
/// Translates the transform by the given vector.
/// </summary>
/// <param name="translation">The vector to translate by.</param>
public void Translate(Vector3 translation);
/// <summary>
/// Gets the position and rotation of the transform in world space.
/// </summary>
/// <param name="position">The position of the transform.</param>
/// <param name="rotation">The rotation of the transform.</param>
public void GetPositionAndRotation(out Vector3 position, out Quaternion rotation);
/// <summary>
/// Sets the position and rotation of the transform in world space.
/// </summary>
/// <param name="position">The new position of the transform.</param>
/// <param name="rotation">The new rotation of the transform.</param>
public void SetPositionAndRotation(Vector3 position, Quaternion rotation);
/// <summary>
/// Gets the position and rotation of the transform relative to the parent transform.
/// </summary>
/// <param name="position">The local position of the transform.</param>
/// <param name="rotation">The local rotation of the transform.</param>
public void GetLocalPositionAndRotation(out Vector3 position, out Quaternion rotation);
/// <summary>
/// Sets the position and rotation of the transform relative to the parent transform.
/// </summary>
/// <param name="position">The new local position of the transform.</param>
/// <param name="rotation">The new local rotation of the transform.</param>
public void SetLocalPositionAndRotation(Vector3 position, Quaternion rotation);
/// <summary>
/// Rotates the transform to face the given target position.
/// </summary>
/// <param name="target">The position to look at.</param>
public void LookAt(Vector3 target);
/// <summary>
/// Rotates the transform around the given axis by the given angle.
/// </summary>
/// <param name="centerPoint">The point to rotate around.</param>
/// <param name="axis">The axis to rotate around.</param>
/// <param name="angle">The angle to rotate by.</param>
public void RotateAround(Vector3 centerPoint, Vector3 axis, float angle);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71c833e2c02a4823afe8d7832e814abc
timeCreated: 1697047365
@@ -3,9 +3,10 @@
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Abstraction
namespace Engine.Core.Implementation
{
using System;
using Abstraction;
using Extensions;
using Pal3.Core.Utilities;
using UnityEngine;
@@ -50,6 +51,12 @@ namespace Engine.Abstraction
set => _gameObject.isStatic = value;
}
public int Layer
{
get => _gameObject.layer;
set => _gameObject.layer = value;
}
public void SetParent(IGameEntity parent, bool worldPositionStays)
{
_gameObject.transform.SetParent((UnityEngine.Transform)parent?.Transform.NativeObject, worldPositionStays);
@@ -114,11 +121,6 @@ namespace Engine.Abstraction
return component;
}
public void SetLayer(int layerIndex)
{
_gameObject.layer = layerIndex;
}
public IGameEntity FindChild(string name)
{
UnityEngine.Transform childTransform = _gameObject.transform.Find(name);
@@ -3,13 +3,26 @@
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Abstraction
namespace Engine.Core.Implementation
{
using System;
using Abstraction;
public static class PrefabFactory
public static class GameEntityFactory
{
public static IGameEntity Instantiate(object prefab, ITransform transform, bool worldPositionStays = false)
public static IGameEntity Create(string name)
{
return name != null ? new GameEntity(name) : new GameEntity();
}
public static IGameEntity Create(string name, IGameEntity parent, bool worldPositionStays = false)
{
IGameEntity gameEntity = Create(name);
gameEntity.SetParent(parent, worldPositionStays);
return gameEntity;
}
public static IGameEntity Create(string name, object prefab, IGameEntity parent, bool worldPositionStays = false)
{
if (prefab.GetType() != typeof(UnityEngine.Object) && !prefab.GetType().IsSubclassOf(typeof(UnityEngine.Object)))
{
@@ -18,14 +31,15 @@ namespace Engine.Abstraction
Object gameObject = UnityEngine.Object.Instantiate(
(UnityEngine.Object) prefab,
(UnityEngine.Transform) transform.NativeObject,
(UnityEngine.Transform) parent?.Transform?.NativeObject,
worldPositionStays);
if (gameObject == null || gameObject.GetType() != typeof(UnityEngine.GameObject))
{
throw new NullReferenceException("The instantiated object is not UnityEngine.GameObject or game object is null");
throw new NullReferenceException("The instantiated object is not UnityEngine.GameObject or prefab is not found");
}
((UnityEngine.GameObject)gameObject).name = name;
return new GameEntity((UnityEngine.GameObject) gameObject);
}
}
@@ -3,10 +3,11 @@
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Abstraction
namespace Engine.Core.Implementation
{
using System;
using System.Collections;
using Abstraction;
using UnityEngine;
public abstract class GameEntityScript : MonoBehaviour
@@ -3,7 +3,7 @@
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Abstraction
namespace Engine.Core.Implementation
{
using UnityEngine;
@@ -3,9 +3,10 @@
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Abstraction
namespace Engine.Core.Implementation
{
using System.Runtime.CompilerServices;
using Abstraction;
using UnityEngine;
public sealed class Transform : ITransform
@@ -8,13 +8,26 @@ namespace Engine.Coroutine
using System;
using UnityEngine;
/// <summary>
/// A static class that provides yield instructions for coroutines.
/// </summary>
public static class CoroutineYieldInstruction
{
/// <summary>
/// Waits for the specified number of seconds before continuing the coroutine.
/// </summary>
/// <param name="seconds">The number of seconds to wait.</param>
/// <returns>A yield instruction that waits for the specified number of seconds.</returns>
public static object WaitForSeconds(float seconds)
{
return new WaitForSeconds(seconds);
}
/// <summary>
/// Waits until the specified predicate returns true before continuing the coroutine.
/// </summary>
/// <param name="predicate">The predicate to evaluate.</param>
/// <returns>A yield instruction that waits until the predicate returns true.</returns>
public static object WaitUntil(Func<bool> predicate)
{
return new WaitUntil(predicate);
@@ -7,7 +7,7 @@ namespace Engine.Renderer
{
using System.Collections;
using System.Threading;
using Abstraction;
using Core.Implementation;
using Coroutine;
using Extensions;
using UnityEngine;
@@ -5,7 +5,8 @@
namespace Engine.Renderer
{
using Abstraction;
using Core.Abstraction;
using Core.Implementation;
using Extensions;
using UnityEngine;
@@ -5,7 +5,7 @@
namespace Engine.Renderer
{
using Abstraction;
using Core.Implementation;
using UnityEngine;
public class StaticBillboardRenderer : TickableGameEntityScript
@@ -6,7 +6,7 @@
namespace Engine.Renderer
{
using System;
using Abstraction;
using Core.Implementation;
using Extensions;
using UnityEngine;
@@ -5,15 +5,24 @@
namespace Engine.Services
{
/// <summary>
/// Tracks the time since the game started and the delta time between frames.
/// </summary>
public interface IGameTimeProvider
{
public double TimeSinceStartup { get; }
/// <summary>
/// Interface for providing game time information.
/// </summary>
public interface IGameTimeProvider
{
/// <summary>
/// The time since the game started, in seconds.
/// </summary>
public double TimeSinceStartup { get; }
public double RealTimeSinceStartup { get; }
/// <summary>
/// The real time since the game started, in seconds.
/// </summary>
public double RealTimeSinceStartup { get; }
public float DeltaTime { get; }
}
/// <summary>
/// The time in seconds it took to complete the last frame.
/// </summary>
public float DeltaTime { get; }
}
}
@@ -0,0 +1,55 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Services
{
using Core.Abstraction;
using UnityEngine;
/// <summary>
/// Interface for managing physics in the game.
/// </summary>
public interface IPhysicsManager
{
public int MaxRaycastHitCount { get; }
/// <summary>
/// Attempts to perform a raycast from a screen point in the camera's view.
/// </summary>
/// <param name="screenPoint">The screen point to cast the ray from.</param>
/// <param name="hitResult">The resulting hit point and collider game entity, if any.</param>
/// <param name="maxDistance">The maximum distance to cast the ray.</param>
/// <returns>True if the raycast hit a collider, false otherwise.</returns>
public bool TryCameraRaycastFromScreenPoint(Vector2 screenPoint,
out (Vector3 hitPoint, IGameEntity colliderGameEntity) hitResult,
float maxDistance = float.PositiveInfinity);
/// <summary>
/// Casts a ray from a screen point into the scene and returns information about any colliders hit.
/// </summary>
/// <param name="screenPoint">The screen point to cast the ray from.</param>
/// <param name="hitResults">An array of hit results, each containing information about the hit point and the game entity of the collider.</param>
/// <param name="maxDistance">The maximum distance to cast the ray.</param>
/// <returns>The number of colliders hit.</returns>
public int CameraRaycastFromScreenPoint(Vector2 screenPoint,
(Vector3 hitPoint, IGameEntity colliderGameEntity)[] hitResults,
float maxDistance = float.PositiveInfinity);
/// <summary>
/// Casts a box along a ray and returns all hits in the path.
/// </summary>
/// <param name="center">The center of the box.</param>
/// <param name="halfExtents">Half the size of the box in each dimension.</param>
/// <param name="direction">The direction in which to cast the box.</param>
/// <param name="orientation">The orientation of the box.</param>
/// <param name="hitResults">An array of hit results, each containing the hit point and the game entity of the collider.</param>
/// <returns>The number of hits found.</returns>
public int BoxCast(Vector3 center,
Vector3 halfExtents,
Vector3 direction,
Quaternion orientation,
(Vector3 hitPoint, IGameEntity colliderGameEntity)[] hitResults);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 006dda9e830047ac9c97267bfaa594ff
timeCreated: 1697053885
@@ -0,0 +1,80 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Engine.Services
{
using System;
using Core.Abstraction;
using Core.Implementation;
using UnityEngine;
public sealed class PhysicsManager : IPhysicsManager
{
private const int MAX_RAYCAST_HIT_COUNT = 10;
private readonly RaycastHit[] _raycastHits = new RaycastHit[MAX_RAYCAST_HIT_COUNT]; // Cache
private readonly Camera _camera;
public PhysicsManager(Camera camera)
{
_camera = camera;
}
public int MaxRaycastHitCount => MAX_RAYCAST_HIT_COUNT;
public bool TryCameraRaycastFromScreenPoint(Vector2 screenPoint,
out (Vector3 hitPoint, IGameEntity colliderGameEntity) hitResult,
float maxDistance = float.PositiveInfinity)
{
Ray ray = _camera.ScreenPointToRay(screenPoint);
if (Physics.Raycast(ray, out RaycastHit hit))
{
hitResult = (hit.point, new GameEntity(hit.collider.gameObject));
return true;
}
else
{
hitResult = default;
return false;
}
}
public int CameraRaycastFromScreenPoint(Vector2 screenPoint,
(Vector3 hitPoint, IGameEntity colliderGameEntity)[] hitResults,
float maxDistance = float.PositiveInfinity)
{
Ray ray = _camera.ScreenPointToRay(screenPoint);
int hitCount = Physics.RaycastNonAlloc(ray, _raycastHits, maxDistance);
for (int i = 0; i < Math.Min(hitCount, hitResults.Length); i++)
{
hitResults[i] = (_raycastHits[i].point, new GameEntity(_raycastHits[i].collider.gameObject));
}
return hitCount;
}
public int BoxCast(Vector3 center,
Vector3 halfExtents,
Vector3 direction,
Quaternion orientation,
(Vector3 hitPoint, IGameEntity colliderGameEntity)[] hitResults)
{
int hitCount = Physics.BoxCastNonAlloc(center,
halfExtents,
direction,
_raycastHits,
orientation);
for (int i = 0; i < Math.Min(hitCount, hitResults.Length); i++)
{
hitResults[i] = (_raycastHits[i].point, new GameEntity(_raycastHits[i].collider.gameObject));
}
return hitCount;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8a062bd2de8345afb86e6e2f6971ce71
timeCreated: 1697053568
@@ -13,8 +13,10 @@ namespace Engine.Services
/// <summary>
/// ServiceLocator singleton.
/// </summary>
public class ServiceLocator : Singleton<ServiceLocator>
public sealed class ServiceLocator : Singleton<ServiceLocator>
{
private ServiceLocator() { } // Hide constructor, use Instance instead.
/// <summary>
/// Currently registered services.
/// </summary>
@@ -10,23 +10,6 @@ namespace Engine.Utilities
public static class UnityEngineUtility
{
public static unsafe void ApplyTransparencyBasedOnColorLuminance(Texture2D texture)
{
var pixels = texture.GetPixels();
fixed (float* src = &pixels[0].r)
{
var p = src;
for (var i = 0; i < texture.width * texture.height; i++, p += 4)
{
*(p + 3) = 0.299f * *p + 0.587f * *(p + 1) + 0.114f * *(p + 2);
}
}
texture.SetPixels(pixels);
texture.Apply(updateMipmaps: false);
}
public static bool IsHandheldDevice()
{
return SystemInfo.deviceType == DeviceType.Handheld;
@@ -11,10 +11,12 @@ namespace Pal3.Core.Contract.Constants
public const int InvalidScriptId = 0;
public const int SystemScriptIdMax = 99;
public const int SystemScriptIdMax = 100;
public const int CommandIdMax = 512;
public const int PortalScriptIdMax = 1000;
public const short MainStoryVariableName = -0x8000;
}
}
@@ -11,7 +11,8 @@ namespace Pal3.Game.Actor
using Core.Contract.Enums;
using Data;
using Dev.Presenters;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using GameSystems.Combat;
using Scene;
@@ -30,7 +31,7 @@ namespace Pal3.Game.Actor
float movementMaxYDifferentialCrossPlatform,
Func<int, int[], HashSet<Vector2Int>> getAllActiveActorBlockingTilePositions)
{
var actorGameEntity = new GameEntity($"Actor_{actor.Id}_{actor.Name}");
var actorGameEntity = GameEntityFactory.Create($"Actor_{actor.Id}_{actor.Name}");
// Attach ScnNpcInfo to the GameEntity for better debuggability
#if UNITY_EDITOR
@@ -115,7 +116,7 @@ namespace Pal3.Game.Actor
ElementPosition elementPosition,
bool isDropShadowEnabled)
{
var actorGameEntity = new GameEntity($"CombatActor_{actor.Id}_{actor.Name}");
IGameEntity actorGameEntity = GameEntityFactory.Create($"CombatActor_{actor.Id}_{actor.Name}");
// Attach CombatActorInfo to the GameEntity for better debuggability
#if UNITY_EDITOR
@@ -14,7 +14,8 @@ namespace Pal3.Game.Actor.Controllers
using Core.Contract.Constants;
using Core.Contract.Enums;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Engine.Logging;
using Engine.Renderer;
@@ -228,8 +229,8 @@ namespace Pal3.Game.Actor.Controllers
private void RenderShadow()
{
_shadow = new GameEntity("Shadow");
_shadow.SetParent(GameEntity, worldPositionStays: false);
_shadow = GameEntityFactory.Create("Shadow",
GameEntity, worldPositionStays: false);
ITransform shadowTransform = _shadow.Transform;
shadowTransform.LocalRotation = Quaternion.Euler(90f, 0f, 0f);
shadowTransform.LocalScale = new Vector3(1.4f, 1.4f, 1f);
@@ -253,8 +254,8 @@ namespace Pal3.Game.Actor.Controllers
var sprites = _resourceProvider.GetEmojiSprites(emojiType);
var emojiGameEntity = new GameEntity($"Emoji_{emojiType.ToString()}");
emojiGameEntity.SetParent(GameEntity, worldPositionStays: false);
IGameEntity emojiGameEntity = GameEntityFactory.Create($"Emoji_{emojiType.ToString()}",
GameEntity, worldPositionStays: false);
emojiGameEntity.Transform.LocalScale = new Vector3(1.5f, 1.5f, 1.5f);
emojiGameEntity.Transform.LocalPosition = new Vector3(0f, GetActorHeight(), 0f);
@@ -13,15 +13,18 @@ namespace Pal3.Game.Actor.Controllers
using Core.Command.SceCommands;
using Core.Contract.Constants;
using Core.Contract.Enums;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Engine.Navigation;
using Engine.Services;
using Input;
using GamePlay;
using Script.Waiter;
using UnityEngine;
using Quaternion = UnityEngine.Quaternion;
using Vector3 = UnityEngine.Vector3;
public class ActorController : GameEntityScript,
ICommandExecutor<ActorSetFacingCommand>,
@@ -18,7 +18,8 @@ namespace Pal3.Game.Actor.Controllers
using Core.DataReader.Nav;
using Core.Primitives;
using Core.Utilities;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Coroutine;
using Engine.Extensions;
using Engine.Logging;
@@ -7,8 +7,8 @@ namespace Pal3.Game.Actor.Controllers
{
using System;
using System.Collections;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Implementation;
using Engine.Coroutine;
using GameSystems.Combat;
using Scene;
@@ -13,7 +13,7 @@ namespace Pal3.Game.Actor.Controllers
using Core.Command.SceCommands;
using Core.Contract.Enums;
using Core.Primitives;
using Engine.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Engine.Services;
using Script.Waiter;
@@ -11,7 +11,7 @@ namespace Pal3.Game.Actor.Controllers
using Core.Command;
using Core.Command.SceCommands;
using Core.Contract.Enums;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Services;
using Scene;
@@ -11,7 +11,7 @@ namespace Pal3.Game.Actor.Controllers
using Core.Command;
using Core.Command.SceCommands;
using Core.Contract.Constants;
using Engine.Abstraction;
using Engine.Core.Implementation;
public sealed class LongKuiController : GameEntityScript,
ICommandExecutor<LongKuiSwitchModeCommand>
@@ -18,7 +18,8 @@ namespace Pal3.Game.Audio
using Core.DataReader.Scn;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Coroutine;
using Engine.Extensions;
using Scene;
@@ -202,8 +203,7 @@ namespace Pal3.Game.Audio
IGameEntity audioSourceParent = parent.FindChild(audioSourceName);
if (audioSourceParent == null)
{
audioSourceParent = new GameEntity(audioSourceName);
audioSourceParent.SetParent(parent, worldPositionStays: true);
audioSourceParent = GameEntityFactory.Create(audioSourceName, parent, worldPositionStays: true);
audioSourceParent.Transform.Position = parent.Transform.Position;
}
@@ -19,8 +19,8 @@ namespace Pal3.Game.Camera
using Core.DataReader.Scn;
using Core.Primitives;
using Core.Utilities;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Utilities;
using GamePlay;
@@ -497,11 +497,6 @@ namespace Pal3.Game.Camera
_cameraOffset = cameraPosition - _lastLookAtPoint;
}
public Ray ScreenPointToRay(Vector2 position)
{
return _camera.ScreenPointToRay(position);
}
public float GetFieldOfView()
{
return _camera.fieldOfView;
@@ -29,7 +29,7 @@ namespace Pal3.Game.Command
private readonly Dictionary<Type, MethodInfo> _commandExecutorExecuteMethodInfoCache = new();
private CommandDispatcher() { }
private CommandDispatcher() { } // Hide constructor, use Instance instead.
private CommandDispatcher(ICommandExecutorRegistry<TCommand> commandExecutorRegistry)
{
@@ -22,7 +22,7 @@ namespace Pal3.Game.Command
private readonly Dictionary<Type, HashSet<object>> _executors = new ();
private CommandExecutorRegistry() { }
private CommandExecutorRegistry() { } // Hide constructor, use Instance instead.
/// <inheritdoc />
public void Register<T>(ICommandExecutor<T> executor) where T : TCommand
@@ -6,7 +6,7 @@
namespace Pal3.Game.Command.Extensions
{
using Core.Command;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Newtonsoft.Json;
public class AttachSfxToGameEntityRequest : ICommand
@@ -6,7 +6,7 @@
namespace Pal3.Game.Command.Extensions
{
using Core.Command;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Newtonsoft.Json;
public class StopSfxPlayingAtGameEntityRequest : ICommand
@@ -6,7 +6,7 @@
namespace Pal3.Game.Dev.Presenters
{
using Core.DataReader.Gdb;
using Engine.Abstraction;
using Engine.Core.Implementation;
/// <summary>
/// CombatActorInfo holder component to present ScnObjectInfo in the Unity inspector.
@@ -6,7 +6,7 @@
namespace Pal3.Game.Dev.Presenters
{
using Core.DataReader.Lgt;
using Engine.Abstraction;
using Engine.Core.Implementation;
/// <summary>
/// LightNode holder component to present LightNode in the Unity inspector.
@@ -6,7 +6,7 @@
namespace Pal3.Game.Dev.Presenters
{
using Core.Primitives;
using Engine.Abstraction;
using Engine.Core.Implementation;
/// <summary>
/// BlendFlag and GameBoxMaterial holder component to present MaterialInfo in the Unity inspector.
@@ -6,7 +6,7 @@
namespace Pal3.Game.Dev.Presenters
{
using Core.DataReader.Scn;
using Engine.Abstraction;
using Engine.Core.Implementation;
/// <summary>
/// ScnNpcInfo holder component to present ScnNpcInfo in the Unity inspector.
@@ -6,7 +6,7 @@
namespace Pal3.Game.Dev.Presenters
{
using Core.DataReader.Scn;
using Engine.Abstraction;
using Engine.Core.Implementation;
/// <summary>
/// ScnObjectInfo holder component to present ScnObjectInfo in the Unity inspector.
@@ -6,7 +6,8 @@
namespace Pal3.Game.Effect
{
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Vector3 = UnityEngine.Vector3;
@@ -80,8 +81,8 @@ namespace Pal3.Game.Effect
object vfxPrefab = resourceProvider.GetVfxEffectPrefab((int)effectParameter);
if (vfxPrefab != null)
{
_effect = PrefabFactory.Instantiate(vfxPrefab, Transform, worldPositionStays: false);
_effect.Name = "VFX_" + effectParameter;
_effect = GameEntityFactory.Create(name: $"VFX_{effectParameter}",
vfxPrefab, GameEntity, worldPositionStays: false);
}
}
}
@@ -17,7 +17,8 @@ namespace Pal3.Game.Effect
using Core.Primitives;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Scene;
@@ -94,13 +95,13 @@ namespace Pal3.Game.Effect
object vfxPrefab = _resourceProvider.GetVfxEffectPrefab(command.EffectGroupId);
if (vfxPrefab != null)
{
ITransform parentTransform = null;
IGameEntity parent = null;
Vector3 localPosition = Vector3.zero;
if (_effectPositionCommand is EffectSetPositionCommand positionCommand &&
_sceneManager.GetSceneRootGameEntity() is {} sceneRootGameEntity)
{
parentTransform = sceneRootGameEntity.Transform;
parent = sceneRootGameEntity;
localPosition = new GameBoxVector3(
positionCommand.GameBoxXPosition,
positionCommand.GameBoxYPosition,
@@ -108,14 +109,14 @@ namespace Pal3.Game.Effect
}
else if (_effectPositionCommand is EffectAttachToActorCommand actorCommand)
{
parentTransform = currentScene.GetActorGameEntity(actorCommand.ActorId).Transform;
parent = currentScene.GetActorGameEntity(actorCommand.ActorId);
}
if (parentTransform != null)
if (parent != null)
{
IGameEntity vfx = PrefabFactory.Instantiate(vfxPrefab, parentTransform, false);
vfx.Name = "VFX_" + command.EffectGroupId;
vfx.Transform.LocalPosition += localPosition;
IGameEntity effectEntity = GameEntityFactory.Create(name: $"VFX_{command.EffectGroupId}",
vfxPrefab, parent, worldPositionStays: false);
effectEntity.Transform.LocalPosition += localPosition;
}
}
@@ -12,7 +12,8 @@ namespace Pal3.Game.Effect
using Core.DataReader.Pol;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.DataLoader;
using Engine.Extensions;
using Engine.Renderer;
@@ -74,8 +75,8 @@ namespace Pal3.Game.Effect
yPosition = _sceneObjectRenderer.GetMeshBounds().max.y;
}
EffectGameEntity = new GameEntity($"Effect_{GraphicsEffectType.Fire.ToString()}_{FireEffectType.ToString()}");
EffectGameEntity.SetParent(GameEntity, worldPositionStays: false);
EffectGameEntity = GameEntityFactory.Create($"Effect_{GraphicsEffectType.Fire.ToString()}_{FireEffectType.ToString()}",
GameEntity, worldPositionStays: false);
EffectGameEntity.Transform.LocalScale = new Vector3(info.Size, info.Size, info.Size);
EffectGameEntity.Transform.LocalPosition = new Vector3(0f, yPosition, 0f);
@@ -6,7 +6,8 @@
namespace Pal3.Game.Effect
{
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Vector3 = UnityEngine.Vector3;
@@ -21,6 +22,7 @@ namespace Pal3.Game.Effect
private const float PORTAL_DEFAULT_SIZE = 1.3f;
private const float PORTAL_ANIMATION_ROTATION_SPEED = 5f;
private const int PORTAL_RAY_EFFECT_ID = 0;
private RotatingSpriteEffect _baseEffect;
private IGameEntity _rayEffect;
@@ -38,11 +40,11 @@ namespace Pal3.Game.Effect
new Vector3(PORTAL_DEFAULT_SIZE, PORTAL_DEFAULT_SIZE, PORTAL_DEFAULT_SIZE),
PORTAL_ANIMATION_ROTATION_SPEED);
object rayEffectPrefab = resourceProvider.GetVfxEffectPrefab(0);
object rayEffectPrefab = resourceProvider.GetVfxEffectPrefab(PORTAL_RAY_EFFECT_ID);
if (rayEffectPrefab != null)
{
_rayEffect = PrefabFactory.Instantiate(rayEffectPrefab, Transform, worldPositionStays: false);
_rayEffect.Name = "VFX_0";
_rayEffect = GameEntityFactory.Create($"VFX_{PORTAL_RAY_EFFECT_ID}",
rayEffectPrefab, GameEntity, worldPositionStays: false);
}
}
@@ -7,7 +7,8 @@ namespace Pal3.Game.Effect
{
using System;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using UnityEngine;
@@ -33,8 +34,8 @@ namespace Pal3.Game.Effect
Texture2D texture = resourceProvider.GetEffectTexture(textureName, out var hasAlphaChannel);
_root = new GameEntity($"RotatingSpriteEffect_{textureName}");
_root.SetParent(GameEntity, worldPositionStays: false);
_root = GameEntityFactory.Create($"RotatingSpriteEffect_{textureName}",
GameEntity, worldPositionStays: false);
_spriteRenderer = _root.AddComponent<SpriteRenderer>();
@@ -14,7 +14,7 @@ namespace Pal3.Game.GamePlay
using Core.Contract.Constants;
using Core.Contract.Enums;
using Core.Primitives;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Logging;
using Engine.Renderer;
@@ -15,7 +15,7 @@ namespace Pal3.Game.GamePlay
using Core.Command.SceCommands;
using Core.Contract.Constants;
using Core.Contract.Enums;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Logging;
using Scene;
using Scene.SceneObjects;
@@ -12,14 +12,18 @@ namespace Pal3.Game.GamePlay
using Core.Contract.Constants;
using Core.Contract.Enums;
using Core.DataReader.Nav;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Coroutine;
using Engine.Extensions;
using Engine.Renderer;
using Scene;
using State;
using UnityEngine;
using Vector2 = UnityEngine.Vector2;
using Vector2Int = UnityEngine.Vector2Int;
using Vector3 = UnityEngine.Vector3;
public partial class PlayerGamePlayManager
{
@@ -37,14 +41,12 @@ namespace Pal3.Game.GamePlay
{
if (!_lastInputTapPosition.HasValue) return;
Ray ray = _cameraManager.ScreenPointToRay(_lastInputTapPosition.Value);
if (!_physicsManager.TryCameraRaycastFromScreenPoint(_lastInputTapPosition.Value,
out (Vector3 hitPoint, IGameEntity colliderGameEntity) hitResult)) return;
if (!Physics.Raycast(ray, out RaycastHit hit)) return;
if (_sceneManager.GetCurrentScene()
.GetMeshColliders().Any(_ => _.Value == hit.collider))
if (hitResult.colliderGameEntity.GetComponent<NavMesh>() != null)
{
Pal3.Instance.StartCoroutine(JumpAsync(hit.point));
Pal3.Instance.StartCoroutine(JumpAsync(hitResult.hitPoint));
}
}
@@ -54,8 +56,8 @@ namespace Pal3.Game.GamePlay
{
var sprites = _resourceProvider.GetJumpIndicatorSprites();
_jumpIndicatorGameEntity = new GameEntity($"JumpIndicator");
_jumpIndicatorGameEntity.SetParent(_playerActorGameEntity, worldPositionStays: false);
_jumpIndicatorGameEntity = GameEntityFactory.Create($"JumpIndicator",
_playerActorGameEntity, worldPositionStays: false);
_jumpIndicatorGameEntity.Transform.LocalScale = new Vector3(3f, 3f, 3f);
_jumpIndicatorGameEntity.Transform.LocalPosition = new Vector3(0f,
_playerActorActionController.GetActorHeight() + 1f, 0f);
@@ -6,7 +6,6 @@
namespace Pal3.Game.GamePlay
{
using System.Collections.Generic;
using System.Linq;
using Actor.Controllers;
using Command;
using Command.Extensions;
@@ -14,10 +13,13 @@ namespace Pal3.Game.GamePlay
using Core.Contract.Constants;
using Core.Contract.Enums;
using Core.DataReader.Nav;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Scene;
using Scene.SceneObjects.Common;
using UnityEngine;
using Quaternion = UnityEngine.Quaternion;
using Vector2 = UnityEngine.Vector2;
using Vector3 = UnityEngine.Vector3;
public partial class PlayerGamePlayManager
{
@@ -46,94 +48,96 @@ namespace Pal3.Game.GamePlay
{
if (!_lastInputTapPosition.HasValue) return;
Ray ray = _cameraManager.ScreenPointToRay(_lastInputTapPosition.Value);
if (!Physics.Raycast(ray, out RaycastHit hit)) return;
if (!_physicsManager.TryCameraRaycastFromScreenPoint(_lastInputTapPosition.Value,
out (Vector3 hitPoint, IGameEntity colliderGameEntity) hitResult)) return;
int layerIndex;
bool isPositionOnStandingPlatform;
if (hit.collider.gameObject.GetComponent<StandingPlatformController>() is { } standingPlatformController)
if (hitResult.colliderGameEntity.GetComponent<StandingPlatformController>() is { } standingPlatformController)
{
layerIndex = standingPlatformController.LayerIndex;
isPositionOnStandingPlatform = true;
}
else
else if (hitResult.colliderGameEntity.GetComponent<NavMesh>() is { } navMesh)
{
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;
}
layerIndex = navMesh.NavLayerIndex;
isPositionOnStandingPlatform = false;
}
else // Raycast hit a collider that is neither a standing platform nor a navmesh
{
return; // Do nothing
}
_playerActorMovementController.PortalToPosition(hit.point, layerIndex, isPositionOnStandingPlatform);
_playerActorMovementController.PortalToPosition(hitResult.hitPoint, 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 readonly (Vector3 hitPoint, IGameEntity colliderGameEntity)[] _hitResults = new (Vector3, IGameEntity)[10];
private readonly Dictionary<int, (Vector3 point, bool isPlatform)> _validTapPoints = new ();
private void MoveToTapPosition(bool isDoubleTap)
{
if (!_lastInputTapPosition.HasValue) return;
Scene currentScene = _sceneManager.GetCurrentScene();
var meshColliders = currentScene.GetMeshColliders();
Ray ray = _cameraManager.ScreenPointToRay(_lastInputTapPosition.Value);
int hitCount = _physicsManager.CameraRaycastFromScreenPoint(
_lastInputTapPosition.Value,
_hitResults);
var hitCount = Physics.RaycastNonAlloc(ray, _raycastHits, 500f);
if (hitCount == 0) return;
Tilemap tilemap = currentScene.GetTilemap();
_tapPoints.Clear();
_validTapPoints.Clear();
for (var i = 0; i < hitCount; i++)
{
RaycastHit hit = _raycastHits[i];
(Vector3 hitPoint, IGameEntity colliderGameEntity) = _hitResults[i];
if (hit.collider.gameObject.GetComponent<StandingPlatformController>() is { }
if (colliderGameEntity.GetComponent<ActorController>() != null)
{
continue; // Ignore actor
}
if (colliderGameEntity.GetComponent<StandingPlatformController>() is { }
standingPlatformController)
{
_tapPoints[standingPlatformController.LayerIndex] = (hit.point, true);
_validTapPoints[standingPlatformController.LayerIndex] = (hitPoint, true);
continue;
}
var layerIndex = meshColliders.FirstOrDefault(_ => _.Value == hit.collider).Key;
int layerIndex = _playerActorManager.LastKnownLayerIndex ?? 0;
if (!tilemap.TryGetTile(hit.point, layerIndex, out NavTile _))
if (colliderGameEntity.GetComponent<NavMesh>() is { } navMesh)
{
layerIndex = navMesh.NavLayerIndex;
}
if (!tilemap.TryGetTile(hitPoint, layerIndex, out NavTile _))
{
continue;
}
Vector3 cameraPosition = _cameraManager.GetCameraTransform().Position;
var distanceToCamera = Vector3.Distance(cameraPosition, hit.point);
var distanceToCamera = Vector3.Distance(cameraPosition, hitPoint);
if (_tapPoints.ContainsKey(layerIndex))
if (_validTapPoints.ContainsKey(layerIndex))
{
var existingDistance = Vector3.Distance(cameraPosition, _tapPoints[layerIndex].point);
var existingDistance = Vector3.Distance(cameraPosition, _validTapPoints[layerIndex].point);
if (distanceToCamera < existingDistance)
{
_tapPoints[layerIndex] = (hit.point, false);
_validTapPoints[layerIndex] = (hitPoint, false);
}
}
else
{
_tapPoints[layerIndex] = (hit.point, false);
_validTapPoints[layerIndex] = (hitPoint, false);
}
}
if (_tapPoints.Count > 0)
if (_validTapPoints.Count > 0)
{
_playerActorMovementController.MoveToTapPoint(_tapPoints, isDoubleTap);
_playerActorMovementController.MoveToTapPoint(_validTapPoints, isDoubleTap);
}
}
@@ -20,16 +20,21 @@ namespace Pal3.Game.GamePlay
using Core.DataReader.Scn;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Logging;
using Engine.Services;
using GameSystems.Team;
using Input;
using Scene;
using Scene.SceneObjects;
using State;
using UnityEngine;
using UnityEngine.InputSystem;
using Quaternion = UnityEngine.Quaternion;
using Vector2 = UnityEngine.Vector2;
using Vector2Int = UnityEngine.Vector2Int;
using Vector3 = UnityEngine.Vector3;
public partial class PlayerGamePlayManager : IDisposable,
ICommandExecutor<ActorEnablePlayerControlCommand>,
ICommandExecutor<ActorSetTilePositionCommand>,
@@ -49,6 +54,7 @@ namespace Pal3.Game.GamePlay
private readonly PlayerInputActions _inputActions;
private readonly SceneManager _sceneManager;
private readonly CameraManager _cameraManager;
private readonly IPhysicsManager _physicsManager;
private string _currentMovementSfxAudioName = string.Empty;
@@ -79,7 +85,8 @@ namespace Pal3.Game.GamePlay
TeamManager teamManager,
PlayerInputActions inputActions,
SceneManager sceneManager,
CameraManager cameraManager)
CameraManager cameraManager,
IPhysicsManager physicsManager)
{
_resourceProvider = Requires.IsNotNull(resourceProvider, nameof(resourceProvider));
_gameStateManager = Requires.IsNotNull(gameStateManager, nameof(gameStateManager));
@@ -88,6 +95,7 @@ namespace Pal3.Game.GamePlay
_inputActions = Requires.IsNotNull(inputActions, nameof(inputActions));
_sceneManager = Requires.IsNotNull(sceneManager, nameof(sceneManager));
_cameraManager = Requires.IsNotNull(cameraManager, nameof(cameraManager));
_physicsManager = Requires.IsNotNull(physicsManager, nameof(physicsManager));
_inputActions.Gameplay.OnTap.performed += OnTapPerformed;
_inputActions.Gameplay.OnMove.performed += OnMovePerformed;
@@ -20,8 +20,8 @@ namespace Pal3.Game
using Core.FileSystem;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Implementation;
using Engine.Extensions;
using Engine.Logging;
using Engine.Services;
@@ -21,7 +21,7 @@ namespace Pal3.Game.GameSystems.Combat
using Core.DataReader.Txt;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Logging;
using GamePlay;
using Scene;
@@ -20,7 +20,7 @@ namespace Pal3.Game.GameSystems.Combat
using Core.Primitives;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Logging;
using Scene;
@@ -118,6 +118,7 @@ namespace Pal3.Game.GameSystems.Combat
{
// Stop combat music
CommandDispatcher<ICommand>.Instance.Dispatch(new StopScriptMusicCommand());
CommandDispatcher<ICommand>.Instance.Dispatch(new CameraFadeInCommand());
_sceneManager.UnloadCombatScene();
ResetCameraPosition();
}
@@ -12,7 +12,7 @@ namespace Pal3.Game.GameSystems.Minimap
using Core.Contract.Enums;
using Core.DataReader.Nav;
using Core.Utilities;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Scene;
using State;
@@ -15,7 +15,7 @@ namespace Pal3.Game.GameSystems.Team
using Core.Command.SceCommands;
using Core.Contract.Enums;
using Core.Utilities;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Logging;
using GamePlay;
using Scene;
+8 -2
View File
@@ -24,7 +24,8 @@ namespace Pal3.Game
using Data;
using Dev;
using Effect;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Coroutine;
using Engine.Extensions;
using Engine.Logging;
@@ -144,6 +145,7 @@ namespace Pal3.Game
private GameSettings _gameSettings;
private ICpkFileSystem _fileSystem;
private GameResourceProvider _gameResourceProvider;
private IPhysicsManager _physicsManager;
private FileSystemCacheManager _fileSystemCacheManager;
private PlayerInputActions _inputActions;
private InputManager _inputManager;
@@ -209,6 +211,9 @@ namespace Pal3.Game
_gameResourceProvider = ServiceLocator.Instance.Get<GameResourceProvider>();
_gameResourceProvider.UseTextureCache(_textureCache);
ServiceLocator.Instance.Register<IPhysicsManager>(_physicsManager =
new PhysicsManager(mainCamera));
ServiceLocator.Instance.Register(_fileSystemCacheManager =
new FileSystemCacheManager(_fileSystem)
);
@@ -379,7 +384,8 @@ namespace Pal3.Game
_teamManager,
_inputActions,
_sceneManager,
_cameraManager)
_cameraManager,
_physicsManager)
);
ServiceLocator.Instance.Register(_minimapManager =
@@ -12,7 +12,8 @@ namespace Pal3.Game.Rendering.Renderer
using Core.DataReader.Cvd;
using Core.Utilities;
using Dev.Presenters;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.DataLoader;
using Engine.Extensions;
using Engine.Logging;
@@ -32,7 +33,7 @@ namespace Pal3.Game.Rendering.Renderer
private Color _tintColor;
private float _currentTime;
private float _currentAnimationTime;
private float _animationDuration;
private CancellationTokenSource _animationCts = new ();
@@ -56,14 +57,15 @@ namespace Pal3.Game.Rendering.Renderer
_materialFactory = materialFactory;
_animationDuration = cvdFile.AnimationDuration;
_tintColor = tintColor ?? Color.White;
_currentTime = initTime;
_currentAnimationTime = initTime;
foreach (CvdGeometryNode node in cvdFile.RootNodes)
{
BuildTextureCache(node, textureProvider, _textureCache);
}
var root = new GameEntity("Cvd Mesh");
IGameEntity root = GameEntityFactory.Create("Cvd Mesh",
GameEntity, worldPositionStays: false);
for (var i = 0; i < cvdFile.RootNodes.Length; i++)
{
@@ -75,13 +77,11 @@ namespace Pal3.Game.Rendering.Renderer
_textureCache,
root);
}
root.SetParent(GameEntity, worldPositionStays: false);
}
public float GetCurrentTime()
public float GetCurrentAnimationTime()
{
return _currentTime;
return _currentAnimationTime;
}
public void SetCurrentTime(float time)
@@ -212,8 +212,7 @@ namespace Pal3.Game.Rendering.Renderer
Dictionary<string, Texture2D> textureCache,
IGameEntity parent)
{
var meshEntity = new GameEntity(meshName);
meshEntity.SetParent(parent, worldPositionStays: false);
IGameEntity meshEntity = GameEntityFactory.Create(meshName, parent, worldPositionStays: false);
if (node.IsGeometryNode)
{
@@ -253,7 +252,8 @@ namespace Pal3.Game.Rendering.Renderer
if (string.IsNullOrEmpty(textureName) || !textureCache.ContainsKey(textureName)) continue;
var meshSectionEntity = new GameEntity($"{sectionHashKey}");
IGameEntity meshSectionEntity = GameEntityFactory.Create($"{sectionHashKey}",
meshEntity, worldPositionStays: false);
// Attach BlendFlag and GameBoxMaterial to the GameEntity for better debuggability.
#if UNITY_EDITOR
@@ -289,8 +289,6 @@ namespace Pal3.Game.Rendering.Renderer
MeshRenderer = meshRenderer,
MeshDataBuffer = meshDataBuffer
};
meshSectionEntity.SetParent(meshEntity, worldPositionStays: false);
}
_renderers.Add(nodeMeshes);
@@ -343,7 +341,7 @@ namespace Pal3.Game.Rendering.Renderer
private void UpdateMesh(float time)
{
_currentTime = time;
_currentAnimationTime = time;
foreach ((CvdGeometryNode node, var renderMeshComponents) in _renderers)
{
@@ -462,30 +460,22 @@ namespace Pal3.Game.Rendering.Renderer
bool startFromBeginning,
CancellationToken cancellationToken)
{
double startTime;
if (startFromBeginning)
{
startTime = GameTimeProvider.Instance.TimeSinceStartup;
}
else
{
startTime = GameTimeProvider.Instance.TimeSinceStartup - _currentTime;
}
double startTime = GameTimeProvider.Instance.TimeSinceStartup - (startFromBeginning ? 0 : _currentAnimationTime);
while (!cancellationToken.IsCancellationRequested)
{
var currentTime = timeScale > 0 ?
(float)(GameTimeProvider.Instance.TimeSinceStartup - startTime) * timeScale :
(duration - (float)(GameTimeProvider.Instance.TimeSinceStartup - startTime)) * -timeScale;
// Calculate the elapsed time and adjust it based on the time scale.
float elapsed = (float)(GameTimeProvider.Instance.TimeSinceStartup - startTime);
float adjustedTime = timeScale > 0 ? elapsed * timeScale : (duration - elapsed) * -timeScale;
if ((timeScale > 0f && currentTime >= duration) ||
(timeScale < 0f && currentTime <= 0f))
// Check if the animation is complete based on the time scale and either the duration or the zero-bound.
bool isComplete = timeScale > 0 ? adjustedTime >= duration : adjustedTime <= 0;
if (isComplete)
{
yield break;
}
UpdateMesh(currentTime);
UpdateMesh(adjustedTime);
yield return null;
}
@@ -14,7 +14,8 @@ namespace Pal3.Game.Rendering.Renderer
using Core.Utilities;
using Dev;
using Dev.Presenters;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.DataLoader;
using Engine.Extensions;
using Engine.Logging;
@@ -55,6 +56,7 @@ namespace Pal3.Game.Rendering.Renderer
private IGameEntity[] _meshEntities;
// Tag node
private PolFile _tagNodePolFile;
private Mv3TagNode[] _tagNodesInfo;
private uint[][] _tagNodeFrameTicks;
private IGameEntity[] _tagNodes;
@@ -87,6 +89,7 @@ namespace Pal3.Game.Rendering.Renderer
_materialFactory = materialFactory;
_textureProvider = textureProvider;
_tintColor = tintColor ?? Color.White;
_tagNodePolFile = tagNodePolFile;
_events = mv3File.AnimationEvents;
_totalGameBoxTicks = mv3File.TotalGameBoxTicks;
@@ -146,7 +149,7 @@ namespace Pal3.Game.Rendering.Renderer
InitSubMeshes(i, ref mesh, ref material);
}
if (tagNodePolFile != null)
if (_tagNodePolFile != null)
{
for (var i = 0; i < _tagNodesInfo.Length; i++)
{
@@ -156,15 +159,16 @@ namespace Pal3.Game.Rendering.Renderer
continue;
}
_tagNodes[i] = new GameEntity(tagNodePolFile.NodeDescriptions[0].Name);
_tagNodes[i] = GameEntityFactory.Create(_tagNodePolFile.NodeDescriptions[0].Name,
GameEntity, worldPositionStays: true);
var tagNodeRenderer = _tagNodes[i].AddComponent<PolyModelRenderer>();
tagNodeRenderer.Render(tagNodePolFile,
tagNodeRenderer.Render(_tagNodePolFile,
tagNodeTextureProvider,
_materialFactory,
isStaticObject: false,
tagNodeTintColor);
_tagNodes[i].SetParent(GameEntity, worldPositionStays: true);
_tagNodes[i].Transform.SetLocalPositionAndRotation(
mv3File.TagNodes[i].TagFrames[0].GameBoxPosition.ToUnityPosition(UnityPrimitivesConvertor.GameBoxMv3UnitToUnityUnit),
mv3File.TagNodes[i].TagFrames[0].GameBoxRotation.Mv3QuaternionToUnityQuaternion());
@@ -198,7 +202,8 @@ namespace Pal3.Game.Rendering.Renderer
_frameTicks[index][i] = keyFrames[i].GameBoxTick;
}
_meshEntities[index] = new GameEntity(mv3Mesh.Name);
_meshEntities[index] = GameEntityFactory.Create(mv3Mesh.Name,
GameEntity, worldPositionStays: false);
// Attach BlendFlag and GameBoxMaterial to the GameEntity for better debuggability
#if UNITY_EDITOR
@@ -252,8 +257,6 @@ namespace Pal3.Game.Rendering.Renderer
_renderMeshComponents[index].Mesh = renderMesh;
_renderMeshComponents[index].MeshRenderer = meshRenderer;
_meshEntities[index].SetParent(GameEntity, worldPositionStays: false);
}
public void StartAnimation(int loopCount = -1)
@@ -428,6 +431,8 @@ namespace Pal3.Game.Rendering.Renderer
continue;
}
if (cancellationToken.IsCancellationRequested) yield break;
// Animates the mesh
for (var i = 0; i < _meshCount; i++)
{
@@ -457,27 +462,30 @@ namespace Pal3.Game.Rendering.Renderer
}
// Animates the tag nodes
for (var i = 0; i < _tagNodesInfo.Length; i++)
if (_tagNodePolFile != null)
{
if (_tagNodes[i] == null) continue;
for (var i = 0; i < _tagNodesInfo.Length; i++)
{
if (_tagNodes[i] == null) continue;
var frameTicks = _tagNodeFrameTicks[i];
var frameTicks = _tagNodeFrameTicks[i];
var currentFrameIndex = CoreUtility.GetFloorIndex(frameTicks, tick);
var currentFrameTick = _tagNodeFrameTicks[i][currentFrameIndex];
var nextFrameIndex = currentFrameIndex < frameTicks.Length - 1 ? currentFrameIndex + 1 : 0;
var nextFrameTick = nextFrameIndex == 0 ? endTick : _tagNodeFrameTicks[i][nextFrameIndex];
var currentFrameIndex = CoreUtility.GetFloorIndex(frameTicks, tick);
var currentFrameTick = _tagNodeFrameTicks[i][currentFrameIndex];
var nextFrameIndex = currentFrameIndex < frameTicks.Length - 1 ? currentFrameIndex + 1 : 0;
var nextFrameTick = nextFrameIndex == 0 ? endTick : _tagNodeFrameTicks[i][nextFrameIndex];
var influence = (float)(tick - currentFrameTick) / (nextFrameTick - currentFrameTick);
var influence = (float)(tick - currentFrameTick) / (nextFrameTick - currentFrameTick);
Vector3 position = Vector3.Lerp(
_tagNodesInfo[i].TagFrames[currentFrameIndex].GameBoxPosition.ToUnityPosition(),
_tagNodesInfo[i].TagFrames[nextFrameIndex].GameBoxPosition.ToUnityPosition(), influence);
Quaternion rotation = Quaternion.Slerp(
_tagNodesInfo[i].TagFrames[currentFrameIndex].GameBoxRotation.Mv3QuaternionToUnityQuaternion(),
_tagNodesInfo[i].TagFrames[nextFrameIndex].GameBoxRotation.Mv3QuaternionToUnityQuaternion(), influence);
Vector3 position = Vector3.Lerp(
_tagNodesInfo[i].TagFrames[currentFrameIndex].GameBoxPosition.ToUnityPosition(),
_tagNodesInfo[i].TagFrames[nextFrameIndex].GameBoxPosition.ToUnityPosition(), influence);
Quaternion rotation = Quaternion.Slerp(
_tagNodesInfo[i].TagFrames[currentFrameIndex].GameBoxRotation.Mv3QuaternionToUnityQuaternion(),
_tagNodesInfo[i].TagFrames[nextFrameIndex].GameBoxRotation.Mv3QuaternionToUnityQuaternion(), influence);
_tagNodes[i].Transform.SetLocalPositionAndRotation(position, rotation);
_tagNodes[i].Transform.SetLocalPositionAndRotation(position, rotation);
}
}
yield return null;
@@ -12,7 +12,8 @@ namespace Pal3.Game.Rendering.Renderer
using Core.DataReader.Pol;
using Core.Primitives;
using Dev.Presenters;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Coroutine;
using Engine.DataLoader;
using Engine.Extensions;
@@ -162,7 +163,7 @@ namespace Pal3.Game.Rendering.Renderer
return;
}
IGameEntity meshEntity = new GameEntity(meshNode.Name);
IGameEntity meshEntity = GameEntityFactory.Create(meshNode.Name, GameEntity, worldPositionStays: false);
meshEntity.IsStatic = _isStaticObject;
// Attach BlendFlag and GameBoxMaterial to the GameEntity for better debuggability
@@ -234,8 +235,6 @@ namespace Pal3.Game.Rendering.Renderer
materials,
false);
}
meshEntity.SetParent(GameEntity, worldPositionStays: false);
}
}
@@ -14,7 +14,8 @@ namespace Pal3.Game.Rendering.Renderer
using Core.DataReader.Mtl;
using Core.Primitives;
using Core.Utilities;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.DataLoader;
using Engine.Extensions;
using Engine.Logging;
@@ -294,9 +295,9 @@ namespace Pal3.Game.Rendering.Renderer
private void SetupBone(BoneNode boneNode, Bone parentBone)
{
IGameEntity boneEntity = new GameEntity($"{boneNode.Id}_{boneNode.Name}_{boneNode.Type}");
IGameEntity boneEntity = GameEntityFactory.Create($"{boneNode.Id}_{boneNode.Name}_{boneNode.Type}",
parentBone == null ? GameEntity : parentBone.GameEntity, worldPositionStays: true);
boneEntity.SetParent(parentBone == null ? GameEntity : parentBone.GameEntity, worldPositionStays: true);
boneEntity.Transform.SetLocalPositionAndRotation(boneNode.GameBoxTranslation.ToUnityPosition(),
boneNode.GameBoxRotation.MshQuaternionToUnityQuaternion());
@@ -341,8 +342,8 @@ namespace Pal3.Game.Rendering.Renderer
private void RenderSubMesh(MshMesh subMesh, int subMeshIndex)
{
_meshEntities[subMeshIndex] = new GameEntity($"SubMesh_{subMeshIndex}");
_meshEntities[subMeshIndex].SetParent(GameEntity, worldPositionStays: false);
_meshEntities[subMeshIndex] = GameEntityFactory.Create($"SubMesh_{subMeshIndex}",
GameEntity, worldPositionStays: false);
_vertexBuffer[subMeshIndex] = new Vector3[subMesh.Vertices.Length];
@@ -15,13 +15,14 @@ namespace Pal3.Game.Scene
using Core.DataReader.Ini;
using Core.DataReader.Pol;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.DataLoader;
using Engine.Extensions;
using GameSystems.Combat;
using Rendering.Material;
using Rendering.Renderer;
using Vector3 = UnityEngine.Vector3;
using Quaternion = UnityEngine.Quaternion;
@@ -76,12 +77,11 @@ namespace Pal3.Game.Scene
private void RenderMesh(PolFile polFile, ITextureResourceProvider textureProvider)
{
// Render mesh
_mesh = new GameEntity($"Mesh_{_combatSceneName}");
_mesh = GameEntityFactory.Create($"Mesh_{_combatSceneName}",
_parent, worldPositionStays: false);
_mesh.IsStatic = true; // Combat Scene mesh is static
var polyMeshRenderer = _mesh.AddComponent<PolyModelRenderer>();
_mesh.SetParent(_parent, worldPositionStays: false);
polyMeshRenderer.Render(polFile,
textureProvider,
_materialFactory,
+53
View File
@@ -0,0 +1,53 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Pal3.Game.Scene
{
using Core.DataReader.Nav;
using Engine.Core.Implementation;
using Engine.Extensions;
using UnityEngine;
/// <summary>
/// Represents a navigation mesh used for pathfinding in a game scene.
/// </summary>
public sealed class NavMesh : GameEntityScript
{
public int NavLayerIndex { get; private set; }
private MeshCollider _meshCollider;
protected override void OnEnableGameEntity()
{
// Set layer to NavMeshes for the attached GameEntity
// Because NavMeshes should not collide with anything else, it is only used for raycast.
// This behaviour is configured in Physics settings (Edit -> Project Settings -> Physics)
GameEntity.Layer = LayerMask.NameToLayer("NavMeshes");
}
protected override void OnDisableGameEntity()
{
if (_meshCollider != null)
{
_meshCollider.sharedMesh.Destroy();
_meshCollider.Destroy();
_meshCollider = null;
}
}
public void Init(int layerIndex, NavFaceLayer navFaceLayer)
{
NavLayerIndex = layerIndex;
_meshCollider = GameEntity.AddComponent<MeshCollider>();
_meshCollider.convex = false;
_meshCollider.sharedMesh = new Mesh()
{
vertices = navFaceLayer.GameBoxVertices.ToUnityPositions(),
triangles = navFaceLayer.GameBoxTriangles.ToUnityTriangles(),
};
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e789e40b014a4aa0b93814523e02f422
timeCreated: 1697055751
+19 -40
View File
@@ -22,8 +22,9 @@ namespace Pal3.Game.Scene
using Core.Primitives;
using Data;
using Effect;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Engine.Logging;
using Engine.Navigation;
@@ -60,8 +61,7 @@ namespace Pal3.Game.Scene
private Light _mainLight;
private readonly List<Light> _pointLights = new();
private readonly List<IGameEntity> _navMeshLayers = new ();
private readonly Dictionary<int, MeshCollider> _meshColliders = new ();
private readonly List<IGameEntity> _navMeshEntities = new ();
private readonly HashSet<int> _activatedSceneObjects = new ();
private readonly Dictionary<int, IGameEntity> _actorEntities = new ();
@@ -89,15 +89,9 @@ namespace Pal3.Game.Scene
_mesh.Destroy();
foreach (MeshCollider meshCollider in _meshColliders.Values)
foreach (IGameEntity navMeshEntity in _navMeshEntities)
{
meshCollider.sharedMesh.Destroy();
meshCollider.Destroy();
}
foreach (IGameEntity navMeshLayer in _navMeshLayers)
{
navMeshLayer.Destroy();
navMeshEntity.Destroy();
}
foreach (int sceneObjectId in _activatedSceneObjects)
@@ -221,11 +215,6 @@ namespace Pal3.Game.Scene
return _actorEntities;
}
public Dictionary<int, MeshCollider> GetMeshColliders()
{
return _meshColliders;
}
public bool IsPositionInsideJumpableArea(int layerIndex, Vector2Int tilePosition)
{
foreach (var objectId in _activatedSceneObjects)
@@ -245,12 +234,11 @@ namespace Pal3.Game.Scene
private void RenderMesh()
{
// Render mesh
_mesh = new GameEntity($"Mesh_{ScnFile.SceneInfo.CityName}_{ScnFile.SceneInfo.SceneName}");
_mesh = GameEntityFactory.Create($"Mesh_{ScnFile.SceneInfo.CityName}_{ScnFile.SceneInfo.SceneName}",
_parent, worldPositionStays: false);
_mesh.IsStatic = true; // Scene mesh is static
var polyMeshRenderer = _mesh.AddComponent<PolyModelRenderer>();
_mesh.SetParent(_parent, worldPositionStays: false);
polyMeshRenderer.Render(ScenePolyMesh.PolFile,
ScenePolyMesh.TextureProvider,
_materialFactory,
@@ -291,25 +279,16 @@ namespace Pal3.Game.Scene
return;
}
int raycastOnlyLayer = LayerMask.NameToLayer("RaycastOnly");
for (var i = 0; i < NavFile.FaceLayers.Length; i++)
{
var navMesh = new GameEntity($"NavMesh_Layer_{i}");
navMesh.IsStatic = true; // NavMesh is static
navMesh.SetLayer(raycastOnlyLayer);
navMesh.SetParent(_parent, worldPositionStays: false);
IGameEntity navMeshGameEntity = GameEntityFactory.Create($"NavMesh_Layer_{i}",
_parent, worldPositionStays: false);
navMeshGameEntity.IsStatic = true; // NavMesh is static
var meshCollider = navMesh.AddComponent<MeshCollider>();
meshCollider.convex = false;
meshCollider.sharedMesh = new Mesh()
{
vertices = NavFile.FaceLayers[i].GameBoxVertices.ToUnityPositions(),
triangles = NavFile.FaceLayers[i].GameBoxTriangles.ToUnityTriangles(),
};
NavMesh navMesh = navMeshGameEntity.AddComponent<NavMesh>();
navMesh.Init(layerIndex: i, NavFile.FaceLayers[i]);
_meshColliders[i] = meshCollider;
_navMeshLayers.Add(navMesh);
_navMeshEntities.Add(navMeshGameEntity);
}
}
@@ -340,8 +319,8 @@ namespace Pal3.Game.Scene
// });
// }
var mainLightEntity = new GameEntity($"LightSource_Main");
mainLightEntity.SetParent(_parent, worldPositionStays: false);
IGameEntity mainLightEntity = GameEntityFactory.Create($"LightSource_Main",
_parent, worldPositionStays: false);
mainLightEntity.Transform.SetPositionAndRotation(mainLightPosition, mainLightRotation);
_mainLight = mainLightEntity.AddComponent<Light>();
@@ -388,8 +367,8 @@ namespace Pal3.Game.Scene
private void AddPointLight(IGameEntity parent, float yOffset)
{
// Add a point light to the fire fx
var lightSource = new GameEntity($"LightSource_Point");
lightSource.SetParent(parent, worldPositionStays: false);
IGameEntity lightSource = GameEntityFactory.Create($"LightSource_Point",
parent, worldPositionStays: false);
lightSource.Transform.LocalPosition = new Vector3(0f, yOffset, 0f);
var lightComponent = lightSource.AddComponent<Light>();
@@ -491,6 +470,7 @@ namespace Pal3.Game.Scene
private void CreateActorObject(Actor actor, Color tintColor, Tilemap tileMap)
{
if (_actorEntities.ContainsKey(actor.Id)) return;
IGameEntity actorGameEntity = ActorFactory.CreateActorGameEntity(_resourceProvider,
actor,
tileMap,
@@ -500,9 +480,8 @@ namespace Pal3.Game.Scene
ActorMovementMaxYDifferentialCrossLayer,
ActorMovementMaxYDifferentialCrossPlatform,
GetAllActiveActorBlockingTilePositions);
actorGameEntity.SetParent(_parent, worldPositionStays: false);
int layerIndex = LayerMask.NameToLayer("Ignore Raycast");
actorGameEntity.SetLayer(layerIndex); // Ignore raycast for all actors
_actorEntities[actor.Id] = actorGameEntity;
}
+1 -1
View File
@@ -17,7 +17,7 @@ namespace Pal3.Game.Scene
using Core.DataReader.Scn;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Core.Implementation;
using Engine.DataLoader;
using SceneObjects;
using State;
@@ -18,7 +18,8 @@ namespace Pal3.Game.Scene
using Core.DataReader.Scn;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Engine.Logging;
using Newtonsoft.Json;
@@ -102,8 +103,8 @@ namespace Pal3.Game.Scene
CommandDispatcher<ICommand>.Instance.Dispatch(new ScenePreLoadingNotification(scnFile.SceneInfo));
EngineLogger.Log("Loading scene: " + JsonConvert.SerializeObject(scnFile.SceneInfo));
_currentSceneRoot = new GameEntity($"Scene_{sceneCityName}_{sceneName}");
_currentSceneRoot.SetParent(null, worldPositionStays: false);
_currentSceneRoot = GameEntityFactory.Create($"Scene_{sceneCityName}_{sceneName}",
null, worldPositionStays: false);
_currentScene = _currentSceneRoot.AddComponent<Scene>();
_currentScene.Init(_resourceProvider,
_sceneStateManager,
@@ -140,8 +141,8 @@ namespace Pal3.Game.Scene
HideCurrentScene();
_currentCombatSceneRoot = new GameEntity($"CombatScene_{combatSceneName}");
_currentCombatSceneRoot.SetParent(null, worldPositionStays: false);
_currentCombatSceneRoot = GameEntityFactory.Create($"CombatScene_{combatSceneName}",
null, worldPositionStays: false);
_currentCombatScene = _currentCombatSceneRoot.AddComponent<CombatScene>();
_currentCombatScene.Init(_resourceProvider);
@@ -14,7 +14,7 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Services;
@@ -48,11 +48,18 @@ namespace Pal3.Game.Scene.SceneObjects
}
else
{
var effectiveTime = GameTimeProvider.Instance.RealTimeSinceStartup;
// This is to prevent player from entering back to previous
// scene when holding the stick while transferring between scenes.
// We simply disable the auto trigger for a short time window after
// a fresh scene load.
var effectiveTime = GameTimeProvider.Instance.RealTimeSinceStartup + 0.35f; // 0.35 seconds
// a fresh scene load if the auto trigger is used for scene transfer.
if (ObjectInfo.ScriptId != ScriptConstants.InvalidScriptId &&
ObjectInfo.ScriptId < ScriptConstants.PortalScriptIdMax)
{
effectiveTime += 1f; // 1 second
}
_triggerController = sceneObjectGameEntity.AddComponent<TilemapTriggerController>();
_triggerController.Init(ObjectInfo.TileMapTriggerRect, ObjectInfo.LayerIndex, effectiveTime);
_triggerController.OnPlayerActorEntered += OnPlayerActorEntered;
@@ -16,7 +16,7 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.DataReader.Scn;
using Core.Primitives;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Extensions;
[ScnSceneObject(SceneObjectType.Chest)]
@@ -17,7 +17,8 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Primitives;
using Core.Utilities;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.DataLoader;
using Engine.Extensions;
using Engine.Services;
@@ -79,8 +80,8 @@ namespace Pal3.Game.Scene.SceneObjects
// Upper indicator
{
_upperInteractionIndicatorGameEntity = new GameEntity("Climbable_Interaction_Indicator_Upper");
_upperInteractionIndicatorGameEntity.SetParent(sceneObjectGameEntity, worldPositionStays: false);
_upperInteractionIndicatorGameEntity = GameEntityFactory.Create("Climbable_Interaction_Indicator_Upper",
sceneObjectGameEntity, worldPositionStays: false);
_upperInteractionIndicatorGameEntity.Transform.LocalScale = new Vector3(1f, -1f, 1f);
_upperInteractionIndicatorGameEntity.Transform.Position = upperPosition;
_upperInteractionIndicatorRenderer = _upperInteractionIndicatorGameEntity.AddComponent<CvdModelRenderer>();
@@ -96,8 +97,8 @@ namespace Pal3.Game.Scene.SceneObjects
// Lower indicator
{
_lowerInteractionIndicatorGameEntity = new GameEntity("Climbable_Interaction_Indicator_Lower");
_lowerInteractionIndicatorGameEntity.SetParent(sceneObjectGameEntity, worldPositionStays: false);
_lowerInteractionIndicatorGameEntity = GameEntityFactory.Create("Climbable_Interaction_Indicator_Lower",
sceneObjectGameEntity, worldPositionStays: false);
_lowerInteractionIndicatorGameEntity.Transform.LocalScale = new Vector3(1f, 1f, 1f);
_lowerInteractionIndicatorGameEntity.Transform.Position = lowerPosition;
_lowerInteractionIndicatorRenderer = _lowerInteractionIndicatorGameEntity.AddComponent<CvdModelRenderer>();
@@ -10,10 +10,10 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Rendering.Renderer;
using Color = Core.Primitives.Color;
#if PAL3
@@ -7,7 +7,8 @@ namespace Pal3.Game.Scene.SceneObjects.Common
{
using System;
using Actor.Controllers;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Engine.Services;
using GamePlay;
@@ -5,7 +5,7 @@
namespace Pal3.Game.Scene.SceneObjects.Common
{
using Engine.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Rendering.Renderer;
using UnityEngine;
@@ -7,7 +7,8 @@ namespace Pal3.Game.Scene.SceneObjects.Common
{
using System;
using Actor.Controllers;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Engine.Extensions;
using Engine.Services;
using GamePlay;
@@ -10,7 +10,7 @@ namespace Pal3.Game.Scene.SceneObjects.Common
using Command.Extensions;
using Core.Command;
using Core.Primitives;
using Engine.Abstraction;
using Engine.Core.Implementation;
using Engine.Services;
public sealed class TilemapTriggerController : GameEntityScript,
@@ -13,7 +13,7 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Services;
using State;
@@ -16,8 +16,8 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Coroutine;
using Engine.Extensions;
@@ -153,7 +153,11 @@ namespace Pal3.Game.Scene.SceneObjects
public override void Deactivate()
{
_cancellationTokenSource.Cancel();
if (!_cancellationTokenSource.IsCancellationRequested)
{
_cancellationTokenSource.Cancel();
}
_isInteractionInProgress = false;
if (_platformController != null)
@@ -10,7 +10,7 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Services;
using Rendering.Renderer;
@@ -17,7 +17,7 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Coroutine;
using Engine.Extensions;
using Rendering.Renderer;
@@ -12,10 +12,10 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Color = Core.Primitives.Color;
using Vector3 = UnityEngine.Vector3;
@@ -14,12 +14,12 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.DataReader.Scn;
using Core.Primitives;
using Data;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Services;
using State;
using Color = Core.Primitives.Color;
using Vector2Int = UnityEngine.Vector2Int;
using Vector3 = UnityEngine.Vector3;
@@ -13,8 +13,8 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Services;
using State;
@@ -15,7 +15,7 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Services;
using Color = Core.Primitives.Color;
@@ -17,8 +17,8 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.DataReader.Nav;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Color = Core.Primitives.Color;
@@ -11,7 +11,7 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Renderer;
@@ -16,8 +16,8 @@ namespace Pal3.Game.Scene.SceneObjects
using Core.Contract.Enums;
using Core.DataReader.Scn;
using Data;
using Engine.Abstraction;
using Engine.Animation;
using Engine.Core.Abstraction;
using Engine.Extensions;
using Engine.Services;
using GameSystems.Team;
Loaded 100 of 136 files, more files were not shown because too many files have changed in this diff. Show more