Skip to content

Commit 9641797

Browse files
committed
Refactor ammunition for Fusion networking support
Updated Ammunition and derived classes to inherit from NetworkBehaviour and use Fusion's despawn mechanism. Added NetworkObject and NetworkTransform requirements, and migrated prefabs to Resources with FusionPrefab labels and required network components. Also updated material sun direction properties in atmosphere system.
1 parent 50183aa commit 9641797

File tree

13 files changed

+152
-17
lines changed

13 files changed

+152
-17
lines changed
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
using UnityEngine;
22
using VehicleSystem.Vehicles;
3+
using Fusion;
4+
using System.Security.Cryptography;
35

46
namespace AmmunitionSystem.Ammunitions
57
{
6-
public class Ammunition : MonoBehaviour
8+
[RequireComponent(typeof(NetworkObject))]
9+
[RequireComponent(typeof(NetworkTransform))]
10+
public class Ammunition : NetworkBehaviour
711
{
812
public AmmunitionSystem.Ammunition ammunitionData;
913
public Vehicle ownerVehicle;
1014
public virtual void SetRocket(Transform targetTransform) { }
15+
16+
protected virtual void Start()
17+
{
18+
Invoke(nameof(OnDestroy), ammunitionData.lifetime);
19+
}
20+
21+
protected virtual void OnDestroy()
22+
{
23+
Runner.Despawn(Object);
24+
}
1125
}
1226
}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicBullet/BasicBullet.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ private void Awake()
1212
rb = GetComponent<Rigidbody>();
1313
}
1414

15-
private void Start()
15+
protected override void Start()
1616
{
17+
base.Start();
1718
rb.linearVelocity = transform.forward * ammunitionData.speed;
18-
19-
Destroy(gameObject, ammunitionData.lifetime);
2019
}
2120

2221
private void OnCollisionEnter(Collision collision)
@@ -33,7 +32,7 @@ private void OnCollisionEnter(Collision collision)
3332

3433
unit.TakeDamage(ammunitionData.damage);
3534

36-
Destroy(gameObject);
35+
OnDestroy();
3736
}
3837
}
3938
}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicRocket/BasicRocket.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ private void Awake()
2121
currentSpeed = speed * 0.5f;
2222
}
2323

24-
private void Start()
25-
{
26-
Destroy(gameObject, ammunitionData.lifetime);
27-
}
28-
2924
public override void SetRocket(Transform targetTransform)
3025
{
3126
target = targetTransform;
@@ -76,7 +71,7 @@ private void OnCollisionEnter(Collision collision)
7671
Destroy(explosionEffect, 2f);
7772
}
7873

79-
Destroy(gameObject);
74+
OnDestroy();
8075
}
8176
}
8277
}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicTankShell/BasicTankShell.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ private void Awake()
1414
rb = GetComponent<Rigidbody>();
1515
}
1616

17-
private void Start()
17+
protected override void Start()
1818
{
19+
base.Start();
1920
rb.linearVelocity = transform.forward * ammunitionData.speed;
20-
Destroy(gameObject, ammunitionData.lifetime);
2121
}
2222

2323
private void OnCollisionEnter(Collision collision)
@@ -45,7 +45,7 @@ private void OnCollisionEnter(Collision collision)
4545
Destroy(explosionEffect, 2f);
4646
}
4747

48-
Destroy(gameObject);
48+
Runner.Despawn(Object);
4949
}
5050
}
5151
}

Red Strike/Assets/PlanetAtmosphereSystem/AtmosphereMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Material:
4747
- _GunesYonu: {r: -0.91, g: 0.4, b: 3.24, a: 0}
4848
- _RenkUzak: {r: 0, g: 0.10166844, b: 2.152374, a: 1}
4949
- _RenkYakin: {r: 0, g: 5.670685, b: 8, a: 1}
50-
- _SunDirection: {r: -0.085740685, g: 0.86959785, b: 0.48625922, a: 0}
50+
- _SunDirection: {r: 0.055360053, g: -0.9478202, b: -0.31396222, a: 0}
5151
m_BuildTextureStacks: []
5252
m_AllowLocking: 1
5353
--- !u!114 &1522106816477559216

Red Strike/Assets/PlanetAtmosphereSystem/CloudMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Material:
4343
m_Colors:
4444
- _Color: {r: 0, g: 3.8274493, b: 5.992155, a: 1}
4545
- _GunesYonu: {r: -1, g: 0, b: 0, a: 0}
46-
- _SunDirection: {r: -0.085740685, g: 0.86959785, b: 0.48625922, a: 0}
46+
- _SunDirection: {r: 0.055360053, g: -0.9478202, b: -0.31396222, a: 0}
4747
m_BuildTextureStacks: []
4848
m_AllowLocking: 1
4949
--- !u!114 &8499732345945835446

