LoginSignup
0
0

More than 5 years have passed since last update.

複数パスをUnity上でまとめて選択するウインドウ

Last updated at Posted at 2015-11-11

概要

Unityで作業していると異なるディレクトリにあるファイルを複数選択したい時がよくあります。
結構手間だったので複数パス貼り付けて一気にオブジェクトを選択するウインドウを作りました。

1.SourceTree等でクリップボードへのパスをコピー
2.カスタムウインドウにペースト
3.選択ボタンを押す

この操作でUnity上で簡単に複数オブジェクトの選択ができます。

スクリーンショット 2015-11-11 1.25.52.png

スクリーンショット 2015-11-12 1.32.01.png

コード

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

/// <summary>
/// パスからUnity上でまとめてオブジェクトを選択するセレクトするウインドウ. 
/// </summary>
public class CustomSelectWindow : EditorWindow {
    string text;

    [MenuItem ("Custom/PathSelector")]
    static void Init () {
        EditorWindow.GetWindow (typeof (CustomSelectWindow));
    }

    void OnGUI() {
        EditorGUILayout.HelpBox ("アセットのパスを改行かカンマで区切った文字列をペーストしてください", MessageType.Info);
        string prev = text;
        text = EditorGUILayout.TextArea (text, GUILayout.Height (120), GUILayout.ExpandWidth (true));

        if (GUILayout.Button ("選択", GUILayout.MaxWidth (100))) {
            Select(text);
        }
    }

    public static void Select(string paths)
    {
        paths = paths.Trim ();
        string[] split = paths.Split (new char[]{ '\n', ',' });
        List<Object> objs = new List<Object>();
        foreach (string path in split) {
            // Assetsから前は削除
            string fromAssets = path.Substring(path.IndexOf("Assets"));
            Object obj = AssetDatabase.LoadAssetAtPath (fromAssets, typeof(Object));
            if (obj) {
                Debug.Log ("Selection Add : " + fromAssets);
                objs.Add (obj);
            }
        }

        // 選択
        Selection.objects = objs.ToArray();
    }
}
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