// To be run on client
        public override void Process()
        {
            if (CustomNetworkManager.IsServer)
            {
                return;                                            // Run extra logic for server, handled in ElectricalArc.
            }
            if (MatrixManager.IsInitialized == false)
            {
                return;
            }
            if (PlayerManager.LocalPlayer == null)
            {
                return;
            }

            if (ClientScene.prefabs.TryGetValue(prefabAssetID, out var prefab) == false)
            {
                Logger.LogError(
                    $"Couldn't spawn {nameof(ElectricalArc)}; client doesn't know about this {nameof(prefabAssetID)}: {prefabAssetID}.",
                    Category.Firearms);
                return;
            }

            var settings = new ElectricalArcSettings(prefab, startObject, endObject, startPosition, endPosition, arcCount, duration);

            new ElectricalArc().CreateArcs(settings);
        }
 /// <summary>
 /// Sends a message to all clients, informing them to create an electrical arc with the given settings.
 /// </summary>
 public static ElectricalArcMessage SendToAll(ElectricalArcSettings arcSettings)
 {
     if (arcSettings.arcEffectPrefab.TryGetComponent <NetworkIdentity>(out var identity) == false)
     {
         Logger.LogError(
             $"No {nameof(NetworkIdentity)} found on {arcSettings.arcEffectPrefab}!",
             Category.NetMessage);
         return(default);
Beispiel #3
0
        /// <summary>
        /// Informs all clients and the server to create arcs with the given settings.
        /// While the arcs are active, the server emits a regular pulse event with which can be subscribed to, for handling damage etc.
        /// </summary>
        /// <returns>an arc instance created on the server</returns>
        public static ElectricalArc ServerCreateNetworkedArcs(ElectricalArcSettings settings)
        {
            ElectricalArcMessage.SendToAll(settings);

            var arc = new ElectricalArc();

            arc.CreateArcs(settings);
            return(arc);
        }
Beispiel #4
0
        private LightningBoltScript CreateSingleArc(ElectricalArcSettings settings)
        {
            LightningBoltScript arc = GameObject.Instantiate(settings.arcEffectPrefab).GetComponent <LightningBoltScript>();

            arc.StartObject   = settings.startObject;
            arc.EndObject     = settings.endObject;
            arc.StartPosition = settings.startPosition;
            arc.EndPosition   = settings.endPosition;

            arc.GetComponentInChildren <ElectricalArcGlow>().SetIntensity(1f / settings.arcCount);

            return(arc);
        }
Beispiel #5
0
        public void CreateArcs(ElectricalArcSettings settings)
        {
            Settings = settings;

            if (settings.reachCheck && CanReach() == false)
            {
                return;
            }

            arcs = new LightningBoltScript[settings.arcCount];
            for (int i = 0; i < settings.arcCount; i++)
            {
                arcs[i] = CreateSingleArc(settings);
            }

            UpdateManager.Add(TriggerArc, arcs[0].Duration);
            UpdateManager.Add(DoPulse, PULSE_INTERVAL);
            UpdateManager.Add(EndArcs, settings.duration);
        }
 /// <summary>
 /// Sends a message to all clients, informing them to create an electrical arc with the given settings.
 /// </summary>
 public static ElectricalArcMessage SendToAll(ElectricalArcSettings arcSettings)
 {
     if (arcSettings.arcEffectPrefab.TryGetComponent <NetworkIdentity>(out var identity))
     {
         var msg = new ElectricalArcMessage
         {
             prefabAssetID = identity.assetId,
             startObject   = arcSettings.startObject,
             endObject     = arcSettings.endObject,
             startPosition = arcSettings.startPosition,
             endPosition   = arcSettings.endPosition,
             arcCount      = arcSettings.arcCount,
             duration      = arcSettings.duration,
         };
         msg.SendToAll();
         return(msg);
     }
     else
     {
         Logger.LogError($"No {nameof(NetworkIdentity)} found on {arcSettings.arcEffectPrefab}!", Category.NetMessage);
         return(default);
        // To be run on client
        public override void Process()
        {
            if (CustomNetworkManager.IsServer)
            {
                return;                                            // Run extra logic for server, handled in ElectricalArc.
            }
            if (!MatrixManager.IsInitialized)
            {
                return;
            }

            if (CustomNetworkManager.IsServer == false && PlayerManager.LocalPlayer == null)
            {
                return;
            }

            if (ClientScene.prefabs.TryGetValue(prefabAssetID, out var prefab))
            {
                var settings = new ElectricalArcSettings(prefab, startObject, endObject, startPosition, endPosition, arcCount, duration);
                new ElectricalArc().CreateArcs(settings);
            }
        }