public static TimedRoutine Fade(this AudioSource target, float fadeToVolume, float fadeTime, bool stopPlaybackOnStop = false)
        {
            if (target == null)
            {
                return(null);
            }

            float        startVolume = target.volume;
            TimedRoutine fadeAction  = new TimedRoutine(fadeTime);

            fadeAction.OnLerp = (float timeNormalized) =>
            {
                target.volume = Mathf.Lerp(startVolume, fadeToVolume, timeNormalized);
            };

            fadeAction.OnStop = (bool isComplete) =>
            {
                if (stopPlaybackOnStop)
                {
                    target.Stop();
                }
            };

            fadeAction.Start();

            return(fadeAction);
        }
Beispiel #2
0
        //Creates a temporary raycaster that will destroy itself after a short while
        public static Raycaster CreateTempRaycaster()
        {
            GameObject   r_obj = new GameObject("Temp Raycaster");
            Raycaster    ray   = r_obj.AddComponent <Raycaster>();
            TimedRoutine time  = new TimedRoutine(.5f);

            //destroy the object when the timer runs out
            time.Start(() => { GameObject.Destroy(r_obj); });
            return(ray);
        }
Beispiel #3
0
        void Awake()
        {
            CreateBoxColliderForOptimization();

            raycastChecker = new TimedRoutine(.1f, () => { DoRaycast(); });

            if (updateOnAwake)
            {
                DoRaycast();
            }
        }
Beispiel #4
0
        void Awake()
        {
            if (lightToRandomize == null)
            {
                return;
            }

            updateInterval = new TimedRoutine();

            lightToRandomize = GetComponent <Light>();

            current_light = lightToRandomize.intensity;

            _light_start_position = transform.localPosition;
        }
Beispiel #5
0
        public override void TryActivate()
        {
            base.TryActivate();

            if (shootCooldown.IsRunning)
            {
                return;
            }

            GameObject missle = (GameObject)Instantiate(projectilePrefab, emitPoint.position, Quaternion.identity);

            Rigidbody body = missle.GetComponent <Rigidbody>();

            body.velocity = emitPoint.forward * (owner.velocity.magnitude + shotVelocity);

            shootCooldown = new TimedRoutine(shootCooldownTime);
            shootCooldown.Start();
        }
Beispiel #6
0
        //Called each time an object comes into view
        public override void BindDataToView(ShotData data)
        {
            if (this.data != null)
            {
                //Debug.Log( "OOPS this data is still alive " + this.data.shotData );
                this.data.IsAlive = false;
                lifetime.Reset();
                NotifyLifetimeEnd();
            }

            //before this call this object (the view) does not have an instance assigned
            //so we bind our data to this view and then do any additional setup required
            //example: we could set the text used by a ui text object by reading some value from the data
            base.BindDataToView(data);

            //Debug.Log( "Activating shot "+data.shotData );

            lifetime = new TimedRoutine(maxLifetime, NotifyLifetimeEnd);
            lifetime.Start();

            shotBehavior.Setup(this);
        }