示例#1
0
        private void OnEnable()
        {
            builtInPath            = EditorApplication.applicationContentsPath + "/Resources/ScriptTemplates";
            customPath             = Application.dataPath + "/EditorDefaultResources/ScriptTemplates";
            builtInScriptTemplates = FindScriptTemplates(builtInPath, true);
            customScriptTemplates  = FindScriptTemplates(customPath, false);

            var listToSelectIn = selectedIsBuiltIn ? builtInScriptTemplates : customScriptTemplates;

            if (selectedIndex > 0 && selectedIndex < listToSelectIn.Count)
            {
                selectedTemplate = listToSelectIn[selectedIndex];
            }

            if (builtInScriptTemplates.Count > 0)
            {
                try {
                    builtInScriptTemplates[0].SaveToFile();
                    hasWriteAccessToBuiltins = true;
                }
                catch (UnauthorizedAccessException) {
                    hasWriteAccessToBuiltins = false;
                }
            }

            selectTemplateMenu = new GenericMenu();
            foreach (var template in customScriptTemplates)
            {
                selectTemplateMenu.AddItem(new GUIContent("Custom/" + template.name), false, TemplateSelected, template);
            }

            foreach (var template in builtInScriptTemplates)
            {
                selectTemplateMenu.AddItem(new GUIContent("Built in/" + template.name), false, TemplateSelected, template);
            }
        }
示例#2
0
 private void TemplateSelected(object template)
 {
     selectedTemplate = (ScriptTemplateFile)template;
 }