Beispiel #1
0
        /// <summary>
        /// Tell all clients + server to perform a shot with the specified parameters.
        /// </summary>
        /// <param name="direction">Direction of shot from shooter</param>
        /// <param name="damageZone">body part being targeted</param>
        /// <param name="shooter">gameobject of player making the shot</param>
        /// <param name="isSuicide">if the shooter is shooting themselves</param>
        /// <returns></returns>
        public static CastProjectileMessage SendToAll(GameObject shooter, GameObject projectilePrefab, Vector2 direction, BodyPartType damageZone)
        {
            if (CustomNetworkManager.IsServer)
            {
                ShootProjectile(projectilePrefab, shooter, direction, damageZone);
            }

            Guid assetID;

            if (projectilePrefab.TryGetComponent <NetworkIdentity>(out var networkIdentity))
            {
                assetID = networkIdentity.assetId;
            }
            else
            {
                Logger.LogError($"{projectilePrefab} doesn't have a network identity!", Category.NetMessage);
            }

            var msg = new CastProjectileMessage
            {
                Shooter          = shooter ? shooter.GetComponent <NetworkIdentity>().netId : NetId.Invalid,
                ProjectilePrefab = assetID,
                Direction        = direction,
                DamageZone       = damageZone,
            };

            msg.SendToAll();
            return(msg);
        }
Beispiel #2
0
        /// <summary>
        /// Tell all clients + server to perform a shot with the specified parameters.
        /// </summary>
        /// <param name="direction">Direction of shot from shooter</param>
        /// <param name="damageZone">body part being targeted</param>
        /// <param name="shooter">gameobject of player making the shot</param>
        /// <param name="isSuicide">if the shooter is shooting themselves</param>
        /// <returns></returns>
        public static CastProjectileMessage SendToAll(GameObject shooter, GameObject projectilePrefab, Vector2 direction, BodyPartType damageZone)
        {
            if (CustomNetworkManager.IsServer)
            {
                ShootProjectile(projectilePrefab.name, shooter, direction, damageZone);
            }

            var msg = new CastProjectileMessage
            {
                Shooter = shooter ? shooter.GetComponent <NetworkIdentity>().netId : NetId.Invalid,
                ProjectilePrefabName = projectilePrefab.name,
                Direction            = direction,
                DamageZone           = damageZone,
            };

            msg.SendToAll();
            return(msg);
        }