반응형
반응형

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using GooglePlayGames;

using UnityEngine.UI;


public class GoogleManager : MonoBehaviour {


public Text tx_id;

public Text tx_userName;

//public Text tx_Email;

public FacebookManager fb;


void Start()

{

PlayGamesPlatform.DebugLogEnabled = true;

PlayGamesPlatform.Activate ();

LogIn ();

}


public void LogIn()

{

Social.localUser.Authenticate ((bool success) => {

if (success) {

Debug.Log("You've successfully logged in");

tx_id.text = Social.localUser.id;

tx_userName.text = Social.localUser.userName;

//tx_Email.text = ((PlayGamesLocalUser)Social.localUser).Email + "-" + PlayGamesPlatform.Instance.GetUserEmail();

//fb.LogIn();

} else {

Debug.Log("Login failed for some reason : " + Social.Active);

Debug.Log("UserName : " + Social.localUser.userName);

Debug.Log("Id : " + Social.localUser.id);

}

/*

GooglePlayGames.OurUtils.PlayGamesHelperObject.RunOnGameThread(

() => {

Debug.Log("Local user's email is " + ((PlayGamesLocalUser)Social.localUser).Email);

});

*/

});

}


public void LogOut()

{

((PlayGamesPlatform)Social.Active).SignOut ();

tx_id.text = "No ID";

tx_userName.text = "No UserName";

//tx_Email.text = "No Email";

}

}



반응형
반응형

페이스북 앱을 만들었을경우 invitable_friends 를 가져 올수 있는데


유저의 해당 앱에 초대할 친구 목록이다 즉 가입이 안된 친구들 목록이다


나의 친구중


//해당앱에 초대된 유저

FB.API ("/me/friends?fields=id,name,picture", HttpMethod.GET, FriendListCallBack);

​//해당앱에 초대가 안된 유저 
FB.API ("/me/invitable_friends?fields=id,name,picture", HttpMethod.GET, InvitableFriendListCallBack);



​ using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;
using Facebook.MiniJSON;



public class FBHolder : MonoBehaviour {
    public GameObject DialogLoggedIn;
    public GameObject DialogLoggedOut;
    public GameObject DialogUserName;
    public GameObject DialogPrifilePic;

    public GameObject FriendListGm;
    public GameObject Invitable_FriendListGM;

    private Dictionary<string,string> friendListDic;
    private Dictionary<string,string> invitable_friendListDic;

    void Awake(){
        FB.Init (SetInit, OnHideUnity);    
    }

    private void SetInit(){

        //Screen.SetResolution( Screen.width, Screen.width * 16 / 9, true );

        Debug.Log ("FB init donw");

        if (FB.IsLoggedIn) {
            Debug.Log ("Fb Logged In");
        } else {
            Debug.Log ("Fb Not Logged In");
        }

        //DealWidthFBMenu (FB.IsLoggedIn);
    }


    private void OnHideUnity(bool isGameShown){
        if(isGameShown){
            Time.timeScale = 0;
        }else{
            Time.timeScale = 1;
        }
    }

    public void FbLogin(){

        List<string> permissions = new List<string> ();
        permissions.Add ("public_profile");

        FB.LogInWithReadPermissions (permissions, AuthCallBack);
    }

    void AuthCallBack(IResult result){
        if (result.Error != null) {
            Debug.Log (result.Error);
        } else {
            if (FB.IsLoggedIn) {
                Debug.Log ("Fb Logged In AuthCallBack");

            } else {
                Debug.Log ("Fb Not Logged In AuthCallBack");
            }

            DealWidthFBMenu (FB.IsLoggedIn);
        }
    }



    void DealWidthFBMenu(bool isLoggedIn){
        if (isLoggedIn) {
            DialogLoggedIn.SetActive (true);
            DialogLoggedOut.SetActive (false);

            FB.API ("/me?fields=first_name", HttpMethod.GET, DialogUserNameCallBack);
            FB.API ("/me/picture?type=square&height=128&width=128", HttpMethod.GET, DialogUserProfileImgCallBack);
            FB.API ("/me/friends?fields=id,name,picture", HttpMethod.GET, FriendListCallBack);
            FB.API ("/me/invitable_friends?fields=id,name,picture", HttpMethod.GET, InvitableFriendListCallBack);
        } else {
            DialogLoggedIn.SetActive (false);
            DialogLoggedOut.SetActive (true);
        }
    }


