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

【供養】アセットコピーするの作ったけどCtrl+Dで大体解決してた

Last updated at Posted at 2018-09-14

エディタ拡張書いたの初めてなので記念に
ただの供養です

using UnityEditor;
using UnityEngine;
using System.Linq;
using System.IO;


/// <summary>
/// 指定したオブジェクトをコピーするやつ~
/// </summary>
public class CopyWizard : ScriptableWizard
{

	public Object copyBaseAsset;
	public string baseName = "";

	[Multiline(20)]
	public string createNameList;


	private Object prevObject = null;
	[MenuItem("Custom/Copy")]
	static void Open()
	{
		DisplayWizard<CopyWizard>("一括コピー");
	}

	void OnWizardUpdate()
	{
		if (prevObject == copyBaseAsset) {
			return;
		}
		prevObject = copyBaseAsset;
		baseName = copyBaseAsset.name;
	}

	void OnWizardCreate()
	{
		var path = AssetDatabase.GetAssetPath(copyBaseAsset);

		var extension = Path.GetExtension(path);
		string dirPath = Path.GetDirectoryName(path);

		var list = createNameList.SplitLine().ToList();
		list.RemoveAll(str => {
			return str.IsNullOrEmpty();
		});

		for (int i = 0; i < list.Count; i++) {

			string fileName = baseName + list[i] + extension;
			fileName = fileName.Trim();
			string createPath = Path.Combine(dirPath, fileName);
			AssetDatabase.CopyAsset(path, createPath);
			AssetDatabase.ImportAsset(createPath);
		}
	}
}

image.png
BaseName + CreateNameListの改行で区切った分データができます

material_001 ~ 008まで できるよ

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