From the course: Unity 5: 2D Emulate Palette Swapping for Sprites

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Saving scriptable objects

Saving scriptable objects

- So now that we're able to get the path from the selected asset when we try to create our new color palette, let's actually look into how to save the scriptable object itself. In our Scripts folder, let's create a new C Sharp script, and we're gonna call this CustomAssetUtility. Let's open this up in MonoDevelop. Since this is gonna be a utility class, we won't need to extend mono behavior, and we can delete the Start and Update methods. Let's also include the UnityEditor name space. So now let's create a public static method that we can use to create our asset. Here, we'll type out public static. Our type is going to be a generic, so we're gonna use T to represent the return value. We're gonna call our method CreateAsset, and we're also gonna pass in T as the generic type, as well. Then we'll need the path, where to create our file, so this is going to be a string called path. And we wanna let the method know that T represents a scriptable object. Now let's close out the method…

Contents