Compare commits
2 Commits
65b153f97d
...
d9aac0158d
| Author | SHA1 | Date | |
|---|---|---|---|
| d9aac0158d | |||
| 4922a91a04 |
@@ -1,14 +1,15 @@
|
|||||||
namespace Marro.PacManUdon
|
using UdonSharp;
|
||||||
{
|
using UnityEngine;
|
||||||
using UdonSharp;
|
using VRC.SDK3.Data;
|
||||||
using UnityEngine;
|
|
||||||
using VRC.SDK3.Data;
|
|
||||||
using VRC.SDKBase;
|
|
||||||
using VRC.Udon;
|
|
||||||
|
|
||||||
|
namespace Marro.PacManUdon
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof(Animator))]
|
||||||
|
[RequireComponent(typeof(Renderer))]
|
||||||
|
[RequireComponent(typeof(Collider))]
|
||||||
public class BonusFruit : UdonSharpBehaviour
|
public class BonusFruit : UdonSharpBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField, UdonSynced, FieldChangeCallback(nameof(FruitType))] PacManFruitType fruitType;
|
PacManFruitType fruitType;
|
||||||
|
|
||||||
Animator animator;
|
Animator animator;
|
||||||
new Renderer renderer;
|
new Renderer renderer;
|
||||||
@@ -67,7 +68,6 @@
|
|||||||
this.fruitType = fruitType;
|
this.fruitType = fruitType;
|
||||||
value = (int)fruitScoreValue[PacManConstants.FruitTypeToValue(fruitType)];
|
value = (int)fruitScoreValue[PacManConstants.FruitTypeToValue(fruitType)];
|
||||||
animator.SetFloat("FruitType", PacManConstants.FruitTypeToValue(fruitType));
|
animator.SetFloat("FruitType", PacManConstants.FruitTypeToValue(fruitType));
|
||||||
RequestSerialization();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFrozen(bool frozen)
|
public void SetFrozen(bool frozen)
|
||||||
@@ -80,7 +80,6 @@
|
|||||||
renderer.enabled = active;
|
renderer.enabled = active;
|
||||||
collider.enabled = active;
|
collider.enabled = active;
|
||||||
this.active = active;
|
this.active = active;
|
||||||
RequestSerialization();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacManFruitType FruitType
|
public PacManFruitType FruitType
|
||||||
@@ -101,18 +100,17 @@
|
|||||||
get => active;
|
get => active;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataDictionary fruitScoreValue = new DataDictionary()
|
private readonly DataDictionary fruitScoreValue = new DataDictionary()
|
||||||
{
|
{
|
||||||
{(int)PacManFruitType.None , 0},
|
{(int)PacManFruitType.None , 0},
|
||||||
{(int)PacManFruitType.Cherries , 100},
|
{(int)PacManFruitType.Cherries , 100},
|
||||||
{(int)PacManFruitType.Strawberry, 300},
|
{(int)PacManFruitType.Strawberry, 300},
|
||||||
{(int)PacManFruitType.Peach , 500},
|
{(int)PacManFruitType.Peach , 500},
|
||||||
{(int)PacManFruitType.Apple , 700},
|
{(int)PacManFruitType.Apple , 700},
|
||||||
{(int)PacManFruitType.Grapes , 1000},
|
{(int)PacManFruitType.Grapes , 1000},
|
||||||
{(int)PacManFruitType.Galaxian , 2000},
|
{(int)PacManFruitType.Galaxian , 2000},
|
||||||
{(int)PacManFruitType.Bell , 3000},
|
{(int)PacManFruitType.Bell , 3000},
|
||||||
{(int)PacManFruitType.Key , 5000}
|
{(int)PacManFruitType.Key , 5000}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,6 @@ namespace Marro.PacManUdon
|
|||||||
[SerializeField] private int pelletCountOverride = -1;
|
[SerializeField] private int pelletCountOverride = -1;
|
||||||
|
|
||||||
private Maze maze;
|
private Maze maze;
|
||||||
private VRCObjectPool pelletPool;
|
|
||||||
private Intermission2Pole intermission2Pole;
|
private Intermission2Pole intermission2Pole;
|
||||||
|
|
||||||
private Animator mazeSpriteAnimator;
|
private Animator mazeSpriteAnimator;
|
||||||
@@ -65,14 +64,13 @@ namespace Marro.PacManUdon
|
|||||||
}
|
}
|
||||||
|
|
||||||
maze = mazes[0];
|
maze = mazes[0];
|
||||||
pelletPool = maze.pelletContainer.GetComponent<VRCObjectPool>();
|
|
||||||
mazeSpriteAnimator = maze.mazeSprite.GetComponent<Animator>();
|
mazeSpriteAnimator = maze.mazeSprite.GetComponent<Animator>();
|
||||||
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
|
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
|
||||||
|
|
||||||
ghostManager.Initialize(maze.ghostTargets, pacMan, this);
|
ghostManager.Initialize(maze.ghostTargets, pacMan, this);
|
||||||
pacMan.Initialize(playerInput, pelletPool, this);
|
pacMan.Initialize(playerInput, this);
|
||||||
bonusFruit.Initialize();
|
bonusFruit.Initialize();
|
||||||
pelletManager.Initialize(pelletPool);
|
pelletManager.Initialize();
|
||||||
statusDisplay.Initialize();
|
statusDisplay.Initialize();
|
||||||
playerInput.Initialize(this);
|
playerInput.Initialize(this);
|
||||||
soundManager.Initialize();
|
soundManager.Initialize();
|
||||||
@@ -114,7 +112,6 @@ namespace Marro.PacManUdon
|
|||||||
public void StartGameButtonPressed()
|
public void StartGameButtonPressed()
|
||||||
{
|
{
|
||||||
Debug.Log($"{gameObject} Start Game Button was pressed!");
|
Debug.Log($"{gameObject} Start Game Button was pressed!");
|
||||||
TakeOwnership();
|
|
||||||
StartTimeSequence(PacManTimeSequence.StartNewGame);
|
StartTimeSequence(PacManTimeSequence.StartNewGame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +139,7 @@ namespace Marro.PacManUdon
|
|||||||
{
|
{
|
||||||
Debug.Log($"{gameObject} New level started!");
|
Debug.Log($"{gameObject} New level started!");
|
||||||
|
|
||||||
pelletCountTotal = pelletPool.Pool.Length;
|
pelletCountTotal = pelletManager.PelletCount;
|
||||||
pelletCountRemaining = pelletCountTotal;
|
pelletCountRemaining = pelletCountTotal;
|
||||||
ghostManager.SetPelletsRemaining(pelletCountRemaining);
|
ghostManager.SetPelletsRemaining(pelletCountRemaining);
|
||||||
ghostManager.NewLevel();
|
ghostManager.NewLevel();
|
||||||
@@ -283,7 +280,7 @@ namespace Marro.PacManUdon
|
|||||||
|
|
||||||
void SetPelletsActive(bool active)
|
void SetPelletsActive(bool active)
|
||||||
{
|
{
|
||||||
pelletPool.gameObject.SetActive(active);
|
pelletManager.gameObject.SetActive(active);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMazeVisible(bool visible)
|
void SetMazeVisible(bool visible)
|
||||||
@@ -315,10 +312,6 @@ namespace Marro.PacManUdon
|
|||||||
{
|
{
|
||||||
// Debug.Log($"{gameObject} State transitioning from {gameState} to {newGameState}");
|
// Debug.Log($"{gameObject} State transitioning from {gameState} to {newGameState}");
|
||||||
gameState = newGameState;
|
gameState = newGameState;
|
||||||
if (Networking.IsOwner(gameObject))
|
|
||||||
{
|
|
||||||
RequestSerialization();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void IncrementLevel()
|
private void IncrementLevel()
|
||||||
@@ -348,7 +341,6 @@ namespace Marro.PacManUdon
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetScore(this.score + score);
|
SetScore(this.score + score);
|
||||||
RequestSerialization();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetScore(int score)
|
void SetScore(int score)
|
||||||
@@ -370,20 +362,12 @@ namespace Marro.PacManUdon
|
|||||||
|
|
||||||
public void DecrementLives()
|
public void DecrementLives()
|
||||||
{
|
{
|
||||||
if (!Networking.IsOwner(gameObject))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Debug.Log($"{gameObject} Decremented lives from {extraLives} to {extraLives - 1}");
|
// Debug.Log($"{gameObject} Decremented lives from {extraLives} to {extraLives - 1}");
|
||||||
SetExtraLives(extraLives - 1);
|
SetExtraLives(extraLives - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IncrementLives()
|
void IncrementLives()
|
||||||
{
|
{
|
||||||
if (!Networking.IsOwner(gameObject))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Debug.Log($"{gameObject} Incremented lives from {extraLives} to {extraLives + 1}");
|
// Debug.Log($"{gameObject} Incremented lives from {extraLives} to {extraLives + 1}");
|
||||||
SetExtraLives(extraLives + 1);
|
SetExtraLives(extraLives + 1);
|
||||||
}
|
}
|
||||||
@@ -414,14 +398,6 @@ namespace Marro.PacManUdon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TakeOwnership()
|
|
||||||
{
|
|
||||||
Networking.SetOwner(Networking.LocalPlayer, gameObject);
|
|
||||||
Networking.SetOwner(Networking.LocalPlayer, pacMan.gameObject);
|
|
||||||
Networking.SetOwner(Networking.LocalPlayer, pelletPool.gameObject);
|
|
||||||
ghostManager.SetOwner(Networking.LocalPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
|
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
|
||||||
{
|
{
|
||||||
data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) };
|
data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) };
|
||||||
|
|||||||
@@ -145,7 +145,6 @@ namespace Marro.PacManUdon
|
|||||||
|
|
||||||
faceInStartingDirectionUntilUnfrozen = true;
|
faceInStartingDirectionUntilUnfrozen = true;
|
||||||
UpdateAnimator();
|
UpdateAnimator();
|
||||||
RequestSerialization();
|
|
||||||
|
|
||||||
// Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}");
|
// Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}");
|
||||||
}
|
}
|
||||||
@@ -666,7 +665,6 @@ namespace Marro.PacManUdon
|
|||||||
}
|
}
|
||||||
this.scattering = scattering;
|
this.scattering = scattering;
|
||||||
UpdateAnimator();
|
UpdateAnimator();
|
||||||
RequestSerialization();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFrozen(bool frozen, bool ignoreIfCaught = false, bool keepAnimating = false)
|
public void SetFrozen(bool frozen, bool ignoreIfCaught = false, bool keepAnimating = false)
|
||||||
@@ -781,7 +779,7 @@ namespace Marro.PacManUdon
|
|||||||
|
|
||||||
void OnTriggerEnter(Collider other)
|
void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent<PacManGhostCollider>())
|
if (other.gameObject.GetComponent<PacManGhostCollider>())
|
||||||
{
|
{
|
||||||
if (isScared)
|
if (isScared)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -92,7 +92,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetScattering(true, reverseDirection: false);
|
SetScattering(true, reverseDirection: false);
|
||||||
RequestSerialization();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewLevel()
|
public void NewLevel()
|
||||||
@@ -333,15 +332,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetOwner(VRCPlayerApi player)
|
|
||||||
{
|
|
||||||
Networking.SetOwner(player, gameObject);
|
|
||||||
foreach (Ghost ghost in ghosts)
|
|
||||||
{
|
|
||||||
Networking.SetOwner(player, ghost.gameObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float GetTargetSpeed(Ghost ghost, PacManGhostState ghostState, bool isScared, bool inTunnel)
|
public float GetTargetSpeed(Ghost ghost, PacManGhostState ghostState, bool isScared, bool inTunnel)
|
||||||
{
|
{
|
||||||
if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering)
|
if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
namespace Marro.PacManUdon
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using VRC.SDK3.Components;
|
||||||
|
using VRC.SDKBase;
|
||||||
|
|
||||||
|
namespace Marro.PacManUdon
|
||||||
{
|
{
|
||||||
using System;
|
[RequireComponent(typeof(Animator))]
|
||||||
using UdonSharp;
|
[RequireComponent(typeof(Renderer))]
|
||||||
using UnityEngine;
|
|
||||||
using VRC.SDKBase;
|
|
||||||
using VRC.Udon;
|
|
||||||
using VRC.SDK3.Components;
|
|
||||||
|
|
||||||
public class PacMan : GridMover
|
public class PacMan : GridMover
|
||||||
{
|
{
|
||||||
private GameManager gameController;
|
private GameManager gameController;
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
private Vector3 startScale;
|
private Vector3 startScale;
|
||||||
private Animator animator;
|
private Animator animator;
|
||||||
new Renderer renderer;
|
new Renderer renderer;
|
||||||
private VRCObjectPool pelletPool;
|
|
||||||
private bool hideUntilUnfrozen;
|
private bool hideUntilUnfrozen;
|
||||||
private bool dead;
|
private bool dead;
|
||||||
private bool kinematic;
|
private bool kinematic;
|
||||||
@@ -28,12 +27,11 @@
|
|||||||
private Vector2[] predefinedPath;
|
private Vector2[] predefinedPath;
|
||||||
private int predefinedPathIndex;
|
private int predefinedPathIndex;
|
||||||
|
|
||||||
private Vector2 syncedPosition;
|
|
||||||
private Vector2 targetDirection;
|
private Vector2 targetDirection;
|
||||||
private float freezeSeconds;
|
private float freezeSeconds;
|
||||||
private bool frozen;
|
private bool frozen;
|
||||||
|
|
||||||
#region Animator constants
|
#region Animator constants
|
||||||
private const string AnimatorKeyDead = "Dead";
|
private const string AnimatorKeyDead = "Dead";
|
||||||
private const string AnimatorKeyDirection = "Direction";
|
private const string AnimatorKeyDirection = "Direction";
|
||||||
private const float AnimatorDirectionNone = 0f;
|
private const float AnimatorDirectionNone = 0f;
|
||||||
@@ -42,14 +40,13 @@
|
|||||||
private const float AnimatorDirectionUp = 0.75f;
|
private const float AnimatorDirectionUp = 0.75f;
|
||||||
private const float AnimatorDirectionDown = 1f;
|
private const float AnimatorDirectionDown = 1f;
|
||||||
private const float AnimatorDirectionRightBig = 1.25f;
|
private const float AnimatorDirectionRightBig = 1.25f;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public void Initialize(PlayerInput input, VRCObjectPool pelletPool, GameManager gameController)
|
public void Initialize(PlayerInput input, GameManager gameController)
|
||||||
{
|
{
|
||||||
this.gameController = gameController;
|
this.gameController = gameController;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.pelletPool = pelletPool;
|
|
||||||
animator = GetComponent<Animator>();
|
animator = GetComponent<Animator>();
|
||||||
renderer = GetComponent<Renderer>();
|
renderer = GetComponent<Renderer>();
|
||||||
frozen = false;
|
frozen = false;
|
||||||
@@ -62,8 +59,7 @@
|
|||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
// Debug.Log($"{gameObject} Reset!");
|
// Debug.Log($"{gameObject} Reset!");
|
||||||
transform.localPosition = startPosition;
|
transform.SetLocalPositionAndRotation(startPosition, startRotation);
|
||||||
transform.localRotation = startRotation;
|
|
||||||
transform.localScale = startScale;
|
transform.localScale = startScale;
|
||||||
direction = Vector2.left;
|
direction = Vector2.left;
|
||||||
targetDirection = Vector2.left;
|
targetDirection = Vector2.left;
|
||||||
@@ -145,23 +141,20 @@
|
|||||||
// Debug.Log($"{gameObject} crossed Y tile center from {currentPosition} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
|
// Debug.Log($"{gameObject} crossed Y tile center from {currentPosition} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Networking.IsOwner(gameObject))
|
Vector2 inputDirection = input.GetDirection();
|
||||||
{
|
if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
|
||||||
Vector2 inputDirection = input.GetDirection();
|
&& (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) && (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border
|
||||||
if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
|
&& !GridMoverTools.CheckCollisionInDirection(transform, nextPosition, inputDirection))
|
||||||
&& (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) && (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border
|
{ // Check if the requested direction does not have a wall
|
||||||
&& !GridMoverTools.CheckCollisionInDirection(transform, nextPosition, inputDirection))
|
if (inputDirection.x != 0)
|
||||||
{ // Check if the requested direction does not have a wall
|
{ // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
|
||||||
if (inputDirection.x != 0)
|
SetDirection(inputDirection + new Vector2(0, GridMoverTools.PositionToGrid(nextPosition).y - nextPosition.y).normalized);
|
||||||
{ // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
|
|
||||||
SetDirection(inputDirection + new Vector2(0, GridMoverTools.PositionToGrid(nextPosition).y - nextPosition.y).normalized);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetDirection(inputDirection + new Vector2(GridMoverTools.PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized);
|
|
||||||
}
|
|
||||||
SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetDirection(inputDirection + new Vector2(GridMoverTools.PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized);
|
||||||
|
}
|
||||||
|
SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextPosition;
|
return nextPosition;
|
||||||
@@ -211,7 +204,7 @@
|
|||||||
// Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}");
|
// Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}");
|
||||||
if (!gameObject.activeInHierarchy)
|
if (!gameObject.activeInHierarchy)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
animator.SetBool(AnimatorKeyDead, dead);
|
animator.SetBool(AnimatorKeyDead, dead);
|
||||||
if (dead)
|
if (dead)
|
||||||
{
|
{
|
||||||
@@ -326,15 +319,7 @@
|
|||||||
Pellet pellet = other.gameObject.GetComponent<Pellet>();
|
Pellet pellet = other.gameObject.GetComponent<Pellet>();
|
||||||
if (pellet)
|
if (pellet)
|
||||||
{
|
{
|
||||||
if (Networking.IsOwner(gameObject))
|
pellet.gameObject.SetActive(false);
|
||||||
{
|
|
||||||
pelletPool.Return(pellet.gameObject);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pellet.pelletRenderer.enabled = false;
|
|
||||||
pellet.gameObject.SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pellet.isPowerPellet)
|
if (pellet.isPowerPellet)
|
||||||
{
|
{
|
||||||
@@ -348,7 +333,7 @@
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent<BonusFruit>())
|
else if (other.gameObject.GetComponent<BonusFruit>())
|
||||||
{
|
{
|
||||||
gameController.GotFruit();
|
gameController.GotFruit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
using UdonSharp;
|
using UdonSharp;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(Renderer))]
|
||||||
public class Pellet : UdonSharpBehaviour
|
public class Pellet : UdonSharpBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] public bool isPowerPellet = false;
|
public bool isPowerPellet = false;
|
||||||
public Renderer pelletRenderer;
|
public Renderer pelletRenderer;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
|
|||||||
@@ -1,42 +1,24 @@
|
|||||||
namespace Marro.PacManUdon
|
using UdonSharp;
|
||||||
{
|
using UnityEngine;
|
||||||
using UdonSharp;
|
|
||||||
using UnityEngine;
|
|
||||||
using VRC.SDK3.Components;
|
|
||||||
using VRC.SDKBase;
|
|
||||||
using VRC.Udon;
|
|
||||||
|
|
||||||
|
namespace Marro.PacManUdon
|
||||||
|
{
|
||||||
public class PelletManager : UdonSharpBehaviour
|
public class PelletManager : UdonSharpBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] Pellet[] pellets;
|
Pellet[] pellets;
|
||||||
VRCObjectPool pelletPool;
|
|
||||||
Renderer[] pelletRenderers;
|
Renderer[] pelletRenderers;
|
||||||
Animator[] powerPellets;
|
Animator[] powerPellets;
|
||||||
|
|
||||||
|
|
||||||
bool powerPelletBlinkEnabled;
|
bool powerPelletBlinkEnabled;
|
||||||
float powerPelletBlinkToggleInterval;
|
float powerPelletBlinkToggleInterval;
|
||||||
float powerPelletBlinkProgress;
|
float powerPelletBlinkProgress;
|
||||||
bool powerPelletBlinkCurrentlyVisible;
|
bool powerPelletBlinkCurrentlyVisible;
|
||||||
|
|
||||||
public void Initialize(VRCObjectPool pelletPool)
|
|
||||||
{
|
|
||||||
gameObject.SetActive(true);
|
|
||||||
this.pelletPool = pelletPool;
|
|
||||||
pelletRenderers = new Renderer[pelletPool.Pool.Length];
|
|
||||||
for (int i = 0; i < pelletRenderers.Length; i++)
|
|
||||||
{
|
|
||||||
pelletRenderers[i] = pelletPool.Pool[i].GetComponent<Renderer>();
|
|
||||||
}
|
|
||||||
|
|
||||||
powerPellets = GetComponentsInChildren<Animator>(true);
|
|
||||||
// Debug.Log($"{gameObject} Initialized, powerPellets: {powerPellets}");
|
|
||||||
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
|
|
||||||
SetPowerPelletsBlink(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
|
gameObject.SetActive(true);
|
||||||
|
pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
|
||||||
|
|
||||||
pelletRenderers = new Renderer[pellets.Length];
|
pelletRenderers = new Renderer[pellets.Length];
|
||||||
for (int i = 0; i < pelletRenderers.Length; i++)
|
for (int i = 0; i < pelletRenderers.Length; i++)
|
||||||
{
|
{
|
||||||
@@ -91,12 +73,9 @@
|
|||||||
|
|
||||||
public void RestoreAllPellets()
|
public void RestoreAllPellets()
|
||||||
{
|
{
|
||||||
foreach (GameObject pellet in pelletPool.Pool)
|
foreach (var pellet in pellets)
|
||||||
{
|
{
|
||||||
if (pelletPool.TryToSpawn() == false)
|
pellet.gameObject.SetActive(true);
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Renderer pelletRenderer in pelletRenderers)
|
foreach (Renderer pelletRenderer in pelletRenderers)
|
||||||
@@ -104,5 +83,7 @@
|
|||||||
pelletRenderer.enabled = true;
|
pelletRenderer.enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int PelletCount => pellets.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ namespace Marro.PacManUdon
|
|||||||
bool waitingForTimeSequenceFinalize;
|
bool waitingForTimeSequenceFinalize;
|
||||||
bool jumpingToTimeSequence;
|
bool jumpingToTimeSequence;
|
||||||
PacManTimeSequence currentTimeSequence;
|
PacManTimeSequence currentTimeSequence;
|
||||||
[UdonSynced] float timeSequenceSecondsPassed;
|
float timeSequenceSecondsPassed;
|
||||||
int timeSequenceProgress;
|
int timeSequenceProgress;
|
||||||
float[] timeSequenceKeyframeTimes;
|
float[] timeSequenceKeyframeTimes;
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ namespace Marro.PacManUdon
|
|||||||
|
|
||||||
private void TimeSequencePrepareForFinish(PacManTimeSequence timeSequence)
|
private void TimeSequencePrepareForFinish(PacManTimeSequence timeSequence)
|
||||||
{
|
{
|
||||||
if (Networking.IsOwner(gameObject))
|
if (networkManager.IsOwner)
|
||||||
{
|
{
|
||||||
TimeSequenceExecuteFinalize(timeSequence);
|
TimeSequenceExecuteFinalize(timeSequence);
|
||||||
if (!jumpingToTimeSequence)
|
if (!jumpingToTimeSequence)
|
||||||
|
|||||||
Reference in New Issue
Block a user