Game Development Reference
In-Depth Information
the C# generics so that it can be reused for any type of SerializableObject you
want to throw at it. You don't have to use the class I provided; you can just use the code
earlier instead if you wish, just replace the code where the helper function is used.
Note
The C# generics is a fairly advanced C# topic, which we won't go into in this topic. If you
want to know more, check out http://msdn.microsoft.com/en-us/library/
ms379564(v=vs.80).aspx ; alternatively, it will be better to try The C# Programming Yel-
low Book , Rob Miles , Department of Computer Science , The University of Hull , which is a
fantastic C# primer topic available at http://www.robmiles.com/c-yellow-book/ .
To show how we use this, let's create our editor script, which will create the conversation
assets for us. Create a new folder in Assets\Scripts named Editor . In this folder,
create a new script named ConversationAssetCreator in the Editor folder un-
der Assets\Scripts and then replace its contents with the following code:
using UnityEditor;
using UnityEngine;
public class ConversationAssetCreator : MonoBehaviour {
[MenuItem("Assets/Create/Conversation")]
public static void CreateAsset()
{
CustomAssetUtility.CreateAsset<Conversation>();
}
}
So, by using the helper function, instead of all the tangle of code to first generate our asset
and then save it, we simply call our utility, tell it the type of asset we want to create (in
angle brackets), and away it goes. I have crated the utility as well so that it can also take a
string parameter if you want to force the folder you want to create the asset in; otherwise,
it will take whatever is currently selected in the editor.
To test this out, create a new folder in the Asset folder named Resources (so we can
call assets directly from the code if we so wish) and then create another folder in Re-
sources named Conversations . This just keeps all our conversations in one place
and doesn't clutter up the hierarchy. If you so wish, you could create further subfolders to
Search WWH ::




Custom Search