Skip to content

Commit

Permalink
feat: Add Vector util
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Jan 5, 2025
1 parent d814e06 commit 18472e4
Show file tree
Hide file tree
Showing 30 changed files with 482 additions and 408 deletions.
4 changes: 2 additions & 2 deletions Assets/JCSUnity/Scripts/Actions/2D/AI/JCS_2DAIStateSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum JCS_AIMoveActionType
[ReadOnly]
private JCS_AIMoveActionType mAIMoveActionType = JCS_AIMoveActionType.NONE;

private JCS_Vector<JCS_AIAction> mAIActions = null;
private JCS_Vec<JCS_AIAction> mAIActions = null;

/* Setter & Getter */

Expand All @@ -49,7 +49,7 @@ public enum JCS_AIMoveActionType

private void Awake()
{
this.mAIActions = new JCS_Vector<JCS_AIAction>();
this.mAIActions = new JCS_Vec<JCS_AIAction>();

// add all the ai action into the array.
JCS_AIAction[] actions = this.GetComponents<JCS_AIAction>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public class JCS_2DSequenceShootActionNoDetection : MonoBehaviour, JCS_IAction
private float mShootGap = 0.1f;

//** Sequence Data **
private JCS_Vector<int> mThread = null; // main thread
private JCS_Vector<float> mTimers = null; // timer per thread
private JCS_Vector<int> mShootCount = null; // how many shoot should process per thread
private JCS_Vector<int> mShootCounter = null; // counter per thread
private JCS_Vector<Vector3> mShootPos = null;
private JCS_Vector<Vector3> mShootAngles = null;
private JCS_Vec<int> mThread = null; // main thread
private JCS_Vec<float> mTimers = null; // timer per thread
private JCS_Vec<int> mShootCount = null; // how many shoot should process per thread
private JCS_Vec<int> mShootCounter = null; // counter per thread
private JCS_Vec<Vector3> mShootPos = null;
private JCS_Vec<Vector3> mShootAngles = null;

/* Setter & Getter */

Expand Down Expand Up @@ -108,12 +108,12 @@ private void Awake()
mShootAction.OverrideShoot = true;
mCursorShootAction.OverrideShoot = true;

mThread = new JCS_Vector<int>();
mTimers = new JCS_Vector<float>();
mShootCount = new JCS_Vector<int>();
mShootCounter = new JCS_Vector<int>();
mShootPos = new JCS_Vector<Vector3>();
mShootAngles = new JCS_Vector<Vector3>();
mThread = new JCS_Vec<int>();
mTimers = new JCS_Vec<float>();
mShootCount = new JCS_Vec<int>();
mShootCounter = new JCS_Vec<int>();
mShootPos = new JCS_Vec<Vector3>();
mShootAngles = new JCS_Vec<Vector3>();
}

private void Update()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public class JCS_SequenceShootAction : MonoBehaviour, JCS_IAction
private JCS_DetectAreaObject mDetectedObject = null;

//** Sequence Data **
private JCS_Vector<int> mThread = null; // main thread
private JCS_Vector<float> mTimers = null; // timer per thread
private JCS_Vector<int> mShootCount = null; // how many shoot should process per thread
private JCS_Vector<int> mShootCounter = null; // counter per thread
private JCS_Vector<Vector3> mShootPos = null;
private JCS_Vector<Transform> mTargetsPerSequence = null;
private JCS_Vector<bool> mShootDirection = null;
private JCS_Vec<int> mThread = null; // main thread
private JCS_Vec<float> mTimers = null; // timer per thread
private JCS_Vec<int> mShootCount = null; // how many shoot should process per thread
private JCS_Vec<int> mShootCounter = null; // counter per thread
private JCS_Vec<Vector3> mShootPos = null;
private JCS_Vec<Transform> mTargetsPerSequence = null;
private JCS_Vec<bool> mShootDirection = null;

/* Setter & Getter */

Expand All @@ -113,13 +113,13 @@ private void Awake()
// override the shoot effect in the base one.
mShootAction.OverrideShoot = true;

