1
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "BITKits.Extensions.Netcode",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"NetCode"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89e093a0b52306b4ca0df7b580fa4b80
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
70
Packages/Common~/Extensions/Netcode/EntityNet.cs
Normal file
70
Packages/Common~/Extensions/Netcode/EntityNet.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine.Events;
|
||||
using System.Linq;
|
||||
using Unity.Netcode;
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
public class EntityNet : NetworkBehaviour, IEntity
|
||||
{
|
||||
GenericEvent genericEvent = new();
|
||||
Processor processor = new();
|
||||
public IEntityComponent[] entityComponents { get; set; }
|
||||
protected virtual void Awake()
|
||||
{
|
||||
entityComponents = GetComponentsInChildren<IEntityComponent>(true);
|
||||
entityComponents.ForEach(x => x.Initialize(this));
|
||||
}
|
||||
protected virtual void Start()
|
||||
{
|
||||
entityComponents.ForEach(x => x.OnAwake());
|
||||
entityComponents.ForEach(x => x.OnStart());
|
||||
}
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
entityComponents.ForEach(x => x.OnDestroyComponent());
|
||||
}
|
||||
protected virtual void Update()
|
||||
{
|
||||
entityComponents.ForEach(x => x.OnUpdate(Time.deltaTime));
|
||||
}
|
||||
protected virtual void FixedUpdate()
|
||||
{
|
||||
entityComponents.ForEach(x => x.OnFixedUpdate(Time.fixedDeltaTime));
|
||||
}
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
entityComponents.ForEach(x => x.OnLateUpdate(Time.deltaTime));
|
||||
}
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
Set<bool>(nameof(EntityComponent.isLocalPlayer), IsLocalPlayer);
|
||||
IEntity.LocalPlayer = this;
|
||||
entityComponents.ForEach(x => x.OnSpawn());
|
||||
}
|
||||
public override void OnNetworkDespawn()
|
||||
{
|
||||
entityComponents.ForEach(x => x.OnDespawn());
|
||||
IEntity.LocalPlayer = null;
|
||||
}
|
||||
public void AddListener<T>(Action<T> action) => genericEvent.AddListener<T>(action);
|
||||
public void Invoke<T>(T value) => genericEvent.Invoke<T>(value);
|
||||
public void RemoveListener<T>(Action<T> action) => genericEvent.RemoveListener<T>(action);
|
||||
public void AddListener<T>(string key, Action<T> action) => genericEvent.AddListener<T>(key, action);
|
||||
public void Invoke<T>(string key, T value) => genericEvent.Invoke<T>(key, value);
|
||||
public void RemoveListener<T>(string key, Action<T> action) => genericEvent.RemoveListener<T>(key, action);
|
||||
public T Get<T>(string key = default) => genericEvent.Get<T>(key) ?? GetComponent<T>();
|
||||
public void Set<T>(T value) => genericEvent.Set<T>(value);
|
||||
public void Set<T>(string key, T value) => genericEvent.Set<T>(key, value);
|
||||
public T GetContext<T>(T value = default) => processor.GetContext<T>(value);
|
||||
public void AddProcessor<T>(Func<T, T> func) => processor.AddProcessor<T>(func);
|
||||
public void RemoveProcessor<T>(Func<T, T> func) => processor.RemoveProcessor<T>(func);
|
||||
public T GetContext<T>(string key, T value) => processor.GetContext<T>(value);
|
||||
public void AddProcessor<T>(string key, Func<T, T> func) => processor.AddProcessor<T>(key, func);
|
||||
public void RemoveProcessor<T>(string key, Func<T, T> func) => processor.RemoveProcessor<T>(key, func);
|
||||
}
|
||||
}
|
11
Packages/Common~/Extensions/Netcode/EntityNet.cs.meta
Normal file
11
Packages/Common~/Extensions/Netcode/EntityNet.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8b04d4ffe4d6814b80998a3671f9c9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
51
Packages/Common~/Extensions/Netcode/EntityNetComponent.cs
Normal file
51
Packages/Common~/Extensions/Netcode/EntityNetComponent.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using Unity.Netcode;
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
public class EntityNetComponent : NetworkBehaviour, IEntityComponent
|
||||
{
|
||||
public IEntity entity { get; set; }
|
||||
public bool isLocalPlayer => IsLocalPlayer;
|
||||
|
||||
public virtual void Initialize(IEntity entity)
|
||||
{
|
||||
this.entity = entity;
|
||||
}
|
||||
public virtual void OnAwake()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnDestroyComponent()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnFixedUpdate(float deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnLateUpdate(float deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnSetOverride(bool value)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnSpawn()
|
||||
{
|
||||
}
|
||||
public virtual void OnDespawn()
|
||||
{
|
||||
}
|
||||
public virtual void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnUpdate(float deltaTime)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 859dc7b24b884c045b9ad09957cf53f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12
Packages/Common~/Extensions/Netcode/NetcodeExtensions.cs
Normal file
12
Packages/Common~/Extensions/Netcode/NetcodeExtensions.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Netcode;
|
||||
using BITKit;
|
||||
namespace BITKit.Entities
|
||||
{
|
||||
public static partial class NetcodeExtensions
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a47d3d48b0bddd49a334e076415ed4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Packages/Common~/Extensions/Netcode/NetcodeManager.cs
Normal file
34
Packages/Common~/Extensions/Netcode/NetcodeManager.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit
|
||||
{
|
||||
public class NetcodeManager : MonoBehaviour
|
||||
{
|
||||
public NetworkManager networkManager;
|
||||
public UnityEvent onServerStarted = new();
|
||||
public UnityEvent<ulong> onClientConnectedCallback = new();
|
||||
public UnityEvent<ulong> onClientDisconnectCallback = new();
|
||||
void Start()
|
||||
{
|
||||
networkManager.OnServerStarted += onServerStarted.Invoke;
|
||||
networkManager.OnClientConnectedCallback += onClientConnectedCallback.Invoke;
|
||||
networkManager.OnClientDisconnectCallback += onClientDisconnectCallback.Invoke;
|
||||
}
|
||||
public void StartHost()
|
||||
{
|
||||
networkManager.StartHost();
|
||||
}
|
||||
public void StartClient()
|
||||
{
|
||||
networkManager.StartClient();
|
||||
}
|
||||
public void Disconnect()
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Extensions/Netcode/NetcodeManager.cs.meta
Normal file
11
Packages/Common~/Extensions/Netcode/NetcodeManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36d51129db87bab4b88e2292855dc3a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user