코루틴에서 CallBack 함수 적용하기


작업소스 
http://freebox.myqnapcloud.com:8080/share.cgi?ssid=05TshSe



using UnityEngine;
using System.Collections;
using System; // System 네임스페이스 Action을 사용하려면 System 네임스페이스가 있어야 한다.
 
// 코루틴 콜백 1초뒤에 값을 콜백
public class CallBackTest : MonoBehaviour
{
    void Start()
    {
        // 3 : 값을 적용
        StartCoroutine(Get(10, 20, Add));
    }
 
    // 2 : 적용된 값을 출력 
    void Add(int result)
    {
        print("result " + result);
    }
 
    // 1 : 1초 뒤에 정해진 값을 fun(result); result에 넣어주고 
    IEnumerator Get(int a, int b, Action<int> fun) //Action = 델리게이트
    {
        yield return new WaitForSeconds(1);
 
        int result = a + b;
 
        fun(result);
    }
 
}
==
https://graph.facebook.com/857177887702829/picture <- 페이스북 사진 주소



===== [  정보 클래스 싱글턴으로 만들기 ] =====



using UnityEngine;
using System.Collections;
using System.Collections.Generic;
 
// 플레이어( 친구 정보를 담을 클래스)
public class UserItem
{
    // 생성자 함수
   public UserItem(long id, string name){
        this.id = id;
        this.nickName = name;
    }
    public string nickName;
    public long id;
    public Texture picture;
    public int score;
    public int heart;
}
 
 
public class PlayerData : MonoBehaviour {
 
    // PlayerData 클래스 스태틱으로 만들기(싱글턴) 씬이 바뀌어도 클래스에 접근이 가능하다.
    static PlayerData instance = null;
 
    public string nickName;
    public Texture picture; // Texture : 스프라이트 속성을 가지기 이전의 순수한 이미지 데이터
    public long id;
    
    // 친구 정보를 담을 딕셔너리< 키, 값 >    
    public IDictionary<longUserItem> items = new Dictionary<longUserItem>();
 
 
    public static PlayerData Inst
    {
        get
        {
            return instance;
        }
    }
 
 
    void Start () 
    {
        
        instance = this// this : PlayerData의 주소값 즉, 자기 자신의 주소값을 대입.
 
        // 씬이 바뀌어도 현재(this) 클래스는 보존하도록 한다.
        DontDestroyOnLoad(this); ;
 
 
    }
 
 
    public void ToLobby()
    {
        Application.LoadLevel("Lobby");
    }
 
}






댓글

이 블로그의 인기 게시물

날짜 시간 시간차 시간 계산 하기

C++ 언어 퍼센트 구하는 방법 / 기본 언어 퍼센트 구하는 방법