/** Check the playable time against the Wwise event duration to see if playback should occur.
     */
    private bool ShouldPlay(UnityEngine.Playables.Playable playable)
    {
        var previousTime = UnityEngine.Playables.PlayableExtensions.GetPreviousTime(playable);
        var currentTime  = UnityEngine.Playables.PlayableExtensions.GetTime(playable);

#if UNITY_EDITOR
        // In editor, do not automatically play the event if the cursor is already in the section.
        if (!UnityEditor.EditorApplication.isPlaying)
        {
            if (previousTime == 0.0 && System.Math.Abs(currentTime - previousTime) > 1.0)
            {
                return(false);
            }
        }
#endif

        if (retriggerEvent)
        {
            return(true);
        }

        // If max and min duration values from metadata are equal, we can assume a deterministic event.
        if (eventDurationMax == eventDurationMin && eventDurationMin != -1f)
        {
            return(currentTime < eventDurationMax);
        }

        currentTime -= previousEventStartTime;

        var maxDuration = currentDuration == -1f ? (float)UnityEngine.Playables.PlayableExtensions.GetDuration(playable) : currentDuration;
        return(currentTime < maxDuration);
    }
    public override void ProcessFrame(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info,
                                      object playerData)
    {
        if (parameter != null)
        {
            // If we are overriding the track object, the rtpcObject will have been resolved in AkRTPCPlayable::CreatePlayable().
            if (!overrideTrackObject)
            {
                // At this point, rtpcObject will have been set to the timeline owner object in AkRTPCPlayable::CreatePlayable().
                // If the track object is null, we keep using the timeline owner object. Otherwise, we swap it for the track object.
                var obj = playerData as UnityEngine.GameObject;
                if (obj != null)
                {
                    rtpcObject = obj;
                }
            }

            if (setRTPCGlobally || rtpcObject == null)
            {
                parameter.SetGlobalValue(RTPCValue);
            }
            else
            {
                parameter.SetValue(rtpcObject, RTPCValue);
            }
        }

        base.ProcessFrame(playable, info, playerData);
    }
    public override void PrepareFrame(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
    {
        base.PrepareFrame(playable, info);

        if (akEvent == null)
        {
            return;
        }

        var shouldPlay = ShouldPlay(playable);

        if (IsScrubbing(info) && shouldPlay)
        {
            requiredActions |= Actions.Seek;

            if (!eventIsPlaying)
            {
                requiredActions |= Actions.Playback | Actions.DelayedStop;
                CheckForFadeInFadeOut(playable);
            }
        }
        else if (!eventIsPlaying && (requiredActions & Actions.Playback) == 0)
        {
            // The clip is playing but the event hasn't been triggered. We need to start the event and jump to the correct time.
            requiredActions |= Actions.Retrigger;
            CheckForFadeInFadeOut(playable);
        }
        else
        {
            CheckForFadeOut(playable, UnityEngine.Playables.PlayableExtensions.GetTime(playable));
        }
    }
Example #4
0
        static StackObject *ProcessFrame_7(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 4);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Object @playerData = (System.Object) typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            UnityEngine.Playables.FrameData @info = (UnityEngine.Playables.FrameData) typeof(UnityEngine.Playables.FrameData).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            UnityEngine.Playables.Playable @playable = (UnityEngine.Playables.Playable) typeof(UnityEngine.Playables.Playable).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 4);
            UnityEngine.Playables.IPlayableBehaviour instance_of_this_method;
            instance_of_this_method = (UnityEngine.Playables.IPlayableBehaviour) typeof(UnityEngine.Playables.IPlayableBehaviour).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.ProcessFrame(@playable, @info, @playerData);

            return(__ret);
        }
