x


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?

more ▼

asked Dec 08 '10 at 12:57 AM

Skjalg gravatar image

Skjalg
1.4k 24 33 50

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
     }
}
more ▼

answered Dec 14 '10 at 12:12 AM

Skjalg gravatar image

Skjalg
1.4k 24 33 50

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5061
x354
x15
x3

asked: Dec 08 '10 at 12:57 AM

Seen: 1054 times

Last Updated: Jan 03 '11 at 12:48 AM