diff --git a/Assets/Prefabs/Projectile.prefab b/Assets/Prefabs/Projectile.prefab index 30327523..f96bb1fc 100644 --- a/Assets/Prefabs/Projectile.prefab +++ b/Assets/Prefabs/Projectile.prefab @@ -4595,7 +4595,6 @@ GameObject: - component: {fileID: 5633959673307472571} - component: {fileID: 1740834482409443228} - component: {fileID: 4459588035354191565} - - component: {fileID: 4032372881333096458} m_Layer: 14 m_Name: Projectile m_TagString: Untagged @@ -4782,16 +4781,3 @@ MonoBehaviour: localPlayerAuthority: 0 m_AssetId: 858b1226127ef9f4e8d16c9610e691b6 m_SceneId: 0 ---- !u!114 &4032372881333096458 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8038540346792760480} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 665fa8c1c261a9a4dbd28a2cb558e853, type: 3} - m_Name: - m_EditorClassIdentifier: - syncInterval: 0.1 diff --git a/Assets/Scripts/Behaviours/Projectile.cs b/Assets/Scripts/Behaviours/Projectile.cs index d1a2d34f..4fc80dfc 100644 --- a/Assets/Scripts/Behaviours/Projectile.cs +++ b/Assets/Scripts/Behaviours/Projectile.cs @@ -31,8 +31,6 @@ namespace SanAndreasUnity.Behaviours GameObject prefab, Vector3 position, Quaternion rotation, - AudioClip audioClip, - Geometry.GeometryParts model, Ped shooterPed) { NetStatus.ThrowIfNotOnServer(); @@ -41,12 +39,6 @@ namespace SanAndreasUnity.Behaviours var projectile = go.GetComponentOrThrow(); - if (audioClip != null) - { - projectile.AudioSource.clip = audioClip; - projectile.AudioSource.Play(); - } - if (shooterPed != null) { var projectileCollider = projectile.GetComponentOrThrow(); @@ -57,11 +49,6 @@ namespace SanAndreasUnity.Behaviours } } - if (model != null) - { - model.AttachFrames(projectile.m_modelAttachTransform, MaterialFlags.Default); - } - return projectile; } @@ -69,14 +56,33 @@ namespace SanAndreasUnity.Behaviours { this.RigidBody = this.GetComponentOrThrow(); this.AudioSource = this.GetComponentOrThrow(); - } - private void Start() - { if (NetStatus.IsServer) - Destroy(this.gameObject, this.lifeTime); + Object.Destroy(this.gameObject, this.lifeTime); + + if (Weapon.ProjectileSound != null) + { + this.AudioSource.clip = Weapon.ProjectileSound; + this.AudioSource.Play(); + } + + if (Weapon.ProjectileModel != null) + { + Weapon.ProjectileModel.AttachFrames(m_modelAttachTransform, MaterialFlags.Default); + } this.RigidBody.velocity = this.transform.forward * this.speed; + + if (!NetStatus.IsServer) + { + // disable all colliders + var colliders = this.gameObject.GetComponentsInChildren(); + foreach (var c in colliders) + { + c.enabled = false; + } + } + } private void Update() diff --git a/Assets/Scripts/Behaviours/Weapon.cs b/Assets/Scripts/Behaviours/Weapon.cs index b42c0c4a..fd8ed042 100644 --- a/Assets/Scripts/Behaviours/Weapon.cs +++ b/Assets/Scripts/Behaviours/Weapon.cs @@ -168,12 +168,32 @@ namespace SanAndreasUnity.Behaviours WeaponId.RocketLauncherHS, }; - private Geometry.GeometryParts m_projectileModel; + private static Geometry.GeometryParts s_projectileModel; + public static Geometry.GeometryParts ProjectileModel + { + get + { + if (s_projectileModel != null) + return s_projectileModel; + F.RunExceptionSafe(LoadProjectileModel); + return s_projectileModel; + } + } + private static AudioClip s_projectileSound; + public static AudioClip ProjectileSound + { + get + { + if (s_projectileSound != null) + return s_projectileSound; + F.RunExceptionSafe(LoadProjectileAudio); + return s_projectileSound; + } + } - - static Weapon () + static Weapon () { // obtain all weapon types var myType = typeof (Weapon); @@ -291,13 +311,16 @@ namespace SanAndreasUnity.Behaviours return weapon; } - void LoadProjectileModel() + static void LoadProjectileModel() { + if (s_projectileModel != null) + return; + var def = Item.GetDefinition(WeaponId.RocketProjectile); - m_projectileModel = Geometry.Load (def.ModelName, def.TextureDictionaryName); + s_projectileModel = Geometry.Load (def.ModelName, def.TextureDictionaryName); } - void LoadProjectileAudio() + static void LoadProjectileAudio() { if (null == s_projectileSound) { @@ -392,8 +415,8 @@ namespace SanAndreasUnity.Behaviours { this.ProjectilePrefab = WeaponsSettings.projectilePrefab; this.ReloadTime = WeaponsSettings.projectileReloadTime; - F.RunExceptionSafe(this.LoadProjectileModel); - F.RunExceptionSafe(this.LoadProjectileAudio); + F.RunExceptionSafe(LoadProjectileModel); + F.RunExceptionSafe(LoadProjectileAudio); } } @@ -661,7 +684,7 @@ namespace SanAndreasUnity.Behaviours if (this.FiresProjectile) { - Projectile.Create(this.ProjectilePrefab, firePos, Quaternion.LookRotation(fireDir), s_projectileSound, m_projectileModel, m_ped); + Projectile.Create(this.ProjectilePrefab, firePos, Quaternion.LookRotation(fireDir), m_ped); return; } diff --git a/Assets/Scripts/Networking/NetworkedProjectile.cs b/Assets/Scripts/Networking/NetworkedProjectile.cs deleted file mode 100644 index 61f41528..00000000 --- a/Assets/Scripts/Networking/NetworkedProjectile.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Mirror; -using SanAndreasUnity.Behaviours; -using SanAndreasUnity.Behaviours.Vehicles; -using SanAndreasUnity.Utilities; -using UnityEngine; - -namespace SanAndreasUnity.Net -{ - public class NetworkedProjectile : NetworkBehaviour - { - private Projectile m_projectile; - - private void Awake() - { - m_projectile = this.GetComponentOrThrow(); - - if (!NetStatus.IsServer) - { - F.RunExceptionSafe(() => Vehicle.AssignExplosionSound(this.gameObject)); - - // disable all colliders - var colliders = this.gameObject.GetComponentsInChildren(); - foreach (var c in colliders) - { - c.enabled = false; - } - } - } - } -} diff --git a/Assets/Scripts/Networking/NetworkedProjectile.cs.meta b/Assets/Scripts/Networking/NetworkedProjectile.cs.meta deleted file mode 100644 index 07778a78..00000000 --- a/Assets/Scripts/Networking/NetworkedProjectile.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 665fa8c1c261a9a4dbd28a2cb558e853 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: