Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/// <summary>
/// ポップアップしてメッセージをユーザに伝える
/// Debug.LogErrorは読んでもらえないがち…それはそう…
/// </summary>
public class PopupContentMessage : PopupWindowContent
{
private string showmessage = "default message";
/// <summary>
/// サイズを取得する
/// </summary>
public override Vector2 GetWindowSize()
{
return new Vector2(300, 150);
}
/// <summary>
/// GUI描画
/// </summary>
public override void OnGUI(Rect rect)
{
GUIStyle centerbold = new GUIStyle()
{
//alignment = TextAnchor.MiddleCenter,
//fontStyle = FontStyle.Bold,
wordWrap = true,
richText = true
};
EditorGUILayout.LabelField(showmessage,centerbold);
//if (GUILayout.Button("OK"))
{
}
}
public void SetMessage(string newContent)
{
showmessage = newContent;
}
/// <summary>
/// 開いたときの処理
/// </summary>
public override void OnOpen()
{
}
/// <summary>
/// 閉じたときの処理
/// </summary>
public override void OnClose()
{
}
}
@neon-izm

This comment has been minimized.

Copy link
Owner Author

neon-izm commented Mar 15, 2019

Usage

HogeBehaviour.cs

private void OnGUI() 
{
      if(someErrorCaused)
      {
           // クリックした位置を視点とするRectを作る
           // 本来のポップアップの用途として使う場合はボタンのRectを渡す
           var mouseRect = new Rect(Event.current.mousePosition, Vector2.one);

           // PopupWindowContentを生成
           var content = new PopupContentMessage();

           content.SetMessage("something\n wrong \n たすけて");
            // 開く
           PopupWindow.Show(mouseRect, content);
      }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.