2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Unity】Projectウィンドウの現在のフォルダにAssetを作る。

Last updated at Posted at 2016-05-10

UnityにScriptableObjectを作るメニューを追加しようとして

あれ、
Projectウィンドウの現在いるフォルダにUnityで普通にAssetを作った時みたいに
名前も編集状態になるようにするにはどうすればよかったんだっけ?

と悩みまくったので記事に残して置こうと思う。
Assetを作るメニューを追加したときにいつも忘れてしまう。

MyMenu.cs
using UnityEngine;
using UnityEditor;

public class MyMenu
{
	/// <summary>
	/// 空のScriptableObjectを作る。
	/// </summary>
	[MenuItem("Assets/Create/ScriptableObject")]
	public static void createScriptableObject()
	{
		ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance<ScriptableObject>(), "New ScriptableObject.asset");
	}
}

AssetDatabase.CreateAssetではなくて
ProjectWindowUtil.CreateAssetを使う。

プロジェクトウィンドウを扱うのだから、ProjectWindowUtilを使うのは
当たり前のような話ですが、似たような機能が多くて混乱しますね。


この記事を書いたちょっと後に「UnityEngine.CreateAssetMenuAttribute」というものに出会う。

これを使えば、さっき書いた事がもっと簡単にできるという話です。
このページで詳しく書いてあるのでリンク貼っときます。
http://baba-s.hatenablog.com/entry/2015/06/13/000000

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?