Create a diving minigame MVP (#6)
- Obstacles - Tiles - Object pooling - Monster spawns - Scoring - Minigame End Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Co-authored-by: AlexanderT <alexander@foolhardyhorizons.com> Reviewed-on: #6
This commit is contained in:
3
Assets/External/OptimizedRopesAndCables/OptimizedRope.asmdef
vendored
Normal file
3
Assets/External/OptimizedRopesAndCables/OptimizedRope.asmdef
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "OptimizedRope"
|
||||
}
|
||||
7
Assets/External/OptimizedRopesAndCables/OptimizedRope.asmdef.meta
vendored
Normal file
7
Assets/External/OptimizedRopesAndCables/OptimizedRope.asmdef.meta
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7c43f01316c63c43a8b70a1dd6bdfac
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -75,8 +75,20 @@ namespace GogoGaga.OptimizedRopesAndCables
|
||||
|
||||
public bool IsPrefab => gameObject.scene.rootCount == 0;
|
||||
|
||||
private void Start()
|
||||
// Track initialization state
|
||||
private bool isInitialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// Public method to explicitly initialize the rope.
|
||||
/// Call this after setting up endpoints if creating ropes at runtime.
|
||||
/// </summary>
|
||||
/// <returns>True if initialization was successful, false otherwise</returns>
|
||||
public bool Initialize()
|
||||
{
|
||||
// Skip if already initialized
|
||||
if (isInitialized)
|
||||
return true;
|
||||
|
||||
InitializeLineRenderer();
|
||||
if (AreEndPointsValid())
|
||||
{
|
||||
@@ -84,7 +96,17 @@ namespace GogoGaga.OptimizedRopesAndCables
|
||||
targetValue = currentValue;
|
||||
currentVelocity = Vector3.zero;
|
||||
SetSplinePoint(); // Ensure initial spline point is set correctly
|
||||
isInitialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Use the same initialization method to avoid code duplication
|
||||
Initialize();
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
@@ -208,15 +230,62 @@ namespace GogoGaga.OptimizedRopesAndCables
|
||||
return point;
|
||||
}
|
||||
|
||||
public Vector3 GetPointAt(float t)
|
||||
/// <summary>
|
||||
/// Set the start point of the rope
|
||||
/// </summary>
|
||||
public void SetStartPoint(Transform newStartPoint, bool recalculateRope = false)
|
||||
{
|
||||
if (!AreEndPointsValid())
|
||||
{
|
||||
Debug.LogError("StartPoint or EndPoint is not assigned.", gameObject);
|
||||
return Vector3.zero;
|
||||
}
|
||||
startPoint = newStartPoint;
|
||||
if (recalculateRope)
|
||||
RecalculateRope();
|
||||
}
|
||||
|
||||
return GetRationalBezierPoint(startPoint.position, currentValue, endPoint.position, t, StartPointWeight, midPointWeight, EndPointWeight);
|
||||
/// <summary>
|
||||
/// Set the end point of the rope
|
||||
/// </summary>
|
||||
public void SetEndPoint(Transform newEndPoint, bool recalculateRope = false)
|
||||
{
|
||||
endPoint = newEndPoint;
|
||||
if (recalculateRope)
|
||||
RecalculateRope();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the mid point of the rope
|
||||
/// </summary>
|
||||
public void SetMidPoint(Transform newMidPoint, bool recalculateRope = false)
|
||||
{
|
||||
midPoint = newMidPoint;
|
||||
if (recalculateRope)
|
||||
RecalculateRope();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a point along the rope at the specified position (0-1)
|
||||
/// </summary>
|
||||
public Vector3 GetPointAt(float position)
|
||||
{
|
||||
position = Mathf.Clamp01(position);
|
||||
Vector3 mid = GetMidPoint();
|
||||
return GetRationalBezierPoint(startPoint.position, mid, endPoint.position, position, StartPointWeight, midPointWeight, EndPointWeight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force recalculation of the rope
|
||||
/// </summary>
|
||||
public void RecalculateRope()
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
if (AreEndPointsValid())
|
||||
{
|
||||
SetSplinePoint();
|
||||
SimulatePhysics();
|
||||
NotifyPointsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
@@ -262,61 +331,6 @@ namespace GogoGaga.OptimizedRopesAndCables
|
||||
// Gizmos.DrawSphere(midPos, 0.2f);
|
||||
}
|
||||
|
||||
// New API methods for setting start and end points
|
||||
// with instantAssign parameter to recalculate the rope immediately, without
|
||||
// animating the rope to the new position.
|
||||
// When newStartPoint or newEndPoint is null, the rope will be recalculated immediately
|
||||
|
||||
public void SetStartPoint(Transform newStartPoint, bool instantAssign = false)
|
||||
{
|
||||
startPoint = newStartPoint;
|
||||
prevStartPointPosition = startPoint == null ? Vector3.zero : startPoint.position;
|
||||
|
||||
if (instantAssign || newStartPoint == null)
|
||||
{
|
||||
RecalculateRope();
|
||||
}
|
||||
|
||||
NotifyPointsChanged();
|
||||
}
|
||||
public void SetMidPoint(Transform newMidPoint, bool instantAssign = false)
|
||||
{
|
||||
midPoint = newMidPoint;
|
||||
prevMidPointPosition = midPoint == null ? 0.5f : midPointPosition;
|
||||
|
||||
if (instantAssign || newMidPoint == null)
|
||||
{
|
||||
RecalculateRope();
|
||||
}
|
||||
NotifyPointsChanged();
|
||||
}
|
||||
|
||||
public void SetEndPoint(Transform newEndPoint, bool instantAssign = false)
|
||||
{
|
||||
endPoint = newEndPoint;
|
||||
prevEndPointPosition = endPoint == null ? Vector3.zero : endPoint.position;
|
||||
|
||||
if (instantAssign || newEndPoint == null)
|
||||
{
|
||||
RecalculateRope();
|
||||
}
|
||||
|
||||
NotifyPointsChanged();
|
||||
}
|
||||
|
||||
public void RecalculateRope()
|
||||
{
|
||||
if (!AreEndPointsValid())
|
||||
{
|
||||
lineRenderer.positionCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
currentValue = GetMidPoint();
|
||||
targetValue = currentValue;
|
||||
currentVelocity = Vector3.zero;
|
||||
SetSplinePoint();
|
||||
}
|
||||
|
||||
private void NotifyPointsChanged()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user