Skip to content

Commit 0864bfe

Browse files
committed
Add Fusion networking for player and building prefabs
Introduced CommanderData and PlayerSpawner scripts for Fusion networking, and added PlayerCommander prefab for player instantiation. Updated building and vehicle prefabs to include NetworkObject and NetworkTransform components. Refactored scene objects and moved building prefabs to Resources for runtime spawning. Also improved InputController with singleton pattern and minor material/scene adjustments.
1 parent cd6d6bc commit 0864bfe

31 files changed

+538
-350
lines changed

Red Strike/Assets/InputController/InputController.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public class InputController : MonoBehaviour
3131

3232
public int teamId = 0;
3333

34+
public static InputController Instance;
35+
36+
private void Awake()
37+
{
38+
if (Instance == null) Instance = this;
39+
else Destroy(gameObject);
40+
}
41+
3442
private void Start()
3543
{
3644
mainCamera = Camera.main;
@@ -130,7 +138,7 @@ private void PlaceBuilding()
130138
else
131139
buildingCounts[currentSelectedBuilding.buildingName] = 1;
132140

133-
currentSelectedBuilding = null;
141+
currentSelectedBuilding = null;
134142

135143
Debug.Log(placedObject.name + " yerleştirildi.");
136144
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using UnityEngine;
2+
using Fusion;
3+
4+
namespace NetworkingSystem
5+
{
6+
public class CommanderData : NetworkBehaviour
7+
{
8+
[Networked] public int PlayerMoney { get; set; }
9+
[Networked] public int PlayerTeamID { get; set; }
10+
11+
public override void Spawned()
12+
{
13+
if (Object.HasInputAuthority)
14+
{
15+
Debug.Log($"Benim Komutan objem yüklendi! Takımım: {PlayerTeamID}");
16+
17+
if (InputController.InputController.Instance != null)
18+
{
19+
InputController.InputController.Instance.teamId = PlayerTeamID;
20+
21+
Debug.Log("InputController Takım ID güncellendi: " + PlayerTeamID);
22+
}
23+
else
24+
{
25+
Debug.LogError("Sahne InputController bulunamadı!");
26+
}
27+
28+
if (Runner.IsServer) PlayerMoney = 2000;
29+
}
30+
else
31+
{
32+
Debug.Log($"Rakibin Komutan objesi (Takım: {PlayerTeamID}) yüklendi.");
33+
}
34+
}
35+
}
36+
}

Red Strike/Assets/NetworkingSystem/CommanderData.cs.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.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using UnityEngine;
2+
using Fusion;
3+
4+
namespace NetworkingSystem
5+
{
6+
public class PlayerSpawner : SimulationBehaviour, IPlayerJoined
7+
{
8+
[Header("Player Prefab")]
9+
[SerializeField] private NetworkObject _playerCommanderPrefab;
10+
11+
public void PlayerJoined(PlayerRef player)
12+
{
13+
if (Runner.IsServer)
14+
{
15+
Debug.Log($"Oyuncu Katıldı: {player.PlayerId}. Objesi oluşturuluyor...");
16+
17+
NetworkObject networkPlayer = Runner.Spawn(_playerCommanderPrefab, Vector3.zero, Quaternion.identity, player);
18+
19+
var commanderData = networkPlayer.GetComponent<CommanderData>();
20+
21+
int teamIDToAssign = player.PlayerId;
22+
23+
commanderData.PlayerTeamID = teamIDToAssign;
24+
25+
Debug.Log($"Oyuncu {player.PlayerId} için Takım ID {teamIDToAssign} atandı.");
26+
}
27+
}
28+
}
29+
}

Red Strike/Assets/NetworkingSystem/PlayerSpawner.cs.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/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.16870177, g: 0.23698178, b: 0.95675457, a: 0}
50+
- _SunDirection: {r: -0.085740685, g: 0.86959785, b: 0.48625922, 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.16870177, g: 0.23698178, b: 0.95675457, a: 0}
46+
- _SunDirection: {r: -0.085740685, g: 0.86959785, b: 0.48625922, 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.16870177, g: 0.23698178, b: 0.95675457, a: 0}
57+
- _SunDirection: {r: -0.085740685, g: 0.86959785, b: 0.48625922, a: 0}
5858
m_BuildTextureStacks: []
5959
m_AllowLocking: 1

Red Strike/Assets/BuildingPlacement/Buildings/EnergyTower/EnergyTower.prefab renamed to Red Strike/Assets/Resources/EnergyTower.prefab

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ GameObject:
1616
- component: {fileID: -872241184533086861}
1717
- component: {fileID: -7001656233245260738}
1818
- component: {fileID: 1994267217682172209}
19+
- component: {fileID: 1945554365250611277}
1920
m_Layer: 6
2021
m_Name: EnergyTower
2122
m_TagString: Build
@@ -186,8 +187,26 @@ MonoBehaviour:
186187
ObjectInterest: 1
187188
Flags: 262145
188189
NestedObjects: []
189-
NetworkedBehaviours: []
190+
NetworkedBehaviours:
191+
- {fileID: 1945554365250611277}
190192
ForceRemoteRenderTimeframe: 0
193+
--- !u!114 &1945554365250611277
194+
MonoBehaviour:
195+
m_ObjectHideFlags: 0
196+
m_CorrespondingSourceObject: {fileID: 0}
197+
m_PrefabInstance: {fileID: 0}
198+
m_PrefabAsset: {fileID: 0}
199+
m_GameObject: {fileID: 4083171081778293073}
200+
m_Enabled: 1
201+
m_EditorHideFlags: 0
202+
m_Script: {fileID: 158639473, guid: e725a070cec140c4caffb81624c8c787, type: 3}
203+
m_Name:
204+
m_EditorClassIdentifier:
205+
_stateAuthorityChangeErrorCorrectionDelta: 0
206+
SyncScale: 0
207+
SyncParent: 0
208+
_autoAOIOverride: 1
209+
DisableSharedModeInterpolation: 0
191210
--- !u!1001 &1993968208826293375
192211
PrefabInstance:
193212
m_ObjectHideFlags: 0

Red Strike/Assets/BuildingPlacement/Buildings/EnergyTower/EnergyTower.prefab.meta renamed to Red Strike/Assets/Resources/EnergyTower.prefab.meta

File renamed without changes.

0 commit comments

Comments
 (0)