Game Development Reference
In-Depth Information
46 {
47 //If selection empty, then exit
48 if (Selection.objects == null)
49 return;
50
51 //Current Increment
52 int PostFix = StartNumber;
53
54 //Cycle and rename
55 foreach(Object O in Selection.objects)
56 {
57 O.name = BaseName + PostFix;
58 PostFix += Increment;
59 }
60 }
61 //------------------------------------
62 }
63 //------------------------------------
The following are the comments for code sample 8-1:
•
Line 03
: The editor extensions should include the
UnityEditor
namespace
that allows you to access editor classes and objects.
•
Line 06
: The
BatchRename
class derives not from
MonoBehaviour
, as with
most script files, but from
ScriptableWizard
. Classes deriving from here
will be treated by Unity like independent utilities that may be launched from
the application menu.
•
Lines 17-21
: The
MenuItem
attribute is prefixed to the
CreateWizard
function. This creates a menu entry in the application menu listed under
Edit/Batch Rename
and invokes the
CreateWizard
function when clicked
on to display the
Batch Rename
window.
•
Lines 8-16
: After
CreateWizard
is invoked, the
BatchRename
window
shows. From here, all public class members (including
Base Name
,
Start
Number
, and
Increment
) will automatically feature in the window as
editable fields for the user.