- Home /
How can I list all scripts at a path.
Hi there,
I want to list the scripts at a asset path, recursively, in c#. I also want to be able to grab the file in code and then be able to add it to game objects and do whatever.
Basically do what the Project Tree does.
How can I do this? should I use .Net libraries to achieve this?
Answer by Skjalg · Dec 14, 2010 at 12:12 AM
I ended up doing something like this (copy pasted from different places, so it doesnt add up, but you should get the general idea).
List<DirectoryInfo> directoryInfos = new List<DirectoryInfo>(dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly));
List<FileInfo> fileInfos = new List<FileInfo>(directoryInfo.GetFiles(fileMask, SearchOption.TopDirectoryOnly));
UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(filePath.Remove(0, path), type);
MonoScript script = obj as MonoScript; if (script) { Type scriptType = script.GetClass(); if (scriptType.IsSubclassOf(typeof(MonoBehaviour))) { UnityEngine.Object obj = UnityEngine.Object.FindObjectOfType(scriptType); MonoBehaviour mono = obj as MonoBehaviour; } }
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
A node in a childnode? 1 Answer
instantiate problem help? 1 Answer
Trying to Recreate Transform Child Heirarchy to a List 2 Answers
problem in minimax algorithm 1 Answer