Revert "partial restructuring towards allowing loops"
This reverts commit 20d2a9e6c3
.
This commit is contained in:
parent
20d2a9e6c3
commit
272472eeac
7 changed files with 27 additions and 62 deletions
|
@ -3,10 +3,7 @@ using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Controller : MonoBehaviour {
|
public class Controller : MonoBehaviour {
|
||||||
|
private List<RollerProperties> cableStartingPoints = new();
|
||||||
[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();
|
|
||||||
|
|
||||||
//Initialize
|
//Initialize
|
||||||
void Awake() {
|
void Awake() {
|
||||||
|
@ -40,9 +37,11 @@ public class Controller : MonoBehaviour {
|
||||||
//collisions and physics
|
//collisions and physics
|
||||||
Rigidbody2D rb = go.GetOrAddComponent<Rigidbody2D>();
|
Rigidbody2D rb = go.GetOrAddComponent<Rigidbody2D>();
|
||||||
// mass is based on area, if not provided
|
// mass is based on area, if not provided
|
||||||
rb.useAutoMass = rp.mass < 0;
|
if (rp.mass == null) {
|
||||||
if(rp.mass >= 0) {
|
rb.useAutoMass = rp.mass == null;
|
||||||
rb.mass = rp.mass;
|
}
|
||||||
|
else {
|
||||||
|
rb.mass = rp.mass.Value;
|
||||||
}
|
}
|
||||||
rb.angularDrag = 1;
|
rb.angularDrag = 1;
|
||||||
rb.drag = 1;
|
rb.drag = 1;
|
||||||
|
@ -52,6 +51,8 @@ public class Controller : MonoBehaviour {
|
||||||
|
|
||||||
go.AddComponent<PolygonCollider2D>();
|
go.AddComponent<PolygonCollider2D>();
|
||||||
|
|
||||||
|
//build list of cable starting objects
|
||||||
|
cableStartingPoints.Add(rp);
|
||||||
Debug.Log("Initialized roller: " + go.name);
|
Debug.Log("Initialized roller: " + go.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,6 +73,9 @@ public class Controller : MonoBehaviour {
|
||||||
dist.autoConfigureDistance = false;
|
dist.autoConfigureDistance = false;
|
||||||
rp.distanceJoint2D = dist;
|
rp.distanceJoint2D = dist;
|
||||||
|
|
||||||
|
//remove linked to objects, so only starting points remain
|
||||||
|
cableStartingPoints.Remove(rp.linkTo);
|
||||||
|
|
||||||
//set fixed points only once
|
//set fixed points only once
|
||||||
if (rp.useFixedAttachmentPoint) {
|
if (rp.useFixedAttachmentPoint) {
|
||||||
dist.anchor = rp.attachmentPoint;
|
dist.anchor = rp.attachmentPoint;
|
||||||
|
@ -122,9 +126,7 @@ public class Controller : MonoBehaviour {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log("Initialized "+cables.Count+" cables");
|
Debug.Log("Initialized "+cableStartingPoints.Count+" cables");
|
||||||
|
|
||||||
/* Define cables directly instead
|
|
||||||
var cableNum = 0;
|
var cableNum = 0;
|
||||||
//find and report loops of cables
|
//find and report loops of cables
|
||||||
foreach (var cable in cableStartingPoints) {
|
foreach (var cable in cableStartingPoints) {
|
||||||
|
@ -137,7 +139,7 @@ public class Controller : MonoBehaviour {
|
||||||
}
|
}
|
||||||
visitedSegments.Add(segment);
|
visitedSegments.Add(segment);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +156,7 @@ public class Controller : MonoBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waitedFrames++ > -1) {
|
if (waitedFrames++ > -1) {
|
||||||
CableJointsAlgorithm.TimeStep(cables);
|
CableJointsAlgorithm.TimeStep(cableStartingPoints);
|
||||||
waitedFrames = 0;
|
waitedFrames = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 35789436d28644f99ea0a7f2230944a1
|
|
||||||
timeCreated: 1701891888
|
|
|
@ -1,27 +1,32 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
|
using Unity.VisualScripting;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class RollerProperties : MonoBehaviour {
|
public class RollerProperties : MonoBehaviour {
|
||||||
//settings
|
//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;
|
[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;
|
[SerializeField] public RotationType movement = RotationType.Fixed;
|
||||||
[Tooltip("Mass of the object. Use -1 to automatically calculate based on area.")]
|
[FormerlySerializedAs("fixedAttachmentPoint")] [SerializeField] public bool useFixedAttachmentPoint = false;
|
||||||
[SerializeField] public float mass = -1;
|
[SerializeField] public Vector2 attachmentPoint = new Vector2(0, 0);
|
||||||
|
[SerializeField] public float? mass = null;
|
||||||
|
|
||||||
//references
|
//references
|
||||||
protected internal GameObject text;
|
protected internal GameObject text;
|
||||||
protected internal DistanceJoint2D distanceJoint2D = null;
|
protected internal DistanceJoint2D distanceJoint2D = null;
|
||||||
|
protected internal GameObject linkToGameObject => linkTo.gameObject;
|
||||||
|
|
||||||
//simulation properties
|
//simulation properties
|
||||||
protected internal float actualDistance;
|
protected internal float actualDistance;
|
||||||
|
|
||||||
public (float?, float?) updateDistanceJoints() {
|
public (float?, float?) updateDistanceJoints() {
|
||||||
Vector2? left = null, right = null;
|
Vector2? left = null, right = null;
|
||||||
|
|
||||||
if (linkTo != null) {
|
if (linkTo != null) {
|
||||||
if (useFixedAttachmentPoint && !linkTo.useFixedAttachmentPoint) {
|
if (useFixedAttachmentPoint && !linkTo.useFixedAttachmentPoint) {
|
||||||
//left = attachmentPoint;
|
//left = attachmentPoint;
|
||||||
|
|
|
@ -393,20 +393,6 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: d406720d26e7d1e4ba8afd140d67de7e, type: 3}
|
m_Script: {fileID: 11500000, guid: d406720d26e7d1e4ba8afd140d67de7e, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
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
|
--- !u!1 &1306628726
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"com.csutil.cscore": "https://github.com/cs-util-com/cscore.git?path=CsCore/PlainNetClassLib/src/Plugins",
|
"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.collab-proxy": "2.2.0",
|
||||||
"com.unity.feature.2d": "2.0.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.test-framework": "1.3.9",
|
||||||
"com.unity.textmeshpro": "3.0.6",
|
"com.unity.textmeshpro": "3.0.6",
|
||||||
"com.unity.timeline": "1.8.2",
|
"com.unity.timeline": "1.8.2",
|
||||||
|
|
|
@ -151,7 +151,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"com.unity.ide.rider": {
|
"com.unity.ide.rider": {
|
||||||
"version": "3.0.27",
|
"version": "3.0.26",
|
||||||
"depth": 0,
|
"depth": 0,
|
||||||
"source": "registry",
|
"source": "registry",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
Loading…
Reference in a new issue