So I came here because I had the same question, if there was a setting to specify a default location for new scripts when adding via the Add Component in the inspector button.
Since it seems that none exists, I sat and thought up my own solution. This one is using AssetPostProcessor to handle default locations for scripts
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.IO;
//purpose of this postprocessor is to ensure that listed file extensions
// are not in certain filepaths, when they are they are moved to a
//specified default path
public class FileImportHandler : AssetPostprocessor
{
//only evaluate files imported into these paths
static List<string> pathsToMoveFrom = new List<string>()
{
"Assets"
};
static Dictionary<string,string> defaultFileLocationByExtension = new Dictionary<string, string>()
{
{".mp4", "Assets/StreamingAssets/"},//for IOS, movies need to be in StreamingAssets
{".anim", "Assets/Art/Animations/"},
{".mat", "Assets/Art/Materials/"},
{".fbx", "Assets/Art/Meshes/"},
//Images has subfolders for Textures, Maps, Sprites, etc.
// up to the user to properly sort the images folder
{".bmp", "Assets/Art/Images/"},
{".png", "Assets/Art/Images/"},
{".jpg", "Assets/Art/Images/"},
{".jpeg", "Assets/Art/Images/"},
{".psd", "Assets/Art/Images/"},
{".mixer", "Assets/Audio/Mixers"},
//like images, there are sub folders that the user must manage
{".wav", "Assets/Audio/Sources"},
//like images, there are sub folders that the user must manage
{".cs", "Assets/Dev/Scripts"},
{".shader", "Assets/Dev/Shaders"},
{".cginc", "Assets/Dev/Shaders"}
};
static void OnPostprocessAllAssets (string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
foreach (string oldFilePath in importedAssets)
{
string directory = Path.GetDirectoryName(oldFilePath);
if(!pathsToMoveFrom.Contains(directory))
continue;
string extension = Path.GetExtension(oldFilePath).ToLower();
if(!defaultFileLocationByExtension.ContainsKey(extension))
continue;
string filename = Path.GetFileName(oldFilePath);
string newPath = defaultFileLocationByExtension[extension];
AssetDatabase.MoveAsset(oldFilePath, newPath +filename);
Debug.Log(string.Format("Moving asset ({0}) to path: {1}", filename, newPath));
}
}
}
remember that AssetPostprocessor scripts are Editor scripts (they are in the UnityEditor namespace) so they must be in the Editor folder to work
I just made this about 20 minutes ago and so far it seems to work just fine. though it seems it’ll also force any file with the listed extensions that is moved to one of the “paths to move from” it will also force move the file back to a default path.
that said this script should be nice for enforcing a clean folder hierarchy. hence why I expanded it to include other file extensions so that our teams art lead can enforce that art assets are imported into the correct folder