LoginSignup
2
0

More than 3 years have passed since last update.

【爆速メモ】コンポーネントにヘルプボックスを出したい(unity)

Posted at

コンポーネントにヘルプボックスが表示されていると非常にわかりやすいですよね。
自分はわかりやすいです。
たぶん一週間後の自分とかが非常に助かると思います。
a05.png

なので、自分でもコピペして使えるよう爆速しています。


まずはスクリプトを2つ作ります

ひとつは、コンポーネントをカスタマイズする用
(InspectorのEditの意でテスト命名しました)
a01.png

ふたつめは、普段どおりのスクリプト
(みんな大好き、当記事で好評のxyzの数値入力で自動回転する用のスクリプトです)
a02.png


【コンポーネントをカスタマイズする用のスクリプトはこんなかんじ】
(今回だと、InsEdit.csで作ったやつ)
はじめてさわる場合(自分がそうだった)、ものびへいばーが、えでぃたーに変わったり、
ぱぶりっく おーばーらいど とか書く必要があったり、
そもそも対象のスクリプトと双方向で指定し合う必要があるので、

そのあたりは、「自分はいま、なんのスクリプトを書いているんだろう?」の認識が求められます。

using UnityEngine;
using UnityEditor;

[CanEditMultipleObjects]
[CustomEditor(typeof(autorot))]
public class InsEdit : Editor
{
    public override void OnInspectorGUI()
    {
        //ヘルプボックスを表示 
        EditorGUILayout.HelpBox("x,y,zの数値入力で自動回転します", MessageType.Info);

        base.OnInspectorGUI();

        GUIStyle style = new GUIStyle(EditorStyles.label);
    }
}


【autorot.csは、カスタマイズするので少し追記するところがあります】

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[AddComponentMenu("InsEdit")]
public class autorot : MonoBehaviour
{
    public float Rot_x;
    public float Rot_y;
    public float Rot_z;

    void Update()
    {
        transform.Rotate(Rot_x, Rot_y, Rot_z);
    }
}

【できあがり】
a04.png


カスタム元の自動回転は、こちらの記事からどうぞ!!

【unity】x,y,zを数値入力すれば、ひたすら自動回転するオブジェクトであそぼう
https://qiita.com/sanpeita/items/96b937f3bfcf93382852

2
0
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
2
0