public void AddFrameAt(int frameID, Sprite sprite, AFSound sound = null, double duration = -1.0f) { if (frameID < 0 || frameID > GetTotalFrames()) { throw new ArgumentException("Invalid frame id"); } if (duration < 0) { duration = m_defaultFrameDuration; } m_sprites.Insert(frameID, sprite); m_sounds.Insert(frameID, sound); m_durations.Insert(frameID, duration); m_startTimes.Insert(frameID, 0); if (frameID > 0 && frameID == GetTotalFrames() - 1) { m_startTimes[frameID] = m_startTimes[(int)(frameID - 1)] + m_durations[(int)(frameID - 1)]; } else { UpdateStartTimes(); } }
public void SetFrameSound(int frameID, AFSound sound) { if (frameID < 0 || frameID >= GetTotalFrames()) { throw new ArgumentException("Invalid frame number"); } m_sounds[frameID] = sound; }
public AFSound Add(string name, AFSound sound) { if (!AFObject.IsNull(sound)) { m_sounds.Add(name, sound); } else { UnityEngine.Debug.LogWarning("AFSound could not be null"); } return(sound); }
public void AdvanceTime(double time) { if (!m_playing || !this.gameObject.activeSelf || time <= 0.0f) { return; } int finalFrame = 0; int previousFrame = m_currentFrame; double restTime = 0.0f; bool breakAfterFrame = false; bool dispatchCompleteEvent = false; double totalTime = GetTotalTime(); if (m_loop && m_currentTime >= totalTime) { m_currentTime = 0.0f; m_currentFrame = 0; } if (m_currentTime < totalTime) { m_currentTime += time; finalFrame = m_sprites.Count - 1; while (m_currentTime > m_startTimes[m_currentFrame] + m_durations[m_currentFrame]) { if (m_currentFrame == finalFrame) { if (m_loop && OnComplete.NumListeners == 0) { m_currentTime -= totalTime; m_currentFrame = 0; } else { breakAfterFrame = true; restTime = m_currentTime - totalTime; dispatchCompleteEvent = true; m_currentFrame = finalFrame; m_currentTime = totalTime; } } else { m_currentFrame++; } AFSound sound = m_sounds[m_currentFrame]; if (sound) { sound.Play(); } if (breakAfterFrame) { break; } } if (m_currentFrame == finalFrame && m_currentTime == totalTime) { dispatchCompleteEvent = true; } } if (m_currentFrame != previousFrame) { m_spriteRender.sprite = m_sprites[m_currentFrame]; } if (dispatchCompleteEvent) { OnComplete.Dispatch(true); } if (m_loop && restTime > 0.0f) { AdvanceTime(restTime); } }
public void AddFrame(Sprite sprite, AFSound sound = null, double duration = -1.0f) { AddFrameAt(GetTotalFrames(), sprite, sound, duration); }