Example #5
0
 private void checkForFadeOut(UnityEngine.Playables.Playable playable)
 {
     if (eventTracker != null && !eventTracker.fadeoutTriggered && fadeOutRequired(playable))
     {
         requiredActions |= AkPlayableAction.FadeOut;
     }
 }
    public override void OnBehaviourPlay(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
    {
        base.OnBehaviourPlay(playable, info);

        if (akEvent == null)
        {
            return;
        }

        var shouldPlay = ShouldPlay(playable);

        if (!shouldPlay)
        {
            return;
        }

        requiredActions |= Actions.Playback;

        if (IsScrubbing(info))
        {
            wasScrubbingAndRequiresRetrigger = true;
            // If we've explicitly set the playhead, only play a small snippet.
            requiredActions |= Actions.DelayedStop;
        }
        else if (GetProportionalTime(playable) > alph)
        {
            // we need to jump to the correct position in the case where the event is played from some non-start position.
            requiredActions |= Actions.Seek;
        }

        CheckForFadeInFadeOut(playable);
    }
Example #7
0
 public override void OnBehaviourPause(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
 {
     if (eventObject != null)
     {
         stopEvent();
     }
 }
    /** Check the playable time against the Wwise event duration to see if playback should occur.
     */
    private bool ShouldPlay(UnityEngine.Playables.Playable playable)
    {
        var previousTime = UnityEngine.Playables.PlayableExtensions.GetPreviousTime(playable);
        var currentTime  = UnityEngine.Playables.PlayableExtensions.GetTime(playable);

        if (previousTime == 0.0 && System.Math.Abs(currentTime - previousTime) > 1.0)
        {
            return(false);
        }

        if (retriggerEvent)
        {
            return(true);
        }

        // If max and min duration values from metadata are equal, we can assume a deterministic event.
        if (eventDurationMax == eventDurationMin && eventDurationMin != -1f)
        {
            return(currentTime < eventDurationMax);
        }

        currentTime -= previousEventStartTime;

        var maxDuration = currentDuration == -1f ? (float)UnityEngine.Playables.PlayableExtensions.GetDuration(playable) : currentDuration;

        return(currentTime < maxDuration);
    }
Example #9
0
 public override void OnBehaviourPlay(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
 {
     if (akEvent != null)
     {
         if (ShouldPlay(playable))
         {
             requiredActions |= AkPlayableAction.Playback;
             // If we've explicitly set the playhead, only play a small snippet.
             // We disable scrubbing in edit mode, due to an issue with how FrameData.EvaluationType is handled in edit mode.
             // This is a known issue and Unity are aware of it: https://fogbugz.unity3d.com/default.asp?953109_kitf7pso0vmjm0m0
             if (info.evaluationType == UnityEngine.Playables.FrameData.EvaluationType.Evaluate &&
                 UnityEngine.Application.isPlaying)
             {
                 requiredActions |= AkPlayableAction.DelayedStop;
                 checkForFadeIn((float)UnityEngine.Playables.PlayableExtensions.GetTime(playable));
                 checkForFadeOut(playable);
             }
             else
             {
                 var proportionalTime = getProportionalTime(playable);
                 var alph             = 0.05f;
                 // we need to jump to the correct position in the case where the event is played from some non-start position.
                 if (proportionalTime > alph)
                 {
                     requiredActions |= AkPlayableAction.Seek;
                 }
                 checkForFadeIn((float)UnityEngine.Playables.PlayableExtensions.GetTime(playable));
                 checkForFadeOut(playable);
             }
         }
     }
 }
Example #10
0
    public override void PrepareFrame(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
    {
        if (eventTracker != null)
        {
            // We disable scrubbing in edit mode, due to an issue with how FrameData.EvaluationType is handled in edit mode.
            // This is a known issue and Unity are aware of it: https://fogbugz.unity3d.com/default.asp?953109_kitf7pso0vmjm0m0
            var scrubbing = info.evaluationType == UnityEngine.Playables.FrameData.EvaluationType.Evaluate &&
                            UnityEngine.Application.isPlaying;
            if (scrubbing && ShouldPlay(playable))
            {
                if (!eventTracker.eventIsPlaying)
                {
                    requiredActions |= AkPlayableAction.Playback;
                    requiredActions |= AkPlayableAction.DelayedStop;
                    checkForFadeIn((float)UnityEngine.Playables.PlayableExtensions.GetTime(playable));
                    checkForFadeOut(playable);
                }

                requiredActions |= AkPlayableAction.Seek;
            }
            else             // The clip is playing but the event hasn't been triggered. We need to start the event and jump to the correct time.
            {
                if (!eventTracker.eventIsPlaying && (requiredActions & AkPlayableAction.Playback) == 0)
                {
                    requiredActions |= AkPlayableAction.Retrigger;
                    checkForFadeIn((float)UnityEngine.Playables.PlayableExtensions.GetTime(playable));
                }

                checkForFadeOut(playable);
            }
        }
    }
Example #11
0
        static object PerformMemberwiseClone(ref object o)
        {
            var ins = new UnityEngine.Playables.Playable();

            ins = (UnityEngine.Playables.Playable)o;
            return(ins);
        }
    /** Check the playable time against the Wwise event duration to see if playback should occur.
     */
    private bool ShouldPlay(UnityEngine.Playables.Playable playable)
    {
        if (eventTracker != null)
        {
            var previousTime = UnityEngine.Playables.PlayableExtensions.GetPreviousTime(playable);
            var currentTime  = UnityEngine.Playables.PlayableExtensions.GetTime(playable);

            if (previousTime == 0.0 && System.Math.Abs(currentTime - previousTime) > 1.0)
            {
                return(false);
            }

            // If max and min duration values from metadata are equal, we can assume a deterministic event.
            if (akEventMaxDuration == akEventMinDuration && akEventMinDuration != -1.0f)
            {
                return(currentTime < akEventMaxDuration || eventShouldRetrigger);
            }

            currentTime = currentTime - eventTracker.previousEventStartTime;
            var currentDuration = eventTracker.currentDuration;
            var maxDuration     = currentDuration == -1.0f
                                ? (float)UnityEngine.Playables.PlayableExtensions.GetDuration(playable)
                                : currentDuration;
            return(currentTime < maxDuration || eventShouldRetrigger);
        }

        return(false);
    }
 public override void OnBehaviourPause(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
 {
     base.OnBehaviourPause(playable, info);
     if (eventObject != null && akEvent != null && StopEventAtClipEnd)
     {
         StopEvent();
     }
 }
    private void TriggerFadeOut(UnityEngine.Playables.Playable playable)
    {
        fadeoutTriggered = true;

        var fadeDuration = UnityEngine.Playables.PlayableExtensions.GetDuration(playable) - UnityEngine.Playables.PlayableExtensions.GetTime(playable);

        akEvent.ExecuteAction(eventObject, AkActionOnEventType.AkActionOnEventType_Stop, (int)(fadeDuration * 1000), blendOutCurve);
    }
    private void CheckForFadeOut(UnityEngine.Playables.Playable playable, double currentClipTime)
    {
        var timeLeft = UnityEngine.Playables.PlayableExtensions.GetDuration(playable) - currentClipTime;

        if (blendOutDuration >= timeLeft || easeOutDuration >= timeLeft)
        {
            requiredActions |= Actions.FadeOut;
        }
    }
Example #16
0
    private bool fadeOutRequired(UnityEngine.Playables.Playable playable)
    {
        // Check whether we are currently within a fade out or blend out segment.
        var timeLeft = (float)(UnityEngine.Playables.PlayableExtensions.GetDuration(playable) -
                               UnityEngine.Playables.PlayableExtensions.GetTime(playable));
        var remainingBlendOutDuration = blendOutDuration - timeLeft;
        var remainingEaseOutDuration  = easeOutDuration - timeLeft;

        return(remainingBlendOutDuration >= 0.0f || remainingEaseOutDuration >= 0.0f);
    }
    private void RetriggerEvent(UnityEngine.Playables.Playable playable)
    {
        if (!PostEvent())
        {
            return;
        }

        currentDurationProportion = 1f - SeekToTime(playable);
        previousEventStartTime    = (float)UnityEngine.Playables.PlayableExtensions.GetTime(playable);
    }
    public override void OnBehaviourPause(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
    {
        wasScrubbingAndRequiresRetrigger = false;

        base.OnBehaviourPause(playable, info);
        if (eventObject != null && akEvent != null && StopEventAtClipEnd)
        {
            StopEvent();
        }
    }
    public override void ProcessFrame(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info, object playerData)
    {
        base.ProcessFrame(playable, info, playerData);

        if (akEvent == null)
        {
            return;
        }

        if (!overrideTrackEmitterObject)
        {
            var obj = playerData as UnityEngine.GameObject;
            if (obj != null)
            {
                eventObject = obj;
            }
        }

        if (eventObject == null)
        {
            return;
        }

        if ((requiredActions & Actions.Playback) != 0)
        {
            PlayEvent();
        }

        if ((requiredActions & Actions.Seek) != 0)
        {
            SeekToTime(playable);
        }

        if ((retriggerEvent || wasScrubbingAndRequiresRetrigger) && (requiredActions & Actions.Retrigger) != 0)
        {
            RetriggerEvent(playable);
        }

        if ((requiredActions & Actions.DelayedStop) != 0)
        {
            StopEvent(scrubPlaybackLengthMs);
        }

        if (!fadeinTriggered && (requiredActions & Actions.FadeIn) != 0)
        {
            TriggerFadeIn(playable);
        }

        if (!fadeoutTriggered && (requiredActions & Actions.FadeOut) != 0)
        {
            TriggerFadeOut(playable);
        }

        requiredActions = Actions.None;
    }
    private void CheckForFadeInFadeOut(UnityEngine.Playables.Playable playable)
    {
        var currentClipTime = UnityEngine.Playables.PlayableExtensions.GetTime(playable);

        if (blendInDuration > currentClipTime || easeInDuration > currentClipTime)
        {
            requiredActions |= Actions.FadeIn;
        }

        CheckForFadeOut(playable, currentClipTime);
    }
    void PrintInfo(string FunctionName, UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
    {
        if (PrintDebugInformation)
        {
            var previousTime  = UnityEngine.Playables.PlayableExtensions.GetPreviousTime(playable);
            var currentTime   = UnityEngine.Playables.PlayableExtensions.GetTime(playable);
            var computedDelta = System.Math.Abs(currentTime - previousTime);

            UnityEngine.Debug.Log($"{FunctionName}: prevTime={previousTime}; curTime={currentTime}; computedDelta={computedDelta}; evalType={info.evaluationType}; deltaTime={info.deltaTime}; playState={info.effectivePlayState}; timeHeld={info.timeHeld}; speed={info.effectiveSpeed}; parentSpeed={info.effectiveParentSpeed}");
        }
    }
    private void TriggerFadeIn(UnityEngine.Playables.Playable playable)
    {
        var currentClipTime = UnityEngine.Playables.PlayableExtensions.GetTime(playable);
        var fadeDuration    = UnityEngine.Mathf.Max(easeInDuration, blendInDuration) - currentClipTime;

        if (fadeDuration > 0)
        {
            fadeinTriggered = true;
            akEvent.ExecuteAction(eventObject, AkActionOnEventType.AkActionOnEventType_Pause, 0, blendOutCurve);
            akEvent.ExecuteAction(eventObject, AkActionOnEventType.AkActionOnEventType_Resume, (int)(fadeDuration * 1000), blendInCurve);
        }
    }
Example #23
0
 private void checkForFadeOutImmediate(UnityEngine.Playables.Playable playable)
 {
     if (eventTracker != null && !eventTracker.fadeoutTriggered)
     {
         if (fadeOutRequired(playable))
         {
             var timeLeft = (float)(UnityEngine.Playables.PlayableExtensions.GetDuration(playable) -
                                    UnityEngine.Playables.PlayableExtensions.GetTime(playable));
             triggerFadeOut(timeLeft);
         }
     }
 }
Example #24
0
    // Seek to the current time, taking looping into account.
    // Return the proportion of the current event estimated duration that is left, after the seek.
    protected float seekToTime(UnityEngine.Playables.Playable playable)
    {
        if (eventObject != null && akEvent != null)
        {
            var proportionalTime = getProportionalTime(playable);
            if (proportionalTime < 1.0f)             // Avoids Wwise "seeking beyond end of event: audio will stop" error.
            {
                AkSoundEngine.SeekOnEvent(akEvent.Id, eventObject, proportionalTime);
                return(1.0f - proportionalTime);
            }
        }

        return(1.0f);
    }
Example #25
0
    public override void ProcessFrame(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info,
                                      object playerData)
    {
        if (!overrideTrackEmittorObject)
        {
            var obj = playerData as UnityEngine.GameObject;
            if (obj != null)
            {
                eventObject = obj;
            }
        }

        if (eventObject != null)
        {
            var clipTime = (float)UnityEngine.Playables.PlayableExtensions.GetTime(playable);
            if (actionIsRequired(AkPlayableAction.Playback))
            {
                playEvent();
            }
            if (eventShouldRetrigger && actionIsRequired(AkPlayableAction.Retrigger))
            {
                retriggerEvent(playable);
            }
            if (actionIsRequired(AkPlayableAction.Stop))
            {
                akEvent.Stop(eventObject);
            }
            if (actionIsRequired(AkPlayableAction.DelayedStop))
            {
                stopEvent(scrubPlaybackLengthMs);
            }
            if (actionIsRequired(AkPlayableAction.Seek))
            {
                seekToTime(playable);
            }
            if (actionIsRequired(AkPlayableAction.FadeIn))
            {
                triggerFadeIn(clipTime);
            }
            if (actionIsRequired(AkPlayableAction.FadeOut))
            {
                var timeLeft = (float)(UnityEngine.Playables.PlayableExtensions.GetDuration(playable) -
                                       UnityEngine.Playables.PlayableExtensions.GetTime(playable));
                triggerFadeOut(timeLeft);
            }
        }

        requiredActions = (uint)AkPlayableAction.None;
    }
    private float GetProportionalTime(UnityEngine.Playables.Playable playable)
    {
        // If max and min duration values from metadata are equal, we can assume a deterministic event.
        if (eventDurationMax == eventDurationMin && eventDurationMin != -1f)
        {
            // If the timeline clip has length greater than the event duration, we want to loop.
            return((float)UnityEngine.Playables.PlayableExtensions.GetTime(playable) % eventDurationMax / eventDurationMax);
        }

        var currentTime = (float)UnityEngine.Playables.PlayableExtensions.GetTime(playable) - previousEventStartTime;
        var maxDuration = currentDuration == -1f ? (float)UnityEngine.Playables.PlayableExtensions.GetDuration(playable) : currentDuration;

        // If the timeline clip has length greater than the event duration, we want to loop.
        return(currentTime % maxDuration / maxDuration);
    }
Example #27
0
 protected void retriggerEvent(UnityEngine.Playables.Playable playable)
 {
     if (eventObject != null && akEvent != null && eventTracker != null)
     {
         eventTracker.playingID = akEvent.Post(eventObject,
                                               (uint)AkCallbackType.AK_EndOfEvent | (uint)AkCallbackType.AK_Duration, eventTracker.CallbackHandler, null);
         if (eventTracker.playingID != AkSoundEngine.AK_INVALID_PLAYING_ID)
         {
             eventTracker.eventIsPlaying = true;
             var proportionOfDurationLeft = seekToTime(playable);
             eventTracker.currentDurationProportion = proportionOfDurationLeft;
             eventTracker.previousEventStartTime    = (float)UnityEngine.Playables.PlayableExtensions.GetTime(playable);
         }
     }
 }
    // Seek to the current time, taking looping into account.
    private float SeekToTime(UnityEngine.Playables.Playable playable)
    {
        var proportionalTime = GetProportionalTime(playable);

        if (proportionalTime >= 1f)         // Avoids Wwise "seeking beyond end of event: audio will stop" error.
        {
            return(1f);
        }

        if (eventIsPlaying)
        {
            AkSoundEngine.SeekOnEvent(akEvent.Id, eventObject, proportionalTime);
        }
        return(proportionalTime);
    }
Example #29
0
        static void WriteBackInstance(CSHotFix.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref UnityEngine.Playables.Playable instance_of_this_method)
        {
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            switch (ptr_of_this_method->ObjectType)
            {
            case ObjectTypes.Object:
            {
                __mStack[ptr_of_this_method->Value] = instance_of_this_method;
            }
            break;

            case ObjectTypes.FieldReference:
            {
                var ___obj = __mStack[ptr_of_this_method->Value];
                if (___obj is ILTypeInstance)
                {
                    ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    var t = __domain.GetType(___obj.GetType()) as CLRType;
                    t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.StaticFieldReference:
            {
                var t = __domain.GetType(ptr_of_this_method->Value);
                if (t is ILType)
                {
                    ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.ArrayReference:
            {
                var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as UnityEngine.Playables.Playable[];
                instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method;
            }
            break;
            }
        }
Example #30
0
        static StackObject *OnPlayableCreate_2(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.Playables.Playable @playable = (UnityEngine.Playables.Playable) typeof(UnityEngine.Playables.Playable).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            UnityEngine.Playables.IPlayableBehaviour instance_of_this_method;
            instance_of_this_method = (UnityEngine.Playables.IPlayableBehaviour) typeof(UnityEngine.Playables.IPlayableBehaviour).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.OnPlayableCreate(@playable);

            return(__ret);
        }