Exemplo n.º 1
0
        // Update is called once per frame
        void Update()
        {
            if (Lights == null)
            {
                return;
            }

            //Browse the list of lights
            for (int i = 0; i < Lights.Count; ++i)
            {
                IsOnShadow = !IsOnLight(Lights[i]);
                if (!IsOnShadow)
                {
                    break;
                }
            }

            //Call Events
            if (_lastValue != IsOnShadow)
            {
                OnChangeState.Invoke(IsOnShadow);
            }
            if (IsOnShadow)
            {
                OnEnterShadow.Invoke();
            }
            else
            {
                OnExitShadow.Invoke();
            }

            _lastValue = IsOnShadow;
        }
Exemplo n.º 2
0
        private void _FixedUpdate()
        {
            if (Lights == null || targets == null || targets.Count == 0)
            {
                return;
            }
            ShadowTarget current_st;
            int          nbTargetOnShadow = 0;

            //Browse the list of target
            for (int i = 0; i < targets.Count; ++i)
            {
                current_st            = targets[i];
                current_st.IsOnShadow = !IsOnLight(Lights, current_st.Target.position);

                //Call Events
                if (current_st.LastIsOnShadowEstado != current_st.IsOnShadowEstado)
                {
                    current_st.OnChangeState.Invoke(current_st.IsOnShadow);
                    if (current_st.IsOnShadow)
                    {
                        current_st.OnEnterShadow.Invoke();
                    }
                    else
                    {
                        current_st.OnExitShadow.Invoke();
                    }
                }
                if (current_st.IsOnShadow)
                {
                    current_st.OnShadow.Invoke();
                }
                else
                {
                    current_st.OutShadow.Invoke();
                }

                current_st.Last_IsOnShadow = current_st.IsOnShadow;

                if (current_st.IsOnShadow)
                {
                    nbTargetOnShadow++;
                }
            }

            IsOnShadow = (nbTargetOnShadow >= minimumNbTargetOnShadow);
            //Call Events
            if (LastIsOnShadowEstado != IsOnShadowEstado)
            {
                OnChangeState.Invoke(IsOnShadow);
                if (IsOnShadow)
                {
                    OnEnterShadow.Invoke();
                }
                else
                {
                    OnExitShadow.Invoke();
                }
            }
            if (IsOnShadow)
            {
                OnShadow.Invoke();
            }
            else
            {
                OutShadow.Invoke();
            }

            Last_IsOnShadow = IsOnShadow;
        }