Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ MonoBehaviour:
- Assets/KamranWali/CodeOptPro/SO_Data
- Assets/KamranWali/CodeOptPro/SO_Data
- Assets/KamranWali/CodeOptPro/SO_Data
- Assets/KamranWali/CodeOptPro/SO_Data
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public override void AwakeAdv()
base.AwakeAdv();
_helper.SetManager(this);
}
public override void StartAdv() { }

#region Editor Script
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@ public class UpdateManagerLocal : MonoAdv, ICOPSetup<MonoAdvUpdate>
{
[Header("UpdateManagerLocal Local Properties")]
[SerializeField] private List<MonoAdvUpdate> _objects;
[SerializeField, Min(1)] private int _numUpdate = 1;
[SerializeField, Min(1), Tooltip("Number of objects to update per frame.")] private int _numUpdate = 1;

private int _pointer;
private int _indexUpdate;
private float _timeDelta;
private int _actualNumUpdate; // This is the actual number of objects to update

public override void AwakeAdv()
{
CalculateTimeDelta(); // Calculating the delta time for the update manager
ValidateNumUpdate(); // Validating the actual number of objects to update
}

public override void AwakeAdv() => _timeDelta = _objects.Count / _numUpdate; // Calculating the delta time for the update manager
public override void StartAdv() { }

protected virtual void Update()
{
if (_objects.Count != 0) // Checking if Update is allowed
{
if (_numUpdate == 1) UpdateObject(); // Update 1 obj per frame
else for (_indexUpdate = 0; _indexUpdate < _numUpdate; _indexUpdate++) UpdateObject(); // Update n obj per frame
else for (_indexUpdate = 0; _indexUpdate < _actualNumUpdate; _indexUpdate++) UpdateObject(); // Update n obj per frame
}
}

Expand Down Expand Up @@ -58,5 +64,19 @@ public void AddObject(MonoAdvUpdate obj)
/// This method updates the active object.
/// </summary>
private void UpdateObject() { if (_objects[_pointer = _pointer + 1 >= _objects.Count ? 0 : _pointer + 1].IsActive()) _objects[_pointer].UpdateObject(); }

/// <summary>
/// This method calculates the time delta for the update manager.
/// </summary>
private void CalculateTimeDelta()
{
_timeDelta = ((float)_objects.Count) / ((float)_numUpdate);
_timeDelta = _timeDelta <= 1f ? 1f : _timeDelta; // Validating time delta value
}

/// <summary>
/// This method calculates the actual number of objects to update.
/// </summary>
private void ValidateNumUpdate() => _actualNumUpdate = _objects.Count <= _numUpdate ? _objects.Count : _numUpdate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UnityEngine;

namespace KamranWali.CodeOptPro.ScriptableObjects.Vars
{
[CreateAssetMenu(fileName = "CameraVar",
menuName = "CodeOptPro/ScriptableObjects/Vars/" +
"CameraVar",
order = 1)]
public class CameraVar : BaseVar<Camera> { }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ In this category different type of data types are shared, example bool, float, i
##### 3. Vars
Just like FixedVars this category shares different type of data types as well, example bool, float, int, string etc. The only difference is that you can **NOT** set any values here like FixedVars and the values may change. Vars basically shares values that are constantly changing. For example - You have 5 objects that wants to know the player's position. Then just create a Vector3Var and make the player script constantly update the newly created Vector3Var. Then add the newly created Vector3Var to the other 5 objects. Now all of those 5 objects have access to the player's position without the need of player script reference. Below are all the types.
- **BoolVar** - This Var shares _bool_ data types. To set the value simply call _void BoolVar.SetValue(bool value)_. To get the value just call _bool BoolVar.GetValue()_. To use BoolVar just import by calling _using KamranWali.CodeOptPro.ScriptableObjects.Vars.BoolVar_.
- **CameraVar** - This Var shares _Camera_ data types. To set the value simply call _void CameraVar.SetValue(Camera value)_. To get the value just call _Camera CameraVar.GetValue()_. To use CameraVar just import by calling _using KamranWali.CodeOptPro.ScriptableObjects.Vars.CameraVar_.
- **DoubleVar** - This Var shares _double_ data types. To set the value simply call _void DoubleVar.SetValue(double value)_. To get the value just call _double DoubleVar.GetValue()_. To use DoubleVar just import by calling _using KamranWali.CodeOptPro.ScriptableObjects.Vars.DoubleVar_.
- **FloatVar** - This Var shares _float_ data types. To set the value simply call _void FloatVar.SetValue(float value)_. To get the value just call _float FloatVar.GetValue()_. To use FloatVar just import by calling _using KamranWali.CodeOptPro.ScriptableObjects.Vars.FloatVar_.
- **GameObjectVar** - This Var shares _GameObject_ data types. To set the value simply call _void GameObjectVar.SetValue(GameObject value)_. To get the value just call _GameObject GameObjectVar.GetValue()_. To use GameObjectVar just import by calling _using KamranWali.CodeOptPro.ScriptableObjects.Vars.GameObjectVar_.
Expand Down Expand Up @@ -237,7 +238,11 @@ This is same as _MonoAdvUpdateLocal_. See the details there to understand. The o
Here I will share all the updates done to the newer versions. Below are the updates.
1. Added FixedLayerMaskVar variable.
2. Added Bars.
3. **Bug Fixed** - Fixed the docking issue of the windows.
3. **Bug: Docking (Fixed)** - Fixed the docking issue of the windows.
4. **Bug: UpdateManager Number of Object Update (Fixed)** - There was a bug in UpdateManager where if the __numUpdate_ was greater than __objects.Count_ then the update manager would update an object twice per frame. Fixed this bug by selecting the lower value from the two variables __numUpdate_ and __object.Count_.
5. **Bug: UpdateManager TimeDelta** - There was a bug in __timeDelta_ calculation in UpdateManagers. The fields __objects.Count_ and __numUpdate_ where ints so dividing them were giving wrong result. Used float casting to get the correct __timeDelta_ calculation.
6. **Bug: UpdateManager TimeDelta Calculation** - Now __timeDelta_ is NOT allowed to go below 1 after calculation. If it does then it will be validated to 1. This was causing some update smoothing issue so calculation had to be changed.
7. Added CameraVar variable.
***
## Versioning
The project uses [Semantic Versioning](https://semver.org/). Available versions can be seen in [tags on this repository](https://github.com/deadlykam/CodeOptPro/tags).
Expand Down