Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7c13 committed Aug 1, 2023
1 parent f872dd7 commit 54fb050
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Assets/Scripts/Pal3/Actor/HuaYingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class HuaYingController : FlyingActorController,
private const float ROTATION_SPEED = 10f;
private const float ROTATION_SYNCING_DISTANCE = 2f;
private const float FOLLOW_TARGET_MIN_DISTANCE = 1f;
private const float FOLLOW_TARGET_FLY_SPEED_CHANEG_DISTANCE = 8f;
private const float FOLLOW_TARGET_FLY_SPEED_CHANGE_DISTANCE = 8f;
private const float FOLLOW_TARGET_MAX_DISTANCE = 15f;
private const float FOLLOW_TARGET_X_OFFSET = 0.8f;
private const float FOLLOW_TARGET_Y_OFFSET = -0.8f;
Expand Down Expand Up @@ -127,10 +127,10 @@ private void LateUpdate()
}

// Increase fly speed if the distance is greater than a threshold
var flySpeed = distanceToTarget > FOLLOW_TARGET_FLY_SPEED_CHANEG_DISTANCE ? MaxFlySpeed : DefaultFlySpeed;
var flySpeed = distanceToTarget > FOLLOW_TARGET_FLY_SPEED_CHANGE_DISTANCE ? MaxFlySpeed : DefaultFlySpeed;

_actorActionController.PerformAction(
Vector3.Distance(myNewPosition, transform.position) < FOLLOW_TARGET_FLY_SPEED_CHANEG_DISTANCE - 1f
Vector3.Distance(myNewPosition, transform.position) < FOLLOW_TARGET_FLY_SPEED_CHANGE_DISTANCE - 1f
? _actor.GetMovementAction(MovementMode.Walk)
: _actor.GetMovementAction(MovementMode.Run));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override void PerformAction(string actionName,
movFile = _resourceProvider.GetGameResourceFile<MovFile>(movFilePath);

textureProvider = _resourceProvider.CreateTextureResourceProvider(
Utility.GetRelativeDirectoryPath(movFilePath));
Utility.GetRelativeDirectoryPath(mtlFilePath));
}
catch (Exception ex)
{
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Pal3/GameSystem/DialogueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private IEnumerator RenderDialogueAndWaitAsync(string text,
_dialogueCanvasGroup.enabled = true;
_isSkipDialogueRequested = false;

yield return StartDialogueAnimationAsync(true);
yield return PlayDialogueBackgroundPopAnimationAsync(true);
_isSkipDialogueRequested = false; // Ignore skip request during dialogue rendering animation

foreach (var dialogue in GetSubDialoguesAsync(text))
Expand All @@ -302,7 +302,7 @@ private IEnumerator RenderDialogueAndWaitAsync(string text,
_totalTimeUsedBeforeSkippingTheLastDialogue = timer.Elapsed.TotalSeconds;
}

yield return StartDialogueAnimationAsync(false);
yield return PlayDialogueBackgroundPopAnimationAsync(false);

ResetUI();

Expand All @@ -311,7 +311,7 @@ private IEnumerator RenderDialogueAndWaitAsync(string text,
onFinished?.Invoke();
}

private IEnumerator StartDialogueAnimationAsync(bool showDialogue)
private IEnumerator PlayDialogueBackgroundPopAnimationAsync(bool showDialogue)
{
const float yOffset = DIALOGUE_SHOW_HIDE_ANIMATION_Y_OFFSET;
Transform dialogueCanvasGroupTransform = _dialogueCanvasGroup.transform;
Expand Down
43 changes: 24 additions & 19 deletions Assets/Scripts/Pal3/Script/PalScriptRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,6 @@ private PalScriptRunner(PalScriptType scriptType,
CommandExecutorRegistry<ICommand>.Instance.Register(this);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (!_isDisposed)
{
if (disposing)
{
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
_scriptDataReader.Dispose();
}
_isDisposed = true;
}
}

public bool Update(float deltaTime)
{
var canExecute = true;
Expand Down Expand Up @@ -242,6 +223,30 @@ private void SetVariableValue(int variableName, int value)
}
}

~PalScriptRunner()
{
Dispose(disposing: false);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (!_isDisposed)
{
if (disposing)
{
CommandExecutorRegistry<ICommand>.Instance.UnRegister(this);
_scriptDataReader.Dispose();
}
_isDisposed = true;
}
}

public void Execute(ScriptVarSetValueCommand command)
{
if (!_isExecuting) return;
Expand Down

0 comments on commit 54fb050

Please sign in to comment.