Exemplo n.º 1
0
        public void ReadScene(CustomSceneMod.ScenePack scenePack)
        {
            try
            {
                ClearTrigger();

                if (!File.Exists(scenePack.SettingFilePath))
                {
                    GeoTools.Log("Error! Scene File not exists!");
                    return;
                }

                FileStream fs = new FileStream(scenePack.SettingFilePath, FileMode.Open);
                //打开数据文件
                StreamReader srd = new StreamReader(fs, Encoding.Default);

                while (srd.Peek() != -1)
                {
                    string   str   = srd.ReadLine();
                    string[] chara = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    if (chara.Length > 2)
                    {
                        #region Triggers
                        if (chara[0] == "Triggers")
                        {
                            if (chara[1] == "size")
                            {
                                this.TriggerSize = Convert.ToInt32(chara[2]);
                                //this.gameObject.GetComponent<TimeUI>().TriggerSize = TriggerSize;
                                LoadTrigger();
                            }
                        }
                        else if (chara[0] == "Trigger")
                        {
                            int i = Convert.ToInt32(chara[1]);
                            if (chara[2] == "mesh")
                            {
                                meshtriggers[i].GetComponent <MeshFilter>().mesh = GeoTools.MeshFromObj(chara[3]);
                            }
                            else if (chara[2] == "wmesh")
                            {
                                meshtriggers[i].GetComponent <MeshFilter>().mesh = GeoTools.WMeshFromObj(chara[3]);
                            }
                            else if (chara[2] == "scale")
                            {
                                meshtriggers[i].transform.localScale = new Vector3(
                                    Convert.ToSingle(chara[3]),
                                    Convert.ToSingle(chara[4]),
                                    Convert.ToSingle(chara[5]));
                            }
                            else if (chara[2] == "location")
                            {
                                meshtriggers[i].transform.localPosition = new Vector3(
                                    Convert.ToSingle(chara[3]),
                                    Convert.ToSingle(chara[4]),
                                    Convert.ToSingle(chara[5]));
                            }
                            else if (chara[2] == "rotation")
                            {
                                meshtriggers[i].transform.rotation = new Quaternion(
                                    Convert.ToSingle(chara[3]),
                                    Convert.ToSingle(chara[4]),
                                    Convert.ToSingle(chara[5]),
                                    Convert.ToSingle(chara[6]));
                            }
                            else if (chara[2] == "eulerangles")
                            {
                                meshtriggers[i].transform.Rotate(new Vector3(
                                                                     Convert.ToSingle(chara[3]),
                                                                     Convert.ToSingle(chara[4]),
                                                                     Convert.ToSingle(chara[5])), Space.Self);
                            }
                            else if (chara[2] == "euleranglesworld")
                            {
                                meshtriggers[i].transform.Rotate(new Vector3(
                                                                     Convert.ToSingle(chara[3]),
                                                                     Convert.ToSingle(chara[4]),
                                                                     Convert.ToSingle(chara[5])), Space.World);
                            }
                            else if (chara[2] == "fromtorotation")
                            {
                                meshtriggers[i].transform.rotation = Quaternion.FromToRotation(
                                    new Vector3(Convert.ToSingle(chara[3]),
                                                Convert.ToSingle(chara[4]),
                                                Convert.ToSingle(chara[5])),
                                    new Vector3(Convert.ToSingle(chara[6]),
                                                Convert.ToSingle(chara[7]),
                                                Convert.ToSingle(chara[8]))
                                    );
                            }
                            else if (chara[2] == "shader")
                            {
                                meshtriggers[i].GetComponent <MeshRenderer>().material.shader = Shader.Find("chara[3]");
                            }
                            else if (chara[2] == "texture")
                            {
                                meshtriggers[i].GetComponent <MeshRenderer>().material.mainTexture = GeoTools.LoadTexture(chara[3]);
                            }
                            else if (chara[2] == "stexture")
                            {
                                meshtriggers[i].GetComponent <MeshRenderer>().sharedMaterial.mainTexture = GeoTools.LoadTexture(chara[3]);
                            }
                            else if (chara[2] == "color")
                            {
                                meshtriggers[i].GetComponent <MeshRenderer>().material.color = new Color(
                                    Convert.ToSingle(chara[3]),
                                    Convert.ToSingle(chara[4]),
                                    Convert.ToSingle(chara[5]),
                                    Convert.ToSingle(chara[6]));
                            }
                            else if (chara[2] == "meshcollider")
                            {
                                meshtriggers[i].GetComponent <MeshCollider>().sharedMesh = GeoTools.MeshFromObj(chara[3]);
                                meshtriggers[i].GetComponent <MeshCollider>().convex     = true;
                                meshtriggers[i].GetComponent <MeshCollider>().isTrigger  = true;
                            }
                            else if (chara[2] == "wmeshcollider")
                            {
                                meshtriggers[i].GetComponent <MeshCollider>().sharedMesh = GeoTools.WMeshFromObj(chara[3]);
                                meshtriggers[i].GetComponent <MeshCollider>().convex     = true;
                                meshtriggers[i].GetComponent <MeshCollider>().isTrigger  = true;
                            }
                            ///////////////////////////////////////////////
                        }
                        #endregion
                    }
                }
                srd.Close();
                GeoTools.Log("ReadMeshTrigger Completed!");
            }
            catch (Exception ex)
            {
                GeoTools.Log("Error! ReadMeshTrigger Failed!");
                GeoTools.Log(ex.ToString());
                return;
            }
        }
