public CylinderBarrierData(int _index, string _name, type _type, bool _deletable, CylinderGeometryData _cylinderGeometryData) : base(_index, _name, _type, _deletable, _cylinderGeometryData) { }
public override void set(string key, string value) { // Debug.Log(key); // Debug.Log(value); try { if (value != "") { switch (key) { case "geometry": { if (value == "cube") { CubeGeometryData cubeGeometryData = new CubeGeometryData( new Vector3(0f, 0.5f, 0f), new Vector3(0.2f, 0.2f, 0.2f), new Vector3(0.1f, 0f, 0f) ); WindData newWindData = new WindData(windData.index, windData.name, Data.type.BARRIER, true, cubeGeometryData, 1f, 0f); init(newWindData); } else if (value == "sphere") { SphereGeometryData sphereGeometryData = new SphereGeometryData( new Vector3(0f, 0.5f, 0f), 0.2f ); WindData newWindData = new WindData(windData.index, windData.name, Data.type.BARRIER, true, sphereGeometryData, 1f, 0f); init(newWindData); } else if (value == "cylinder") { CylinderGeometryData cylinderGeometryData = new CylinderGeometryData( new Vector3(0f, 3f, 0f), 0.2f, 0.4f, new Vector3(0f, 0f, 0f) ); WindData newWindData = new WindData(windData.index, windData.name, Data.type.BARRIER, true, cylinderGeometryData, 1f, 0f); init(newWindData); } break; } //key1 { "p_x", "p_y", "p_z" } case "p_x": { Vector3 position = new Vector3(float.Parse(value), windData.geometryData.position.y, windData.geometryData.position.z); windData.geometryData.position = position; break; } case "p_y": { Vector3 position = new Vector3(windData.geometryData.position.x, float.Parse(value), windData.geometryData.position.z); windData.geometryData.position = position; break; } case "p_z": { Vector3 position = new Vector3(windData.geometryData.position.x, windData.geometryData.position.y, float.Parse(value)); windData.geometryData.position = position; break; } //key2 s_r case "s_r": { ((SphereGeometryData)windData.geometryData).r = float.Parse(value); break; } //key3 { "c_r", "c_h" } case "c_r": { ((CylinderGeometryData)windData.geometryData).r = float.Parse(value); break; } case "c_h": { ((CylinderGeometryData)windData.geometryData).height = float.Parse(value); break; } //key4 { "length", "width", "height" } case "length": { ((CubeGeometryData)windData.geometryData).size.x = float.Parse(value); break; } case "width": { ((CubeGeometryData)windData.geometryData).size.z = float.Parse(value); break; } case "height": { ((CubeGeometryData)windData.geometryData).size.y = float.Parse(value); break; } //key5 { "intensity", "interfence" } case "intensity": { windData.intensity = float.Parse(value); break; } case "interfence": { windData.interference = float.Parse(value); break; } //key5 { "cu_x", "cu_y", "cu_z" } case "cu_x": { ((CubeGeometryData)windData.geometryData).direction.x = float.Parse(value); break; } case "cu_y": { ((CubeGeometryData)windData.geometryData).direction.y = float.Parse(value); break; } case "cu_z": { ((CubeGeometryData)windData.geometryData).direction.y = float.Parse(value); break; } default: { break; } } } } catch (System.Exception) { } }
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; } } } }
private Vector3[,,] getCylinderWindArray(CylinderGeometryData cycleGeometryData, float intensity, float interfence) { return(new Vector3[1, 1, 1]); }