Ejemplo n.º 1
0
        public void GenerateWallInfo()
        {
            if (string.IsNullOrEmpty(current_level))
            {
                return;
            }
            string fileName = "./" + XEditorLibrary.Lev + current_level + "_sc.txt";

            if (!File.Exists(fileName))
            {
                return;
            }
            string content = File.ReadAllText(fileName);
            string final   = "";

            string[]      commands    = content.Split(new char[] { '\n' });
            string        append      = "";
            bool          HasPreInfo  = false;
            List <string> RecordWalls = new List <string>();

            for (int i = 0; i < commands.Length; i++)
            {
                if (commands[i].StartsWith("info"))
                {
                    HasPreInfo = true;
                    continue;
                }
                if (!commands[i].StartsWith("opendoor"))
                {
                    final += commands[i] + '\n';
                    continue;
                }
                if (commands[i][commands[i].Length - 1] == '\r')
                {
                    commands[i] = commands[i].Substring(0, commands[i].Length - 1);
                }

                string[] s = commands[i].Split(' ');
                s = commands[i].Split(' ');
                string     wallName = s[1];
                GameObject dynamic  = GameObject.Find("DynamicScene");
                if (dynamic != null)
                {
                    Transform t = XCommon.singleton.FindChildRecursively(dynamic.transform, wallName);
                    if (t != null)
                    {
                        XSpawnWall    spawnWall    = t.GetComponent <XSpawnWall>();
                        XTransferWall transferWall = t.GetComponent <XTransferWall>();
                        XHorseWall    horseWall    = t.GetComponent <XHorseWall>();
                        if (spawnWall != null || transferWall != null)
                        {
                            final += commands[i] + "\r\n";
                            continue;
                        }
                        if (RecordWalls.Contains(wallName))
                        {
                            final += commands[i] + "\r\n";
                            continue;
                        }

                        RecordWalls.Add(wallName);
                        Vector3 pos = t.position;
                        float   r   = t.rotation.eulerAngles.y;
                        append += ("info:" + wallName);
                        append += " ";
                        append += pos.x;
                        append += "|";
                        append += pos.y;
                        append += "|";
                        append += pos.z;
                        append += "|";
                        append += r;
                        if (t.gameObject.activeInHierarchy)
                        {
                            append += " on";
                        }
                        else
                        {
                            append += " off";
                        }

                        BoxCollider c = t.GetComponent <BoxCollider>();
                        if (c != null)
                        {
                            append += " " + (c.size.x * t.localScale.x);
                            append += " " + (t.position.y + c.size.y / 2 * t.localScale.y);
                            append += " " + (c.size.z * t.localScale.z);
                        }
                        if (horseWall != null)
                        {
                            append += " " + horseWall.index;
                        }
                        append += "\r\n";
                    }
                }
                commands[i] += '\r';
                final       += commands[i] + '\n';
            }
            if (!HasPreInfo)
            {
                final += "\r\n";
            }
            final += append;
            File.WriteAllText(fileName, final);
        }
Ejemplo n.º 2
0
        public void LoadWallInfo()
        {
            if (string.IsNullOrEmpty(current_level))
            {
                return;
            }
            string fileName = "./" + XEditorLibrary.Lev + current_level + "_sc.txt";

            if (!File.Exists(fileName))
            {
                return;
            }
            string content = File.ReadAllText(fileName);

            string[]   commands = content.Split(new char[] { '\n' });
            GameObject dynamic  = GameObject.Find("DynamicScene");

            if (dynamic == null)
            {
                return;
            }
            for (int i = 0; i < commands.Length; i++)
            {
                if (commands[i].StartsWith("info"))
                {
                    if (commands[i][commands[i].Length - 1] == '\r')
                    {
                        commands[i] = commands[i].Substring(0, commands[i].Length - 1);
                    }

                    string[]  s        = commands[i].Split(' ');
                    string    wallName = s[0].Substring(5);
                    Transform t        = XCommon.singleton.FindChildRecursively(dynamic.transform, wallName);
                    if (t != null)
                    {
                        string[] sp = s[1].Split('|');
                        t.position = new Vector3(float.Parse(sp[0]), float.Parse(sp[1]), float.Parse(sp[2]));
                        t.rotation = Quaternion.Euler(new Vector3(t.rotation.eulerAngles.x, float.Parse(sp[3]), t.rotation.eulerAngles.z));

                        string strState = s[2];
                        t.gameObject.SetActive(strState == "on");

                        if (s.Length > 5)
                        {
                            string      strBoxX = s[3];
                            string      strBoxY = s[4];
                            string      strBoxZ = s[5];
                            BoxCollider c       = t.GetComponent <BoxCollider>();
                            if (c != null)
                            {
                                float x = float.Parse(strBoxX) / t.localScale.x;
                                float y = (float.Parse(strBoxY) - t.position.y) / t.localScale.y * 2;
                                float z = float.Parse(strBoxZ) / t.localScale.z;
                                c.size = new Vector3(x, y, z);
                            }
                        }
                        if (s.Length > 6)
                        {
                            string     strHorseIndex = s[6];
                            XHorseWall horseWall     = t.GetComponent <XHorseWall>();
                            horseWall.index = int.Parse(strHorseIndex);
                        }
                    }
                }
            }
            UnityEditor.SceneManagement.EditorSceneManager.SaveScene(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
        }