Add onStart event to Player

This commit is contained in:
in0finite 2019-04-25 01:00:31 +02:00
parent 455b9dc04d
commit 30cc4e0384
3 changed files with 26 additions and 8 deletions

View file

@ -2,6 +2,7 @@
using UnityEngine;
using Mirror;
using SanAndreasUnity.Behaviours;
using SanAndreasUnity.Utilities;
namespace SanAndreasUnity.Net
{
@ -15,6 +16,8 @@ namespace SanAndreasUnity.Net
/// <summary>Local player.</summary>
public static Player Local { get; private set; }
public static event System.Action<Player> onStart = delegate {};
[SyncVar(hook=nameof(OnOwnedGameObjectChanged))] GameObject m_ownedGameObject;
Ped m_ownedPed;
//public GameObject OwnedGameObject { get { return m_ownedGameObject; } internal set { m_ownedGameObject = value; } }
@ -49,7 +52,7 @@ namespace SanAndreasUnity.Net
void Start()
{
F.InvokeEventExceptionSafe(onStart, this);
}
void OnOwnedGameObjectChanged(GameObject newGo)

View file

@ -361,6 +361,27 @@ namespace SanAndreasUnity.Utilities
}
/// <summary>
/// Invokes all subscribed delegates, and makes sure any exception is caught and logged, so that all
/// subscribers will get notified.
/// </summary>
public static void InvokeEventExceptionSafe( MulticastDelegate eventDelegate, params object[] parameters )
{
RunExceptionSafe( () => {
var delegates = eventDelegate.GetInvocationList ();
foreach (var del in delegates) {
if (del.Method != null) {
try {
del.Method.Invoke (del.Target, parameters);
} catch(System.Exception ex) {
UnityEngine.Debug.LogException (ex);
}
}
}
});
}
public static void SendMessageToObjectsOfType<T> (string msg, params object[] args) where T : UnityEngine.Object
{
var objects = UnityEngine.Object.FindObjectsOfType<T> ();

View file

@ -1,12 +1,6 @@
# What needs to be done before starting work on multiplayer
- create windows for: start new game ; join game ;
- all scripts should work when Camera.main is null
- killing local ped
# TODO
- scene changing: When network (server/client) is stopped, offline scene should be loaded. But, when switching back to online scene, Loader should not load everything again. Instead, only Cell loading should be done, if the new scene is main scene. But, are old meshes/textures destroyed ? Do we leave memory behind, every time when network is stopped ? Or... just exit the game when network is stopped (display message box first ?).