コード例 #1
0
        private void CallLightning(Vector3?start, Vector3?end)
        {
            System.Random r     = (RandomOverride ?? random);
            int           count = CountRange.Random(r);

            for (int i = 0; i < count; i++)
            {
                LightningBoltParameters p = CreateParameters();
                if (CountProbabilityModifier >= 0.9999f || i == 0 || (float)p.Random.NextDouble() <= CountProbabilityModifier)
                {
                    p.CustomTransform = (CustomTransformHandler == null ? (System.Action <LightningCustomTransformStateInfo>)null : CustomTransform);
                    CreateLightningBolt(p);
                    if (start != null)
                    {
                        p.Start = start.Value;
                    }
                    if (end != null)
                    {
                        p.End = end.Value;
                    }
                }
                else
                {
                    LightningBoltParameters.ReturnParametersToCache(p);
                }
            }
            CreateLightningBoltsNow();
        }
コード例 #2
0
        private static IEnumerator NotifyBolt(LightningBoltDependencies dependencies, LightningBoltParameters p, Transform transform, Vector3 start, Vector3 end)
        {
            float delay    = p.delaySeconds;
            float lifeTime = p.LifeTime;

            yield return(new WaitForSecondsLightning(delay));

            if (dependencies.LightningBoltStarted != null)
            {
                dependencies.LightningBoltStarted(p, start, end);
            }
            LightningCustomTransformStateInfo state = (p.CustomTransform == null ? null : LightningCustomTransformStateInfo.GetOrCreateStateInfo());

            if (state != null)
            {
                state.Parameters        = p;
                state.BoltStartPosition = start;
                state.BoltEndPosition   = end;
                state.State             = LightningCustomTransformState.Started;
                state.Transform         = transform;
                p.CustomTransform(state);
                state.State = LightningCustomTransformState.Executing;
            }

            if (p.CustomTransform == null)
            {
                yield return(new WaitForSecondsLightning(lifeTime));
            }
            else
            {
                while (lifeTime > 0.0f)
                {
                    p.CustomTransform(state);
                    lifeTime -= LightningBoltScript.DeltaTime;
                    yield return(null);
                }
            }

            if (p.CustomTransform != null)
            {
                state.State = LightningCustomTransformState.Ended;
                p.CustomTransform(state);
                LightningCustomTransformStateInfo.ReturnStateInfoToCache(state);
            }
            if (dependencies.LightningBoltEnded != null)
            {
                dependencies.LightningBoltEnded(p, start, end);
            }
            LightningBoltParameters.ReturnParametersToCache(p);
        }