├── Editor.meta ├── Editor ├── AssetInspector.Editor.asmdef ├── AssetInspector.Editor.asmdef.meta ├── AssetInspectorWindow.cs └── AssetInspectorWindow.cs.meta ├── LICENSE.md ├── LICENSE.md.meta ├── README.md ├── README.md.meta ├── package.json └── package.json.meta /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e9daef89d4614c7abbd29198147000a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/AssetInspector.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "AssetInspector.Editor", 3 | "references": [], 4 | "optionalUnityReferences": [], 5 | "includePlatforms": [ 6 | "Editor" 7 | ], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [] 14 | } -------------------------------------------------------------------------------- /Editor/AssetInspector.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: deef0e5dc00844ffbbab75c4047909a8 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/AssetInspectorWindow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | public class AssetInspectorWindow : EditorWindow 7 | { 8 | 9 | [MenuItem("Window/Asset Inspector")] 10 | static void Init() 11 | { 12 | AssetInspectorWindow editor = (AssetInspectorWindow)EditorWindow.GetWindow(typeof(AssetInspectorWindow)); 13 | editor.titleContent = new GUIContent("Asset Inspector"); 14 | } 15 | 16 | [MenuItem("CONTEXT/Object/Delete Child Asset")] 17 | static void DeleteChildAssetMenuItem(MenuCommand command) 18 | { 19 | if (EditorUtility.DisplayDialog("Delete selected asset?", " " + AssetDatabase.GetAssetPath(command.context) + "\n - " + command.context.name + "\n\nYou cannot undo this action.", "Delete", "Cancel")) 20 | { 21 | string assetPath = AssetDatabase.GetAssetPath(command.context); 22 | AssetImporter assetImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(command.context)); 23 | Object mainAsset = AssetDatabase.LoadMainAssetAtPath(assetPath); 24 | Object.DestroyImmediate(command.context, true); 25 | EditorUtility.SetDirty(assetImporter); 26 | assetImporter.SaveAndReimport(); 27 | Selection.activeObject = mainAsset; 28 | } 29 | } 30 | 31 | [MenuItem("CONTEXT/Object/Delete Child Asset", true)] 32 | static bool DeleteChildAssetMenuItemValidate(MenuCommand command) 33 | { 34 | return !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(command.context)) 35 | && !AssetDatabase.IsMainAsset(command.context); 36 | } 37 | 38 | [MenuItem("CONTEXT/Object/Copy Asset")] 39 | static void CopyAssetMenuItem(MenuCommand command) 40 | { 41 | m_AssetCopySource = System.Activator.CreateInstance(command.context.GetType()) as Object; 42 | EditorUtility.CopySerialized(command.context, m_AssetCopySource); 43 | } 44 | 45 | [MenuItem("CONTEXT/Object/Copy Asset", true)] 46 | static bool CopyAssetMenuItemValidate(MenuCommand command) 47 | { 48 | return !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(command.context)); 49 | } 50 | 51 | [MenuItem("CONTEXT/Object/Paste Asset Data")] 52 | static void PasteAssetMenuItem(MenuCommand command) 53 | { 54 | EditorUtility.CopySerialized(m_AssetCopySource, command.context); 55 | } 56 | 57 | [MenuItem("CONTEXT/Object/Paste Asset Data", true)] 58 | static bool PasteAssetMenuItemValidate(MenuCommand command) 59 | { 60 | return !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(command.context)) 61 | && m_AssetCopySource 62 | && m_AssetCopySource.GetType() == command.context.GetType(); 63 | } 64 | 65 | [MenuItem("CONTEXT/Object/Paste Asset As Child")] 66 | static void PasteAssetAsChildMenuItem(MenuCommand command) 67 | { 68 | Object assetCopy = System.Activator.CreateInstance(m_AssetCopySource.GetType()) as Object; 69 | EditorUtility.CopySerialized(m_AssetCopySource, assetCopy); 70 | AssetDatabase.AddObjectToAsset(assetCopy, Selection.activeObject); 71 | AssetDatabase.SaveAssets(); 72 | AssetDatabase.Refresh(); 73 | } 74 | 75 | [MenuItem("CONTEXT/Object/Paste Asset As Child", true)] 76 | static bool PasteAssetAsChildMenuItemValidate(MenuCommand command) 77 | { 78 | return !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(command.context)) 79 | && m_AssetCopySource; 80 | } 81 | 82 | static Object m_AssetCopySource = null; 83 | Vector2 m_ScrollPosition; 84 | Dictionary m_Folds = new Dictionary(); 85 | 86 | void OnGUI() 87 | { 88 | m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition, new GUILayoutOption[0]); 89 | EditorGUILayout.Space(); 90 | DrawAssets(); 91 | EditorGUILayout.EndScrollView(); 92 | } 93 | 94 | void OnSelectionChange() 95 | { 96 | m_Folds.Clear(); 97 | Repaint(); 98 | } 99 | 100 | void DrawAssets() 101 | { 102 | Object activeObject = Selection.activeObject; 103 | if (!activeObject) 104 | return; 105 | 106 | string assetPath = AssetDatabase.GetAssetPath(activeObject); 107 | if (string.IsNullOrEmpty(assetPath)) 108 | return; 109 | 110 | AssetImporter assetImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(activeObject)); 111 | 112 | string newAssetPath = EditorGUILayout.DelayedTextField("Asset Path", assetPath); 113 | SelectableLabelField("GUID", AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(activeObject))); 114 | SelectableLabelField("Time Stamp", assetImporter.assetTimeStamp.ToString()); 115 | assetImporter.userData = TextAreaField("User Data", assetImporter.userData); 116 | 117 | if (newAssetPath != assetPath) 118 | AssetDatabase.MoveAsset(assetPath, newAssetPath); 119 | 120 | EditorGUI.indentLevel++; 121 | 122 | Object[] allAsset = activeObject.GetType() != typeof(SceneAsset) ? 123 | AssetDatabase.LoadAllAssetsAtPath(assetPath).Where(asset => asset != null).ToArray() : 124 | new Object[] { activeObject }; 125 | 126 | foreach (Object asset in allAsset) 127 | DrawAssetElement(asset); 128 | 129 | EditorGUI.indentLevel--; 130 | } 131 | 132 | void DrawAssetElement(Object asset) 133 | { 134 | int instanceID = asset.GetInstanceID(); 135 | m_Folds[instanceID] = EditorGUILayout.InspectorTitlebar(GetFold(instanceID), asset); 136 | if (m_Folds[instanceID]) 137 | { 138 | EditorGUI.BeginChangeCheck(); 139 | asset.name = EditorGUILayout.TextField("Name", asset.name); 140 | asset.hideFlags = (HideFlags)EditorGUILayout.EnumPopup("Hide Flags", asset.hideFlags); 141 | if (EditorGUI.EndChangeCheck()) 142 | AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(asset)).SaveAndReimport(); 143 | 144 | GUI.enabled = !AssetDatabase.IsMainAsset(asset); 145 | EditorGUI.BeginChangeCheck(); 146 | bool isMainAsset = EditorGUILayout.Toggle("Is Main Asset", AssetDatabase.IsMainAsset(asset)); 147 | if (EditorGUI.EndChangeCheck() && isMainAsset) 148 | SetMainObject(asset); 149 | GUI.enabled = true; 150 | } 151 | } 152 | 153 | bool GetFold(int instanceID) 154 | { 155 | if (!m_Folds.ContainsKey(instanceID)) 156 | { 157 | m_Folds[instanceID] = Selection.objects.Any(o => o.GetInstanceID() == instanceID); 158 | } 159 | return m_Folds[instanceID]; 160 | } 161 | 162 | static void SetMainObject(Object asset) 163 | { 164 | string assetPath = AssetDatabase.GetAssetPath(asset); 165 | AssetImporter assetImporter = AssetImporter.GetAtPath(assetPath); 166 | string name = asset.name; 167 | string newPath = System.IO.Path.GetDirectoryName(assetPath) + System.IO.Path.AltDirectorySeparatorChar + name + System.IO.Path.GetExtension(assetPath); 168 | string validate = AssetDatabase.ValidateMoveAsset(assetPath, newPath); 169 | if (string.IsNullOrEmpty(validate) || assetPath == newPath) 170 | { 171 | AssetDatabase.SetMainObject(asset, AssetDatabase.GetAssetPath(asset)); 172 | EditorUtility.SetDirty(assetImporter); 173 | assetImporter.SaveAndReimport(); 174 | AssetDatabase.MoveAsset(assetPath, newPath); 175 | assetPath = newPath; 176 | } 177 | else 178 | { 179 | Debug.Log(validate); 180 | } 181 | } 182 | 183 | static void SelectableLabelField(string key, string val) 184 | { 185 | EditorGUILayout.BeginHorizontal(); 186 | EditorGUILayout.PrefixLabel(key); 187 | int indentLevel = EditorGUI.indentLevel; 188 | EditorGUI.indentLevel = 0; 189 | EditorGUILayout.SelectableLabel(val, GUILayout.Height(16)); 190 | EditorGUI.indentLevel = indentLevel; 191 | EditorGUILayout.EndHorizontal(); 192 | } 193 | 194 | static string TextAreaField(string label, string text, params GUILayoutOption[] options) 195 | { 196 | EditorGUILayout.BeginHorizontal(); 197 | EditorGUILayout.PrefixLabel(label); 198 | int indentLevel = EditorGUI.indentLevel; 199 | EditorGUI.indentLevel = 0; 200 | string newText = EditorGUILayout.TextArea(text, options); 201 | EditorGUI.indentLevel = indentLevel; 202 | EditorGUILayout.EndHorizontal(); 203 | return newText; 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /Editor/AssetInspectorWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c2d73c7d6616f4035829b177ec352de4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 johnsoncodehk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 68e8794075a2a4d0ca03715be8a7df38 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # unity-asset-inspector 2 | 3 | ### Setup 4 | 5 | The following line needs to be added to your Packages/manifest.json file in your Unity Project under the dependencies section: 6 | 7 | ```json 8 | "com.johnsoncodehk.unity-asset-inspector": "https://github.com/johnsoncodehk/unity-asset-inspector.git" 9 | ``` 10 | 11 | ### How To Use 12 | 13 | 1. Open the window from Window/Asset Inspector. 14 | 2. Select a asset from Project window to edit. 15 | 16 | ### Editable fileds 17 | 18 | #### Asset Meta Data 19 | 20 | - File Name 21 | - User Data 22 | - Main Object 23 | 24 | #### Child Asset 25 | 26 | - Name 27 | - Hide Flags 28 | 29 | ### Asset MenuItem 30 | 31 | - Delete Child Asset 32 | - Copy Asset 33 | - Paste Asset Data 34 | - Paste Asset As Child 35 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7ac702a50e4c94d45b0001d5c257f868 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.johnsoncodehk.unity-asset-inspector", 3 | "displayName": "Asset Inspector", 4 | "version": "1.0.0", 5 | "description": "", 6 | "dependencies": {} 7 | } -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17d5af2ae82c142d9933a209e469320f 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------