Red Strike/Assets/PlanetAtmosphereSystem/FogMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ Material:
5454
- _QueueControl: 0
5555
- _QueueOffset: 0
5656
m_Colors:
57-
- _SunDirection: {r: -0.085740685, g: 0.86959785, b: 0.48625922, a: 0}
57+
- _SunDirection: {r: 0.055360053, g: -0.9478202, b: -0.31396222, a: 0}
5858
m_BuildTextureStacks: []
5959
m_AllowLocking: 1

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicBullet/BasicBullet.prefab renamed to Red Strike/Assets/Resources/BasicBullet.prefab

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4993,6 +4993,8 @@ GameObject:
49934993
- component: {fileID: 479660005894198636}
49944994
- component: {fileID: 1946964260706349608}
49954995
- component: {fileID: 8399921387528686190}
4996+
- component: {fileID: 2826271625574869094}
4997+
- component: {fileID: 7424458093106631709}
49964998
m_Layer: 0
49974999
m_Name: BasicBullet
49985000
m_TagString: Ammunition
@@ -5080,6 +5082,43 @@ Rigidbody:
50805082
m_Interpolate: 0
50815083
m_Constraints: 112
50825084
m_CollisionDetection: 0
5085+
--- !u!114 &2826271625574869094
5086+
MonoBehaviour:
5087+
m_ObjectHideFlags: 0
5088+
m_CorrespondingSourceObject: {fileID: 0}
5089+
m_PrefabInstance: {fileID: 0}
5090+
m_PrefabAsset: {fileID: 0}
5091+
m_GameObject: {fileID: 8118776881868709922}
5092+
m_Enabled: 1
5093+
m_EditorHideFlags: 0
5094+
m_Script: {fileID: -1552182283, guid: e725a070cec140c4caffb81624c8c787, type: 3}
5095+
m_Name:
5096+
m_EditorClassIdentifier:
5097+
SortKey: 1769362165
5098+
ObjectInterest: 1
5099+
Flags: 262145
5100+
NestedObjects: []
5101+
NetworkedBehaviours:
5102+
- {fileID: 1946964260706349608}
5103+
- {fileID: 7424458093106631709}
5104+
ForceRemoteRenderTimeframe: 0
5105+
--- !u!114 &7424458093106631709
5106+
MonoBehaviour:
5107+
m_ObjectHideFlags: 0
5108+
m_CorrespondingSourceObject: {fileID: 0}
5109+
m_PrefabInstance: {fileID: 0}
5110+
m_PrefabAsset: {fileID: 0}
5111+
m_GameObject: {fileID: 8118776881868709922}
5112+
m_Enabled: 1
5113+
m_EditorHideFlags: 0
5114+
m_Script: {fileID: 158639473, guid: e725a070cec140c4caffb81624c8c787, type: 3}
5115+
m_Name:
5116+
m_EditorClassIdentifier:
5117+
_stateAuthorityChangeErrorCorrectionDelta: 0
5118+
SyncScale: 0
5119+
SyncParent: 0
5120+
_autoAOIOverride: 1
5121+
DisableSharedModeInterpolation: 0
50835122
--- !u!1 &8375843295593431564
50845123
GameObject:
50855124
m_ObjectHideFlags: 0

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicBullet/BasicBullet.prefab.meta renamed to Red Strike/Assets/Resources/BasicBullet.prefab.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicRocket/BasicRocket.prefab renamed to Red Strike/Assets/Resources/BasicRocket.prefab

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5081,6 +5081,12 @@ PrefabInstance:
50815081
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: c55d3227e1e80664b85bbbab7f559dfd, type: 3}
50825082
insertIndex: -1
50835083
addedObject: {fileID: -7221417610533484965}
5084+
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: c55d3227e1e80664b85bbbab7f559dfd, type: 3}
5085+
insertIndex: -1
5086+
addedObject: {fileID: 1091639899180515772}
5087+
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: c55d3227e1e80664b85bbbab7f559dfd, type: 3}
5088+
insertIndex: -1
5089+
addedObject: {fileID: 7062546724892127153}
50845090
m_SourcePrefab: {fileID: 100100000, guid: c55d3227e1e80664b85bbbab7f559dfd, type: 3}
50855091
--- !u!4 &220564753776504433 stripped
50865092
Transform:
@@ -5159,6 +5165,43 @@ MonoBehaviour:
51595165
speed: 20
51605166
rotationSpeed: 5
51615167
accelerationRate: 1.5
5168+
--- !u!114 &1091639899180515772
5169+
MonoBehaviour:
5170+
m_ObjectHideFlags: 0
5171+
m_CorrespondingSourceObject: {fileID: 0}
5172+
m_PrefabInstance: {fileID: 0}
5173+
m_PrefabAsset: {fileID: 0}
5174+
m_GameObject: {fileID: 595683329615967435}
5175+
m_Enabled: 1
5176+
m_EditorHideFlags: 0
5177+
m_Script: {fileID: -1552182283, guid: e725a070cec140c4caffb81624c8c787, type: 3}
5178+
m_Name:
5179+
m_EditorClassIdentifier:
5180+
SortKey: 1700824606
5181+
ObjectInterest: 1
5182+
Flags: 262145
5183+
NestedObjects: []
5184+
NetworkedBehaviours:
5185+
- {fileID: -7221417610533484965}
5186+
- {fileID: 7062546724892127153}
5187+
ForceRemoteRenderTimeframe: 0
5188+
--- !u!114 &7062546724892127153
5189+
MonoBehaviour:
5190+
m_ObjectHideFlags: 0
5191+
m_CorrespondingSourceObject: {fileID: 0}
5192+
m_PrefabInstance: {fileID: 0}
5193+
m_PrefabAsset: {fileID: 0}
5194+
m_GameObject: {fileID: 595683329615967435}
5195+
m_Enabled: 1
5196+
m_EditorHideFlags: 0
5197+
m_Script: {fileID: 158639473, guid: e725a070cec140c4caffb81624c8c787, type: 3}
5198+
m_Name:
5199+
m_EditorClassIdentifier:
5200+
_stateAuthorityChangeErrorCorrectionDelta: 0
5201+
SyncScale: 0
5202+
SyncParent: 0
5203+
_autoAOIOverride: 1
5204+
DisableSharedModeInterpolation: 0
51625205
--- !u!1001 &2066377962604646727
51635206
PrefabInstance:
51645207
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)