diff --git a/Assets/Controller.cs b/Assets/Controller.cs index 3ac3ca1..553252d 100644 --- a/Assets/Controller.cs +++ b/Assets/Controller.cs @@ -3,10 +3,7 @@ using TMPro; using UnityEngine; public class Controller : MonoBehaviour { - - [Tooltip("List of cables in the scene. Each cable consists of segments describing the link and last/first can optionally be fixed to points.")] - [SerializeField] - public List cables = new(); + private List cableStartingPoints = new(); //Initialize void Awake() { @@ -40,9 +37,11 @@ public class Controller : MonoBehaviour { //collisions and physics Rigidbody2D rb = go.GetOrAddComponent(); // mass is based on area, if not provided - rb.useAutoMass = rp.mass < 0; - if(rp.mass >= 0) { - rb.mass = rp.mass; + if (rp.mass == null) { + rb.useAutoMass = rp.mass == null; + } + else { + rb.mass = rp.mass.Value; } rb.angularDrag = 1; rb.drag = 1; @@ -51,7 +50,9 @@ public class Controller : MonoBehaviour { } go.AddComponent(); - + + //build list of cable starting objects + cableStartingPoints.Add(rp); Debug.Log("Initialized roller: " + go.name); } } @@ -72,6 +73,9 @@ public class Controller : MonoBehaviour { dist.autoConfigureDistance = false; rp.distanceJoint2D = dist; + //remove linked to objects, so only starting points remain + cableStartingPoints.Remove(rp.linkTo); + //set fixed points only once if (rp.useFixedAttachmentPoint) { dist.anchor = rp.attachmentPoint; @@ -122,9 +126,7 @@ public class Controller : MonoBehaviour { } } - Debug.Log("Initialized "+cables.Count+" cables"); - - /* Define cables directly instead + Debug.Log("Initialized "+cableStartingPoints.Count+" cables"); var cableNum = 0; //find and report loops of cables foreach (var cable in cableStartingPoints) { @@ -137,7 +139,7 @@ public class Controller : MonoBehaviour { } visitedSegments.Add(segment); } - }*/ + } } @@ -154,7 +156,7 @@ public class Controller : MonoBehaviour { } if (waitedFrames++ > -1) { - CableJointsAlgorithm.TimeStep(cables); + CableJointsAlgorithm.TimeStep(cableStartingPoints); waitedFrames = 0; } } diff --git a/Assets/Model.cs b/Assets/Model.cs deleted file mode 100644 index 076c3f9..0000000 --- a/Assets/Model.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using JetBrains.Annotations; -using UnityEngine; - -[Serializable] -public class Cable { - [SerializeField] - public List segments; -} - -[Serializable] -public class CableSegment { - [SerializeField] - public GameObject go; - //keep references to all of these, to reduce inefficient getComponent calls - protected RollerProperties rp = null; - protected RollerProperties linkToGO = null; - protected RollerProperties linkToRP = null; - protected DistanceJoint2D dist = null; - - [SerializeField] public bool useFixedAttachmentPoint = false; - - [SerializeField] public Vector2 attachmentPoint = new Vector2(0,0); -} \ No newline at end of file diff --git a/Assets/Model.cs.meta b/Assets/Model.cs.meta deleted file mode 100644 index 13e30de..0000000 --- a/Assets/Model.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 35789436d28644f99ea0a7f2230944a1 -timeCreated: 1701891888 \ No newline at end of file diff --git a/Assets/RollerProperties.cs b/Assets/RollerProperties.cs index d5aec52..47a00df 100644 --- a/Assets/RollerProperties.cs +++ b/Assets/RollerProperties.cs @@ -1,27 +1,32 @@ +using System.Collections.Generic; using TMPro; +using Unity.VisualScripting; using UnityEngine; using UnityEngine.Serialization; [System.Serializable] public class RollerProperties : MonoBehaviour { //settings - [Tooltip("rotation direction, used to determine attachment sides for the cables")] + /// rotation direction, used to determine attachment sides for the cables [SerializeField] public bool clockwise = false; - [Tooltip("Type of movement of the object. Powered behaves like a wheel, which can be toggled with \"t\".")] + [SerializeField] public RollerProperties linkTo = null; + [SerializeField] public List listTest; + [SerializeField] public RollerProperties[] arrayTest; [SerializeField] public RotationType movement = RotationType.Fixed; - [Tooltip("Mass of the object. Use -1 to automatically calculate based on area.")] - [SerializeField] public float mass = -1; + [FormerlySerializedAs("fixedAttachmentPoint")] [SerializeField] public bool useFixedAttachmentPoint = false; + [SerializeField] public Vector2 attachmentPoint = new Vector2(0, 0); + [SerializeField] public float? mass = null; //references protected internal GameObject text; protected internal DistanceJoint2D distanceJoint2D = null; + protected internal GameObject linkToGameObject => linkTo.gameObject; //simulation properties protected internal float actualDistance; public (float?, float?) updateDistanceJoints() { Vector2? left = null, right = null; - if (linkTo != null) { if (useFixedAttachmentPoint && !linkTo.useFixedAttachmentPoint) { //left = attachmentPoint; diff --git a/Assets/Scenes/MultipleCables.unity b/Assets/Scenes/MultipleCables.unity index e8943fb..6ea01ef 100644 --- a/Assets/Scenes/MultipleCables.unity +++ b/Assets/Scenes/MultipleCables.unity @@ -393,20 +393,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d406720d26e7d1e4ba8afd140d67de7e, type: 3} m_Name: m_EditorClassIdentifier: - cables: - - firstRoller: {fileID: 0} - segments: - - go: {fileID: 0} - fixedAttachmentPoint: 0 - attachmentPoint7: {x: 0, y: 0} - - go: {fileID: 0} - fixedAttachmentPoint: 0 - attachmentPoint7: {x: 0, y: 0} - - go: {fileID: 0} - fixedAttachmentPoint: 0 - attachmentPoint7: {x: 0, y: 0} - cabletes: - - 0 --- !u!1 &1306628726 GameObject: m_ObjectHideFlags: 0 diff --git a/Packages/manifest.json b/Packages/manifest.json index 482ad81..047e5e3 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -3,7 +3,7 @@ "com.csutil.cscore": "https://github.com/cs-util-com/cscore.git?path=CsCore/PlainNetClassLib/src/Plugins", "com.unity.collab-proxy": "2.2.0", "com.unity.feature.2d": "2.0.0", - "com.unity.ide.rider": "3.0.27", + "com.unity.ide.rider": "3.0.26", "com.unity.test-framework": "1.3.9", "com.unity.textmeshpro": "3.0.6", "com.unity.timeline": "1.8.2", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 44f94f9..18c0132 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -151,7 +151,7 @@ } }, "com.unity.ide.rider": { - "version": "3.0.27", + "version": "3.0.26", "depth": 0, "source": "registry", "dependencies": {