mThread = new JCS_Vector<int>();
mTimers = new JCS_Vector<float>();
mShootCount = new JCS_Vector<int>();
mShootCounter = new JCS_Vector<int>();
mShootPos = new JCS_Vector<Vector3>();
mTargetsPerSequence = new JCS_Vector<Transform>();
mShootDirection = new JCS_Vector<bool>();
mThread = new JCS_Vec<int>();
mTimers = new JCS_Vec<float>();
mShootCount = new JCS_Vec<int>();
mShootCounter = new JCS_Vec<int>();
mShootPos = new JCS_Vec<Vector3>();
mTargetsPerSequence = new JCS_Vec<Transform>();
mShootDirection = new JCS_Vec<bool>();

// try to get the ability format.
if (mAbilityFormat == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void LookAtMouse()
{
float speed = 10;

Vector3 direction = JCS_Util.VectorDirection(mDirection);
Vector3 direction = JCS_Vector.Direction(mDirection);

// Generate a plane that intersects the transform's position with an upwards normal.
Plane playerPlane = new Plane(direction, mShootAction.SpawnPoint.position);
Expand Down
4 changes: 2 additions & 2 deletions Assets/JCSUnity/Scripts/Actions/3D/JCS_3DLookAtAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void DoLookAt()

Vector3 lookPoint = mTargetTransform.position;
// get direction according to the type.
Vector3 direction = JCS_Util.VectorDirection(mLookDirection);
Vector3 direction = JCS_Vector.Direction(mLookDirection);

transform.LookAt(lookPoint, direction * (int)mState);

Expand Down Expand Up @@ -159,7 +159,7 @@ private void DoAsympLook()
if (forward == Vector3.zero)
return;

Vector3 direction = JCS_Util.VectorDirection(mLookDirection);
Vector3 direction = JCS_Vector.Direction(mLookDirection);

Quaternion dir = Quaternion.LookRotation(forward, direction * (int)mState);

Expand Down
4 changes: 2 additions & 2 deletions Assets/JCSUnity/Scripts/Actions/JCS_DetectAreaAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class JCS_DetectAreaAction : MonoBehaviour
[SerializeField]
private Collider[] mDetectCollider = null;

private JCS_Vector<JCS_DetectAreaObject> mDetectedObjects = null;
private JCS_Vec<JCS_DetectAreaObject> mDetectedObjects = null;

/* Setter & Getter */

Expand Down Expand Up @@ -67,7 +67,7 @@ private void Awake()
}

// create list to manage all detected object
mDetectedObjects = new JCS_Vector<JCS_DetectAreaObject>();
mDetectedObjects = new JCS_Vec<JCS_DetectAreaObject>();
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Assets/JCSUnity/Scripts/Actions/JCS_SimpleTrackAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void Update()
/// <param name="val">Value to add.</param>
public void DeltaTargetPosX(float val)
{
mTargetPos = JCS_Util.IncVecX(mTargetPos, val);
mTargetPos = JCS_Vector.IncVecX(mTargetPos, val);
}

/// <summary>
Expand All @@ -109,7 +109,7 @@ public void DeltaTargetPosX(float val)
/// <param name="val">Value to add.</param>
public void DeltaTargetPosY(float val)
{
mTargetPos = JCS_Util.IncVecY(mTargetPos, val);
mTargetPos = JCS_Vector.IncVecY(mTargetPos, val);
}

/// <summary>
Expand All @@ -118,7 +118,7 @@ public void DeltaTargetPosY(float val)
/// <param name="val">Value to add.</param>
public void DeltaTargetPosZ(float val)
{
mTargetPos = JCS_Util.IncVecZ(mTargetPos, val);
mTargetPos = JCS_Vector.IncVecZ(mTargetPos, val);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,21 @@ public void SpawnATransform()


// randomize the position a bit.
Vector3 randPos = JCS_Util.ApplyRandVector3(
Vector3 randPos = JCS_Vector.ApplyRandVector3(
// use the current spawner position.
objSpawned.transform.position,
new Vector3(mRandPosRangeX, mRandPosRangeY, mRandPosRangeZ),
new JCS_Bool3(mRandPosX, mRandPosY, mRandPosZ));

// randomize the rotation a bit.
Vector3 randRot = JCS_Util.ApplyRandVector3(
Vector3 randRot = JCS_Vector.ApplyRandVector3(
// use the current spawner position.
objSpawned.transform.eulerAngles,
new Vector3(mRandRotRangeX, mRandRotRangeY, mRandRotRangeZ),
new JCS_Bool3(mRandRotationX, mRandRotationY, mRandRotationZ));

// randomize the rotation a bit.
Vector3 randScale = JCS_Util.ApplyRandVector3(
Vector3 randScale = JCS_Vector.ApplyRandVector3(
// use the current spawner position.
objSpawned.transform.localScale,
new Vector3(mRandScaleRangeX, mRandScaleRangeY, mRandScaleRangeZ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,21 @@ public void SpawnATransform()


// randomize the position a bit.
Vector3 randPos = JCS_Util.ApplyRandVector3(
Vector3 randPos = JCS_Vector.ApplyRandVector3(
// use the current spawner position.
objSpawned.transform.position,
new Vector3(mRandPosRangeX, mRandPosRangeY, mRandPosRangeZ),
new JCS_Bool3(mRandPosX, mRandPosY, mRandPosZ));

// randomize the rotation a bit.
Vector3 randRot = JCS_Util.ApplyRandVector3(
Vector3 randRot = JCS_Vector.ApplyRandVector3(
// use the current spawner position.
objSpawned.transform.eulerAngles,
new Vector3(mRandRotRangeX, mRandRotRangeY, mRandRotRangeZ),
new JCS_Bool3(mRandRotationX, mRandRotationY, mRandRotationZ));

// randomize the rotation a bit.
Vector3 randScale = JCS_Util.ApplyRandVector3(
Vector3 randScale = JCS_Vector.ApplyRandVector3(
// use the current spawner position.
objSpawned.transform.localScale,
new Vector3(mRandScaleRangeX, mRandScaleRangeY, mRandScaleRangeZ),
Expand Down
4 changes: 2 additions & 2 deletions Assets/JCSUnity/Scripts/Effects/JCS_Rotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ private void DoRotation()
Vector3 rotateDirection;

if (mBySelf)
rotateDirection = JCS_Util.VectorDirection(mRotateDirection, this.transform);
rotateDirection = JCS_Vector.Direction(mRotateDirection, this.transform);
else
rotateDirection = JCS_Util.VectorDirection(mRotateDirection);
rotateDirection = JCS_Vector.Direction(mRotateDirection);

transform.Rotate(rotateDirection * mRotateSpeed * JCS_Time.DeltaTime(mDeltaTimeType));
}
Expand Down
22 changes: 11 additions & 11 deletions Assets/JCSUnity/Scripts/Effects/Particle/JCS_ParticleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class JCS_ParticleSystem : MonoBehaviour
[Range(50, 5000)]
private int mNumOfParticle = 50;

private JCS_Vector<JCS_Particle> mParticles = null;
private JCS_Vec<JCS_Particle> mParticles = null;
private int mLastAvaliableIndex = 0;

[Separator("Runtime Variables (JCS_ParticleSystem)")]
Expand Down Expand Up @@ -176,14 +176,14 @@ public class JCS_ParticleSystem : MonoBehaviour
private bool mSetToSamePositionWhenActive = true;

//-- Thread
private JCS_Vector<int> mThread = null;
private JCS_Vector<float> mTimers = null; // timer per thread
private JCS_Vector<int> mParticleCount = null; // how many shoot should process per thread
private JCS_Vector<int> mParticleCounter = null; // counter per thread
private JCS_Vec<int> mThread = null;
private JCS_Vec<float> mTimers = null; // timer per thread
private JCS_Vec<int> mParticleCount = null; // how many shoot should process per thread
private JCS_Vec<int> mParticleCounter = null; // counter per thread

/* Setter & Getter */

public JCS_Vector<JCS_Particle> GetParticles() { return this.mParticles; }
public JCS_Vec<JCS_Particle> GetParticles() { return this.mParticles; }

// Binds.
public bool Active { get { return this.mActive; } set { this.mActive = value; } }
Expand Down Expand Up @@ -215,12 +215,12 @@ public class JCS_ParticleSystem : MonoBehaviour

private void Awake()
{
mParticles = new JCS_Vector<JCS_Particle>();
mParticles = new JCS_Vec<JCS_Particle>();

mThread = new JCS_Vector<int>();
mTimers = new JCS_Vector<float>();
mParticleCount = new JCS_Vector<int>();
mParticleCounter = new JCS_Vector<int>();
mThread = new JCS_Vec<int>();
mTimers = new JCS_Vec<float>();
mParticleCount = new JCS_Vec<int>();
mParticleCounter = new JCS_Vec<int>();

mFreezePos = this.transform.position;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class JCS_2DMultiTrackCamera : MonoBehaviour
{
/* Variables */

private JCS_Vector<JCS_Player> mTargetList = null;
private JCS_Vec<JCS_Player> mTargetList = null;

private AudioListener mAudioListener = null;

Expand Down Expand Up @@ -79,7 +79,7 @@ public class JCS_2DMultiTrackCamera : MonoBehaviour

protected void Awake()
{
mTargetList = new JCS_Vector<JCS_Player>();
mTargetList = new JCS_Vec<JCS_Player>();

mAudioListener = this.GetComponent<AudioListener>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private void DoDegreeChangeEffect()
mRandDegreeZ);

// apply it.
transform.eulerAngles = JCS_Util.ApplyRandVector3(transform.eulerAngles, randVal, checkers);
transform.eulerAngles = JCS_Vector.ApplyRandVector3(transform.eulerAngles, randVal, checkers);

// reset timer
mDegreeTimer = 0;
Expand Down
6 changes: 3 additions & 3 deletions Assets/JCSUnity/Scripts/GameObject/JCS_AttackerRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ public class JCS_AttackerRecorder : MonoBehaviour
private Transform mLastAttacker= null;

// Record all the attacker attack this enemy!
private JCS_Vector<Transform> mAttackers = null;
private JCS_Vec<Transform> mAttackers = null;

/* Setter & Getter */

public Transform LastAttacker { get { return this.mLastAttacker; } set { this.mLastAttacker = value; } }
public JCS_Vector<Transform> GetAttackers() { return this.mAttackers; }
public JCS_Vec<Transform> GetAttackers() { return this.mAttackers; }

/* Functions */

private void Awake()
{
mAttackers = new JCS_Vector<Transform>();
mAttackers = new JCS_Vec<Transform>();
}
}
}
6 changes: 3 additions & 3 deletions Assets/JCSUnity/Scripts/Lib/JCS_Pool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ namespace JCSUnity
public class JCS_Pool<T>
{

private JCS_Vector<T> objects = null;
private JCS_Vec<T> objects = null;
private int mLastUseIndex = 0;


public JCS_Vector<T> GetObjects() { return this.objects; }
public JCS_Vec<T> GetObjects() { return this.objects; }
public int LastUseIndex { get { return this.mLastUseIndex; } }

public JCS_Pool(int num)
{
objects = new JCS_Vector<T>(num);
objects = new JCS_Vec<T>(num);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* $File: JCS_Vector.cs $
* $Date: $
* $Revision: $
Expand All @@ -13,15 +13,15 @@ namespace JCSUnity
/// <summary>
/// Vector data structure implementation.
/// </summary>
public class JCS_Vector<T>
public class JCS_Vec<T>
{
private T[] m_array = null;

public T[] array { get { return m_array; } }
public int length { get { return m_array.Length; } }
public bool empty { get { return (length == 0); } }

public JCS_Vector(int length = 0)
public JCS_Vec(int length = 0)
{
m_array = new T[length];
}
Expand Down Expand Up @@ -158,8 +158,5 @@ public void clear()
m_array = null;
m_array = new T[0];
}

}
}


2 changes: 2 additions & 0 deletions Assets/JCSUnity/Scripts/Lib/JCS_Vec.cs.meta

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

Loading

0 comments on commit 18472e4

Please sign in to comment.