Exemplo n.º 1
0
        /// <summary>
        /// Generate AssetPostprocessor editor script file.
        /// </summary>
        protected override void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp)
        {
            ExcelMachine machine = target as ExcelMachine;

            sp.workSheetName      = machine.WorkSheetName;
            sp.dataClassName      = machine.GetComposedDataClassName();
            sp.workSheetClassName = machine.GetComposedWorkSheetClassName();

            // where the imported excel file is.
            sp.importedFilePath = Path.GetDirectoryName(machine.excelFilePath);

            // path where the .asset file will be created.
//            string path = Path.GetDirectoryName(machine.excelFilePath);
//            path += "/" + machine.WorkSheetName + ".asset";
            sp.assetFilepath           = TrimDirPrefix(machine.exportFilePath, "Assets");
            sp.assetPostprocessorClass = machine.WorkSheetName + "AssetPostprocessor";
            sp.template = GetTemplate("PostProcessor");

            // write a script to the given folder.
            using (var writer = new StreamWriter(TargetPathForAssetPostProcessorFile(machine.WorkSheetName)))
            {
                writer.Write(new ScriptGenerator(sp).ToString());
                writer.Close();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate script files with the given templates.
        /// Total four files are generated, two for runtime and others for editor.
        /// </summary>
        protected virtual ScriptPrescription Generate(BaseMachine m)
        {
            if (m == null)
            {
                return(null);
            }

            ScriptPrescription sp = new ScriptPrescription();

            if (m.onlyCreateDataClass)
            {
                CreateDataClassScript(m, sp);
            }
            else
            {
                CreateScriptableObjectClassScript(m, sp);
                CreateScriptableObjectEditorClassScript(m, sp);
                CreateDataClassScript(m, sp);
                CreateAssetCreationScript(m, sp);
            }

            AssetDatabase.Refresh();

            return(sp);
        }
        /// <summary>
        /// Create a data class which describes the spreadsheet and write it down on the specified folder.
        /// </summary>
        protected void CreateEnumScript(BaseMachine machine, ScriptPrescription sp)
        {
            // check the directory path exists
            string fullPath   = TargetPathForEnum(machine.WorkSheetName);
            string folderPath = Path.GetDirectoryName(fullPath);

            if (!Directory.Exists(folderPath))
            {
                EditorUtility.DisplayDialog(
                    "Warning",
                    "The folder for runtime script files does not exist. Check the path " + folderPath + " exists.",
                    "OK"
                    );
                return;
            }

            List <MemberFieldData> fieldList = new List <MemberFieldData>();

            //FIXME: replace ValueType to CellType and support Enum type.
            foreach (ColumnHeader header in machine.ColumnHeaderList)
            {
                if (header.type == CellType.Enum)
                {
                    MemberFieldData member = new MemberFieldData();
                    member.Name        = header.name;
                    member.type        = header.type;
                    member.IsArrayType = header.isArray;
                    fieldList.Add(member);
                }
            }

            // write a script to the given folder.
            using (var writer = new StreamWriter(fullPath))
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("namespace MasterData");
                builder.AppendLine("{");
                foreach (var field in fieldList)
                {
                    builder.AppendLine("    public enum " + field.Name.ToUpper());
                    builder.AppendLine("    {");

                    var enumField = machine.EnumFiledList.Find(data => data.name == field.Name);
                    foreach (var enumID in enumField.enumList)
                    {
                        builder.AppendLine("        " + enumID + ",");
                    }

                    builder.AppendLine("        Max,");
                    builder.AppendLine("    }");
                    builder.AppendLine("");
                }

                builder.AppendLine("}");
                writer.Write(builder.ToString());
                writer.Close();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a data class which describes the spreadsheet and write it down on the specified folder.
        /// </summary>
        protected void CreateDataClassScript(BaseMachine machine, ScriptPrescription sp)
        {
            // check the directory path exists
            string fullPath   = TargetPathForData(machine.WorkSheetName);
            string folderPath = Path.GetDirectoryName(fullPath);

            if (!Directory.Exists(folderPath))
            {
                EditorUtility.DisplayDialog(
                    "Warning",
                    "The folder for runtime script files does not exist. Check the path " + folderPath + " exists.",
                    "OK"
                    );
                return;
            }

            List <MemberFieldData> fieldList = new List <MemberFieldData>();
            string keyListStr = "";

            //FIXME: replace ValueType to CellType and support Enum type.
            foreach (ColumnHeader header in machine.ColumnHeaderList)
            {
                MemberFieldData member = new MemberFieldData();
                member.Name        = header.name;
                member.type        = header.type;
                member.IsArrayType = header.isArray;
                member.IsKey       = header.isKey;
                if (member.IsKey)
                {
                    keyListStr += member.Name + "$";
                }
                fieldList.Add(member);
            }
            if (keyListStr == "")
            {
                Debug.Log(machine.ColumnHeaderList);
                keyListStr = machine.ColumnHeaderList[0].name;
            }
            else if (keyListStr.EndsWith("$"))
            {
                keyListStr = keyListStr.Substring(0, keyListStr.Length - 1);
            }

            sp.className  = machine.WorkSheetName + "Data";
            sp.template   = GetTemplate("DataClass");
            sp.keyListStr = keyListStr;

            sp.memberFields = fieldList.ToArray();

            // write a script to the given folder.
            using (var writer = new StreamWriter(fullPath))
            {
                writer.Write(new ScriptGenerator(sp).ToString());
                writer.Close();
            }
        }
Exemplo n.º 5
0
        private static void ReimportMachine(BaseMachine machine, bool reimport)
        {
            var editor = Editor.CreateEditor(machine) as BaseMachineEditor;

            if (editor == null)
            {
                return;
            }
            editor.Import(reimport);
        }
Exemplo n.º 6
0
        private static void GenerateMachine(BaseMachine machine, bool onlyDataClass)
        {
            var editor = Editor.CreateEditor(machine) as BaseMachineEditor;

            if (editor == null)
            {
                return;
            }
            machine.onlyCreateDataClass = onlyDataClass;
            editor.Generate(machine);
        }
        ///
        /// Create utility class which has menu item function to create an asset file.
        ///
        protected override void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp)
        {
            sp.className               = machine.WorkSheetName;
            sp.worksheetClassName      = machine.WorkSheetName;
            sp.assetFileCreateFuncName = "Create" + machine.WorkSheetName + "AssetFile";
            sp.template = GetTemplate("AssetFileClass");

            // write a script to the given folder.
            using (var writer = new StreamWriter(TargetPathForAssetFileCreateFunc(machine.WorkSheetName)))
            {
                writer.Write(new NewScriptGenerator(sp).ToString());
                writer.Close();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Draw column headers on the Inspector view.
        /// </summary>
        protected void DrawHeaderSetting(BaseMachine m)
        {
            if (m.HasColumnHeader())
            {
                GUILayout.Label("Type Settings:", headerStyle);

                // Title
                const int MEMBER_WIDTH = 100;
                using (new GUILayout.HorizontalScope(EditorStyles.toolbar))
                {
                    GUILayout.Label("Member", GUILayout.MinWidth(MEMBER_WIDTH));
                    GUILayout.FlexibleSpace();
                    string[] names  = { "Type", "Key", "Array" };
                    int[]    widths = { 50, 30, 40 };
                    for (int i = 0; i < names.Length; i++)
                    {
                        GUILayout.Label(new GUIContent(names[i]), GUILayout.Width(widths[i]));
                    }
                }

                // Each cells
                using (new EditorGUILayout.VerticalScope("box"))
                {
                    foreach (ColumnHeader header in m.ColumnHeaderList)
                    {
                        GUILayout.BeginHorizontal();

                        // show member field with label, read-only
                        EditorGUILayout.LabelField(header.name, GUILayout.MinWidth(MEMBER_WIDTH));
                        GUILayout.FlexibleSpace();

                        // specify type with enum-popup
                        header.type = (CellType)EditorGUILayout.EnumPopup(header.type, GUILayout.Width(60));
                        GUILayout.Space(20);

                        // array toggle
                        header.isKey = EditorGUILayout.Toggle(header.isKey, GUILayout.Width(20));
                        GUILayout.Space(10);

                        // array toggle
                        header.isArray = EditorGUILayout.Toggle(header.isArray, GUILayout.Width(20));
                        GUILayout.Space(10);
                        GUILayout.EndHorizontal();
                    }
                }
            }
        }
        protected void DrawHeaderSetting(BaseMachine m)
        {
            if (m.HasHeadColumn())
            {
                GUIStyle headerStyle = GUIHelper.MakeHeader();
                GUILayout.Label("Type Settings:", headerStyle);

                const int MEMBER_WIDTH = 100;
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                GUILayout.Label("Member", GUILayout.MinWidth(MEMBER_WIDTH));
                GUILayout.FlexibleSpace();
                string[] names  = { "Type", "Array" };
                int[]    widths = { 55, 40 };
                for (int i = 0; i < names.Length; i++)
                {
                    GUILayout.Label(new GUIContent(names[i]), GUILayout.Width(widths[i]));
                }
                GUILayout.EndHorizontal();//EditorStyles.toolbar

                //curretScroll = EditorGUILayout.BeginScrollView(curretScroll, false, false);
                EditorGUILayout.BeginVertical("box");

                //string lastCellName = string.Empty;
                foreach (HeaderColumn header in m.HeaderColumnList)
                {
                    GUILayout.BeginHorizontal();

                    // member field label
                    EditorGUILayout.LabelField(header.name, GUILayout.MinWidth(MEMBER_WIDTH));
                    GUILayout.FlexibleSpace();

                    // type enum popup
                    header.type = (CellType)EditorGUILayout.EnumPopup(header.type, GUILayout.Width(60));
                    GUILayout.Space(20);

                    // array toggle
                    header.isArray = EditorGUILayout.Toggle(header.isArray, GUILayout.Width(20));
                    GUILayout.Space(10);
                    GUILayout.EndHorizontal();
                }

                EditorGUILayout.EndVertical(); //box
                //EditorGUILayout.EndScrollView();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create a ScriptableObject class and write it down on the specified folder.
        /// </summary>
        protected void CreateScriptableObjectClassScript(BaseMachine machine, ScriptPrescription sp)
        {
            sp.className     = machine.WorkSheetName;
            sp.dataClassName = machine.WorkSheetName + "Data";
            sp.template      = GetTemplate("ScriptableObjectClass");
            for (var i = 0; i < machine.ColumnHeaderList.Count; i++)
            {
                sp.cellTypeList.Add(machine.ColumnHeaderList[i].type);
            }
            // check the directory path exists
            string fullPath   = TargetPathForClassScript(machine.WorkSheetName);
            string folderPath = Path.GetDirectoryName(fullPath);

            if (!Directory.Exists(folderPath))
            {
                EditorUtility.DisplayDialog(
                    "Warning",
                    "The folder for runtime script files does not exist. Check the path " + folderPath + " exists.",
                    "OK"
                    );
                return;
            }

            StreamWriter writer = null;

            try
            {
                // write a script to the given folder.
                writer = new StreamWriter(fullPath);
                writer.Write(new ScriptGenerator(sp).ToString());
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.Message);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                    writer.Dispose();
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create a ScriptableObject editor class and write it down on the specified folder.
        /// </summary>
        protected void CreateScriptableObjectEditorClassScript(BaseMachine machine, ScriptPrescription sp)
        {
            sp.worksheetName      = machine.WorkSheetName;
            sp.className          = machine.WorkSheetName + "Representation" + "Editor";
            sp.worksheetClassName = machine.WorkSheetName + "Representation";
            sp.dataClassName      = machine.WorkSheetName + "Representation" + "Data";
            sp.template           = GetTemplate("ScriptableObjectEditorClass");

            // check the directory path exists
            string fullPath   = TargetPathForEditorScript(machine.WorkSheetName);
            string folderPath = Path.GetDirectoryName(fullPath);

            if (!Directory.Exists(folderPath))
            {
                EditorUtility.DisplayDialog(
                    "Warning",
                    "The folder for editor script files does not exist. Check the path " + folderPath + " exists.",
                    "OK"
                    );
                return;
            }

            StreamWriter writer = null;

            try
            {
                // write a script to the given folder.
                writer = new StreamWriter(fullPath);
                writer.Write(new ScriptGenerator(sp).ToString());
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                    writer.Dispose();
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Create a data class which describes the spreadsheet and write it down on the specified folder.
        /// </summary>
        protected void CreateDataClassScript(BaseMachine machine, ScriptPrescription sp)
        {
            // check the directory path exists
            string fullPath   = TargetPathForData(machine.WorkSheetName);
            string folderPath = Path.GetDirectoryName(fullPath);

            if (!Directory.Exists(folderPath))
            {
                EditorUtility.DisplayDialog(
                    "Warning",
                    "The folder for runtime script files does not exist. Check the path " + folderPath + " exists.",
                    "OK"
                    );
                return;
            }

            List <MemberFieldData> fieldList = new List <MemberFieldData>();

            //FIXME: replace ValueType to CellType and support Enum type.
            foreach (ColumnHeader header in machine.ColumnHeaderListDict.GetValue(machine.WorkSheetName).list)
            {
                MemberFieldData member = new MemberFieldData();
                member.Name        = header.name;
                member.type        = header.type;
                member.IsArrayType = header.isArray;

                fieldList.Add(member);
            }

            sp.className = machine.GetComposedDataClassName();
            sp.template  = GetTemplate("DataClass");

            sp.memberFields = fieldList.ToArray();

            // write a script to the given folder.
            using (var writer = new StreamWriter(fullPath))
            {
                writer.Write(new ScriptGenerator(sp).ToString());
                writer.Close();
            }
        }
 protected virtual void CreateAssetCreationScript(BaseMachine m, ScriptPrescription sp)
 {
     Debug.LogWarning("!!! It should be implemented in the derived class !!!");
 }
Exemplo n.º 14
0
 public static void CreateGenerateDirectory(BaseMachine machine)
 {
     Directory.CreateDirectory(Application.dataPath + Path.DirectorySeparatorChar + machine.RuntimeClassPath);
     Directory.CreateDirectory(Application.dataPath + Path.DirectorySeparatorChar + machine.EditorClassPath);
 }