마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드로 연동한 유니티의 파이어베이스가 실행이 되지 않습니다

0 추천

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 = "로그인 실패";
                    }
                });
        }
    }
}

boolks (240 포인트) 님이 2018년 5월 12일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...