projectile should be visible on clients

This commit is contained in:
in0finite 2020-12-26 23:01:32 +01:00
parent c365cfe4af
commit e825ecb6d4
5 changed files with 55 additions and 81 deletions

View file

@ -4595,7 +4595,6 @@ GameObject:
- component: {fileID: 5633959673307472571} - component: {fileID: 5633959673307472571}
- component: {fileID: 1740834482409443228} - component: {fileID: 1740834482409443228}
- component: {fileID: 4459588035354191565} - component: {fileID: 4459588035354191565}
- component: {fileID: 4032372881333096458}
m_Layer: 14 m_Layer: 14
m_Name: Projectile m_Name: Projectile
m_TagString: Untagged m_TagString: Untagged
@ -4782,16 +4781,3 @@ MonoBehaviour:
localPlayerAuthority: 0 localPlayerAuthority: 0
m_AssetId: 858b1226127ef9f4e8d16c9610e691b6 m_AssetId: 858b1226127ef9f4e8d16c9610e691b6
m_SceneId: 0 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

View file

@ -31,8 +31,6 @@ namespace SanAndreasUnity.Behaviours
GameObject prefab, GameObject prefab,
Vector3 position, Vector3 position,
Quaternion rotation, Quaternion rotation,
AudioClip audioClip,
Geometry.GeometryParts model,
Ped shooterPed) Ped shooterPed)
{ {
NetStatus.ThrowIfNotOnServer(); NetStatus.ThrowIfNotOnServer();
@ -41,12 +39,6 @@ namespace SanAndreasUnity.Behaviours
var projectile = go.GetComponentOrThrow<Projectile>(); var projectile = go.GetComponentOrThrow<Projectile>();
if (audioClip != null)
{
projectile.AudioSource.clip = audioClip;
projectile.AudioSource.Play();
}
if (shooterPed != null) if (shooterPed != null)
{ {
var projectileCollider = projectile.GetComponentOrThrow<Collider>(); var projectileCollider = projectile.GetComponentOrThrow<Collider>();
@ -57,11 +49,6 @@ namespace SanAndreasUnity.Behaviours
} }
} }
if (model != null)
{
model.AttachFrames(projectile.m_modelAttachTransform, MaterialFlags.Default);
}
return projectile; return projectile;
} }
@ -69,14 +56,33 @@ namespace SanAndreasUnity.Behaviours
{ {
this.RigidBody = this.GetComponentOrThrow<Rigidbody>(); this.RigidBody = this.GetComponentOrThrow<Rigidbody>();
this.AudioSource = this.GetComponentOrThrow<AudioSource>(); this.AudioSource = this.GetComponentOrThrow<AudioSource>();
}
private void Start()
{
if (NetStatus.IsServer) 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; this.RigidBody.velocity = this.transform.forward * this.speed;
if (!NetStatus.IsServer)
{
// disable all colliders
var colliders = this.gameObject.GetComponentsInChildren<Collider>();
foreach (var c in colliders)
{
c.enabled = false;
}
}
} }
private void Update() private void Update()

View file

@ -168,12 +168,32 @@ namespace SanAndreasUnity.Behaviours
WeaponId.RocketLauncherHS, 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; 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 // obtain all weapon types
var myType = typeof (Weapon); var myType = typeof (Weapon);
@ -291,13 +311,16 @@ namespace SanAndreasUnity.Behaviours
return weapon; return weapon;
} }
void LoadProjectileModel() static void LoadProjectileModel()
{ {
if (s_projectileModel != null)
return;
var def = Item.GetDefinition<WeaponDef>(WeaponId.RocketProjectile); var def = Item.GetDefinition<WeaponDef>(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) if (null == s_projectileSound)
{ {
@ -392,8 +415,8 @@ namespace SanAndreasUnity.Behaviours
{ {
this.ProjectilePrefab = WeaponsSettings.projectilePrefab; this.ProjectilePrefab = WeaponsSettings.projectilePrefab;
this.ReloadTime = WeaponsSettings.projectileReloadTime; this.ReloadTime = WeaponsSettings.projectileReloadTime;
F.RunExceptionSafe(this.LoadProjectileModel); F.RunExceptionSafe(LoadProjectileModel);
F.RunExceptionSafe(this.LoadProjectileAudio); F.RunExceptionSafe(LoadProjectileAudio);
} }
} }
@ -661,7 +684,7 @@ namespace SanAndreasUnity.Behaviours
if (this.FiresProjectile) 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; return;
} }

View file

@ -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<Projectile>();
if (!NetStatus.IsServer)
{
F.RunExceptionSafe(() => Vehicle.AssignExplosionSound(this.gameObject));
// disable all colliders
var colliders = this.gameObject.GetComponentsInChildren<Collider>();
foreach (var c in colliders)
{
c.enabled = false;
}
}
}
}
}

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 665fa8c1c261a9a4dbd28a2cb558e853
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: