public void OnButtonCharacterShow(){

print ("show");

DialogMgr.ShowDialog(CharacterSelectPrefab, OnCharacterSelectOk, OnCharacterSelectCancel, "Character Select", "Buy ??");

}


void OnCharacterSelectOk(){

print ("Select ok");

}

void OnCharacterSelectCancel(){

print ("Select Cancel");

}

//////////////////////////////////////////////////////////

using UnityEngine;

using System.Collections;


public class DialogMgr : MonoBehaviour{

static GameObject DialogPrefab;

static GameObject DialogParent;

static GameObject DialogPurchasePrefab;

static GameObject DialogPurchaseParent;

static string title = "Game Purchase";

static string message = "";

//static GameObject AddressDialogPrefab;

//static GameObject AddressDialogParent;

public static void ShowDialog(GameObject prefab, Dialog.OnButtonEvent okFunction, Dialog.OnButtonEvent cancelFunction,

string title, string message){

if(null == DialogParent){

UICamera cam = GameObject.FindObjectOfType<UICamera>();

DialogParent = cam.gameObject;

}

GameObject obj = null;

if (prefab == null) {

Debug.LogError("prefab is null");

return;

}

else {

obj = NGUITools.AddChild(DialogParent, prefab);

obj.transform.position = new Vector3(0.0f, 0.0f, -1.5f);

}

Dialog dlg = obj.GetComponent<Dialog>();

dlg.Title.text = title;

dlg.Message.text = message;

dlg.eventButtonOk += okFunction;

dlg.eventButtonCancel += cancelFunction;

NGUITools.AdjustDepth(obj, 100);

}

/*

public static void ShowAddressDialog( Dialog.OnButtonEvent okFunction, Dialog.OnButtonEvent cancelFunction){

if(null == AddressDialogParent){

UICamera cam = GameObject.FindObjectOfType<UICamera>();

AddressDialogParent = cam.gameObject;

}

if(null == AddressDialogPrefab){

DialogPrefab = Resources.Load("Prefabs/AddressBody") as GameObject;

}

GameObject obj = NGUITools.AddChild(AddressDialogParent, AddressDialogPrefab);

Dialog dlg = obj.GetComponent<Dialog>();

//dlg.Title.text = title;

//dlg.Message.text = message;

dlg.eventButtonOk += okFunction;

dlg.eventButtonCancel += cancelFunction;

NGUITools.AdjustDepth(obj, 100);

}

*/

public static void ShowPurchaseDialog(Dialog.OnButtonEvent okFunction, Dialog.OnButtonEvent cancelFunction){

if(null == DialogPurchaseParent){

UICamera cam = GameObject.FindObjectOfType<UICamera>();

DialogPurchaseParent = cam.gameObject;

}

if(null == DialogPurchasePrefab){

DialogPurchasePrefab = Resources.Load("Prefabs/Player_BackGround") as GameObject;

}

GameObject obj1 = NGUITools.AddChild(DialogPurchaseParent, DialogPurchasePrefab);

Dialog dlgPurchase = obj1.GetComponent<Dialog>();

dlgPurchase.Title.text = title;

dlgPurchase.Message.text = message;

dlgPurchase.eventButtonOk += okFunction;

dlgPurchase.eventButtonCancel += cancelFunction;

NGUITools.AdjustDepth(obj1, 300);

}

// Use this for initialization

void Start () {

}

// Update is called once per frame

void Update () {

}

}


Dummy.prefab


+ Recent posts