更改文件架构
This commit is contained in:
19
Packages/Common~/Scripts/Mirror/BITKit.Mirror.asmdef
Normal file
19
Packages/Common~/Scripts/Mirror/BITKit.Mirror.asmdef
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "BITKit.Mirror",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:30817c1a0e6d646d99c048fc403f5979"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"MIRROR"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99a47d73d3ad3374b9d12c982228df71
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/Mirror/Editor.meta
Normal file
8
Packages/Common~/Scripts/Mirror/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 746e68fdd30794243b4f7225a1a10b05
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "BITKit.Extensions.Mirror.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:30817c1a0e6d646d99c048fc403f5979",
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:99a47d73d3ad3374b9d12c982228df71"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"UNITY_EDITOR",
|
||||
"ODIN_INSPECTOR",
|
||||
"MIRROR"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c63f24f43f81c2742ac43760694351c1
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,21 @@
|
||||
/* using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEditor;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
namespace Mirror
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(NetworkBehaviour), true)]
|
||||
public class NetworkBehaviourInspector : Editor
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
VisualElement container = new();
|
||||
InspectorElement.FillDefaultInspector(container, serializedObject, this);
|
||||
return container;
|
||||
}
|
||||
}
|
||||
} */
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf91eeecdb2df964c8bfb9bb1eb8b2f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Packages/Common~/Scripts/Mirror/Indexer.cs
Normal file
10
Packages/Common~/Scripts/Mirror/Indexer.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace Mirror
|
||||
{
|
||||
public class Indexer : NetworkBehaviour
|
||||
{
|
||||
public Dictionary<string, Object> dictionary = new();
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/Mirror/Indexer.cs.meta
Normal file
11
Packages/Common~/Scripts/Mirror/Indexer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e4a027917d8d764d9925945cef9deca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
111
Packages/Common~/Scripts/Mirror/MirrorHelper.cs
Normal file
111
Packages/Common~/Scripts/Mirror/MirrorHelper.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using UnityEngine.Events;
|
||||
namespace Mirror
|
||||
{
|
||||
public partial struct NetworkConstant
|
||||
{
|
||||
public const string Connect = "Connect";
|
||||
public const string StartServer = "StartServer";
|
||||
public const string StartClient = "StartClient";
|
||||
public const string StartHost = "StartHost";
|
||||
public const string StopServer = "StopServer";
|
||||
public const string StopClient = "StopClient";
|
||||
public const string StopHost = "StopHost";
|
||||
public const string TryStartServer = "TryStartServer";
|
||||
public const string TryStartClient = "TryStartClient";
|
||||
public const string TryStartHost = "TryStartHost";
|
||||
public const string TryDisconnect = "TryDisconnect";
|
||||
public const string OnStartServer = "OnStartServer";
|
||||
public const string OnStartClient = "OnStartClient";
|
||||
public const string OnStartHost = "OnStartHost";
|
||||
public const string OnStopServer = "OnStopServer";
|
||||
public const string OnStopClient = "OnStopClient";
|
||||
public const string OnStopHost = "OnStopHost";
|
||||
public const string Disconnect = "Disconnect";
|
||||
}
|
||||
public enum SyncDictionaryOperation : byte
|
||||
{
|
||||
OP_ADD,
|
||||
OP_CLEAR,
|
||||
OP_REMOVE,
|
||||
OP_SET
|
||||
}
|
||||
public interface INetworkSupport
|
||||
{
|
||||
Indexer GetIndexer();
|
||||
string GetID();
|
||||
}
|
||||
public static class MirrorHelper
|
||||
{
|
||||
public static void Write(this NetworkWriter writer, Root root)
|
||||
{
|
||||
var identity = root.root.GetComponent<NetworkIdentity>();
|
||||
var id = root.Get(root.id);
|
||||
|
||||
writer.Write(identity);
|
||||
writer.Write(id);
|
||||
}
|
||||
public static Root GetRoot(this NetworkReader reader)
|
||||
{
|
||||
var identity = reader.Read<NetworkIdentity>();
|
||||
var id = reader.Read<string>();
|
||||
if (identity.TryGetComponent<Root>(out var root))
|
||||
{
|
||||
return root.Get(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void Write(this NetworkWriter writer, INetworkSupport self)
|
||||
{
|
||||
writer.Write(self.GetIndexer());
|
||||
writer.Write(self.GetID());
|
||||
}
|
||||
public static INetworkSupport ReadNetworkSupport(this NetworkReader reader)
|
||||
{
|
||||
var indexer = reader.Read<Indexer>();
|
||||
var id = reader.Read<string>();
|
||||
return indexer.dictionary.Get(id) as INetworkSupport;
|
||||
}
|
||||
public static void Write(this NetworkWriter writer, Rigidbody rigidbody)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public class SyncCallback<TKey, TValue>
|
||||
{
|
||||
public SyncDictionaryOperation op;
|
||||
public TKey key;
|
||||
public TValue value;
|
||||
}
|
||||
public class NetworkDictionary<TKey, TValue> : SyncDictionary<TKey, TValue>
|
||||
{
|
||||
public class SyncCallback : Mirror.SyncCallback<TKey, TValue> { }
|
||||
UnityAction<Mirror.SyncCallback<TKey, TValue>> onCallback;
|
||||
public NetworkDictionary()
|
||||
{
|
||||
Callback += OnCallback;
|
||||
}
|
||||
public void AddListener(UnityAction<Mirror.SyncCallback<TKey, TValue>> callback)
|
||||
{
|
||||
onCallback += callback;
|
||||
}
|
||||
public void RemoveListener(UnityAction<Mirror.SyncCallback<TKey, TValue>> callback)
|
||||
{
|
||||
onCallback -= callback;
|
||||
}
|
||||
void OnCallback(Operation op, TKey key, TValue value)
|
||||
{
|
||||
onCallback?.Invoke(new SyncCallback<TKey, TValue>()
|
||||
{
|
||||
op = (SyncDictionaryOperation)((byte)op),
|
||||
key = key,
|
||||
value = value,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/Mirror/MirrorHelper.cs.meta
Normal file
11
Packages/Common~/Scripts/Mirror/MirrorHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fd869820270ce24b8e267ae4c75a482
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
18
Packages/Common~/Scripts/Mirror/NetworkInteractivable.cs
Normal file
18
Packages/Common~/Scripts/Mirror/NetworkInteractivable.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using UnityEngine.Events;
|
||||
using Sirenix.OdinInspector;
|
||||
namespace Mirror
|
||||
{
|
||||
public abstract class NetworkInteractivable : NetworkBehaviour
|
||||
{
|
||||
public virtual void Excute(NetworkIdentity identity, string action) { }
|
||||
public virtual bool CanInteractive() => true;
|
||||
public virtual string GetDescription() => "Dev";
|
||||
public virtual string GetID() => name;
|
||||
public virtual void SetHighlight() { }
|
||||
public virtual Vector3 GetPosition() => transform.position;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5441fe8af244e8b4e8c60781caca4afc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Packages/Common~/Scripts/Mirror/Spawner.cs
Normal file
20
Packages/Common~/Scripts/Mirror/Spawner.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace Mirror
|
||||
{
|
||||
public class Spawner : NetworkInteractivable
|
||||
{
|
||||
public NetworkIdentity prefab;
|
||||
public int amount=1;
|
||||
[ServerCallback]
|
||||
public override void Excute(NetworkIdentity identity, string action)
|
||||
{
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
var instance = Instantiate(prefab.gameObject, transform.position, transform.rotation);
|
||||
NetworkServer.Spawn(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/Mirror/Spawner.cs.meta
Normal file
11
Packages/Common~/Scripts/Mirror/Spawner.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4f6940d3d5fd934197158d4cc7db89d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user