Browse Source

Player transferes name across

master
JoshuaReason 5 years ago
parent
commit
4305e82c96
7 changed files with 365 additions and 2 deletions
  1. +159
    -0
      Assets/Scenes/ClientScene.unity
  2. +7
    -0
      Assets/Scenes/ClientScene.unity.meta
  3. +157
    -0
      Assets/Scenes/ServerScene.unity
  4. +7
    -0
      Assets/Scenes/ServerScene.unity.meta
  5. +26
    -0
      Assets/Scipts/Multiplayer/Client/ClientManager.cs
  6. +6
    -0
      Assets/Scipts/Multiplayer/Server/LoginManager.cs
  7. +3
    -2
      Assets/Scipts/Multiplayer/Server/ServerManager.cs

+ 159
- 0
Assets/Scenes/ClientScene.unity View File

@ -0,0 +1,159 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 10
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &914867460
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 914867462}
- component: {fileID: 914867461}
m_Layer: 0
m_Name: ClientManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &914867461
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 914867460}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4286216c0dea5f64e8d5a8b674f60424, type: 3}
m_Name:
m_EditorClassIdentifier:
ServerAddress: 127.0.0.1
Port: 4444
ConnectOnStart: 0
Name: The Black Burrito
--- !u!4 &914867462
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 914867460}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

+ 7
- 0
Assets/Scenes/ClientScene.unity.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 072093f84b590984bab8d08bf3d32443
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 157
- 0
Assets/Scenes/ServerScene.unity View File

@ -0,0 +1,157 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 10
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &555203924
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 555203926}
- component: {fileID: 555203925}
m_Layer: 0
m_Name: ServerManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &555203925
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 555203924}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6f767c4220f486f49aba41a71b372a1f, type: 3}
m_Name:
m_EditorClassIdentifier:
StartOnAwake: 1
Port: 4444
--- !u!4 &555203926
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 555203924}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

+ 7
- 0
Assets/Scenes/ServerScene.unity.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 075d02d7077bafa4b9167ef449159fca
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 26
- 0
Assets/Scipts/Multiplayer/Client/ClientManager.cs View File

@ -20,10 +20,13 @@ namespace Multiplayer
[Tooltip("Connects client to server on awake")] [Tooltip("Connects client to server on awake")]
[SerializeField] [SerializeField]
private bool ConnectOnStart = false; private bool ConnectOnStart = false;
public string Name;
#endregion #endregion
//Returns if client is current connected to a server //Returns if client is current connected to a server
public bool IsConnected { get; private set; } public bool IsConnected { get; private set; }
public byte ID { get; private set; }
//UNET client class which connects to the server; //UNET client class which connects to the server;
private NetworkClient uNetClient; private NetworkClient uNetClient;
@ -74,8 +77,11 @@ namespace Multiplayer
private void OnConnected(NetworkMessage msg) private void OnConnected(NetworkMessage msg)
{ {
IsConnected = true; IsConnected = true;
ID = (byte)msg.conn.connectionId;
Debug.Log("Successfully connected to server"); Debug.Log("Successfully connected to server");
Debug.Log("Connection ID: " + msg.conn.connectionId); Debug.Log("Connection ID: " + msg.conn.connectionId);
SendMessage(LoginMsgID.Name, new StringMsg(ID, Name));
} }
private void OnDisconnected(NetworkMessage msg) private void OnDisconnected(NetworkMessage msg)
@ -84,5 +90,25 @@ namespace Multiplayer
Debug.Log("Disconnected from Server"); Debug.Log("Disconnected from Server");
} }
/// <summary>
/// Sends message to server
/// </summary>
/// <param name="msgType">Message type, used to determin message handler</param>
/// <param name="msg">The message to send</param>
/// <param name="channel">Which channel to send on, by deafult sends on Reliable</param>
/// <param name="BackLog">If client isn't connected to server add to BackLog, by default true</param>
public void SendMessage(short msgType, MessageBase msg, ServerChannel channel = ServerChannel.Reliable)
{
//if client isn't connected add to backlog
if (IsConnected)
{
Debug.Log("Player not connected to server");
}
uNetClient.SendByChannel(msgType, msg, (int)channel);
}
} }
} }

+ 6
- 0
Assets/Scipts/Multiplayer/Server/LoginManager.cs View File

@ -12,6 +12,12 @@ namespace Multiplayer
private ServerManager ServerManager; private ServerManager ServerManager;
public LoginManager(ServerManager ServerManager)
{
this.ServerManager = ServerManager;
RegisterHandles();
}
public void RegisterHandles() public void RegisterHandles()
{ {
ServerManager.Server.RegisterHandler(LoginMsgID.Name, OnPlayerLogin); ServerManager.Server.RegisterHandler(LoginMsgID.Name, OnPlayerLogin);

+ 3
- 2
Assets/Scipts/Multiplayer/Server/ServerManager.cs View File

@ -20,7 +20,7 @@ namespace Multiplayer
public Dictionary<int, Player> AllPlayers; public Dictionary<int, Player> AllPlayers;
public NetworkServerSimple Server { get; private set; } public NetworkServerSimple Server { get; private set; }
private LoginManager loginManager;
@ -50,6 +50,7 @@ namespace Multiplayer
Server.Configure(ChannelConfig.DefaultTopology()); Server.Configure(ChannelConfig.DefaultTopology());
Debug.Log("Starting Server on " + Port); Debug.Log("Starting Server on " + Port);
loginManager = new LoginManager(this);
Server.Listen(Port); Server.Listen(Port);
} }
@ -64,7 +65,7 @@ namespace Multiplayer
private void OnConnect(NetworkMessage msg) private void OnConnect(NetworkMessage msg)
{ {
Debug.Log("New Connection: \n Address: " + msg.conn.address + "\n ID: " + msg.conn.connectionId); Debug.Log("New Connection: \n Address: " + msg.conn.address + "\n ID: " + msg.conn.connectionId);
msg.conn.Send(LoginMsgID.QueryName, new PlayerMsg((byte)msg.conn.connectionId));
//msg.conn.Send(LoginMsgID.QueryName, new PlayerMsg((byte)msg.conn.connectionId));
} }
private void OnDisconnect(NetworkMessage msg) private void OnDisconnect(NetworkMessage msg)

Loading…
Cancel
Save