Esempio n. 1
0
        //------------------------------------------------------------------------------
        public override void OnInspectorGUI()
        {
            m_targetTemplate = target as XenoTemplate;
            Undo.RecordObject(m_targetTemplate, "Modify template");

            if (m_selectedElement >= m_targetTemplate.TemplateElements.Count)
            {
                SelectLastElement();
            }

            SetupGuiStyles();

            SaveAndRefreshGUI();

            TemplateElementsGUI();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            TemplateDetailsGUI();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }

            HandleDragAndDrop(m_elementSelectorRect, m_elementDetailsRect);
        }
Esempio n. 2
0
        //------------------------------------------------------------------------------
        private static XenoTemplate ExtractTemplatesNew(String templateFilePath)
        {
            XenoTemplate template = AssetDatabase.LoadAssetAtPath(
                templateFilePath,
                typeof(XenoTemplate)
                ) as XenoTemplate;

            return(template);
        }
Esempio n. 3
0
        //------------------------------------------------------------------------------
        public static void GenerateFiles(String templateFilePath, String userSuppliedName, String targetPath)
        {
            if (!File.Exists(templateFilePath))
            {
                return;
            }

            String templateExtension = Path.GetExtension(templateFilePath);

            if (templateExtension == ".asset")
            {
                XenoTemplate template = ExtractTemplatesNew(templateFilePath);

                // Generate per-instance data
                foreach (XenoTemplateElement element in template.TemplateElements)
                {
                    element.GenerateInstanceData(userSuppliedName, targetPath);
                }

                // Build a token replacement table for all sub-templates
                Dictionary <String, String> tokenReplacements = new Dictionary <String, String>();
                LoadCustomMappings(ref tokenReplacements);

                tokenReplacements.Add(@"%TEMPLATE_TOKEN%", userSuppliedName);

                foreach (XenoTemplateElement element in template.TemplateElements)
                {
                    String token = String.Format(@"%TEMPLATE_NAME\({0}\)%", element.ElementName);
                    tokenReplacements.Add(token, element.InstanceName);
                }

                // Generate one new asset file for each subTemplate
                foreach (XenoTemplateElement element in template.TemplateElements)
                {
                    GenerateFileFromTemplateElement(element, tokenReplacements);
                }
            }
            else
            {
                Debug.LogErrorFormat(
                    "Unable to generate files from unknown template type: \"{0}\"",
                    templateFilePath
                    );
            }
        }
Esempio n. 4
0
        //------------------------------------------------------------------------------
        public static void GenerateFileNames(String templateFilePath, String userSuppliedName, ref List <String> fileNames, ref String error)
        {
            fileNames.Clear();
            error = String.Empty;

            if (!File.Exists(templateFilePath))
            {
                return;
            }

            String targetPath = EditorUtils.GetDirectoryPathOfSelectedAsset();

            if (targetPath == null)
            {
                targetPath = "Assets";
            }

            String templateExtension = Path.GetExtension(templateFilePath);

            if (templateExtension == ".asset")
            {
                XenoTemplate template = ExtractTemplatesNew(templateFilePath);
                if (template == null)
                {
                    error = String.Format(
                        "Incompatible template \"{0}\". Is it from a later version of Unity?",
                        templateFilePath
                        );
                    return;
                }

                foreach (XenoTemplateElement element in template.TemplateElements)
                {
                    element.GenerateInstanceData(userSuppliedName, targetPath);
                    fileNames.Add(String.Format("{0}{1}", element.InstanceName, element.Extension));
                }
            }
            else
            {
                error = String.Format(
                    "Unable to generate files from unknown template type: \"{0}\"",
                    templateFilePath
                    );
            }
        }
Esempio n. 5
0
        //
        // Public menu methods
        //

        //------------------------------------------------------------------------------
        public static void CreateXenoTemplate(string path)
        {
            XenoTemplate template = ScriptableObject.CreateInstance <XenoTemplate>();

            //String targetPath = EditorUtils.ValidateAssetPath(
            //    EditorUtils.GetDirectoryPathOfSelectedAsset(),
            //    XenoTemplateTool.TemplateFileFolderName
            //);

            String rawPath = String.Format("{0}/NewXenoTemplate.asset", path);

            //String uniquePath = AssetDatabase.GenerateUniqueAssetPath(rawPath);

            AssetDatabase.CreateAsset(template, rawPath);
            AssetDatabase.SetLabels(template, new String[] { XenoTemplateTool.TemplateLabel });

            Selection.activeObject = template;
        }