- Home /
Automated prefab script switching?
Greetings!
In the process of converting my project from UnityScript to C#, I'd like to automate the switching of scripts on my existing prefabs. They're all using the old UnityScript scripts, and I'd like to change them all to use the new C# versions.
Maybe there's already a tool out there, on the Asset Store or otherwise, that could get the job done. I couldn't find any, so I looked into creating my own editor script to do that, but I'm not quite sure where to start as the documentation is rather limited on the subject. For instance, I couldn't figure out how to access the prefabs in a project. Here's the very general algorithm I had in mind:
for each prefab in the project
for each component in the prefab
if it is a UnityScript
switch it for the C# script of the same name
Does that make any sense?
Thanks for helping out!
Well, I see a problem with class names. If your new C# script implement the same class as your old script you have the class two times. But if you can circumvent this problem you can of course use an editor script. Some classes that might help: Selection, AssetDatabase, EditorUtility. You can add a new component the same way as you do at runtime, use AddComponent and make sure you save your changes. I always do it that way: Instantiate the old prefab, apply your changes, use EditorUtility.ReplacePrefab to update the prefab.
Hmmm ,although you mgith have a poitn about class names, I'm quite sure I've had both a UnityScript and a C# one coexist at the same time without any problems. Oh well, thanks for the tips!
Answer by microp · May 01, 2011 at 05:25 PM
The information provided by Bunny83 sounds like a good starting point. Thanks!
Your answer
Follow this Question
Related Questions
Automatically update prefab instance 1 Answer
Script is working incorrectly. (rotation) 1 Answer
Monster Spawner 3 Answers
How to provide undo for EditorScript changes to a prefab? 1 Answer
Need help converting Javascript to C# 3 Answers