Most weapons are projectile based -> Lots of GameObjects in play at once.
Continously deleting and allocating projectiles would be terrible for performance.
GC considered harmful.
Encapsuates a List of PooledGameObject.
Ctor is passed size of pool and allocates accordingly.
Also supports Allocate(int), however this is never used.
Internally uses CircularListIterator to keep moving through pool and find unused object.
If all instances are in use, null is returned.
Two approaches:
Be intrusive and add PoolingComponent to GameObject
or
Encapsulate GameObject and move all pool operations into owner class
Two approaches:
or
Keep internals of GameObject and pooling seperate.
Different GOs have different state, needs to be reset accordingly.
ResetComponent is used to reset state.
Encapsulate GameObject and move all pool operations into owner class
Be intrusive and add PoolingComponent to GameObject
Request() changes the object to owned.
Instance is used to access the internal GameObject.
Release() resets the object and clears it for reacquisition.
Also calls each ResetComponent.
{
"Prefabs": [
[ "Prefab/SphereProjectile", 30 ],
[ "Prefab/BounceProjectile", 180 ],
[ "Prefab/GravityProjectile", 60],
[ "Prefab/BlobProjectile", 60 ],
[ "Prefab/UltimateProjectile", 4 ]
],
"Usage": [
"This file defines the path to all GameObject prefabs which should",
"have GoPools created for them on startup.",
"[Path, Instances]",
"Path: A string that defines the prefabs location relative to Assets/.",
"Instances: An integer that defines the amount of Prefab ",
"instances that should be allocated.",
"This may be omitted. In this case, 8 instances will be allocated."
]
}
Reads the config file and creates the pools from it.
Stores a collection of GameObjectPools.
Requests are issued using the prefab:
Request(GameObject prefab)
Exists(GameObject prefab)
Allocate(GameObject prefab)
GetNumInstances(GameObject prefab)
Reset() needs to be called when changing scenes, as Unity kills all GameObjects in a scene.
Dynamic gravity switching based on proximity didn't work out
Switching gravity based on player input (gravity switch button) proved to be less confusing and easier to execute.
Basic execution order for a gravity switch:
FixedUpdate:
void FixedUpdate()
{
m_rigidBody.AddForce(m_gravityVec*100, ForceMode.Acceleration);
if (m_fRotationTime <= 1.1f)
{
transform.localRotation = Quaternion.Slerp(m_quatOldRotation, m_quatNewRotation, m_fRotationTime);
m_fRotationTime += 0.1f;
}
}
Using Quaternion.Slerp with the old Rotation effectively locks the player into the rotation for its duration.
Since its only 10 fixedUpdate frames (=0.2 seconds) it's not really noticeable.
It also prevents the rotation from going wrong and the player 'tilting'.
Using Unitys built in input manager and set the bindings in the editor.
This turned out to cause massive problems when more than one controler was plugged in.
Write our own input handler and set the bindings via a JSON file to remain flexible.
Use XboxCtrlrInput(XCI) as a wrapper, since it handles multiple controlers well and is easy to use.
The bindings are stored in three dictionaries (Axis, Buttons, DPad) within the players PlayerInput class.
A reference to the PlayerInput class is then used to get the abstracted Input.