diff --git a/Assets/Materials.meta b/Assets/Materials.meta new file mode 100644 index 0000000..2f66df8 --- /dev/null +++ b/Assets/Materials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 52e9a7db466d20e45b8707a5080aeae4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Materials/LocalGreeen.mat b/Assets/Materials/LocalGreeen.mat new file mode 100644 index 0000000..1b2b096 --- /dev/null +++ b/Assets/Materials/LocalGreeen.mat @@ -0,0 +1,76 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: LocalGreeen + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 0, g: 1, b: 0.20915246, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/Materials/LocalGreeen.mat.meta b/Assets/Materials/LocalGreeen.mat.meta new file mode 100644 index 0000000..f61188d --- /dev/null +++ b/Assets/Materials/LocalGreeen.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 05e8da9df63e1334593bb52aba04fd2f +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Materials/RemoteBlue.mat b/Assets/Materials/RemoteBlue.mat new file mode 100644 index 0000000..4af356a --- /dev/null +++ b/Assets/Materials/RemoteBlue.mat @@ -0,0 +1,76 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: RemoteBlue + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 0, g: 0.72122526, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/Materials/RemoteBlue.mat.meta b/Assets/Materials/RemoteBlue.mat.meta new file mode 100644 index 0000000..794637e --- /dev/null +++ b/Assets/Materials/RemoteBlue.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7256cf30b17151f49955bf872bf681d3 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs.meta b/Assets/Prefabs.meta new file mode 100644 index 0000000..31322fe --- /dev/null +++ b/Assets/Prefabs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: edde46517365f8348b79ff810fa11a68 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/LocalPlayer.prefab b/Assets/Prefabs/LocalPlayer.prefab new file mode 100644 index 0000000..0628fa8 --- /dev/null +++ b/Assets/Prefabs/LocalPlayer.prefab @@ -0,0 +1,111 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 0} + m_RootGameObject: {fileID: 1359508890942550} + m_IsPrefabAsset: 1 +--- !u!1 &1359508890942550 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 6 + m_Component: + - component: {fileID: 4001230648210922} + - component: {fileID: 33388123346024876} + - component: {fileID: 23241386347225878} + - component: {fileID: 65640171084380956} + - component: {fileID: 114813168408472538} + m_Layer: 0 + m_Name: LocalPlayer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4001230648210922 +Transform: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1359508890942550} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 1, 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} +--- !u!23 &23241386347225878 +MeshRenderer: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1359508890942550} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 4294967295 + m_Materials: + - {fileID: 2100000, guid: 05e8da9df63e1334593bb52aba04fd2f, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &33388123346024876 +MeshFilter: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1359508890942550} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!65 &65640171084380956 +BoxCollider: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1359508890942550} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!114 &114813168408472538 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1359508890942550} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 381a091376fde4f4cbb8edc78f431073, type: 3} + m_Name: + m_EditorClassIdentifier: + moveIncrement: 0.01 diff --git a/Assets/Prefabs/LocalPlayer.prefab.meta b/Assets/Prefabs/LocalPlayer.prefab.meta new file mode 100644 index 0000000..f90398a --- /dev/null +++ b/Assets/Prefabs/LocalPlayer.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 88f2120ea01cef248ba929e8eea4c759 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/RemotePlayer.prefab b/Assets/Prefabs/RemotePlayer.prefab new file mode 100644 index 0000000..516d633 --- /dev/null +++ b/Assets/Prefabs/RemotePlayer.prefab @@ -0,0 +1,98 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 0} + m_RootGameObject: {fileID: 1737980672629790} + m_IsPrefabAsset: 1 +--- !u!1 &1737980672629790 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 6 + m_Component: + - component: {fileID: 4928728998406288} + - component: {fileID: 33104186725661092} + - component: {fileID: 23526387874829878} + - component: {fileID: 65482818743642420} + m_Layer: 0 + m_Name: RemotePlayer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4928728998406288 +Transform: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1737980672629790} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 1, 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} +--- !u!23 &23526387874829878 +MeshRenderer: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1737980672629790} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 4294967295 + m_Materials: + - {fileID: 2100000, guid: 7256cf30b17151f49955bf872bf681d3, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &33104186725661092 +MeshFilter: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1737980672629790} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!65 &65482818743642420 +BoxCollider: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1737980672629790} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} diff --git a/Assets/Prefabs/RemotePlayer.prefab.meta b/Assets/Prefabs/RemotePlayer.prefab.meta new file mode 100644 index 0000000..b98513b --- /dev/null +++ b/Assets/Prefabs/RemotePlayer.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bdf6a76720f2a98408b6639537d99358 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/ClientScene.unity b/Assets/Scenes/ClientScene.unity index a33ff4e..2b9d7f6 100644 --- a/Assets/Scenes/ClientScene.unity +++ b/Assets/Scenes/ClientScene.unity @@ -140,10 +140,15 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 4286216c0dea5f64e8d5a8b674f60424, type: 3} m_Name: m_EditorClassIdentifier: - ServerAddress: 10.17.38.221 + SetSingletonOnAwake: 1 + isPersistant: 1 + ServerAddress: 127.0.0.1 Port: 4444 ConnectOnStart: 0 - Name: The Nardliest one + GameSceneName: TestScene + Name: The Black Burrito + IsConnected: 0 + ID: 0 --- !u!4 &914867462 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/ServerScene.unity b/Assets/Scenes/ServerScene.unity index 6a5eb5f..d80dd9b 100644 --- a/Assets/Scenes/ServerScene.unity +++ b/Assets/Scenes/ServerScene.unity @@ -140,6 +140,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6f767c4220f486f49aba41a71b372a1f, type: 3} m_Name: m_EditorClassIdentifier: + SetSingletonOnAwake: 1 + isPersistant: 1 StartOnAwake: 1 Port: 4444 --- !u!4 &555203926 diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity new file mode 100644 index 0000000..9778a1f --- /dev/null +++ b/Assets/Scenes/TestScene.unity @@ -0,0 +1,563 @@ +%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 &6342918 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6342922} + - component: {fileID: 6342921} + - component: {fileID: 6342920} + - component: {fileID: 6342919} + m_Layer: 0 + m_Name: Sphere (1) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!135 &6342919 +SphereCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 6342918} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Radius: 0.5 + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &6342920 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 6342918} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 4294967295 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &6342921 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 6342918} + m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &6342922 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 6342918} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 10, y: 0, z: 10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &695038879 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 695038883} + - component: {fileID: 695038882} + - component: {fileID: 695038881} + - component: {fileID: 695038880} + m_Layer: 0 + m_Name: Plane + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!64 &695038880 +MeshCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 695038879} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Convex: 0 + m_CookingOptions: 14 + m_SkinWidth: 0.01 + m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &695038881 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 695038879} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 4294967295 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &695038882 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 695038879} + m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &695038883 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 695038879} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 2, y: 2, z: 2} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &801355672 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 801355674} + - component: {fileID: 801355673} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &801355673 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 801355672} + m_Enabled: 1 + serializedVersion: 8 + m_Type: 1 + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_CookieSize: 10 + m_Shadows: + m_Type: 0 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_Lightmapping: 4 + m_LightShadowCasterMode: 0 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &801355674 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 801355672} + m_LocalRotation: {x: 0.42238665, y: -0.47888616, z: -0.013989174, w: 0.76945555} + m_LocalPosition: {x: 8.19, y: 6.6, z: -0.05} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 39.54, y: -76.157005, z: -33.539} +--- !u!1 &843646321 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 843646324} + - component: {fileID: 843646323} + - component: {fileID: 843646322} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &843646322 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 843646321} + m_Enabled: 1 +--- !u!20 &843646323 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 843646321} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &843646324 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 843646321} + m_LocalRotation: {x: 0.33499312, y: -0, z: -0, w: 0.9422206} + m_LocalPosition: {x: 0.89, y: 7.04, z: -7.58} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 39.144, y: 0, z: 0} +--- !u!1 &1713353743 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1713353747} + - component: {fileID: 1713353746} + - component: {fileID: 1713353745} + - component: {fileID: 1713353744} + m_Layer: 0 + m_Name: Sphere + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!135 &1713353744 +SphereCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1713353743} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Radius: 0.5 + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1713353745 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1713353743} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 4294967295 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &1713353746 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1713353743} + m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1713353747 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1713353743} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -10, y: 0.04, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2130458414 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2130458416} + - component: {fileID: 2130458415} + m_Layer: 0 + m_Name: GameManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &2130458415 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2130458414} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 47007430424d8684091e01d8323cdb7e, type: 3} + m_Name: + m_EditorClassIdentifier: + SetSingletonOnAwake: 1 + isPersistant: 0 + LocalPlayerPrefab: {fileID: 1359508890942550, guid: 88f2120ea01cef248ba929e8eea4c759, + type: 2} + RemotePlayerPrefab: {fileID: 1737980672629790, guid: bdf6a76720f2a98408b6639537d99358, + type: 2} + mapTop: {x: 10, y: 1, z: 10} + mapBot: {x: -10, y: 1, z: -10} +--- !u!4 &2130458416 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2130458414} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 1.3958592, y: 2.1128974, z: 0.37714672} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scenes/TestScene.unity.meta b/Assets/Scenes/TestScene.unity.meta new file mode 100644 index 0000000..f4238fd --- /dev/null +++ b/Assets/Scenes/TestScene.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3a82ef4cc5d678b418d3a37252b80f6d +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs b/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs new file mode 100644 index 0000000..65b623e --- /dev/null +++ b/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs @@ -0,0 +1,52 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Networking; + +namespace Multiplayer +{ + + public class ClientLoginManager + { + + private ClientManager ClientManager; + + public ClientLoginManager(ClientManager ClientManager) + { + this.ClientManager = ClientManager; + RegisterHandlers(); + } + + private void RegisterHandlers() + { + ClientManager.Client.RegisterHandler(MsgType.Connect, OnConnected); + ClientManager.Client.RegisterHandler(MsgType.Disconnect, OnDisconnected); + ClientManager.Client.RegisterHandler(LoginMsgID.QueryName, OnRecieveID); + } + + private void OnConnected(NetworkMessage msg) + { + ClientManager.IsConnected = true; + Debug.Log("Successfully connected to server"); + } + + private void OnDisconnected(NetworkMessage msg) + { + ClientManager.IsConnected = false; + Debug.Log("Disconnected from Server"); + } + + private void OnRecieveID(NetworkMessage msg) + { + PlayerMsg playerMsg; + if (!Utility.ReadMessage(msg, out playerMsg)) + return; + + Debug.Log("Recieved ID from server: " + playerMsg.ID); + + ClientManager.ID = playerMsg.ID; + ClientManager.SendMessage(LoginMsgID.Name, new StringMsg(ClientManager.ID, ClientManager.Name)); + } + } + +} \ No newline at end of file diff --git a/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs.meta b/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs.meta new file mode 100644 index 0000000..09d4dca --- /dev/null +++ b/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 76346cae951d3bd4cb9fb36bbe3de68f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scipts/Multiplayer/Client/ClientManager.cs b/Assets/Scipts/Multiplayer/Client/ClientManager.cs index 8024cf7..9bcd03e 100644 --- a/Assets/Scipts/Multiplayer/Client/ClientManager.cs +++ b/Assets/Scipts/Multiplayer/Client/ClientManager.cs @@ -6,7 +6,7 @@ using UnityEngine.Networking; namespace Multiplayer { - public class ClientManager : MonoBehaviour + public class ClientManager : MonoSingleton { #region Inspector Variables @@ -21,15 +21,20 @@ namespace Multiplayer [SerializeField] private bool ConnectOnStart = false; + [SerializeField] + private string GameSceneName; + public string Name; #endregion //Returns if client is current connected to a server - public bool IsConnected { get; private set; } - public byte ID { get; private set; } + public bool IsConnected; + public byte ID; //UNET client class which connects to the server; - private NetworkClient uNetClient; + public NetworkClient Client { get; private set;} + + public ClientLoginManager loginManager; /// /// Call to connect client to host @@ -56,51 +61,15 @@ namespace Multiplayer Debug.Log("Attempting to connect to: '" + ServerAddress + "' on port : '" + Port + "'"); - uNetClient = new NetworkClient(); - RegisterHandlers(uNetClient); - - uNetClient.Configure(ChannelConfig.DefaultTopology()); - uNetClient.Connect(ServerAddress, Port); - } - - /// - /// Helper function which sets up all necessary handlers for message types - /// - /// - private void RegisterHandlers(NetworkClient client) - { - client.RegisterHandler(MsgType.Connect, OnConnected); - client.RegisterHandler(MsgType.Disconnect, OnDisconnected); - client.RegisterHandler(LoginMsgID.QueryName, OnRecieveID); - } - - - private void OnConnected(NetworkMessage msg) - { - IsConnected = true; - ID = (byte)msg.conn.connectionId; - Debug.Log("Successfully connected to server"); - } - - private void OnDisconnected(NetworkMessage msg) - { - IsConnected = false; - Debug.Log("Disconnected from Server"); - } - - private void OnRecieveID(NetworkMessage msg) - { - PlayerMsg playerMsg; - if (!Utility.ReadMessage(msg, out playerMsg)) - return; - - Debug.Log("Recieved ID from server: " + playerMsg.ID); + Client = new NetworkClient(); + loginManager = new ClientLoginManager(this); - ID = playerMsg.ID; - SendMessage(LoginMsgID.Name, new StringMsg(ID, Name)); + Client.Configure(ChannelConfig.DefaultTopology()); + Client.RegisterHandler(PlayerMsgID.GameStart, StartGame); + Client.Connect(ServerAddress, Port); } - + /// /// Sends message to server /// @@ -111,12 +80,16 @@ namespace Multiplayer public void SendMessage(short msgType, MessageBase msg, ServerChannel channel = ServerChannel.Reliable) { //if client isn't connected add to backlog - if (IsConnected) - { + if (!IsConnected) Debug.Log("Player not connected to server"); - } - uNetClient.SendByChannel(msgType, msg, (int)channel); + Debug.Log("Sending message to server"); + Client.SendByChannel(msgType, msg, (int)channel); + } + + public void StartGame(NetworkMessage msg) + { + UnityEngine.SceneManagement.SceneManager.LoadScene(GameSceneName); } } } diff --git a/Assets/Scipts/Multiplayer/Client/PlayersManager.cs b/Assets/Scipts/Multiplayer/Client/PlayersManager.cs new file mode 100644 index 0000000..dcc4d0f --- /dev/null +++ b/Assets/Scipts/Multiplayer/Client/PlayersManager.cs @@ -0,0 +1,63 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Networking; + + +namespace Multiplayer +{ + + public class PlayersManager : MonoSingleton + { + + public GameObject LocalPlayerPrefab; + public GameObject RemotePlayerPrefab; + + public Vector3 mapTop; + public Vector3 mapBot; + + private Dictionary RemotePlayers; + private GameObject PlayerObject; + + private void Start() + { + OnGameStart(); + } + + public void OnGameStart() + { + ClientManager.Instance.Client.RegisterHandler(PlayerMsgID.Position, RecievePosition); + InstantaiateLocalPlayer(); + } + + public void InstantaiateLocalPlayer() + { + Vector3 startPos = new Vector3(Random.Range(mapBot.x, mapTop.x), Random.Range(mapBot.y, mapTop.y), Random.Range(mapBot.z, mapTop.z)); + PlayerObject = GameObject.Instantiate(LocalPlayerPrefab); + PlayerObject.transform.position = startPos; + } + + public void InstantiateRemotePlayer(byte playerID) + { + RemotePlayers.Add(playerID, Instantiate(RemotePlayerPrefab)); + } + + public void SendPosition(Vector3 position) { + ClientManager.Instance.SendMessage(PlayerMsgID.Position, new VectorMsg(ClientManager.Instance.ID, position)); + } + + public void RecievePosition(NetworkMessage msg) + { + + VectorMsg vectorMsg; + if (!Utility.ReadMessage(msg, out vectorMsg)) + return; + + if (!RemotePlayers.ContainsKey(vectorMsg.ID)) + InstantiateRemotePlayer(vectorMsg.ID); + + RemotePlayers[vectorMsg.ID].transform.position = vectorMsg.vector; + } + + } +} diff --git a/Assets/Scipts/Multiplayer/Client/PlayersManager.cs.meta b/Assets/Scipts/Multiplayer/Client/PlayersManager.cs.meta new file mode 100644 index 0000000..75ab16d --- /dev/null +++ b/Assets/Scipts/Multiplayer/Client/PlayersManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 47007430424d8684091e01d8323cdb7e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs b/Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs index bb6627e..87bdcf7 100644 --- a/Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs +++ b/Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs @@ -11,6 +11,9 @@ namespace Multiplayer { public const short Position = 200; public const short Rotation = 201; + public const short GameStart = 202; + public const short GameWin = 203; + public const short GameOver = 204; } public class PlayerMsg : MessageBase diff --git a/Assets/Scipts/Multiplayer/Server/Player.cs b/Assets/Scipts/Multiplayer/Server/Player.cs index 77ea838..5f9ec6f 100644 --- a/Assets/Scipts/Multiplayer/Server/Player.cs +++ b/Assets/Scipts/Multiplayer/Server/Player.cs @@ -14,8 +14,8 @@ namespace Multiplayer public NetworkConnection Connection; - public Vector3 Position { get; private set; } - public Quaternion Rotation { get; private set; } + public Vector3 Position { get; set; } + public Quaternion Rotation { get; set; } public string Name { get; private set; } diff --git a/Assets/Scipts/Multiplayer/Server/PlayerServerManager.cs b/Assets/Scipts/Multiplayer/Server/PlayerServerManager.cs new file mode 100644 index 0000000..a48ef43 --- /dev/null +++ b/Assets/Scipts/Multiplayer/Server/PlayerServerManager.cs @@ -0,0 +1,50 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Networking; + +namespace Multiplayer +{ + + public class PlayerServerManager + { + + private ServerManager ServerManager; + + public PlayerServerManager(ServerManager ServerManager) + { + this.ServerManager = ServerManager; + RegisterHandlers(); + } + + private void RegisterHandlers() + { + ServerManager.Server.RegisterHandler(PlayerMsgID.Position, RecievePosition); + } + + private void RecievePosition(NetworkMessage msg) + { + VectorMsg vectorMsg; + if (!Utility.ReadMessage(msg, out vectorMsg)) + return; + + if (!ServerManager.AllPlayers.ContainsKey(vectorMsg.ID)) + { + Debug.Log("Recieved position from unknown player"); + return; + } + + Player player = ServerManager.AllPlayers[vectorMsg.ID]; + player.Position = vectorMsg.vector; + + foreach(Player otherPlayer in ServerManager.AllPlayers.Values) + { + if (otherPlayer.Equals(player)) + continue; + + otherPlayer.Connection.Send(PlayerMsgID.Position, vectorMsg); + } + } + + } +} diff --git a/Assets/Scipts/Multiplayer/Server/PlayerServerManager.cs.meta b/Assets/Scipts/Multiplayer/Server/PlayerServerManager.cs.meta new file mode 100644 index 0000000..6be0088 --- /dev/null +++ b/Assets/Scipts/Multiplayer/Server/PlayerServerManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e4c34eff406f78479e8bdee3a395684 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scipts/Multiplayer/Server/ServerManager.cs b/Assets/Scipts/Multiplayer/Server/ServerManager.cs index d0b7132..a625c69 100644 --- a/Assets/Scipts/Multiplayer/Server/ServerManager.cs +++ b/Assets/Scipts/Multiplayer/Server/ServerManager.cs @@ -7,7 +7,7 @@ using UnityEngine.Networking; namespace Multiplayer { - public class ServerManager : MonoBehaviour + public class ServerManager : MonoSingleton { [SerializeField] @@ -21,6 +21,7 @@ namespace Multiplayer public NetworkServerSimple Server { get; private set; } private LoginManager loginManager; + private PlayerServerManager playerManager; @@ -46,9 +47,19 @@ namespace Multiplayer Debug.Log("Starting Server on " + Port); loginManager = new LoginManager(this); + playerManager = new PlayerServerManager(this); + Server.Listen(Port); } + [ContextMenu("Start Game")] + public void StartGame() + { + foreach (Player player in AllPlayers.Values) + { + player.Connection.Send(PlayerMsgID.GameStart, new PlayerMsg(player.ID)); + } + } private void Update() { diff --git a/Assets/Scipts/TestPlayerScript.cs b/Assets/Scipts/TestPlayerScript.cs new file mode 100644 index 0000000..089f992 --- /dev/null +++ b/Assets/Scipts/TestPlayerScript.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class TestPlayerScript : MonoBehaviour { + + private Vector3 lastSentPos; + + public float moveIncrement = 0.01f; + + + // Use this for initialization + void Start () { + SendPosition(); + } + + // Update is called once per frame + void FixedUpdate () { + if (Vector3.Distance(lastSentPos, transform.position) > moveIncrement) + SendPosition(); + } + + private void SendPosition() + { + lastSentPos = transform.position; + + Multiplayer.VectorMsg msg = new Multiplayer.VectorMsg(Multiplayer.ClientManager.Instance.ID, transform.position); + Multiplayer.ClientManager.Instance.SendMessage(Multiplayer.PlayerMsgID.Position, msg); + } +} diff --git a/Assets/Scipts/TestPlayerScript.cs.meta b/Assets/Scipts/TestPlayerScript.cs.meta new file mode 100644 index 0000000..824b741 --- /dev/null +++ b/Assets/Scipts/TestPlayerScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 381a091376fde4f4cbb8edc78f431073 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scipts/Utility.meta b/Assets/Scipts/Utility.meta new file mode 100644 index 0000000..7a4a9e0 --- /dev/null +++ b/Assets/Scipts/Utility.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d8f1eb6d7087cce4ba563412eda16744 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scipts/Utility/Singleton.cs b/Assets/Scipts/Utility/Singleton.cs new file mode 100644 index 0000000..e0956b7 --- /dev/null +++ b/Assets/Scipts/Utility/Singleton.cs @@ -0,0 +1,47 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MonoSingleton : MonoBehaviour where T : MonoSingleton +{ + + public static T Instance { get; private set; } + + [Header("Singleton Settings")] + public bool SetSingletonOnAwake; + public bool isPersistant; + + protected virtual void Awake() + { + if (SetSingletonOnAwake) + SetAsSingleton(); + } + + private void SetAsSingleton() + { + if (Instance != null && Instance != this) + Destroy(this); + else + Instance = (T)this; + + if (isPersistant) + DontDestroyOnLoad(transform.root); + } + +} + +public class Singleton where T : Singleton, new() +{ + private static T instance; + public static T Instance + { + get + { + if (instance == null) + instance = new T(); + return instance; + } + private set { } + } + +} diff --git a/Assets/Scipts/Utility/Singleton.cs.meta b/Assets/Scipts/Utility/Singleton.cs.meta new file mode 100644 index 0000000..9894c3f --- /dev/null +++ b/Assets/Scipts/Utility/Singleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b4e0222e29f37a648acb11847629863b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: