public void toAddConfiguration(Data.type type) { // Debug.Log(type); Data objectData = null; switch (type) { case Data.type.BARRIER: { number = number + 1; CubeGeometryData cubeGeometryData = new CubeGeometryData( new Vector3(0f, 0.5f, 0f), new Vector3(0.2f, 0.2f, 0.2f), new Vector3(0f, 0f, 0f) ); // Debug.Log(number); objectData = new BarrierData(number, "Barrier" + number.ToString(), Data.type.BARRIER, true, cubeGeometryData); break; } case Data.type.WIND: { number = number + 1; CubeGeometryData cubeGeometryData = new CubeGeometryData( new Vector3(0f, 0.5f, 0f), new Vector3(0.2f, 0.2f, 0.2f), new Vector3(0f, 0f, 0f) ); // Debug.Log(number); objectData = new WindData(number, "Wind" + number.ToString(), Data.type.WIND, true, cubeGeometryData, 1f, 0f); break; } case Data.type.SMOKE: { number = number + 1; CycleGeometryData cycleGeometryData = new CycleGeometryData( new Vector3(0f, 0.5f, 0f), 0.1f, new Vector3(0f, 0f, 0f) ); PhysicalData physicalData = new PhysicalData( 0.01f, 10.0f, 1000, 3f ); objectData = new SmokeData(number, "Smoke" + number.ToString(), Data.type.SMOKE, true, cycleGeometryData, physicalData, SmokeData.SmokeType.SMOKE, new Color(0, 0, 0)); break; } default: { string logString = "[Error] the " + new Data().dataTypeToString(type) + " object can't be added"; addLog(logString); break; } } if (objectData != null) { // Debug.Log(objectData.dataType); ObjectConfigurationPanel.GetComponent <ObjectConfigurationPanelController>().showConfigurePanel(objectData, ObjectConfigurationPanelController.ConfigurationMode.ADD); } }
public void load(string path) { //删除现有的object List <int> deleteIndex = new List <int>(); foreach (var item in data) { if (item.Key > 2) { deleteIndex.Add(item.Key); } } foreach (var item in deleteIndex) { destroyObject(item); } StreamReader sr = new StreamReader(path, Encoding.Default); string line; string[] lineParts; //configuration line = sr.ReadLine(); lineParts = line.Split('-'); number = int.Parse(lineParts[1].Substring(lineParts[1].IndexOf('=') + 1)); //ground line = sr.ReadLine(); lineParts = line.Split('-'); ((GroundData)data[0]).size = float.Parse(lineParts[5].Substring(lineParts[5].IndexOf('=') + 1)); setData(data[0]); //light line = sr.ReadLine(); lineParts = line.Split('-'); ((LightData)data[1]).intensity = float.Parse(lineParts[5].Substring(lineParts[5].IndexOf('=') + 1)); string[] RGB = lineParts[6].Split(':'); int r = int.Parse(RGB[1].Substring(RGB[1].IndexOf('=') + 1)); int g = int.Parse(RGB[2].Substring(RGB[2].IndexOf('=') + 1)); int b = int.Parse(RGB[3].Substring(RGB[3].IndexOf('=') + 1)); ((LightData)data[1]).color = new Color(r, g, b); setData(data[1]); //logDensity line = sr.ReadLine(); lineParts = line.Split('-'); ((LogSmokeDensityData)data[2]).logFlag = bool.Parse(lineParts[5].Substring(lineParts[5].IndexOf('=') + 1)); ((LogSmokeDensityData)data[2]).interval = float.Parse(lineParts[6].Substring(lineParts[6].IndexOf('=') + 1)); setData(data[2]); //data while ((line = sr.ReadLine()) != null) { lineParts = line.Split('-'); Data newData = new Data(0, "", 0, false); newData.index = int.Parse(lineParts[1].Substring(lineParts[1].IndexOf('=') + 1)); newData.name = lineParts[2].Substring(lineParts[2].IndexOf('=') + 1); newData.deletable = bool.Parse(lineParts[4].Substring(lineParts[4].IndexOf('=') + 1)); switch (lineParts[3].Substring(lineParts[3].IndexOf('=') + 1)) { case "BARRIER": { newData.dataType = Data.type.BARRIER; BarrierData barrierData = null; Vector3 position = vector3Parse(lineParts[6].Substring(lineParts[6].IndexOf('=') + 1)); string typeString = lineParts[5].Substring(lineParts[5].IndexOf('=') + 1); switch (typeString) { case "cube": { Vector3 size = vector3Parse(lineParts[7].Substring(lineParts[7].IndexOf('=') + 1)); Vector3 direction = vector3Parse(lineParts[8].Substring(lineParts[8].IndexOf('=') + 1)); CubeGeometryData cubeGeometryData = new CubeGeometryData(position, size, direction); barrierData = new BarrierData(newData.index, newData.name, newData.dataType, newData.deletable, cubeGeometryData); addObject(barrierData); break; } case "sphere": { float radius = float.Parse((lineParts[7].Substring(lineParts[7].IndexOf('=') + 1))); SphereGeometryData sphereGeometryData = new SphereGeometryData(position, radius); barrierData = new BarrierData(newData.index, newData.name, newData.dataType, newData.deletable, sphereGeometryData); addObject(barrierData); break; } case "cylinder": { float radius = float.Parse((lineParts[7].Substring(lineParts[7].IndexOf('=') + 1))); float height = float.Parse((lineParts[8].Substring(lineParts[8].IndexOf('=') + 1))); Vector3 direction = vector3Parse(lineParts[9].Substring(lineParts[9].IndexOf('=') + 1)); CylinderGeometryData cylinderGeometryData = new CylinderGeometryData(position, radius, height, direction); barrierData = new BarrierData(newData.index, newData.name, newData.dataType, newData.deletable, cylinderGeometryData); addObject(barrierData); break; } } break; } case "WIND": { newData.dataType = Data.type.WIND; WindData windData = null; float intensity = float.Parse(lineParts[5].Substring(lineParts[5].IndexOf('=') + 1)); float interfence = float.Parse(lineParts[6].Substring(lineParts[6].IndexOf('=') + 1)); Vector3 position = vector3Parse(lineParts[8].Substring(lineParts[8].IndexOf('=') + 1)); string typeString = lineParts[7].Substring(lineParts[7].IndexOf('=') + 1); switch (typeString) { case "cube": { Vector3 size = vector3Parse(lineParts[9].Substring(lineParts[9].IndexOf('=') + 1)); Vector3 direction = vector3Parse(lineParts[10].Substring(lineParts[10].IndexOf('=') + 1)); CubeGeometryData cubeGeometryData = new CubeGeometryData(position, size, direction); windData = new WindData(newData.index, newData.name, newData.dataType, newData.deletable, cubeGeometryData, intensity, interfence); addObject(windData); break; } case "sphere": { float radius = float.Parse((lineParts[9].Substring(lineParts[9].IndexOf('=') + 1))); SphereGeometryData sphereGeometryData = new SphereGeometryData(position, radius); windData = new WindData(newData.index, newData.name, newData.dataType, newData.deletable, sphereGeometryData, intensity, interfence); addObject(windData); break; } case "cylinder": { float radius = float.Parse((lineParts[9].Substring(lineParts[9].IndexOf('=') + 1))); float height = float.Parse((lineParts[10].Substring(lineParts[10].IndexOf('=') + 1))); Vector3 direction = Vector3.zero; CylinderGeometryData cylinderGeometryData = new CylinderGeometryData(position, radius, height, direction); windData = new WindData(newData.index, newData.name, newData.dataType, newData.deletable, cylinderGeometryData, intensity, interfence); addObject(windData); break; } } break; } case "SMOKE": { newData.dataType = Data.type.SMOKE; SmokeData smokeData = null; string smokeTypeString = lineParts[5].Substring(lineParts[5].IndexOf('=') + 1); switch (smokeTypeString) { case "smoke": { float duration = float.Parse(lineParts[6].Substring(lineParts[6].IndexOf('=') + 1)); int maxNumber = int.Parse(lineParts[7].Substring(lineParts[7].IndexOf('=') + 1)); float particleSize = float.Parse(lineParts[8].Substring(lineParts[8].IndexOf('=') + 1)); float speed = float.Parse(lineParts[9].Substring(lineParts[9].IndexOf('=') + 1)); RGB = lineParts[10].Split(':'); int r_value = int.Parse(RGB[1].Substring(RGB[1].IndexOf('=') + 1)); int g_value = int.Parse(RGB[2].Substring(RGB[2].IndexOf('=') + 1)); int b_value = int.Parse(RGB[3].Substring(RGB[3].IndexOf('=') + 1)); Color color = new Color(r_value, g_value, b_value); Vector3 position = vector3Parse(lineParts[12].Substring(lineParts[12].IndexOf('=') + 1)); string typeString = lineParts[11].Substring(lineParts[11].IndexOf('=') + 1); switch (typeString) { case "cycle": { float radius = float.Parse((lineParts[13].Substring(lineParts[13].IndexOf('=') + 1))); Vector3 direction = vector3Parse(lineParts[14].Substring(lineParts[14].IndexOf('=') + 1)); CycleGeometryData cycleGeometryData = new CycleGeometryData(position, radius, direction); smokeData = new SmokeData(newData.index, newData.name, newData.dataType, newData.deletable, cycleGeometryData, new PhysicalData(particleSize, duration, maxNumber, speed), SmokeData.SmokeType.SMOKE, color); addObject(smokeData); break; } case "cylinder": { float radius = float.Parse((lineParts[13].Substring(lineParts[13].IndexOf('=') + 1))); float height = float.Parse((lineParts[14].Substring(lineParts[14].IndexOf('=') + 1))); Vector3 direction = vector3Parse((lineParts[15].Substring(lineParts[15].IndexOf('=') + 1))); CylinderGeometryData cylinderGeometryData = new CylinderGeometryData(position, radius, height, direction); smokeData = new SmokeData(newData.index, newData.name, newData.dataType, newData.deletable, cylinderGeometryData, new PhysicalData(particleSize, duration, maxNumber, speed), SmokeData.SmokeType.SMOKE, color); addObject(smokeData); break; } } break; } case "fire": { CycleGeometryData cycleGeometryData = new CycleGeometryData( new Vector3(0f, 0.5f, 0f), 0.1f, new Vector3(0f, 0f, 0f) ); PhysicalData physicalData = new PhysicalData( 0.01f, 10.0f, 1000, 3f ); smokeData = new SmokeData(smokeData.index, smokeData.name, Data.type.BARRIER, true, cycleGeometryData, physicalData, SmokeData.SmokeType.FIRE, new Color(0, 0, 0)); addObject(smokeData); break; } case "explosion": { CycleGeometryData cycleGeometryData = new CycleGeometryData( new Vector3(0f, 0.5f, 0f), 0.1f, new Vector3(0f, 0f, 0f) ); PhysicalData physicalData = new PhysicalData( 0.01f, 10.0f, 1000, 3f ); smokeData = new SmokeData(smokeData.index, smokeData.name, Data.type.BARRIER, true, cycleGeometryData, physicalData, SmokeData.SmokeType.FIRE, new Color(0, 0, 0)); addObject(smokeData); break; } } break; } } } }
public override void set(string key, string value) { // Debug.Log(key); // Debug.Log(value); try { if (value != "") { switch (key) { case "smoke type": { if (value == "smoke") { CycleGeometryData cycleGeometryData = new CycleGeometryData( new Vector3(0f, 0.5f, 0f), 0.1f, new Vector3(0f, 0f, 0f) ); PhysicalData physicalData = new PhysicalData( 0.01f, 10.0f, 1000, 3f ); SmokeData newSmokeData = new SmokeData(smokeData.index, smokeData.name, Data.type.SMOKE, true, cycleGeometryData, physicalData, SmokeData.SmokeType.SMOKE, new Color(0, 0, 0)); init(newSmokeData); } else if (value == "fire") { CycleGeometryData cycleGeometryData = new CycleGeometryData( new Vector3(0f, 0.5f, 0f), 0.1f, new Vector3(0f, 0f, 0f) ); PhysicalData physicalData = new PhysicalData( 0.01f, 10.0f, 1000, 3f ); SmokeData newSmokeData = new SmokeData(smokeData.index, smokeData.name, Data.type.SMOKE, true, cycleGeometryData, physicalData, SmokeData.SmokeType.FIRE, new Color(0, 0, 0)); init(newSmokeData); } else if (value == "explosion") { CycleGeometryData cycleGeometryData = new CycleGeometryData( new Vector3(0f, 0.5f, 0f), 0.1f, new Vector3(0f, 0f, 0f) ); PhysicalData physicalData = new PhysicalData( 0.01f, 10.0f, 1000, 3f ); SmokeData newSmokeData = new SmokeData(smokeData.index, smokeData.name, Data.type.SMOKE, true, cycleGeometryData, physicalData, SmokeData.SmokeType.EXPLOSION, new Color(0, 0, 0)); init(newSmokeData); } break; } //key1 { "cone", "cycle"} case "geometry": { if (value == "cone") { ConeGeometryData coneGeometryData = new ConeGeometryData( new Vector3(0f, 0.5f, 0f), 0.1f, 0.1f, new Vector3(0f, 0f, 0f) ); PhysicalData physicalData = new PhysicalData( 0.01f, 10.0f, 1000, 3f ); SmokeData newSmokeData = new SmokeData(smokeData.index, smokeData.name, Data.type.SMOKE, true, coneGeometryData, physicalData, SmokeData.SmokeType.SMOKE, new Color(0, 0, 0)); init(newSmokeData); } else if (value == "cycle") { CycleGeometryData cycleGeometryData = new CycleGeometryData( new Vector3(0f, 0.5f, 0f), 0.1f, new Vector3(0f, 0f, 0f) ); PhysicalData physicalData = new PhysicalData( 0.01f, 10.0f, 1000, 3f ); SmokeData newSmokeData = new SmokeData(smokeData.index, smokeData.name, Data.type.SMOKE, true, cycleGeometryData, physicalData, SmokeData.SmokeType.SMOKE, new Color(0, 0, 0)); init(newSmokeData); } break; } //key2 { "p_x", "p_y", "p_z" } case "p_x": { Vector3 position = new Vector3(float.Parse(value), smokeData.geometryData.position.y, smokeData.geometryData.position.z); smokeData.geometryData.position = position; break; } case "p_y": { Vector3 position = new Vector3(smokeData.geometryData.position.x, float.Parse(value), smokeData.geometryData.position.z); smokeData.geometryData.position = position; break; } case "p_z": { Vector3 position = new Vector3(smokeData.geometryData.position.x, smokeData.geometryData.position.y, float.Parse(value)); smokeData.geometryData.position = position; break; } //key3 { "cy_r" } case "cy_r": { ((CycleGeometryData)smokeData.geometryData).r = float.Parse(value); break; } //key4 { "co_r", "co_h" } case "co_r": { ((ConeGeometryData)smokeData.geometryData).r = float.Parse(value); break; } case "co_h": { ((ConeGeometryData)smokeData.geometryData).height = float.Parse(value); break; } //key5 { "co_x", "co_y", "co_z" } case "co_x": { ((ConeGeometryData)smokeData.geometryData).direction.x = float.Parse(value); break; } case "co_y": { ((ConeGeometryData)smokeData.geometryData).direction.y = float.Parse(value); break; } case "co_z": { ((ConeGeometryData)smokeData.geometryData).direction.y = float.Parse(value); break; } //key5 { "cy_x", "cy_y", "cy_z" } case "cy_x": { ((CycleGeometryData)smokeData.geometryData).direction.x = float.Parse(value); break; } case "cy_y": { ((CycleGeometryData)smokeData.geometryData).direction.y = float.Parse(value); break; } case "cy_z": { ((CycleGeometryData)smokeData.geometryData).direction.y = float.Parse(value); break; } //key6 = { "duration", "maxNumber" }; case "duration": { smokeData.physicalData.duration = float.Parse(value); break; } case "maxNumber": { smokeData.physicalData.maxNumber = int.Parse(value); break; } //key7 = { "particle size", "speed" }; case "particle size": { smokeData.physicalData.particleSize = float.Parse(value); break; } case "speed": { smokeData.physicalData.speed = float.Parse(value); break; } //key8 { "R", "G", "B"} case "R": { Color color = new Color(float.Parse(value), smokeData.color.g, smokeData.color.b); smokeData.color = color; break; } case "G": { Color color = new Color(smokeData.color.r, float.Parse(value), smokeData.color.b); smokeData.color = color; break; } case "B": { Color color = new Color(smokeData.color.r, smokeData.color.g, float.Parse(value)); smokeData.color = color; break; } default: { break; } } } } catch (System.Exception) { } }