Revert "partial restructuring towards allowing loops"

This reverts commit 20d2a9e6c3.
This commit is contained in:
Felix Klenner 2024-01-19 02:40:58 +01:00
parent 20d2a9e6c3
commit 272472eeac
7 changed files with 27 additions and 62 deletions

View file

@ -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<Cable> cables = new();
private List<RollerProperties> cableStartingPoints = new();
//Initialize
void Awake() {
@ -40,9 +37,11 @@ public class Controller : MonoBehaviour {
//collisions and physics
Rigidbody2D rb = go.GetOrAddComponent<Rigidbody2D>();
// 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<PolygonCollider2D>();
//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;
}
}

View file

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;
[Serializable]
public class Cable {
[SerializeField]
public List<CableSegment> 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);
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 35789436d28644f99ea0a7f2230944a1
timeCreated: 1701891888

View file

@ -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<RollerProperties> 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;

View file

@ -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

View file

@ -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",

View file

@ -151,7 +151,7 @@
}
},
"com.unity.ide.rider": {
"version": "3.0.27",
"version": "3.0.26",
"depth": 0,
"source": "registry",
"dependencies": {