FadeOut Effect

Introduction

This tutorial shows you how to implement fade-out effect in Unreal using Wave SDK. See the example below.

Project Settings

../_images/ProjectSettings_FadeOut.png

Select Enable Fade Out to enable this feature. This setting is disabled by default for better performance. For more project settings, see Optional Project Settings.

Note

Important: Because this setting is newly added and disabled by default. Please make sure Enable Fade Out is enabled especially when you upgraded Wave SDK to 4.4.0 from older version.

Example

Note

Important: Please replace com.htc.vr.sdk.VR with com.htc.vr.sdk.VRActivityDelegate when you upgraded Wave SDK to 4.0.0 from older version, or you will build android app failed.

First, create a new Java file with following content: (Path: plugin/Source/java)

package com.htc.vr.unreal;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;

import java.lang.Runnable;

import com.htc.vr.sdk.VRActivityDelegate;
import com.htc.vr.unreal.*;
import com.epicgames.ue4.GameActivity;

public class FadeOutStaticActivity {

    public static String TAG="FadeOutStaticActivityRunable";

    public static FadeOutStaticActivityRunable mFadeOutStaticActivityRunable;
    public static Handler mHandler;
    public static Context hContext;
    public static VRActivityDelegate mVRActivityDelegate;

    public FadeOutStaticActivity() {
    }

    static class FadeOutStaticActivityRunable implements Runnable {
        public FadeOutStaticActivityRunable(){
            if ( hContext.getMainLooper() == null ) {
                Log.e(TAG, "hContext.getMainLooper() is null.");
            }
            mHandler = new Handler(hContext.getMainLooper());
            if ( mHandler == null ) {
                Log.e(TAG, "mHandler is null.");
            }
        };

        @Override
        public void run() {
                Runnable rable = new Runnable() {
                    @Override
                    public void run() {
                        Intent pIntent = new Intent(Intent.ACTION_MAIN);
                        if ( pIntent == null ) {
                            Log.e(TAG, "pIntent is null.");
                        }
                        pIntent.addCategory(Intent.CATEGORY_HOME);
                        pIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                        pIntent.putExtra("QuickMenuEvent", 1);
                        hContext.startActivity(pIntent);
                    }
                };
            Log.d(TAG, "mVRActivityDelegate.doVRStartActivity begin.");
            mVRActivityDelegate.doVRStartActivity(rable);
            Log.d(TAG, "mVRActivityDelegate.doVRStartActivity finish.");
        }
    }

    public static void onFadeOutStaticActivity(Context context, VRActivityDelegate vr) {
        Log.d(TAG, "onFadeOutStaticActivity begin.");
        hContext = context;
        mVRActivityDelegate = vr;
        mFadeOutStaticActivityRunable = new FadeOutStaticActivityRunable();
        if ( mFadeOutStaticActivityRunable == null ) {
            Log.e(TAG, "mFadeOutStaticActivityRunable is null.");
        }
        mHandler.postDelayed(mFadeOutStaticActivityRunable, 1);
        Log.d(TAG, "onFadeOutStaticActivity finish.");
    } //onFadeOutStaticActivity();
}

Second, create a new CPP file with following content: (Path: plugin/Source/plugin/Private)

#include "FadeOutService.h"

#if PLATFORM_ANDROID

#include "AndroidPlatform.h"
#include "Android/AndroidApplication.h"
#include "Android/AndroidJNI.h"
#include "Android/AndroidJava.h"

#include <android/log.h>
#include <android_native_app_glue.h>
#include <jni.h>

#endif

DEFINE_LOG_CATEGORY_STATIC(LogWaveVRFadeOut, Log, All);

void UFadeOutService::UFadeOut()
{
#if PLATFORM_ANDROID
    if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
    {
        jmethodID Method = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "getApplicationContext", "()Landroid/content/Context;", false);
        jobject Context = FJavaWrapper::CallObjectMethod(Env, FAndroidApplication::GetGameActivityThis(), Method);
        jmethodID MethodmVR = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "getVRInstance", "()Lcom/htc/vr/sdk/VRActivityDelegate;", false);
        jobject mVRActivityDelegate = FJavaWrapper::CallObjectMethod(Env, FAndroidApplication::GetGameActivityThis(), MethodmVR);
        jclass classActivity = FAndroidApplication::FindJavaClass("com/htc/vr/unreal/FadeOutStaticActivity");
        jmethodID onFadeOutMethod = FJavaWrapper::FindStaticMethod(Env, classActivity, "onFadeOutStaticActivity", "(Landroid/content/Context;Lcom/htc/vr/sdk/VRActivityDelegate;)V", true);
        Env->CallStaticVoidMethod(classActivity, onFadeOutMethod, Context, mVRActivityDelegate);
    }
    else
    {
        // Could not get Java ENV
    }
#endif
}