diff --git a/Assets/Mirror/Examples/Tanks/Prefabs/Projectile.prefab b/Assets/Mirror/Examples/Tanks/Prefabs/Projectile.prefab new file mode 100644 index 000000000..938c99dd5 --- /dev/null +++ b/Assets/Mirror/Examples/Tanks/Prefabs/Projectile.prefab @@ -0,0 +1,246 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &63476987332307980 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8035186136109819211} + - component: {fileID: 9118274893554935717} + - component: {fileID: 69063397099238371} + m_Layer: 0 + m_Name: 3D Model + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &8035186136109819211 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 63476987332307980} + m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0.05, y: 0.1, z: 0.05} + m_Children: [] + m_Father: {fileID: 24373266488650541} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} +--- !u!33 &9118274893554935717 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 63476987332307980} + m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &69063397099238371 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 63476987332307980} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: cba1b63a0bccc4b12ac25f05d0ae2dd1, 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!1 &5890560936853567077 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 24373266488650541} + - component: {fileID: 1713098107664522388} + - component: {fileID: 2355290524794870353} + - component: {fileID: 4629190479245867726} + - component: {fileID: 7082621516996595528} + m_Layer: 0 + m_Name: Projectile + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &24373266488650541 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5890560936853567077} + 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: + - {fileID: 8035186136109819211} + - {fileID: 7830988697844474908} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1713098107664522388 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5890560936853567077} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9b91ecbcc199f4492b9a91e820070131, type: 3} + m_Name: + m_EditorClassIdentifier: + m_ServerOnly: 0 + m_LocalPlayerAuthority: 0 + m_AssetId: b7dd46dbf38c643f09e206f9fa4be008 + m_SceneId: 0 +--- !u!136 &2355290524794870353 +CapsuleCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5890560936853567077} + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_Enabled: 1 + m_Radius: 0.05 + m_Height: 0.2 + m_Direction: 1 + m_Center: {x: 0, y: 0, z: 0} +--- !u!54 &4629190479245867726 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5890560936853567077} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_UseGravity: 0 + m_IsKinematic: 0 + m_Interpolate: 1 + m_Constraints: 0 + m_CollisionDetection: 1 +--- !u!114 &7082621516996595528 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5890560936853567077} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8f49b83f111a64bc7a5275af4f6f930b, type: 3} + m_Name: + m_EditorClassIdentifier: + syncInterval: 0.1 + destroyAfter: 5 + rigidBody: {fileID: 4629190479245867726} + force: 1000 +--- !u!1 &9126921595194253319 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7830988697844474908} + - component: {fileID: 4878977110396366525} + m_Layer: 0 + m_Name: Point Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &7830988697844474908 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9126921595194253319} + 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: 24373266488650541} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!108 &4878977110396366525 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9126921595194253319} + m_Enabled: 1 + serializedVersion: 8 + m_Type: 2 + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Intensity: 5 + m_Range: 2 + 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: 3 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_ShadowRadius: 0 + m_ShadowAngle: 0 diff --git a/Assets/Mirror/Examples/Tanks/Prefabs/Projectile.prefab.meta b/Assets/Mirror/Examples/Tanks/Prefabs/Projectile.prefab.meta new file mode 100644 index 000000000..f6d4068e9 --- /dev/null +++ b/Assets/Mirror/Examples/Tanks/Prefabs/Projectile.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b7dd46dbf38c643f09e206f9fa4be008 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mirror/Examples/Tanks/Prefabs/Tank.prefab b/Assets/Mirror/Examples/Tanks/Prefabs/Tank.prefab index b28fd1a8e..f94b6000a 100644 --- a/Assets/Mirror/Examples/Tanks/Prefabs/Tank.prefab +++ b/Assets/Mirror/Examples/Tanks/Prefabs/Tank.prefab @@ -13,6 +13,7 @@ GameObject: - component: {fileID: 2240606817507776182} - component: {fileID: 114250499875391520} - component: {fileID: 6900008319038825817} + - component: {fileID: 5194388907919410155} - component: {fileID: 114654712548978148} m_Layer: 0 m_Name: Tank @@ -34,6 +35,7 @@ Transform: m_Children: - {fileID: 7831918942946891954} - {fileID: 6564220120147636086} + - {fileID: 5718089106632469514} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -108,6 +110,19 @@ NavMeshAgent: m_BaseOffset: 0 m_WalkableMask: 4294967295 m_ObstacleAvoidanceType: 0 +--- !u!135 &5194388907919410155 +SphereCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1916082411674582} + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_Enabled: 1 + serializedVersion: 2 + m_Radius: 0.5 + m_Center: {x: 0, y: 0.25, z: 0} --- !u!114 &114654712548978148 MonoBehaviour: m_ObjectHideFlags: 0 @@ -125,6 +140,9 @@ MonoBehaviour: animator: {fileID: 2240606817507776182} rotationSpeed: 80 shootKey: 32 + projectilePrefab: {fileID: 5890560936853567077, guid: b7dd46dbf38c643f09e206f9fa4be008, + type: 3} + projectileMount: {fileID: 5718089106632469514} --- !u!1 &4426914200102054949 GameObject: m_ObjectHideFlags: 0 @@ -194,6 +212,36 @@ Light: m_UseColorTemperature: 0 m_ShadowRadius: 0 m_ShadowAngle: 0 +--- !u!1 &4730779867780281009 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5718089106632469514} + m_Layer: 0 + m_Name: ProjectileMount + m_TagString: Untagged + m_Icon: {fileID: -964228994112308473, guid: 0000000000000000d000000000000000, type: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5718089106632469514 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4730779867780281009} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0.412, z: 0.936} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 4492442352427800} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &7831918942947279416 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Mirror/Examples/Tanks/Scenes/Scene.unity b/Assets/Mirror/Examples/Tanks/Scenes/Scene.unity index 7b6271b6f..fc8e49e02 100644 --- a/Assets/Mirror/Examples/Tanks/Scenes/Scene.unity +++ b/Assets/Mirror/Examples/Tanks/Scenes/Scene.unity @@ -455,7 +455,8 @@ MonoBehaviour: type: 3} autoCreatePlayer: 1 playerSpawnMethod: 1 - spawnPrefabs: [] + spawnPrefabs: + - {fileID: 5890560936853567077, guid: b7dd46dbf38c643f09e206f9fa4be008, type: 3} --- !u!114 &1282001521 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Mirror/Examples/Tanks/Scripts/Projectile.cs b/Assets/Mirror/Examples/Tanks/Scripts/Projectile.cs new file mode 100644 index 000000000..83609ee56 --- /dev/null +++ b/Assets/Mirror/Examples/Tanks/Scripts/Projectile.cs @@ -0,0 +1,36 @@ +using UnityEngine; +using Mirror; + +public class Projectile : NetworkBehaviour +{ + public float destroyAfter = 5; + public Rigidbody rigidBody; + public float force = 1000; + + public override void OnStartServer() + { + Invoke(nameof(DestroySelf), destroyAfter); + } + + // set velocity for server and client. this way we don't have to sync the + // position, because both the server and the client simulate it. + void Start() + { + rigidBody.AddForce(transform.forward * force); + } + + // destroy for everyone on the server + [Server] + void DestroySelf() + { + NetworkServer.Destroy(gameObject); + } + + // ServerCallback because we don't want a warning if OnTriggerEnter is + // called on the client + [ServerCallback] + void OnTriggerEnter(Collider co) + { + NetworkServer.Destroy(gameObject); + } +} diff --git a/Assets/Mirror/Examples/Tanks/Scripts/Projectile.cs.meta b/Assets/Mirror/Examples/Tanks/Scripts/Projectile.cs.meta new file mode 100644 index 000000000..387ece6ac --- /dev/null +++ b/Assets/Mirror/Examples/Tanks/Scripts/Projectile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8f49b83f111a64bc7a5275af4f6f930b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mirror/Examples/Tanks/Scripts/Move.cs b/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs similarity index 57% rename from Assets/Mirror/Examples/Tanks/Scripts/Move.cs rename to Assets/Mirror/Examples/Tanks/Scripts/Tank.cs index aacaff598..b076780ae 100644 --- a/Assets/Mirror/Examples/Tanks/Scripts/Move.cs +++ b/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs @@ -3,12 +3,19 @@ namespace Mirror.Examples.Movement { - public class Move : NetworkBehaviour + public class Tank : NetworkBehaviour { + [Header("Components")] public NavMeshAgent agent; public Animator animator; + + [Header("Movement")] public float rotationSpeed = 100; + + [Header("Firing")] public KeyCode shootKey = KeyCode.Space; + public GameObject projectilePrefab; + public Transform projectileMount; void Update() { @@ -28,8 +35,24 @@ void Update() // shoot if (Input.GetKeyDown(shootKey)) { - animator.SetTrigger("Shoot"); + CmdFire(); } } + + // this is called on the server + [Command] + void CmdFire() + { + GameObject projectile = Instantiate(projectilePrefab, projectileMount.position, transform.rotation); + NetworkServer.Spawn(projectile); + RpcOnFire(); + } + + // this is called on the tank that fired for all observers + [ClientRpc] + void RpcOnFire() + { + animator.SetTrigger("Shoot"); + } } } diff --git a/Assets/Mirror/Examples/Tanks/Scripts/Move.cs.meta b/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs.meta similarity index 100% rename from Assets/Mirror/Examples/Tanks/Scripts/Move.cs.meta rename to Assets/Mirror/Examples/Tanks/Scripts/Tank.cs.meta diff --git a/Assets/Mirror/Examples/Tanks/Textures/ProjectileMaterial.mat b/Assets/Mirror/Examples/Tanks/Textures/ProjectileMaterial.mat new file mode 100644 index 000000000..d231b59c8 --- /dev/null +++ b/Assets/Mirror/Examples/Tanks/Textures/ProjectileMaterial.mat @@ -0,0 +1,77 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: ProjectileMaterial + 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 + - _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.8901961, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/Mirror/Examples/Tanks/Textures/ProjectileMaterial.mat.meta b/Assets/Mirror/Examples/Tanks/Textures/ProjectileMaterial.mat.meta new file mode 100644 index 000000000..84c957ed6 --- /dev/null +++ b/Assets/Mirror/Examples/Tanks/Textures/ProjectileMaterial.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cba1b63a0bccc4b12ac25f05d0ae2dd1 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: