Exemple #1
0
        public sealed override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
        {
            cachedSqrThreshold  = vfxValues.GetFloat(velocityThresholdPropertyId);
            cachedSqrThreshold *= cachedSqrThreshold;

            cachedRatePerSqrUnit  = vfxValues.GetFloat(ratePerUnitPropertyId);
            cachedRatePerSqrUnit *= cachedRatePerSqrUnit;

            if (!state.playing || state.deltaTime == 0)
            {
                return;
            }

            Vector3 pos         = vfxValues.GetVector3(positionPropertyId);
            float   sqrDistance = Vector3.SqrMagnitude(m_OldPosition - pos);

            if (sqrDistance < cachedSqrThreshold * state.deltaTime)
            {
                state.spawnCount += sqrDistance * cachedRatePerSqrUnit;

                state.vfxEventAttribute.SetVector3(oldPositionAttributeId, m_OldPosition);
                state.vfxEventAttribute.SetVector3(positionAttributeId, pos);
            }
            m_OldPosition = pos;
        }
        public sealed override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
        {
            if (!state.playing || state.deltaTime == 0)
            {
                return;
            }

            float threshold = vfxValues.GetFloat(velocityThresholdPropertyId);

            Vector3 pos  = vfxValues.GetVector3(positionPropertyId);
            float   dist = Vector3.Magnitude(m_OldPosition - pos);

            if (threshold <= 0.0f || dist < threshold * state.deltaTime)
            {
                float count = dist * vfxValues.GetFloat(ratePerUnitPropertyId);
                if (vfxValues.GetBool(clampToOnePropertyId))
                {
                    count = Mathf.Min(count, 1.0f);
                }
                state.spawnCount += count;

                state.vfxEventAttribute.SetVector3(oldPositionAttributeId, m_OldPosition);
                state.vfxEventAttribute.SetVector3(positionAttributeId, pos);
            }
            m_OldPosition = pos;
        }
 public sealed override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
 {
     if (m_LoopCurrentIndex != m_LoopMaxCount && state.totalTime > m_WaitingForTotalTime)
     {
         if (state.playing)
         {
             m_WaitingForTotalTime = state.totalTime + vfxValues.GetFloat(delayPropertyID);
             state.playing         = false;                                                   //We are in playing state, if m_LoopCurrentIndex + 1 == m_LoopMaxCount, we have finished here
             m_LoopCurrentIndex    = m_LoopCurrentIndex + 1 > 0 ? m_LoopCurrentIndex + 1 : 0; //It's possible to count to infinite if m_LoopMaxCount < 0, this ternary avoid stop going back to zero
         }
         else
         {
             m_WaitingForTotalTime = vfxValues.GetFloat(loopDurationPropertyID);
             state.totalTime       = 0.0f;
             state.playing         = true; //We are in not playing state, we was waiting for the moment when restart will be launch
         }
     }
 }
Exemple #4
0
        public sealed override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
        {
            if (m_RemainingLoops == int.MinValue)
            {
                m_RemainingLoops = vfxValues.GetInt(numLoopsPropertyID);
            }

            if (state.totalTime > vfxValues.GetFloat(loopDurationPropertyID))
            {
                if (!m_Waiting)
                {
                    m_WaitTTL = vfxValues.GetFloat(delayPropertyID);
                    m_Waiting = true;
                }
                else
                {
                    m_WaitTTL -= state.deltaTime;

                    if (m_WaitTTL < 0.0f)
                    {
                        m_Waiting       = false;
                        state.totalTime = 0.0f;

                        if (m_RemainingLoops > 0) // if positive, remove one from count
                        {
                            m_RemainingLoops--;
                        }

                        if (m_RemainingLoops != 0)                         // if 0, stop forever
                        {
                            state.playing = true;                          // Re-enable the spawn context
                        }
                        m_RemainingLoops = Math.Max(-1, m_RemainingLoops); // sustain at -1 if in infinite mode
                    }
                    else
                    {
                        state.playing = false; // Stop the Spawn context for the duration of the delay
                    }
                }
            }
        }
 public sealed override void OnPlay(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
 {
     // Evaluate Loop Count only when hitting start;
     // LoopCount < 0 means infinite mode
     // LoopCount == 0 means no spawn
     m_LoopMaxCount        = vfxValues.GetInt(loopCountPropertyID);
     m_WaitingForTotalTime = vfxValues.GetFloat(loopDurationPropertyID);
     m_LoopCurrentIndex    = 0;
     if (m_LoopMaxCount == m_LoopCurrentIndex)
     {
         state.playing = false;
     }
 }
Exemple #6
0
        public sealed override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
        {
            if (state.totalTime < m_LastTime)
            {
                // We got reset shomehow (loop and delay?)
                Reset(vfxValues.GetFloat(startTimePropertyID), vfxValues.GetFloat(durationPropertyID), vfxValues.GetUInt(countPropertyID), state.totalTime);
            }

            if (state.deltaTime > 0.0f && m_Remaining >= 0 && state.totalTime > m_StartTime)
            {
                float frameRatio = Mathf.Clamp01((state.totalTime - m_StartTime) / state.deltaTime);  // How much of the entirety of a frame did we elapse
                float count      = Mathf.Min(m_Remaining, frameRatio * m_Rate * state.deltaTime);

                m_Remaining -= count;
                m_Incoming  += count;

                int toSpawn = (int)Mathf.Floor(m_Incoming);
                state.spawnCount += toSpawn;
                m_Incoming       -= toSpawn;
            }

            m_LastTime = state.totalTime;
        }
Exemple #7
0
    public override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
    {
        Vector3 checkPosition = vfxValues.GetVector3(CheckPositionID);
        float   maxDistance   = vfxValues.GetFloat(MaxDistanceID);
        bool    InvertCheck   = vfxValues.GetBool(InvertCheckID);
        Vector3 position      = state.vfxEventAttribute.GetVector3(AttribPositionID);

        bool test = (checkPosition - position).sqrMagnitude > (maxDistance * maxDistance);

        if (test != InvertCheck)
        {
            state.spawnCount = 0;
        }
    }
Exemple #8
0
 public override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
 {
     s_ReadTotalTimeThroughInput = vfxValues.GetFloat(s_totalTimeID);
     s_ReadInternalTotalTime     = state.totalTime;
 }
Exemple #9
0
 public sealed override void OnPlay(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
 {
     Reset(vfxValues.GetFloat(startTimePropertyID), vfxValues.GetFloat(durationPropertyID), vfxValues.GetUInt(countPropertyID));
 }
Exemple #10
0
 public override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
 {
     state.spawnCount = s_SpawnCount;
     state.totalTime  = vfxValues.GetFloat("totalTime");
     state.vfxEventAttribute.SetFloat("lifetime", s_LifeTime);
 }