1
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 1 year has passed since last update.

Unityで保存したプレハブにショートカットで飛べる機能を作った

Last updated at Posted at 2022-10-23

ソースコード

using System;
using UnityEditor;
using UnityEngine;

public class SelectLastSavedPrefab
{
    private const string SavePrefabKey = "save_prefab_key";

    [MenuItem("SavePrefabPath/LoadAsset #&p")]
    private static void SelectLastSelectPrefab()
    {
        try
        {
            var loadAssetGUID = PlayerPrefs.GetString(SavePrefabKey);
            var assetPath = AssetDatabase.GUIDToAssetPath(loadAssetGUID);
            var TargetAssets =
                AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
            Selection.activeObject = TargetAssets;
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }

    [MenuItem("SavePrefabPath/LoadAsset #&l")]
    private static void SaveLastSelectPrefab()
    {
        try
        {
            var selection = Selection.assetGUIDs[0];
            var assetPath = AssetDatabase.GUIDToAssetPath(selection);
            var TargetAssets =
                AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
            if (TargetAssets == null)
            {
                Debug.LogWarning($"{assetPath} is Not GameObject!");
                return;
            }

            PlayerPrefs.SetString(SavePrefabKey, Selection.assetGUIDs[0]);
            PlayerPrefs.Save();
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }
}

使い方

  • プレハブの参照のセーブ

    • mac
      • Shift + Option + L
    • windows
      • Shift + Alt + L
  • プレハブの参照のロード

    • mac
      • Shift + Option + P
    • windows
      • Shift + Alt + P

もしくはメニューから開けます!
メニュー.png

これを使うシチュエーション

作業をしていてプレハブの更新をした後に、作業していたプレハブに戻るのがちょっとだけ楽になれます

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