rope rebuild giving errors

This commit is contained in:
BOTAlex 2024-02-15 01:32:08 +01:00
parent 5fb3197aba
commit 32f5f27201
3 changed files with 29 additions and 25 deletions

View File

@ -3734,20 +3734,12 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: m_AddedGameObjects: []
- targetCorrespondingSourceObject: {fileID: 3032075919872812610, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3}
insertIndex: -1
addedObject: {fileID: 4910321061857220296}
m_AddedComponents: m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 809911508645467208, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} - targetCorrespondingSourceObject: {fileID: 809911508645467208, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 1683288374126251323} addedObject: {fileID: 1683288374126251323}
m_SourcePrefab: {fileID: 100100000, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} m_SourcePrefab: {fileID: 100100000, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3}
--- !u!4 &1683288374126251322 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 3032075919872812610, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3}
m_PrefabInstance: {fileID: 1683288374126251321}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1683288374126251323 --- !u!114 &1683288374126251323
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3891,7 +3883,7 @@ PrefabInstance:
serializedVersion: 2 serializedVersion: 2
m_Modification: m_Modification:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 1683288374126251322} m_TransformParent: {fileID: 0}
m_Modifications: m_Modifications:
- target: {fileID: 144529238244638330, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3} - target: {fileID: 144529238244638330, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
@ -3950,11 +3942,6 @@ PrefabInstance:
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
--- !u!4 &4910321061857220296 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 144529238244638330, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3}
m_PrefabInstance: {fileID: 4910321061857220295}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &5796191506433166633 --- !u!1001 &5796191506433166633
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4822,6 +4809,7 @@ PrefabInstance:
SceneRoots: SceneRoots:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_Roots: m_Roots:
- {fileID: 4910321061857220295}
- {fileID: 1683288374126251321} - {fileID: 1683288374126251321}
- {fileID: 1536317696} - {fileID: 1536317696}
- {fileID: 4158834148864819266} - {fileID: 4158834148864819266}

View File

@ -5,6 +5,7 @@ using System.Linq;
using Unity.Netcode; using Unity.Netcode;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using static UnityEditor.Experimental.GraphView.GraphView;
public class NetworkedGameSetup : NetworkBehaviour public class NetworkedGameSetup : NetworkBehaviour
{ {
@ -34,6 +35,13 @@ public class NetworkedGameSetup : NetworkBehaviour
else else
players = GetPlayers(playerIds); players = GetPlayers(playerIds);
StartCoroutine(LateSetupProcedue(players));
}
private IEnumerator LateSetupProcedue(GameObject[] players)
{
yield return new WaitForSecondsRealtime(0.01f);
InitRope(players); InitRope(players);
InitUpgrader(players); InitUpgrader(players);
@ -43,13 +51,7 @@ public class NetworkedGameSetup : NetworkBehaviour
private GameObject[] GetPlayers(List<ulong> playerIds) private GameObject[] GetPlayers(List<ulong> playerIds)
{ {
GameObject[] players = new GameObject[playerIds.Count]; GameObject[] players = NetworkManager.SpawnManager.SpawnedObjects.Select(x=>x.Value.gameObject).ToArray();
for (int i = 0; i < playerIds.Count; i++)
{
ulong playerId = playerIds[i];
players[i] = NetworkManager.SpawnManager.SpawnedObjects[playerId].gameObject;
}
return players; return players;
} }
@ -70,10 +72,8 @@ public class NetworkedGameSetup : NetworkBehaviour
private void InitRope(GameObject[] players) private void InitRope(GameObject[] players)
{ {
RopeSimulator ropeSim = GetComponentInChildren<RopeSimulator>();
// Assuming 2 players // Assuming 2 players
ropeSim.BuildRope(players[0].GetComponent<RopeJoint>(), players[1].GetComponent<RopeJoint>()); RopeSimulator.instance.BuildRope(players[0].GetComponent<RopeJoint>(), players[1].GetComponent<RopeJoint>());
} }
private void InitUpgrader(GameObject[] players) private void InitUpgrader(GameObject[] players)

View File

@ -70,6 +70,20 @@ public class RopeSimulator : MonoBehaviour
Dictionary<Collider2D, float> colliderToSquezeForce = new(); Dictionary<Collider2D, float> colliderToSquezeForce = new();
public static RopeSimulator instance;
private void Awake()
{
if (instance == null)
{
instance = this;
}
else
{
Destroy(instance);
}
}
private void Start() private void Start()
{ {
// Example of using rope builder // Example of using rope builder
@ -178,6 +192,8 @@ public class RopeSimulator : MonoBehaviour
private void OnDestroy() private void OnDestroy()
{ {
if (start == null || end == null) return;
start.playerInput.ropeLengthShrinken -= ShrinkenRope; start.playerInput.ropeLengthShrinken -= ShrinkenRope;
end.playerInput.ropeLengthShrinken -= ShrinkenRope; end.playerInput.ropeLengthShrinken -= ShrinkenRope;