Beispiel #1
0
        public void buttonApply_Click(object sender, EventArgs e)
        {
            try
            {
                Component asset     = (Component)Gui.Scripting.Variables[ParserVar];
                TextAsset textAsset = asset as TextAsset;
                if (textAsset != null)
                {
                    if (!checkBoxJoin.Checked)
                    {
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < dataGridViewContents.Rows.Count - 1; i++)
                        {
                            for (int j = 0; j < dataGridViewContents.Rows[i].Cells.Count; j++)
                            {
                                if (j > 0)
                                {
                                    sb.Append('\t');
                                }
                                sb.Append(dataGridViewContents.Rows[i].Cells[j].Value);
                            }
                            if (textAsset.m_ScriptBuffer != null && TextAssetMode != TextAssetContents.KIOKATSU_LIST)
                            {
                                sb.Append('\r');
                            }
                            sb.Append('\n');
                        }
                        textAsset.m_Script = sb.ToString();
                    }
                    else
                    {
                        textAsset.m_Script = textAsset.m_ScriptBuffer != null
                                                        ? editTextBoxJoinedContent.Text
                                                        : String.Concat(editTextBoxJoinedContent.Text.Split('\r'));
                    }
                    if (textAsset.m_ScriptBuffer != null)
                    {
                        using (BinaryWriter writer = new BinaryWriter(new MemoryStream()))
                        {
                            string[] lines    = textAsset.m_Script.Split('\n');
                            int      numLines = lines.Length;
                            while (lines[numLines - 1].Length == 0)
                            {
                                numLines--;
                            }
                            if (TextAssetMode == TextAssetContents.HONEYSELECT)
                            {
                                writer.Write(numLines);
                                for (int i = 0; i < numLines; i++)
                                {
                                    string[] words = lines[i].Split('\t');
                                    writer.WriteShortName(words[0]);

                                    int numKeyframes = (words.Length - 1) / 10;
                                    writer.Write(numKeyframes);
                                    for (int j = 0; j < numKeyframes; j++)
                                    {
                                        writer.Write(Int32.Parse(words[j * 10 + 1]));
                                        for (int k = 0; k < 9; k++)
                                        {
                                            writer.Write(Single.Parse(words[j * 10 + 2 + k]));
                                        }
                                    }
                                }
                            }
                            else if (TextAssetMode == TextAssetContents.KIOKATSU_LIST)
                            {
                                kList.Write(lines, numLines, writer);
                            }
                            else
                            {
                                throw new Exception("Apply for " + TextAssetMode + " not implemented");
                            }
                            using (BinaryReader reader = new BinaryReader(writer.BaseStream))
                            {
                                reader.BaseStream.Position = 0;
                                textAsset.m_ScriptBuffer   = reader.ReadBytes((int)writer.BaseStream.Length);
                            }
                        }
                    }
                }
                else
                {
                    MonoBehaviour textMB = asset as MonoBehaviour;
                    if (textMB != null && textMB.Parser.type.Members.Count > 4 && textMB.Parser.type.Members[4] is UClass &&
                        ((UClass)textMB.Parser.type.Members[4]).ClassName == "Param" &&
                        ((UClass)textMB.Parser.type.Members[4]).Name == "list")
                    {
                        List <Line> lines = new List <Line>();
                        for (int i = 0; i < dataGridViewContents.Rows.Count - 1; i++)
                        {
                            Line line = new Line();
                            line.m_Words = new List <string>(dataGridViewContents.Rows[i].Cells.Count);
                            for (int j = 0; j < dataGridViewContents.Rows[i].Cells.Count; j++)
                            {
                                if (dataGridViewContents.Rows[i].Cells[j].ReadOnly)
                                {
                                    break;
                                }
                                string value = (string)dataGridViewContents.Rows[i].Cells[j].Value != null
                                                                        ? (string)dataGridViewContents.Rows[i].Cells[j].Value : string.Empty;
                                line.m_Words.Add(value);
                            }
                            lines.Add(line);
                        }
                        MonoBehaviour.StringToParamList(textMB, lines);
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ReportException(ex);
            }
        }