CR - #1
Conversation
| @@ -0,0 +1,11 @@ | |||
| using UnityEngine; | |||
|
|
|||
| [CreateAssetMenu(menuName = "Gameplay/Road Params", fileName = "Road Params")] | |||
There was a problem hiding this comment.
Don't know if it's a good idea to call file names with spaces
|
|
||
| public class GameplayObjectPool : IObjectPool | ||
| { | ||
| #region Constants |
There was a problem hiding this comment.
remove regions that are empty, no code, no need for a region and empty lines
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public class GameplayObjectPool : IObjectPool |
There was a problem hiding this comment.
This class seems to have a "manager" quality - it looks like it's generic, but in fact it deals with very specific objects, each in it's own individual name (look at the 2nd comment here as a good explanation why it's bad: https://softwareengineering.stackexchange.com/questions/129537/can-manager-classes-be-a-sign-of-bad-architecture)
If it creates objects, it should be a factory. if it's a factory, it should create only one type of object.
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public abstract class ObstacleBaseFactory |
There was a problem hiding this comment.
this class seems redundant. you inherit it once, and you don't use the abstraction. you should delete it
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public abstract class RoadBaseFactory |
There was a problem hiding this comment.
this class seems redundant. you inherit it once, and you don't use the abstraction. you should delete it
| Obstacle | ||
| } | ||
|
|
||
| public interface IPooledObject |
There was a problem hiding this comment.
PooledObject means an object that an get the gameObject, in the end. it is too generic, any unity object can have a gameObject
| } | ||
| else | ||
| { | ||
| var sinmpleRoad = (SimpleRoad)_simpleRoadFactory.Create(); |
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public enum PooledObjectType |
There was a problem hiding this comment.
this type describes every object in the game, too generic. follow the main comment at the end of this to remove it completely too
| public override IObstacle Create() | ||
| { | ||
| var asteroid = (GameObject)Object.Instantiate(_obstacleParams.AsteroidPrefab); | ||
| return asteroid.GetComponent<AsteroidObstacle>(); |
There was a problem hiding this comment.
GetComponent doesn't necessarily get the object that you just created, see https://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html (it might get you a different one that you created earlier)
|
|
||
| #region Methods | ||
|
|
||
| public void AddObjectToPool(IPooledObject obj) |
There was a problem hiding this comment.
that is actually removing an object from the game, right?
| var newObs = RandomizeNewObstacle(); | ||
| if (newObs != null) | ||
| { | ||
| var pos = RandomPositionOnRoad(); | ||
| GameplayElements.Instance.AddObstacleToRoad(newObs, _lastRoadIndex, pos); | ||
| } |
There was a problem hiding this comment.
this is a duplicate of lines 32-37. simply, you can send the parameters of AddObstacleToRoad to the RandomizeNewObstacle method, if it does create an obstacle it will use them, won't otherwise
|
|
||
| public static void Initialize() | ||
| { | ||
| _awaitService = CreateAwaitService(); |
There was a problem hiding this comment.
seems like a lot of these can be NativeSingleton s
|
I haven't looked at everything, but this is what I found so far: |
|
first I'll begin with the things I don't like, but are not wrong. I'll state my reason for my disliking them. |
|
I think you don't need the IPooledObject interface. correct me if I'm wrong: for example, in AsteroidFactory, when instantiating the object, you use getComponent in order to get the "underlying" object of the GameObject that is the asteroid (BaseObstacle) and return it. but you never use the BaseObstacle itself (it's properties or whatnot), you just end up using GetGameObject (I'm referring to GameplayObjectPool: line 41 and using it in line 63. right after you get it in line 63 you immediately get the game object, so what is it for?). Happens in ObstacleController as well, you don't really use the type you created, so you can just refer to all game objects as themselves, not as the classes you created for them |
|
Lastly, regarding GameplayObjectPool. this class is bound to get out of hand very fast with every new type of game component. As you can see, your switch case options are actually copies of one another: instead, you can create a dictionary that it's key will be the object tag (see next comment) and the value will be the queue, something like this: |
|
I found something inside gameObject that can help differentiate between different types of them, instead of converting them into your own objects and then get the game object again. it's called tag https://docs.unity3d.com/ScriptReference/GameObject-tag.html |
No description provided.