Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfofRome committed Apr 8, 2023
1 parent 3246476 commit 8b1e700
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Assets/Scripts/Pal3/Actor/ActorMovementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,9 @@ private void ReachingToEndOfPath()
case EndOfPathActionType.WaitAndReverse:
{
_actionController.PerformAction(_actor.GetIdleAction());
var waypoints = _currentPath.GetAllWayPoints();
waypoints.Reverse();
StartCoroutine(WaitForSomeTimeAndFollowPathAsync(waypoints.ToArray(),
Vector3[] waypoints = _currentPath.GetAllWayPoints();
Array.Reverse(waypoints);
StartCoroutine(WaitForSomeTimeAndFollowPathAsync(waypoints,
_currentPath.MovementMode,
_movementCts.Token));
break;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Pal3/Actor/Mv3ActorActionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ internal override void DisposeCurrentAction()
if (_mv3AnimationRenderer != null)
{
_mv3AnimationRenderer.AnimationLoopPointReached -= AnimationLoopPointReached;
_mv3AnimationRenderer.DisposeAnimation();
_mv3AnimationRenderer.Dispose();
}

base.DisposeCurrentAction();
Expand Down
13 changes: 6 additions & 7 deletions Assets/Scripts/Pal3/Actor/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Pal3.Actor
{
using System.Collections.Generic;
using UnityEngine;

public enum EndOfPathActionType
Expand All @@ -23,7 +22,7 @@ public class Path

public bool IgnoreObstacle { get; private set; }

private readonly List<Vector3> _wayPoints = new ();
private Vector3[] _wayPoints = {};

private int _currentWayPointIndex;

Expand All @@ -34,7 +33,7 @@ public class Path
{
Clear();

_wayPoints.AddRange(wayPoints);
_wayPoints = wayPoints;
_currentWayPointIndex = 0;

MovementMode = movementMode;
Expand All @@ -46,21 +45,21 @@ public void Clear()
{
MovementMode = 0;
EndOfPathAction = EndOfPathActionType.Idle;
_wayPoints.Clear();
_wayPoints = new Vector3[] {};
_currentWayPointIndex = 0;
}

public bool MoveToNextWayPoint()
{
return ++_currentWayPointIndex < _wayPoints.Count;
return ++_currentWayPointIndex < _wayPoints.Length;
}

public bool IsEndOfPath()
{
return !(_wayPoints.Count > 0 && _currentWayPointIndex < _wayPoints.Count);
return !(_wayPoints.Length > 0 && _currentWayPointIndex < _wayPoints.Length);
}

public List<Vector3> GetAllWayPoints()
public Vector3[] GetAllWayPoints()
{
return _wayPoints;
}
Expand Down
47 changes: 16 additions & 31 deletions Assets/Scripts/Pal3/Renderer/Mv3ModelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class Mv3ModelRenderer : MonoBehaviour, IDisposable
ITextureResourceProvider tagNodeTextureProvider = default,
Color? tagNodeTintColor = default)
{
DisposeAnimation();
Dispose();

_materialFactory = materialFactory;
_textureProvider = textureProvider;
Expand Down Expand Up @@ -106,7 +106,7 @@ public class Mv3ModelRenderer : MonoBehaviour, IDisposable
var materialId = mesh.Attributes[0].MaterialId;
Mv3Material material = mv3File.Materials[materialId];

InitSubMeshes(i, mesh, material);
InitSubMeshes(i, ref mesh, ref material);
}

if (tagNodePolFile != null && _tagNodesInfo is {Length: > 0})
Expand Down Expand Up @@ -136,8 +136,8 @@ public class Mv3ModelRenderer : MonoBehaviour, IDisposable
}

private void InitSubMeshes(int index,
Mv3Mesh mv3Mesh,
Mv3Material material)
ref Mv3Mesh mv3Mesh,
ref Mv3Material material)
{
var textureName = material.TextureNames[0];

Expand Down Expand Up @@ -254,10 +254,21 @@ public void PauseAnimation()
}
}

public void DisposeAnimation()
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)
Expand Down Expand Up @@ -461,31 +472,5 @@ private void OnDisable()
{
Dispose();
}

public void Dispose()
{
DisposeAnimation();

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;
}
}
}
}

0 comments on commit 8b1e700

Please sign in to comment.