.png)

MainView 쪽에서 FireSample을 intent해 유니티를 실행시켰습니다
유니티쪽 스크립트에서는 미리 Eamil InputField 란에 실행되면 asd라는 텍스트가 저장되도록 적어놨는데
intent를 통해 유니티를 실행시키면 아무런 스크립트가 표시되지 않고 register이나 Login 버튼을 눌러도 반응이 없습니다ㅜ Auth를 전달하지 못하는거 같은데 파이어베이스를 안드로이드 스튜디오 내에서 다시 설정 해주어야 하는건가요?
안드로이드 스튜디오에서는
View.OnClickListener listener = new View.OnClickListener(){
@Override
public void onClick(View v){
Intent intent1 = new Intent(MainView.this, FireSample.class);
startActivity(intent1);
}
};
이런 식으로 intent를 하여 유니티의 추출한 gradle을 실행시켰습니다.
이하 안드로이드 스튜디오의 FireSample의 코드입니다.
public class FireSample extends UnityPlayerActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
}
public void onBackPressed()
{
// instead of calling UnityPlayerActivity.onBackPressed() we just ignore the back button event
super.onBackPressed();
}
public void HelloFunction(){
UnityPlayer.UnitySendMessage("FirebaseManager", "EmailIn", "Hello");
}
}
이하 유니티 스크립트 입니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FirebaseManager : MonoBehaviour {
#if UNITY_ANDROID
AndroidJavaObject activity;
// 이메일 InputField
[SerializeField]
InputField emailInput;
// 비밀번호 InputField
[SerializeField]
InputField passInput;
// 결과를 알려줄 텍스트
[SerializeField]
Text resultText;
// 인증을 관리할 객체
Firebase.Auth.FirebaseAuth auth;
// Use this for initialization
void Awake()
{
// 인증을 관리할 객체를 초기화 한다.
auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
AndroidJavaClass jc = new AndroidJavaClass("com.example.hwan.myapplication5");
activity = jc.GetStatic<AndroidJavaObject>("currentActivity");
}
void Start()
{
activity.Call("HelloFunction");
}
#endif
public void EmailIn(string em)
{
emailInput.text = em;
}
// 회원가입 버튼을 눌렀을 때 작동할 함수
public void SignUp()
{
// 회원가입 버튼은 인풋 필드가 비어있지 않을 때 작동한다.
if (emailInput.text.Length != 0 && passInput.text.Length != 0)
{
auth.CreateUserWithEmailAndPasswordAsync(emailInput.text, passInput.text).ContinueWith(
task =>
{
if (!task.IsCanceled && !task.IsFaulted)
{
resultText.text = "회원가입 성공";
}
else
{
resultText.text = "회원가입 실패";
}
});
}
}
// 로그인 버튼을 눌렀을 때 작동할 함수
public void SignIn()
{
// 로그인 버튼은 인풋 필드가 비어있지 않을 때 작동한다.
if (emailInput.text.Length != 0 && passInput.text.Length != 0)
{
auth.SignInWithEmailAndPasswordAsync(emailInput.text, passInput.text).ContinueWith(
task =>
{
if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted)
{
Firebase.Auth.FirebaseUser newUser = task.Result;
resultText.text = "로그인 성공";
}
else
{
resultText.text = "로그인 실패";
}
});
}
}
}