Skip to content

Commit

Permalink
debuging: 同步子弹
Browse files Browse the repository at this point in the history
  • Loading branch information
Caizc committed Sep 21, 2017
1 parent 0a6e094 commit e8adef1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 21 deletions.
Binary file modified Assets/Prefabs/Bolts/Bolt.prefab
Binary file not shown.
Binary file modified Assets/Prefabs/Characters/Ship.prefab
Binary file not shown.
9 changes: 5 additions & 4 deletions Assets/Scripts/gameplay/DestroyByBoundary.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using UnityEngine;
using TrueSync;
using UnityEngine;

public class DestroyByBoundary : MonoBehaviour
{
void OnTriggerExit(Collider other)
public void OnSyncedTriggerExit(TSCollision other)
{
Destroy(other.gameObject);
TrueSyncManager.Destroy(other.gameObject);
}
}
}
4 changes: 0 additions & 4 deletions Assets/Scripts/gameplay/SyncedAttack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ public void OnSyncedTriggerEnter(TSCollision other)
{
health.TakeDamage(Damage);
}
else
{
TrueSyncManager.SyncedDestroy(other.gameObject);
}
}
}
19 changes: 17 additions & 2 deletions Assets/Scripts/gameplay/SyncedHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,29 @@ public class SyncedHealth : TrueSyncBehaviour
/// </summary>
[AddTracking] public int Health = 100;

/// <summary>
/// 是否已死亡/损毁
/// </summary>
[AddTracking] public bool IsDead;

// 临时保存最大生命值/耐久度
private int _maxHealth;

public override void OnSyncedStart()
{
IsDead = false;
_maxHealth = Health;
}

public override void OnSyncedUpdate()
{
if (IsDead)
{
// 如果已死亡/损毁,同步销毁本对象
TrueSyncManager.SyncedDestroy(this.gameObject);
}
}

/// <summary>
/// 受到伤害扣生命值/物品耐久度降低
/// </summary>
Expand Down Expand Up @@ -81,8 +96,8 @@ private void Death()
}
else
{
// 否则,同步销毁本对象
TrueSyncManager.SyncedDestroy(this.gameObject);
// 否则,标记本对象已死亡/损毁
IsDead = true;
}
}
}
17 changes: 6 additions & 11 deletions Assets/Scripts/gameplay/SyncedPlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ public class SyncedPlayerController : TrueSyncBehaviour
// 死亡次数
[AddTracking] private int _death;

void Start()
public override void OnSyncedStart()
{
tsTransform.position = new TSVector(TSRandom.Range(-5, 5), 0, TSRandom.Range(-5, 5));

GameObject inputManagerObject = GameObject.FindWithTag("InputManager");
if (inputManagerObject == null)
{
Expand All @@ -73,7 +75,7 @@ void Start()
Debug.LogError("场景中缺失 SyncedInputManager 组件!");
}

_shotSpawnTransform = shot.GetComponent<TSTransform>();
_shotSpawnTransform = shotSpawn.GetComponent<TSTransform>();
_syncedHealth = GetComponent<SyncedHealth>();

GameObject uiCameraObject = GameObject.Find("UICamera");
Expand All @@ -94,17 +96,8 @@ void Start()
}

_audioSource = GetComponent<AudioSource>();
}

void Update()
{
UpdateHealth();
}

public override void OnSyncedStart()
{
_death = 0;
tsTransform.position = new TSVector(TSRandom.Range(-5, 5), 0, TSRandom.Range(-5, 5));
}

public override void OnSyncedInput()
Expand All @@ -121,6 +114,8 @@ public override void OnSyncedInput()

public override void OnSyncedUpdate()
{
UpdateHealth();

_movX = TrueSyncInput.GetFP(0);
_movY = TrueSyncInput.GetFP(1);
_rotX = TrueSyncInput.GetFP(2);
Expand Down
Binary file modified Assets/TrueSync/Unity/Resources/TrueSyncGlobalConfig.asset
Binary file not shown.

0 comments on commit e8adef1

Please sign in to comment.