<commit_before>/**
 * Created on 2017/03/20 by Inspoy
 * All rights reserved.
 */

using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace SF
{
    public class SFEditorUtils
    {
        /// <summary>
        /// prefabǷһϷUI View
        /// </summary>
        /// <param name="prefab">GameObject</param>
        /// <returns>ǷϷ</returns>
        public static bool checkUIValidation(GameObject prefab)
        {
            bool check = false;
            if (prefab != null)
            {
                string prefabName = prefab.name;
                if (prefabName.Substring(0, 2) == "vw")
                {
                    check = true;
                }
            }
            return check;
        }

        /// <summary>
        /// UI룬ԶPrefabViewű
        /// </summary>
        /// <param name="prefab">ָUI View</param>
        /// <param name="exportPresenter"></param>
        public static void generateUICode(GameObject prefab, bool exportPresenter)
        {
            string viewName = prefab.name.Substring(2);
            Debug.Log(string.Format("Generating SF{0}View{1}...", viewName, exportPresenter ? " with presenter" : ""));

            string viewContent = "";
            string presenterContent = "";
            getViewContent(prefab, out viewContent, out presenterContent);

            string viewFilepath = string.Format("Assets/Scripts/UI/SF{0}View.cs", viewName);
            var viewFile = new FileInfo(viewFilepath);
            var sw = viewFile.CreateText();
            sw.Write(viewContent);
            sw.Close();
            // ļͷע
            SFScriptHeaderGenerator.OnWillCreateAsset(viewFilepath);

            if (exportPresenter)
            {
                string presenterFilepath = string.Format("Assets/Scripts/UI/SF{0}Presenter.cs", viewName);
                var presenterFile = new FileInfo(presenterFilepath);
                var sw2 = presenterFile.CreateText();
                sw2.Write(presenterContent);
                sw2.Close();
                // ļͷע
                SFScriptHeaderGenerator.OnWillCreateAsset(presenterFilepath);
            }

            // PrefabViewű
            string componentName = "SF" + viewName + "View";
            AssetDatabase.Refresh();
            var component = prefab.GetComponent(System.Type.GetType(componentName));
            if (component != null)
            {
                GameObject.DestroyImmediate(component);
            }
            prefab.AddComponent(System.Type.GetType(componentName));<commit_msg>- UIExporter现在可以自动挂载脚本了<commit_after>/**
 * Created on 2017/03/20 by Inspoy
 * All rights reserved.
 */

using System;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace SF
{
    public class SFEditorUtils
    {
        /// <summary>
        /// prefabǷһϷUI View
        /// </summary>
        /// <param name="prefab">GameObject</param>
        /// <returns>ǷϷ</returns>
        public static bool checkUIValidation(GameObject prefab)
        {
            bool check = false;
            if (prefab != null)
            {
                string prefabName = prefab.name;
                if (prefabName.Substring(0, 2) == "vw")
                {
                    check = true;
                }
            }
            return check;
        }

        /// <summary>
        /// UI룬ԶPrefabViewű
        /// </summary>
        /// <param name="prefab">ָUI View</param>
        /// <param name="exportPresenter"></param>
        public static void generateUICode(GameObject prefab, bool exportPresenter)
        {
            string viewName = prefab.name.Substring(2);
            Debug.Log(string.Format("Generating SF{0}View{1}...", viewName, exportPresenter ? " with presenter" : ""));

            string viewContent = "";
            string presenterContent = "";
            getViewContent(prefab, out viewContent, out presenterContent);

            string viewFilepath = string.Format("Assets/Scripts/UI/SF{0}View.cs", viewName);
            var viewFile = new FileInfo(viewFilepath);
            var sw = viewFile.CreateText();
            sw.Write(viewContent);
            sw.Close();
            // ļͷע
            SFScriptHeaderGenerator.OnWillCreateAsset(viewFilepath);

            if (exportPresenter)
            {
                string presenterFilepath = string.Format("Assets/Scripts/UI/SF{0}Presenter.cs", viewName);
                var presenterFile = new FileInfo(presenterFilepath);
                var sw2 = presenterFile.CreateText();
                sw2.Write(presenterContent);
                sw2.Close();
                // ļͷע
                SFScriptHeaderGenerator.OnWillCreateAsset(presenterFilepath);
            }

            // PrefabViewű
            string componentName = "SF" + viewName + "View";
            AssetDatabase.ImportAsset(viewFilepath);
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            var component = prefab.GetComponent(componentName);
            if (component != null)
            { 
                GameObject.DestroyImmediate(component, true);
            }
            prefab.AddComponent(getTypeByName(componentName));
            Debug.Log("Generated!");
        }

        private static Type getTypeByName(string className)
        {
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (type.Name == className)
                    {
                        return type;
                    }
                }
            }
            return null;
{'fraction_non_alphanumeric': 0.10676095205243187, 'fraction_numerical': 0.006209037599172128, 'mean_word_length': 1.6467366499315381, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1994692', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1512, 'n_words': 295}