67 lines
1.5 KiB
C#
67 lines
1.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.Serialization;
|
|
|
|
public class Unit : NetworkBehaviour
|
|
{
|
|
[SerializeField] private UnitMovement _unitMovement;
|
|
[SerializeField] private UnityEvent _onSelect;
|
|
[SerializeField] private UnityEvent _onDeSelect;
|
|
|
|
public static event Action<Unit> ServerOnUnitSpawned;
|
|
public static event Action<Unit> ServerOnUnitDeSpawned;
|
|
public static event Action<Unit> AuthorityOnUnitSpawned;
|
|
public static event Action<Unit> AuthorityOnUnitDeSpawned;
|
|
|
|
public UnitMovement UnitMovement => _unitMovement;
|
|
|
|
#region Server
|
|
|
|
public override void OnStartServer()
|
|
{
|
|
ServerOnUnitSpawned?.Invoke(this);
|
|
}
|
|
|
|
public override void OnStopServer()
|
|
{
|
|
ServerOnUnitDeSpawned?.Invoke(this);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Client
|
|
|
|
public override void OnStartClient()
|
|
{
|
|
if (!isClientOnly) return;
|
|
if (!isOwned) return;
|
|
AuthorityOnUnitSpawned?.Invoke(this);
|
|
}
|
|
|
|
public override void OnStopClient()
|
|
{
|
|
if (!isClientOnly) return;
|
|
if (!isOwned) return;
|
|
AuthorityOnUnitDeSpawned?.Invoke(this);
|
|
}
|
|
|
|
[Client]
|
|
public void Select()
|
|
{
|
|
if (!isOwned) return;
|
|
_onSelect?.Invoke();
|
|
}
|
|
|
|
[Client]
|
|
public void DeSelect()
|
|
{
|
|
if (!isOwned) return;
|
|
_onDeSelect?.Invoke();
|
|
}
|
|
|
|
#endregion
|
|
} |