    void DialogUserNameCallBack(IResult result){
        Text UsetName = DialogUserName.GetComponent<Text> ();

        if (result.Error == null) {
            UsetName.text = "Hi there, " + result.ResultDictionary ["first_name"];
        } else {
            Debug.Log (result.Error);
        }
    }

    void DialogUserProfileImgCallBack(IGraphResult result){
        

        if (result.Texture != null) {
            Image ProfilePic = DialogPrifilePic.GetComponent<Image> ();
            ProfilePic.sprite = Sprite.Create (result.Texture, new Rect (0, 0, 128, 128), new Vector2 ());
        } else {
            Debug.Log (result.Error);
        }
    }


    //게임등록을 안한 유저 
    void InvitableFriendListCallBack(IResult result){
        if (result.Error != null) {
            Debug.Log ("Error : " + result.Error);
        } else {
            invitable_friendListDic =  FriendListParsing.Parsing (result.RawResult);
            SetText ( Invitable_FriendListGM , invitable_friendListDic);
        }
    }


    //게임등록을  유저 
    void FriendListCallBack(IResult result){
        if (result.Error != null) {
            Debug.Log ("Error : " + result.Error);
        } else {
            friendListDic = FriendListParsing.Parsing (result.RawResult);
            SetText (FriendListGm, friendListDic);
        }
    }


    //리스ㅌ트를 텍스트로 뿌려준다 
    void SetText(GameObject gm, Dictionary<string,string> dic){
        Text textField = gm.GetComponent<Text> ();
        foreach (KeyValuePair<string,string> pair in dic) {
            textField.text += string.Format ("{0}", pair.Key, pair.Value)+"\n";
        }
    }


        


}

파싱용 스크립트


using Facebook.MiniJSON;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using Facebook.Unity;

public class FriendListParsing {



    //친구 리스트 파싱 
    static public Dictionary<string,string> Parsing(string text){
        Debug.Log ("parsing " + text);

        //이곳에 json이 담겨져 있ㅏ 
        Dictionary<string, object> dict = (Dictionary<string,object>)Json.Deserialize (text);

        object friendsH;
        List<object> friends = new List<object> ();
        string friendName;

        Dictionary<string,string> friend = new Dictionary<string,string> ();

        if (dict.TryGetValue ("data", out friendsH)) {
            friends = (List<object>)dict ["data"];

            if (friends.Count > 0) {

                for (int i = 0; i< friends.Count; i++) {
                    Dictionary<string,object> friendDict = ((Dictionary<string,object>)(friends [i]));

                    friend [(string)friendDict ["name"]] = (string)friendDict ["name"];

                }
            }
        }


        return friend;
    }
}



http://blog.naver.com/brane7/220712830773


반응형

'Program > Unity' 카테고리의 다른 글

google sdk  (0) 2017.02.23
[Unity3D] Application.LoadLevel(string) is obsolete 마이그레이션  (0) 2017.02.20
반응형

http://worksp.tistory.com/10



유니티 5.3.1 f1 로 버전업 했더니, NGUI 에서 범상치 않은 워닝을 내뱉었다.


1
2
3
Assets/NGUI/Examples/Scripts/Other/LoadLevelOnClick.cs(15,37): 
warning CS0618: `UnityEngine.Application.LoadLevel(string)' is obsolete: 
`Use SceneManager.LoadScene'

cs



Application.LoadLevel 로 씬 이동 하던 것을 SceneManager.LoadScene 으로 사용하란다.


그래서 유니티의 바람대로 SceneManager.LoadScene 으로 고쳐썼더니 네임스페이스가 없다고 한다....


검색해보니 UnityEngine.SceneManagement 라는 네임 스페이스가 추가된 듯.. 



1
using UnityEngine.SceneManagement;
cs


위와 같이 네임스페이스를 추가하니 정상적으로 작동한다.




알고보니 유니티 5.3에서 멀티 씬 편집(Multi-Scene Editing) 을 지원한다고 한다.


아래와 같이 프로젝트 뷰 에서 오른쪽 클릭을 한 후, Open Scene Additive 를 클릭하면...




▼ 이렇게 하이라키 뷰에 여러 씬이 열린다.






또한 SceneManager 추가되었고, 덕분에 자주쓰는 메소드들도 거의 다 구식이 되어버렸다.


