修改命名空间和脚本名称
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AdvancedRope.Editor
|
namespace NB.Rope.Editor
|
||||||
{
|
{
|
||||||
[InitializeOnLoad]
|
[InitializeOnLoad]
|
||||||
public class AssetRatingPrompt : EditorWindow
|
public class AssetRatingPrompt : EditorWindow
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ using UnityEditor.UIElements;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
namespace AdvancedRope.Editor
|
namespace NB.Rope.Editor
|
||||||
{
|
{
|
||||||
[CustomEditor(typeof(VerletRopeGenerator))]
|
[CustomEditor(typeof(VerletRope))]
|
||||||
public class VerletRopeGeneratorEditor : UnityEditor.Editor
|
public class VerletRopeGeneratorEditor : UnityEditor.Editor
|
||||||
{
|
{
|
||||||
public override VisualElement CreateInspectorGUI()
|
public override VisualElement CreateInspectorGUI()
|
||||||
@@ -32,7 +32,7 @@ namespace AdvancedRope.Editor
|
|||||||
{
|
{
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
var rope = (VerletRopeGenerator)target;
|
var rope = (VerletRope)target;
|
||||||
var isDirty = false;
|
var isDirty = false;
|
||||||
|
|
||||||
if (rope.initialPinPoints != null)
|
if (rope.initialPinPoints != null)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
namespace AdvancedRope
|
namespace NB.Rope
|
||||||
{
|
{
|
||||||
public interface IRopeRenderer
|
public interface IRopeRenderer
|
||||||
{
|
{
|
||||||
void Bind(VerletRopeGenerator ropeGenerator);
|
void Bind(VerletRope rope);
|
||||||
void Rebuild();
|
void Rebuild();
|
||||||
void Render();
|
void Render();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AdvancedRope
|
namespace NB.Rope
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(LineRenderer))]
|
[RequireComponent(typeof(LineRenderer))]
|
||||||
public class RopeLineRenderer : MonoBehaviour, IRopeRenderer
|
public class RopeLineRenderer : MonoBehaviour, IRopeRenderer
|
||||||
@@ -9,7 +9,7 @@ namespace AdvancedRope
|
|||||||
[SerializeField] private bool syncWidthWithRenderRadius = true;
|
[SerializeField] private bool syncWidthWithRenderRadius = true;
|
||||||
[SerializeField] private float widthMultiplier = 2f;
|
[SerializeField] private float widthMultiplier = 2f;
|
||||||
|
|
||||||
private VerletRopeGenerator _ropeGenerator;
|
private VerletRope _rope;
|
||||||
private LineRenderer _lineRenderer;
|
private LineRenderer _lineRenderer;
|
||||||
private Vector3[] _positions;
|
private Vector3[] _positions;
|
||||||
|
|
||||||
@@ -19,20 +19,20 @@ namespace AdvancedRope
|
|||||||
ConfigureLineRenderer();
|
ConfigureLineRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Bind(VerletRopeGenerator ropeGenerator)
|
public void Bind(VerletRope rope)
|
||||||
{
|
{
|
||||||
_ropeGenerator = ropeGenerator;
|
_rope = rope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Rebuild()
|
public void Rebuild()
|
||||||
{
|
{
|
||||||
if (_ropeGenerator == null) return;
|
if (_rope == null) return;
|
||||||
|
|
||||||
if (!_lineRenderer)
|
if (!_lineRenderer)
|
||||||
_lineRenderer = GetComponent<LineRenderer>();
|
_lineRenderer = GetComponent<LineRenderer>();
|
||||||
|
|
||||||
ConfigureLineRenderer();
|
ConfigureLineRenderer();
|
||||||
ResizePositionBuffer(_ropeGenerator.Nodes.Count);
|
ResizePositionBuffer(_rope.Nodes.Count);
|
||||||
ApplyWidth();
|
ApplyWidth();
|
||||||
SyncPositions();
|
SyncPositions();
|
||||||
_lineRenderer.enabled = true;
|
_lineRenderer.enabled = true;
|
||||||
@@ -65,9 +65,9 @@ namespace AdvancedRope
|
|||||||
|
|
||||||
private void ApplyWidth()
|
private void ApplyWidth()
|
||||||
{
|
{
|
||||||
if (!_lineRenderer || _ropeGenerator == null || !syncWidthWithRenderRadius) return;
|
if (!_lineRenderer || _rope == null || !syncWidthWithRenderRadius) return;
|
||||||
|
|
||||||
var width = Mathf.Max(0.0001f, _ropeGenerator.RenderRadius * widthMultiplier);
|
var width = Mathf.Max(0.0001f, _rope.RenderRadius * widthMultiplier);
|
||||||
_lineRenderer.startWidth = width;
|
_lineRenderer.startWidth = width;
|
||||||
_lineRenderer.endWidth = width;
|
_lineRenderer.endWidth = width;
|
||||||
}
|
}
|
||||||
@@ -85,9 +85,9 @@ namespace AdvancedRope
|
|||||||
|
|
||||||
private void SyncPositions()
|
private void SyncPositions()
|
||||||
{
|
{
|
||||||
if (_ropeGenerator == null || !_lineRenderer) return;
|
if (_rope == null || !_lineRenderer) return;
|
||||||
|
|
||||||
var nodes = _ropeGenerator.Nodes;
|
var nodes = _rope.Nodes;
|
||||||
var nodeCount = nodes.Count;
|
var nodeCount = nodes.Count;
|
||||||
if (nodeCount == 0)
|
if (nodeCount == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AdvancedRope
|
namespace NB.Rope
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
|
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
|
||||||
public class RopeMeshRenderer : MonoBehaviour, IRopeRenderer
|
public class RopeMeshRenderer : MonoBehaviour, IRopeRenderer
|
||||||
@@ -8,7 +8,7 @@ namespace AdvancedRope
|
|||||||
[SerializeField] private int radialSegments = 8;
|
[SerializeField] private int radialSegments = 8;
|
||||||
[SerializeField] private float textureTiling = 1f;
|
[SerializeField] private float textureTiling = 1f;
|
||||||
|
|
||||||
private VerletRopeGenerator _ropeGenerator;
|
private VerletRope _rope;
|
||||||
private MeshFilter _meshFilter;
|
private MeshFilter _meshFilter;
|
||||||
private Mesh _mesh;
|
private Mesh _mesh;
|
||||||
private Vector3[] _vertices;
|
private Vector3[] _vertices;
|
||||||
@@ -21,9 +21,9 @@ namespace AdvancedRope
|
|||||||
_meshFilter = GetComponent<MeshFilter>();
|
_meshFilter = GetComponent<MeshFilter>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Bind(VerletRopeGenerator ropeGenerator)
|
public void Bind(VerletRope rope)
|
||||||
{
|
{
|
||||||
_ropeGenerator = ropeGenerator;
|
_rope = rope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Rebuild()
|
public void Rebuild()
|
||||||
@@ -43,7 +43,7 @@ namespace AdvancedRope
|
|||||||
|
|
||||||
private void SetupRopeMesh()
|
private void SetupRopeMesh()
|
||||||
{
|
{
|
||||||
if (_ropeGenerator == null) return;
|
if (_rope == null) return;
|
||||||
if (!_meshFilter) _meshFilter = GetComponent<MeshFilter>();
|
if (!_meshFilter) _meshFilter = GetComponent<MeshFilter>();
|
||||||
|
|
||||||
var segmentCount = Mathf.Max(3, radialSegments);
|
var segmentCount = Mathf.Max(3, radialSegments);
|
||||||
@@ -63,8 +63,8 @@ namespace AdvancedRope
|
|||||||
|
|
||||||
_meshFilter.sharedMesh = _mesh;
|
_meshFilter.sharedMesh = _mesh;
|
||||||
|
|
||||||
_radius = _ropeGenerator.RenderRadius;
|
_radius = _rope.RenderRadius;
|
||||||
var nodes = _ropeGenerator.Nodes;
|
var nodes = _rope.Nodes;
|
||||||
var vertexCount = nodes.Count * (segmentCount + 1) + 2;
|
var vertexCount = nodes.Count * (segmentCount + 1) + 2;
|
||||||
var triCount = (nodes.Count - 1) * segmentCount * 6;
|
var triCount = (nodes.Count - 1) * segmentCount * 6;
|
||||||
var capTrisCount = (segmentCount * 3) * 2;
|
var capTrisCount = (segmentCount * 3) * 2;
|
||||||
@@ -142,13 +142,13 @@ namespace AdvancedRope
|
|||||||
|
|
||||||
private void UpdateMeshVertices()
|
private void UpdateMeshVertices()
|
||||||
{
|
{
|
||||||
if (_ropeGenerator == null || _mesh == null) return;
|
if (_rope == null || _mesh == null) return;
|
||||||
|
|
||||||
var segmentCount = Mathf.Max(3, radialSegments);
|
var segmentCount = Mathf.Max(3, radialSegments);
|
||||||
var uvTiling = Mathf.Max(0.01f, textureTiling);
|
var uvTiling = Mathf.Max(0.01f, textureTiling);
|
||||||
|
|
||||||
var verletTransform = _ropeGenerator.transform;
|
var verletTransform = _rope.transform;
|
||||||
var nodes = _ropeGenerator.Nodes;
|
var nodes = _rope.Nodes;
|
||||||
if (nodes.Count < 2) return;
|
if (nodes.Count < 2) return;
|
||||||
|
|
||||||
var lastRotation = Quaternion.identity;
|
var lastRotation = Quaternion.identity;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AdvancedRope
|
namespace NB.Rope
|
||||||
{
|
{
|
||||||
public enum RopeDisconnectType
|
public enum RopeDisconnectType
|
||||||
{
|
{
|
||||||
@@ -12,14 +12,14 @@ namespace AdvancedRope
|
|||||||
}
|
}
|
||||||
public class RopeController : MonoBehaviour
|
public class RopeController : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private VerletRopeGenerator ropePrefab;
|
[SerializeField] private VerletRope ropePrefab;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Increases the length of the rope for 1 unit
|
/// Increases the length of the rope for 1 unit
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rope"></param>
|
/// <param name="rope"></param>
|
||||||
/// <param name="maxRopeNodeCount"></param>
|
/// <param name="maxRopeNodeCount"></param>
|
||||||
public static void IncreaseRopeLength(VerletRopeGenerator rope, int maxRopeNodeCount = 50)
|
public static void IncreaseRopeLength(VerletRope rope, int maxRopeNodeCount = 50)
|
||||||
{
|
{
|
||||||
if(rope.Nodes.Count >= maxRopeNodeCount) return;
|
if(rope.Nodes.Count >= maxRopeNodeCount) return;
|
||||||
rope.IncreaseLength();
|
rope.IncreaseLength();
|
||||||
@@ -30,7 +30,7 @@ namespace AdvancedRope
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rope"></param>
|
/// <param name="rope"></param>
|
||||||
/// <param name="lengthDelta">Length to add in world units</param>
|
/// <param name="lengthDelta">Length to add in world units</param>
|
||||||
public static void IncreaseRopeLength(VerletRopeGenerator rope, float lengthDelta)
|
public static void IncreaseRopeLength(VerletRope rope, float lengthDelta)
|
||||||
{
|
{
|
||||||
if (!rope || lengthDelta <= 0f) return;
|
if (!rope || lengthDelta <= 0f) return;
|
||||||
rope.IncreaseLength(lengthDelta);
|
rope.IncreaseLength(lengthDelta);
|
||||||
@@ -41,7 +41,7 @@ namespace AdvancedRope
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rope"></param>
|
/// <param name="rope"></param>
|
||||||
/// <param name="minRopeNodeCount"></param>
|
/// <param name="minRopeNodeCount"></param>
|
||||||
public static void DecreaseRopeLength(VerletRopeGenerator rope, int minRopeNodeCount = 2)
|
public static void DecreaseRopeLength(VerletRope rope, int minRopeNodeCount = 2)
|
||||||
{
|
{
|
||||||
if(rope.Nodes.Count <= minRopeNodeCount) return;
|
if(rope.Nodes.Count <= minRopeNodeCount) return;
|
||||||
rope.DecreaseLength();
|
rope.DecreaseLength();
|
||||||
@@ -52,7 +52,7 @@ namespace AdvancedRope
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rope"></param>
|
/// <param name="rope"></param>
|
||||||
/// <param name="lengthDelta">Length to remove in world units</param>
|
/// <param name="lengthDelta">Length to remove in world units</param>
|
||||||
public static void DecreaseRopeLength(VerletRopeGenerator rope, float lengthDelta)
|
public static void DecreaseRopeLength(VerletRope rope, float lengthDelta)
|
||||||
{
|
{
|
||||||
if (!rope || lengthDelta <= 0f) return;
|
if (!rope || lengthDelta <= 0f) return;
|
||||||
rope.DecreaseLength(lengthDelta);
|
rope.DecreaseLength(lengthDelta);
|
||||||
@@ -67,7 +67,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="startLocalPos"></param>
|
/// <param name="startLocalPos"></param>
|
||||||
/// <param name="connectionOffset"></param>
|
/// <param name="connectionOffset"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public VerletRopeGenerator ConnectRope(Transform startTransform, VerletRopeGenerator endRope,
|
public VerletRope ConnectRope(Transform startTransform, VerletRope endRope,
|
||||||
int targetNodeIndex, Vector3 startLocalPos = default, Vector3 connectionOffset = default)
|
int targetNodeIndex, Vector3 startLocalPos = default, Vector3 connectionOffset = default)
|
||||||
{
|
{
|
||||||
var rope = Instantiate(ropePrefab);
|
var rope = Instantiate(ropePrefab);
|
||||||
@@ -87,7 +87,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="startLocalPos"></param>
|
/// <param name="startLocalPos"></param>
|
||||||
/// <param name="endLocalPos"></param>
|
/// <param name="endLocalPos"></param>
|
||||||
/// <returns> Connected Rope</returns>
|
/// <returns> Connected Rope</returns>
|
||||||
public VerletRopeGenerator ConnectRope(Transform startTransform, Transform endTransform, Vector3 startLocalPos = default, Vector3 endLocalPos = default)
|
public VerletRope ConnectRope(Transform startTransform, Transform endTransform, Vector3 startLocalPos = default, Vector3 endLocalPos = default)
|
||||||
{
|
{
|
||||||
var rope = Instantiate(ropePrefab);
|
var rope = Instantiate(ropePrefab);
|
||||||
rope.ropeStartPoint = startTransform.TransformPoint(startLocalPos);
|
rope.ropeStartPoint = startTransform.TransformPoint(startLocalPos);
|
||||||
@@ -106,7 +106,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="startLocalPos"></param>
|
/// <param name="startLocalPos"></param>
|
||||||
/// <param name="endLocalPos"></param>
|
/// <param name="endLocalPos"></param>
|
||||||
/// <returns> Connected Rope </returns>
|
/// <returns> Connected Rope </returns>
|
||||||
public VerletRopeGenerator ConnectRope(Transform startTransform, Rigidbody endRigidbody, Vector3 startLocalPos = default, Vector3 endLocalPos = default)
|
public VerletRope ConnectRope(Transform startTransform, Rigidbody endRigidbody, Vector3 startLocalPos = default, Vector3 endLocalPos = default)
|
||||||
{
|
{
|
||||||
var rope = Instantiate(ropePrefab);
|
var rope = Instantiate(ropePrefab);
|
||||||
//rope.InitializeRope();
|
//rope.InitializeRope();
|
||||||
@@ -126,7 +126,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="startLocalPos"></param>
|
/// <param name="startLocalPos"></param>
|
||||||
/// <param name="endLocalPos"></param>
|
/// <param name="endLocalPos"></param>
|
||||||
/// <returns> Connected Rope </returns>
|
/// <returns> Connected Rope </returns>
|
||||||
public VerletRopeGenerator ConnectRope(Rigidbody startRigidbody, Rigidbody endRigidbody, Vector3 startLocalPos = default, Vector3 endLocalPos = default)
|
public VerletRope ConnectRope(Rigidbody startRigidbody, Rigidbody endRigidbody, Vector3 startLocalPos = default, Vector3 endLocalPos = default)
|
||||||
{
|
{
|
||||||
var rope = Instantiate(ropePrefab);
|
var rope = Instantiate(ropePrefab);
|
||||||
//rope.InitializeRope();
|
//rope.InitializeRope();
|
||||||
@@ -145,7 +145,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="targetRope"></param>
|
/// <param name="targetRope"></param>
|
||||||
/// <param name="targetNodeIndex"></param>
|
/// <param name="targetNodeIndex"></param>
|
||||||
/// <param name="connectionOffset"></param>
|
/// <param name="connectionOffset"></param>
|
||||||
public static void ConnectRopeStart(VerletRopeGenerator rope, VerletRopeGenerator targetRope, int targetNodeIndex, Vector3 connectionOffset = default)
|
public static void ConnectRopeStart(VerletRope rope, VerletRope targetRope, int targetNodeIndex, Vector3 connectionOffset = default)
|
||||||
{
|
{
|
||||||
if(!rope || !targetRope) return;
|
if(!rope || !targetRope) return;
|
||||||
rope.UnpinNode(0);
|
rope.UnpinNode(0);
|
||||||
@@ -158,7 +158,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="rope"></param>
|
/// <param name="rope"></param>
|
||||||
/// <param name="startTransform"></param>
|
/// <param name="startTransform"></param>
|
||||||
/// <param name="localPos"></param>
|
/// <param name="localPos"></param>
|
||||||
public static void ConnectRopeStart(VerletRopeGenerator rope, Transform startTransform, Vector3 localPos = default)
|
public static void ConnectRopeStart(VerletRope rope, Transform startTransform, Vector3 localPos = default)
|
||||||
{
|
{
|
||||||
if (!rope) return;
|
if (!rope) return;
|
||||||
rope.PinNode(0, startTransform, localPos);
|
rope.PinNode(0, startTransform, localPos);
|
||||||
@@ -170,7 +170,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="rope"></param>
|
/// <param name="rope"></param>
|
||||||
/// <param name="startRigidbody"></param>
|
/// <param name="startRigidbody"></param>
|
||||||
/// <param name="localPos"></param>
|
/// <param name="localPos"></param>
|
||||||
public static void ConnectRopeStart(VerletRopeGenerator rope, Rigidbody startRigidbody, Vector3 localPos = default)
|
public static void ConnectRopeStart(VerletRope rope, Rigidbody startRigidbody, Vector3 localPos = default)
|
||||||
{
|
{
|
||||||
if (!rope) return;
|
if (!rope) return;
|
||||||
rope.ConnectStartRigidbody(startRigidbody, localPos, 0);
|
rope.ConnectStartRigidbody(startRigidbody, localPos, 0);
|
||||||
@@ -182,7 +182,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="rope"></param>
|
/// <param name="rope"></param>
|
||||||
/// <param name="startRigidbody"></param>
|
/// <param name="startRigidbody"></param>
|
||||||
/// <param name="localPos"></param>
|
/// <param name="localPos"></param>
|
||||||
public static void ConnectRopeStart(VerletRopeGenerator rope, Rigidbody startRigidbody, Vector3 localPos = default, float timeToReach = 0.5f)
|
public static void ConnectRopeStart(VerletRope rope, Rigidbody startRigidbody, Vector3 localPos = default, float timeToReach = 0.5f)
|
||||||
{
|
{
|
||||||
if (!rope) return;
|
if (!rope) return;
|
||||||
rope.ConnectStartRigidbody(startRigidbody, localPos, timeToReach);
|
rope.ConnectStartRigidbody(startRigidbody, localPos, timeToReach);
|
||||||
@@ -195,7 +195,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="targetRope"></param>
|
/// <param name="targetRope"></param>
|
||||||
/// <param name="targetNodeIndex"></param>
|
/// <param name="targetNodeIndex"></param>
|
||||||
/// <param name="connectionOffset"></param>
|
/// <param name="connectionOffset"></param>
|
||||||
public static void ConnectRopeEnd(VerletRopeGenerator rope, VerletRopeGenerator targetRope, int targetNodeIndex, Vector3 connectionOffset = default)
|
public static void ConnectRopeEnd(VerletRope rope, VerletRope targetRope, int targetNodeIndex, Vector3 connectionOffset = default)
|
||||||
{
|
{
|
||||||
if(!rope || !targetRope) return;
|
if(!rope || !targetRope) return;
|
||||||
rope.UnpinNode(-1);
|
rope.UnpinNode(-1);
|
||||||
@@ -208,7 +208,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="rope"></param>
|
/// <param name="rope"></param>
|
||||||
/// <param name="endTransform"></param>
|
/// <param name="endTransform"></param>
|
||||||
/// <param name="localPos"></param>
|
/// <param name="localPos"></param>
|
||||||
public static void ConnectRopeEnd(VerletRopeGenerator rope, Transform endTransform, Vector3 localPos = default)
|
public static void ConnectRopeEnd(VerletRope rope, Transform endTransform, Vector3 localPos = default)
|
||||||
{
|
{
|
||||||
if (!rope) return;
|
if (!rope) return;
|
||||||
rope.PinNode(-1, endTransform, localPos);
|
rope.PinNode(-1, endTransform, localPos);
|
||||||
@@ -220,7 +220,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="rope"></param>
|
/// <param name="rope"></param>
|
||||||
/// <param name="endRigidbody"></param>
|
/// <param name="endRigidbody"></param>
|
||||||
/// <param name="localPos"></param>
|
/// <param name="localPos"></param>
|
||||||
public static void ConnectRopeEnd(VerletRopeGenerator rope, Rigidbody endRigidbody, Vector3 localPos = default)
|
public static void ConnectRopeEnd(VerletRope rope, Rigidbody endRigidbody, Vector3 localPos = default)
|
||||||
{
|
{
|
||||||
if (!rope) return;
|
if (!rope) return;
|
||||||
rope.ConnectEndRigidbody(endRigidbody, localPos);
|
rope.ConnectEndRigidbody(endRigidbody, localPos);
|
||||||
@@ -234,7 +234,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="disconnectType"> Start, End, Both, Destroy</param>
|
/// <param name="disconnectType"> Start, End, Both, Destroy</param>
|
||||||
/// <returns> Disconnected Rope: null if rope destroyed</returns>
|
/// <returns> Disconnected Rope: null if rope destroyed</returns>
|
||||||
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||||
public VerletRopeGenerator DisconnectRope(VerletRopeGenerator rope, RopeDisconnectType disconnectType)
|
public VerletRope DisconnectRope(VerletRope rope, RopeDisconnectType disconnectType)
|
||||||
{
|
{
|
||||||
switch (disconnectType)
|
switch (disconnectType)
|
||||||
{
|
{
|
||||||
@@ -258,14 +258,14 @@ namespace AdvancedRope
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DisconnectRopeStart(VerletRopeGenerator rope)
|
private static void DisconnectRopeStart(VerletRope rope)
|
||||||
{
|
{
|
||||||
rope.DisconnectStartRigidbody();
|
rope.DisconnectStartRigidbody();
|
||||||
rope.UnpinNode(0);
|
rope.UnpinNode(0);
|
||||||
rope.DisconnectFromOtherRope(0);
|
rope.DisconnectFromOtherRope(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DisconnectRopeEnd(VerletRopeGenerator rope)
|
private static void DisconnectRopeEnd(VerletRope rope)
|
||||||
{
|
{
|
||||||
rope.DisconnectEndRigidbody();
|
rope.DisconnectEndRigidbody();
|
||||||
rope.UnpinNode(-1);
|
rope.UnpinNode(-1);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AdvancedRope.TEST
|
namespace NB.Rope.TEST
|
||||||
{
|
{
|
||||||
public class FurGenerator : MonoBehaviour
|
public class FurGenerator : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private Transform capsuleTransform;
|
[SerializeField] private Transform capsuleTransform;
|
||||||
[SerializeField] private VerletRopeGenerator furPrefab;
|
[SerializeField] private VerletRope furPrefab;
|
||||||
[SerializeField] private float furLength = 0.5f;
|
[SerializeField] private float furLength = 0.5f;
|
||||||
[SerializeField] private float radius = 0.5f;
|
[SerializeField] private float radius = 0.5f;
|
||||||
[SerializeField] private float height = 2f;
|
[SerializeField] private float height = 2f;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace AdvancedRope.TEST
|
namespace NB.Rope.TEST
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(RopeController))]
|
[RequireComponent(typeof(RopeController))]
|
||||||
public class RopeConnectorTest : MonoBehaviour
|
public class RopeConnectorTest : MonoBehaviour
|
||||||
@@ -16,7 +16,7 @@ namespace AdvancedRope.TEST
|
|||||||
[SerializeField] private int minRopeNodeCount = 4;
|
[SerializeField] private int minRopeNodeCount = 4;
|
||||||
|
|
||||||
private RopeController _ropeController;
|
private RopeController _ropeController;
|
||||||
private VerletRopeGenerator _activeRope = null;
|
private VerletRope _activeRope = null;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AdvancedRope.TEST
|
namespace NB.Rope.TEST
|
||||||
{
|
{
|
||||||
public class RopeLengthTest : MonoBehaviour
|
public class RopeLengthTest : MonoBehaviour
|
||||||
{
|
{
|
||||||
[Header("Input")] [SerializeField] private KeyCode extendKey = KeyCode.UpArrow;
|
[Header("Input")] [SerializeField] private KeyCode extendKey = KeyCode.UpArrow;
|
||||||
[SerializeField] private KeyCode retractKey = KeyCode.DownArrow;
|
[SerializeField] private KeyCode retractKey = KeyCode.DownArrow;
|
||||||
[SerializeField] private VerletRopeGenerator rope = null;
|
[SerializeField] private VerletRope rope = null;
|
||||||
|
|
||||||
[Header("Length Change")]
|
[Header("Length Change")]
|
||||||
[Min(0.001f)] [SerializeField] private float clickLengthDelta = 0.1f;
|
[Min(0.001f)] [SerializeField] private float clickLengthDelta = 0.1f;
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AdvancedRope
|
namespace NB.Rope
|
||||||
{
|
{
|
||||||
public static class VerletPhysics
|
public static class VerletPhysics
|
||||||
{
|
{
|
||||||
private static List<VerletRopeGenerator> ropeGenerators = new List<VerletRopeGenerator>();
|
private static List<VerletRope> ropeGenerators = new List<VerletRope>();
|
||||||
|
|
||||||
public static void RegisterRopeGenerator(VerletRopeGenerator generator)
|
public static void RegisterRopeGenerator(VerletRope generator)
|
||||||
{
|
{
|
||||||
if (!ropeGenerators.Contains(generator))
|
if (!ropeGenerators.Contains(generator))
|
||||||
{
|
{
|
||||||
ropeGenerators.Add(generator);
|
ropeGenerators.Add(generator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void UnregisterRopeGenerator(VerletRopeGenerator generator)
|
public static void UnregisterRopeGenerator(VerletRope generator)
|
||||||
{
|
{
|
||||||
if (ropeGenerators.Contains(generator))
|
if (ropeGenerators.Contains(generator))
|
||||||
{
|
{
|
||||||
@@ -51,14 +51,14 @@ namespace AdvancedRope
|
|||||||
hitInfo = default;
|
hitInfo = default;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public static bool Raycast(Ray ray, out RopeHitInfo hitInfo, float maxDistance, VerletRopeGenerator excludeGenerator)
|
public static bool Raycast(Ray ray, out RopeHitInfo hitInfo, float maxDistance, VerletRope exclude)
|
||||||
{
|
{
|
||||||
var closestHitDistance = float.MaxValue;
|
var closestHitDistance = float.MaxValue;
|
||||||
var isHit = false;
|
var isHit = false;
|
||||||
RopeHitInfo tempHitInfo = default;
|
RopeHitInfo tempHitInfo = default;
|
||||||
foreach (var generator in ropeGenerators)
|
foreach (var generator in ropeGenerators)
|
||||||
{
|
{
|
||||||
if (generator == excludeGenerator) continue;
|
if (generator == exclude) continue;
|
||||||
if (generator.Raycast(ray, out var hit, maxDistance))
|
if (generator.Raycast(ray, out var hit, maxDistance))
|
||||||
{
|
{
|
||||||
if (hit.Distance >= closestHitDistance) continue;
|
if (hit.Distance >= closestHitDistance) continue;
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
namespace AdvancedRope
|
namespace NB.Rope
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 用于生成并模拟基于 Verlet 积分绳索的基类。
|
/// 用于生成并模拟基于 Verlet 积分绳索的基类。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class VerletRopeGenerator : MonoBehaviour
|
public class VerletRope : MonoBehaviour
|
||||||
{
|
{
|
||||||
#region --- 数据结构 ---
|
#region --- 数据结构 ---
|
||||||
|
|
||||||
@@ -897,7 +897,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="targetRope"></param>
|
/// <param name="targetRope"></param>
|
||||||
/// <param name="targetNodeIndex"></param>
|
/// <param name="targetNodeIndex"></param>
|
||||||
/// <param name="connectionOffset"></param>
|
/// <param name="connectionOffset"></param>
|
||||||
public void ConnectEndToOtherRope(VerletRopeGenerator targetRope, int targetNodeIndex,
|
public void ConnectEndToOtherRope(VerletRope targetRope, int targetNodeIndex,
|
||||||
Vector3 connectionOffset = default)
|
Vector3 connectionOffset = default)
|
||||||
{
|
{
|
||||||
ConnectToOtherRope(-1, targetRope, targetNodeIndex, connectionOffset);
|
ConnectToOtherRope(-1, targetRope, targetNodeIndex, connectionOffset);
|
||||||
@@ -909,7 +909,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="targetRope"></param>
|
/// <param name="targetRope"></param>
|
||||||
/// <param name="targetNodeIndex"></param>
|
/// <param name="targetNodeIndex"></param>
|
||||||
/// <param name="connectionOffset"></param>
|
/// <param name="connectionOffset"></param>
|
||||||
public void ConnectStartToOtherRope(VerletRopeGenerator targetRope, int targetNodeIndex,
|
public void ConnectStartToOtherRope(VerletRope targetRope, int targetNodeIndex,
|
||||||
Vector3 connectionOffset = default)
|
Vector3 connectionOffset = default)
|
||||||
{
|
{
|
||||||
ConnectToOtherRope(0, targetRope, targetNodeIndex, connectionOffset);
|
ConnectToOtherRope(0, targetRope, targetNodeIndex, connectionOffset);
|
||||||
@@ -921,7 +921,7 @@ namespace AdvancedRope
|
|||||||
/// <param name="myNodeIndex">0 表示起点,-1 表示末尾节点</param>
|
/// <param name="myNodeIndex">0 表示起点,-1 表示末尾节点</param>
|
||||||
/// <param name="targetRope"></param>
|
/// <param name="targetRope"></param>
|
||||||
/// <param name="targetNodeIndex">0 表示起点,-1 表示末尾节点</param>
|
/// <param name="targetNodeIndex">0 表示起点,-1 表示末尾节点</param>
|
||||||
public void ConnectToOtherRope(int myNodeIndex, VerletRopeGenerator targetRope, int targetNodeIndex,
|
public void ConnectToOtherRope(int myNodeIndex, VerletRope targetRope, int targetNodeIndex,
|
||||||
Vector3 connectionOffset = default)
|
Vector3 connectionOffset = default)
|
||||||
{
|
{
|
||||||
if (myNodeIndex < 0)
|
if (myNodeIndex < 0)
|
||||||
@@ -1142,7 +1142,7 @@ namespace AdvancedRope
|
|||||||
public struct RopeHitInfo
|
public struct RopeHitInfo
|
||||||
{
|
{
|
||||||
public bool DidHit;
|
public bool DidHit;
|
||||||
public VerletRopeGenerator Rope;
|
public VerletRope Rope;
|
||||||
public Vector3 Point;
|
public Vector3 Point;
|
||||||
public int NodeIndex;
|
public int NodeIndex;
|
||||||
public Vector3 NodePoint;
|
public Vector3 NodePoint;
|
||||||
Reference in New Issue
Block a user