Exemplo n.º 2
0
        public void ReadScene(CustomSceneMod.ScenePack scenePack)
        {
            try
            {
                ClearCube();

                if (!File.Exists(scenePack.SettingFilePath))
                {
                    GeoTools.Log("Error! Scene File not exists!");
                    return;
                }

                FileStream fs = new FileStream(scenePack.SettingFilePath, FileMode.Open);
                //打开数据文件
                StreamReader srd = new StreamReader(fs, Encoding.Default);

                while (srd.Peek() != -1)
                {
                    string   str   = srd.ReadLine();
                    string[] chara = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    if (chara.Length > 2)
                    {
                        #region Cube
                        if (chara[0].ToLower() == "cubes")
                        {
                            if (chara[1].ToLower() == "amount")
                            {
                                CubeAmount = Convert.ToInt32(chara[2]);
                                LoadCube();
                            }
                        }
                        else if (chara[0].ToLower() == "cube")
                        {
                            int i = Convert.ToInt32(chara[1]);
                            if (chara[2] == "mesh")
                            {
                                meshCubes[i].GetComponent <MeshFilter>().mesh = GeoTools.MeshFromObj(chara[3], scenePack);
                            }
                            else if (chara[2] == "wmesh")
                            {
                                meshCubes[i].GetComponent <MeshFilter>().mesh = GeoTools.WMeshFromObj(chara[3], scenePack);
                            }
                            else if (chara[2] == "scale")
                            {
                                meshCubes[i].transform.localScale = new Vector3(
                                    Convert.ToSingle(chara[3]),
                                    Convert.ToSingle(chara[4]),
                                    Convert.ToSingle(chara[5]));
                            }
                            else if (chara[2] == "rotation")
                            {
                                meshCubes[i].transform.rotation = new Quaternion(
                                    Convert.ToSingle(chara[3]),
                                    Convert.ToSingle(chara[4]),
                                    Convert.ToSingle(chara[5]),
                                    Convert.ToSingle(chara[6]));
                            }
                            else if (chara[2] == "eulerangles")
                            {
                                meshCubes[i].transform.Rotate(new Vector3(
                                                                  Convert.ToSingle(chara[3]),
                                                                  Convert.ToSingle(chara[4]),
                                                                  Convert.ToSingle(chara[5])), Space.Self);
                            }
                            else if (chara[2] == "euleranglesworld")
                            {
                                meshCubes[i].transform.Rotate(new Vector3(
                                                                  Convert.ToSingle(chara[3]),
                                                                  Convert.ToSingle(chara[4]),
                                                                  Convert.ToSingle(chara[5])), Space.World);
                            }
                            else if (chara[2] == "fromtorotation")
                            {
                                meshCubes[i].transform.rotation = Quaternion.FromToRotation(
                                    new Vector3(Convert.ToSingle(chara[3]),
                                                Convert.ToSingle(chara[4]),
                                                Convert.ToSingle(chara[5])),
                                    new Vector3(Convert.ToSingle(chara[6]),
                                                Convert.ToSingle(chara[7]),
                                                Convert.ToSingle(chara[8]))
                                    );
                            }
                            else if (chara[2] == "shader")
                            {
                                meshCubes[i].GetComponent <MeshRenderer>().material.shader = Shader.Find("chara[3]");
                            }
                            else if (chara[2] == "texture")
                            {
                                meshCubes[i].GetComponent <MeshRenderer>().material.mainTexture = GeoTools.LoadTexture(chara[3], scenePack);
                            }
                            else if (chara[2] == "stexture")
                            {
                                meshCubes[i].GetComponent <MeshRenderer>().sharedMaterial.mainTexture = GeoTools.LoadTexture(chara[3], scenePack);
                            }
                            else if (chara[2] == "color")
                            {
                                meshCubes[i].GetComponent <MeshRenderer>().material.color = new Color(
                                    Convert.ToSingle(chara[3]),
                                    Convert.ToSingle(chara[4]),
                                    Convert.ToSingle(chara[5]),
                                    Convert.ToSingle(chara[6]));
                            }
                            else if (chara[2] == "meshcollider")
                            {
                                meshCubes[i].GetComponent <MeshCollider>().sharedMesh = GeoTools.MeshFromObj(chara[3], scenePack);
                                meshCubes[i].GetComponent <MeshCollider>().convex     = true;
                            }
                            else if (chara[2] == "wmeshcollider")
                            {
                                meshCubes[i].GetComponent <MeshCollider>().sharedMesh = GeoTools.WMeshFromObj(chara[3], scenePack);
                                meshCubes[i].GetComponent <MeshCollider>().convex     = true;
                            }
                            else if (chara[2].ToLower() == "startlocation" || chara[2].ToLower() == "location")
                            {
                                meshCubes[i].GetComponent <CubeScript>().StartLocation = meshCubes[i].transform.localPosition = new Vector3(
                                    Convert.ToSingle(chara[3]),
                                    Convert.ToSingle(chara[4]),
                                    Convert.ToSingle(chara[5]));
                            }
                            else if (chara[2].ToLower() == "movevector")
                            {
                                meshCubes[i].GetComponent <CubeScript>().MoveVector = new Vector3(
                                    Convert.ToSingle(chara[3]),
                                    Convert.ToSingle(chara[4]),
                                    Convert.ToSingle(chara[5]));
                            }
                            else if (chara[2] == "velocity")
                            {
                                meshCubes[i].GetComponent <CubeScript>().Velocity = Convert.ToSingle(chara[3]);
                            }
                            else if (chara[2] == "control")
                            {
                                meshCubes[i].GetComponent <CubeScript>().Key = (KeyCode)Enum.Parse(typeof(KeyCode), chara[3]);
                            }
                            //else if (chara[2].ToLower() == "parent")
                            //{
                            //    meshCubes[i].GetComponent<CubeScript>().ParentName = chara[3];
                            //}
                            ///////////////////////////////////////////////
                        }

                        #endregion
                    }
                }

                srd.Close();
#if DEBUG
                GeoTools.Log("Read Cube Completed! CubeAmount:" + CubeAmount);
#endif
            }
            catch (Exception ex)
            {
                GeoTools.Log("Error! Read Cube Failed!");
                GeoTools.Log(ex.ToString());
                return;
            }
        }