변경점은 다음과 같다. 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// old
Application.LoadLevel(0);                                       // 로드. 
Application.LoadLevel("SceneName");
AsyncOperation ao = Application.LoadLevelAsync(0);              // 로드. (비동기)
AsyncOperation ao = Application.LoadLevelAsync("SceneName");
Application.LoadLevelAdditive(0);                               // 씬 병합 추가. 
Application.LoadLevelAdditive("SceneName");
Application.LoadLevelAdditiveAsync(0);                          // 씬 병합 추가. (비동기)
Application.LoadLevelAdditiveAsync("SceneName");
Application.UnloadLevel(0);                                     // 언로드. 
Application.UnloadLevel("SceneName");
Application.levelCount;                                // BuildSetting 에 등록 된 씬 개수. 
Application.loadedLevel;                                        // 현재 씬 인덱스. 
Application.loadedLevelName;                                    // 현재 씬 이름. 
 
// 5.3
SceneManager.LoadScene(0);                                      // 로드. 
SceneManager.LoadScene("SceneName");
AsyncOperation ao = SceneManager.LoadSceneAsync(0);             // 로드. (비동기)
AsyncOperation ao = SceneManager.LoadSceneAsync("SceneName");
SceneManager.LoadScene(0, LoadSceneMode.Additive);              // 씬 병합 추가. 
SceneManager.LoadScene("SceneName", LoadSceneMode.Additive);
SceneManager.LoadSceneAsync(0, LoadSceneMode.Additive);         // 씬 병합 추가. (비동기)
SceneManager.LoadSceneAsync("SceneName", LoadSceneMode.Additive);
SceneManager.UnloadScene(0);                                    // 언로드. 
SceneManager.UnloadScene("SceneName");
SceneManager.sceneCount;                                        // 현재 로드 된 씬 개수. 
SceneManager.sceneCountInBuildSettings;                // BuildSetting 에 등록 된 씬 개수. 
SceneManager.GetActiveScene().buildIndex;                       // 현재 씬 인덱스. 
SceneManager.GetActiveScene().name;                             // 현재 씬 이름. 
 
// 씬 정보 조회. 
Scene activeScene = SceneManager.GetActiveScene();
Scene scene1 = SceneManager.GetSceneAt(0);
Scene scene2 = SceneManager.GetSceneByName("SceneName");
Scene scene3 = SceneManager.GetSceneByPath("Assets/SceneName.unity");
Scene[] loadedScenes = SceneManager.GetAllScenes();
 
// Scene 구조체. 
int buildIndex;
string name;
string path;
bool isLoaded;
bool isDirty;       // 씬을 변경(수정)했는지 여부. 
int rootCount;      // 씬의 Root에 있는 GameObject 개수. 
bool IsValid();     // 유효한 씬인지 여부. 
 
// 기타. 
Scene scene = gameObject.scene;                 // 게임오브젝트가 속해있는 씬을 가져오기. 
GameObject go = new GameObject("New Object");   // 게임오브젝트를 생성하면 현재 씬에 추가 됨. 
SceneManager.MoveGameObjectToScene(go, scene);      // 게임오브젝트를 다른 씬으로 이동. 
SceneManager.MergeScenes(sourceScene, destinationScene);    // 씬을 병합. 
 
// SceneManager.Get~() 으로 가져올 수 있는 것은 로드가 끝난 씬만 가능. 
Scene scene = SceneManager.GetSceneByName("SceneName");
bool isValid = scene.IsValid();     // false 가 리턴 됨.
cs



정리하다보니 꽤 많네;;;


아, 그리고 DontDestroyOnLoad 메소드 비스므리 한 것은 아예 없었는데,


Tips 를 참조해 보면, DontDestroyOnLoad 의 사용은 피하는 것이 좋고, Manager 씬을 만들어서 병합하는 것이 좋다고 한다.


앞으로 개발 시 참고해야 할 사항인 것 같다.



PS. Unity 5.3 에서는 과금 플러그인을 이용할 필요가 없을 수도 있겠다.


Unity Service Tab 에서 여러가지를(Unity Ads, Analytics, Cloud Build, In-App Purchasing, Multiplayer) 지원함..




반응형

'Program > Unity' 카테고리의 다른 글

google sdk  (0) 2017.02.23
Facebook - 로그인 - 친구리스트 불러오기  (0) 2017.02.23

+ Recent posts

반응형