LoginSignup
10
10

More than 5 years have passed since last update.

【備忘録】読んだらにゅぅってでてくるYes/Noダイアログ

Last updated at Posted at 2014-06-15

なんかこんなの作った

使い方
* CommonDialog.Open("たいとる","めっせーじ",OKButtonEvent,NoButtonEvent);
Openの中ではInstantiateしていてそのInstantiateされた際にTweenがいい感じににゅぅってしてくれるだけ

↓実際に使っているダイアログの構成

6e707cd4110aaf12f15670ed8804f141.png

↓ソース

CommonDialog.cs
using UnityEngine;
using System.Collections;
using System;

public class CommonDialog : MonoBehaviour
{

    public UILabel Title = null;
    public UILabel Message = null;

    public UIButton AcceptButton;
    public UIButton DeclineButton; 
    public Action OnAccept = null;
    public Action OnDecline = null;

    static public void Open(string title, string message, Action accept, Action decline)
    {
// Prefabのパスは人によって違うので注意
        var clone = Instantiate( Resources.Load("Prefabs/SelectDialogPanel"),Vector3.zero,Quaternion.identity) as GameObject;
        var dialog = clone.GetComponent<CommonDialog>();

        dialog.SetDialog(title,message,accept,decline);
    }

    void Start()
    {
// UIRootに入った瞬間にスケールが直されるので一旦0にする
        transform.localScale = Vector3.zero;
    }

    public void SetDialog(string title, string message, Action accept, Action decline)
    {
        Title.text = title;
        Message.text = message;
        OnAccept = accept;
        OnDecline = decline;

        Title.UpdateNGUIText();
        Message.UpdateNGUIText();

        if (decline == null)
        {
            DeclineButton.gameObject.SetActive(false);
            AcceptButton.transform.position =new Vector3(0,AcceptButton.transform.position.y);
        }
    }

    public void OnAcceptButton()
    {
        if (OnAccept!=null)
            OnAccept();
        Close();
    }

    public void OnDeclineButton()
    {
        if (OnDecline!=null)
            OnDecline();
        Close();
    }

    void Close()
    {
        Destroy (this.gameObject);
    }
}

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10