Skip to content

Instantly share code, notes, and snippets.

@sakura-crowd
Created September 8, 2016 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakura-crowd/45bcf931788afc2674448663be681a11 to your computer and use it in GitHub Desktop.
Save sakura-crowd/45bcf931788afc2674448663be681a11 to your computer and use it in GitHub Desktop.
Unity5.4でモーダルダイアログもどきを作る ref: http://qiita.com/sakura-crowd/items/626a88808c1d3717fb73
using UnityEngine;
using System.Collections;
public class TrashBox : MonoBehaviour {
// エディタのインスペクタで、この変数にヒエラルキーにある Canvas を割り当ててください。
public Canvas canvasConfirmAllHoshiDelete = null;
// Use this for initialization
void Start() {
// ダイアログを表示するときまで、 Canvas を無効にしておく。
if (canvasConfirmAllHoshiDelete != null)
{
canvasConfirmAllHoshiDelete.enabled = false;
}
}
// クリックされた
void OnMouseUpAsButton()
{
confirmAllHoshiDelete();
}
// ダイアログを表示
public void confirmAllHoshiDelete()
{
// Canvas を有効にする
if (canvasConfirmAllHoshiDelete != null)
{
canvasConfirmAllHoshiDelete.enabled = true;
}
}
// Yes ボタンと関連づけたイベントハンドラ関数
public void onButtonYes()
{
// Canvas を無効にする。(ダイアログを閉じる)
canvasConfirmAllHoshiDelete.enabled = false;
// アイテムの削除処理(省略)
}
// No ボタンと関連づけたイベントハンドラ関数
public void onButtonNo()
{
// Canvas を無効にする。(ダイアログを閉じる)
canvasConfirmAllHoshiDelete.enabled = false;
}
}
if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
{
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment