Exemplo n.º 1
0
        static PhysicalData DefaultPhysicalData(Coordinates initPosition)
        {
            var bytesPos        = Bytes.FromBackingArray(Encode.Vector3f((float)initPosition.x, (float)initPosition.y, (float)initPosition.z));
            var shipPhysicsData = new PhysicalData(bytesPos, Bytes.FromBackingArray(new byte[6]), Bytes.FromBackingArray(new byte[7]), Bytes.FromBackingArray(new byte[6]), 0f, 0f);

            return(shipPhysicsData);
        }
Exemplo n.º 2
0
 public SmokeData(int _index, string _name, type _type, bool _deletable, GeometryData _geometryData, PhysicalData _physicalData, SmokeType _smokeType, Color _color) : base(_index, _name, _type, _deletable)
 {
     geometryData = _geometryData;
     physicalData = _physicalData;
     smokeType    = _smokeType;
     color        = _color;
 }
Exemplo n.º 3
0
 public void CalculateClimate(PhysicalData pd)
 {
     climateScore = 0f;         //lower score for colder and more humid region and higher for hotter, dryer region
     //temperature ranging 270-320, outside of that will give more than 1 or negative score
     climateScore += 1 - ((pd.temperature - 270) / 50);
     //humidity give tinier effect to the terrain climate
     climateScore += pd.humidity / 250 - 0.2f;
     Debug.Log("climate Score: " + climateScore);
 }
Exemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     physicalData = new PhysicalData();
     //InitMacAddress ();
     //Debug.Log (Network.player.ipAddress);
     readyToLoadAPI = true;
     isLoaded       = false;
     GetIPLocation();
     //LoadWeatherData ();
 }
Exemplo n.º 5
0
    /* on a scale of 0 m/s to 15 m/s in real life
     * main: 0 - 2
     * turbulence: 0 - 2.5
     * pulse magnitude: 0 - 1
     * pulse frequency: 0 - 0.2
     */

    public void GenerateWind(PhysicalData pd)
    {
        float overallWindSpeed = pd.windSpeed / 15f;
        float windDirection    = pd.windDegree;

        transform.rotation = Quaternion.Euler(new Vector3(0f, windDirection, 0f));
        GetComponent <WindZone> ().windMain           = overallWindSpeed * 2f;
        GetComponent <WindZone> ().windTurbulence     = overallWindSpeed * 3f;
        GetComponent <WindZone> ().windPulseMagnitude = 0.5f + (overallWindSpeed * 1.0f);
        GetComponent <WindZone> ().windPulseFrequency = overallWindSpeed * 0.2f;
    }
Exemplo n.º 6
0
    public void GenerateFog(PhysicalData pd, float wb)
    {
        float hue = ConvertLongitudeToHue(pd.longitude);
        float sat = ConvertTemperatureToSaturation(pd.temperature) * 0.25f;
        float val = 0.2f + wb * 0.4f;

        RenderSettings.fogColor = Color.HSVToRGB(hue, sat, val);
        float density = Mathf.Pow((pd.humidity / 100), 2f) * 0.008f;

        RenderSettings.fogDensity = density * FogDensityWeatherModifer(pd);
    }
Exemplo n.º 7
0
    public Color GenerateLightColor(PhysicalData pd, float wb)
    {
        float hue = ConvertLongitudeToHue(pd.longitude);
        float sat = ConvertTemperatureToSaturation(pd.temperature) * 0.5f;
        float val = 0.2f + wb * 0.8f;

        sat  = SaturationCut(sat, val);
        sat *= SaturationWeatherModifer(pd);
        Debug.Log(hue + "," + sat + "," + val);
        return(Color.HSVToRGB(hue, sat, val));
    }
Exemplo n.º 8
0
    /* guide for range:
     * skybox value (0.2 to 0.9)
     * skybox exposure (0 to 1.6 (in extreme, pitch black and peak light))
     * light intensity (0 to 1.5)
     * light value (0.2 to 0.7 -> 0.7 to 1, shift the saturation towards 0.1 (or less))
     * fog color value (0.2 to 0.6)
     * fog saturation (0 to 0.25)
     * fog density (0 to 0.008 -> may be more than 0.008 if temperature is extremely low)
     * atmosphere thickness (0.3 to 1.8)
     */
    public void GenerateLight(PhysicalData physdata)
    {
        float worldBrightness = ConvertTimeToWorldBrightness(physdata);

        Debug.Log("world brightness level: " + worldBrightness);
        GetComponent <Light> ().color     = GenerateLightColor(physdata, worldBrightness);
        GetComponent <Light> ().intensity = worldBrightness * 1.5f;
        GenerateSkybox(physdata, worldBrightness);
        GenerateFog(physdata, worldBrightness);
        Debug.Log("light color generated");
    }
Exemplo n.º 9
0
    /* all numbers should be used to all parameters that change according to world's light brightness
     * Time -> World Brightness -> color hue, value, light intensity, skybox exposure, etc
     * pitch black: ((sunrise + 1day - sunset) / 2) + sunset (0)
     * nighttime (sunset + 1hour < currenttime < sunrise + 23hours) : abs(pitchblack - currenttime) (0 to 0.2)
     * dawn (surise-1h to sunrise+1h) : (0.2 to 0.5) || shifts hue to red (to 0 or to 1, whichever nearer) with 1 - abs(sunrise - currenttime)
     * peak sunlight: ((sunset - sunrise) / 2) + sunrise (1)
     * daytime (sunrise+1h < currenttime < sunset-1h) : abs(peaksunlight - currenttime) (0.5 to 1)
     * dusk (sunset-1h to sunset+1h) : (0.5 to 0.2) || hue shifts same as dawn
     */
    public float ConvertTimeToWorldBrightness(PhysicalData pd)
    {
        float worldBrightness;

        System.DateTime ct          = System.DateTime.Now.AddHours(timeshift);
        int             sunset      = TimeToMinute(pd.sunsetTime, true);
        int             sunrise     = TimeToMinute(pd.sunriseTime, true);
        int             currenttime = TimeToMinute(ct, false);

        Debug.Log("sunrise time in minutes" + sunrise);
        Debug.Log("sunset time in minutes" + sunset);
        Debug.Log("current time in minutes" + currenttime);
        int peakSunlight = (int)(sunset - sunrise) / 2 + sunrise;

        //nighttime after datechange
        if (currenttime >= 0 && currenttime < sunrise - 60)
        {
            int nightLength = sunrise - (sunset - 1440);
            int pitchBlack  = (nightLength / 2) + (sunset - 1440);
            worldBrightness = ((Mathf.Abs((float)(pitchBlack - currenttime)) / nightLength) * 0.2f) + 0f;
        }
        //dawn
        else if (currenttime >= sunrise - 60 && currenttime < sunrise + 60)
        {
            worldBrightness = 0.2f + ((float)(currenttime - (sunrise - 60)) / 120) * 0.3f;
        }
        //daytime
        else if (currenttime >= sunrise + 60 && currenttime < sunset - 60)
        {
            int dayLength = sunset - sunrise;
            worldBrightness = 1 - ((Mathf.Abs((float)(peakSunlight - currenttime)) / dayLength) * 0.5f);
        }
        //dusk
        else if (currenttime >= sunset - 60 && currenttime < sunset + 60)
        {
            worldBrightness = 0.5f - ((float)(currenttime - (sunset - 60)) / 120f) * 0.3f;
        }
        //nighttime before datechange
        else if (currenttime >= sunset + 60 && currenttime < 1440)
        {
            int nightLength = sunrise + 1440 - sunset;
            int pitchBlack  = (nightLength / 2) + sunset;
            Debug.Log("pitchblack time: " + pitchBlack);
            worldBrightness = ((Mathf.Abs((float)(pitchBlack - currenttime)) / nightLength) * 0.2f) + 0f;
        }
        else
        {
            Debug.Log("world brightness error");
            worldBrightness = 0f;
        }
        return(worldBrightness * WorldBrightnessWeatherModifier(pd));
    }
Exemplo n.º 10
0
    public void GenerateSkybox(PhysicalData pd, float wb)
    {
        float hue = ConvertLongitudeToHue(pd.longitude);
        float sat = ConvertTemperatureToSaturation(pd.temperature);
        float val = 0.2f + 0.7f * wb;

        sat *= SaturationWeatherModifer(pd);
        RenderSettings.skybox.SetFloat("_Exposure", wb * 1.6f);
        RenderSettings.skybox.SetColor("_SkyTint", Color.HSVToRGB(hue, sat, val));
        float atmThickness = Mathf.Clamp(1f + (((pd.pressure - 910) / 150) * 1f), 0.7f, 2f);

        RenderSettings.skybox.SetFloat("_AtmosphereThickness", atmThickness);
    }
Exemplo n.º 11
0
 /* 0 to 8 intensity
  * 1000/500 to 10000/5000
  */
 public void GenerateParticleEffect(PhysicalData pd)
 {
     if (!pd.weatherName.Contains("Rain"))
     {
         GetComponent <ParticleSystem> ().Stop();
     }
     else
     {
         int maxParticle  = (int)((pd.rainIntensity / 8) * 9000 + 1000);
         int emissionRate = (int)((pd.rainIntensity / 8) * 4000 + 1000);
         GetComponent <ParticleSystem> ().maxParticles = maxParticle;
         ParticleSystem.EmissionModule emis = GetComponent <ParticleSystem> ().emission;
         emis.rate = new ParticleSystem.MinMaxCurve(emissionRate);
     }
 }
Exemplo n.º 12
0
    public float WorldBrightnessWeatherModifier(PhysicalData pd)
    {
        return(1 - ((pd.cloudiness / 100) * 0.3f));
//		if (pd.weatherName.Equals ("Clear")) {
//			return 1f;
//		} else if (pd.weatherName.Contains ("Cloud") || pd.weatherName.Equals ("Snow") || pd.weatherName.Equals ("Drizzle")) {
//			return 0.9f;
//		} else if (pd.weatherName.Equals ("Rain")) {
//			return 0.75f;
//		} else if (pd.weatherName.Equals ("Thunderstorm")) {
//			return 0.6f;
//		} else {
//			return 1f;
//		}
    }
Exemplo n.º 13
0
    public float SaturationWeatherModifer(PhysicalData pd)
    {
        return(1 - ((pd.cloudiness / 100) * 0.6f));
        //		if (pd.weatherName.Equals ("Clear")) {
//			return 1f;
//		} else if (pd.weatherName.Contains ("Cloud") || pd.weatherName.Equals ("Snow") || pd.weatherName.Equals ("Drizzle")) {
//			return 0.8f;
//		} else if (pd.weatherName.Equals ("Rain")) {
//			return 0.6f;
//		} else if (pd.weatherName.Equals ("Thunderstorm")) {
//			return 0.4f;
//		} else {
//			return 1f;
//		}
    }
Exemplo n.º 14
0
 public float FogDensityWeatherModifer(PhysicalData pd)
 {
     if (pd.weatherName.Equals("Clear"))
     {
         return(0.8f);
     }
     else if (pd.weatherName.Contains("Cloud") || pd.weatherName.Equals("Snow") || pd.weatherName.Equals("Drizzle"))
     {
         return(1f);
     }
     else if (pd.weatherName.Equals("Rain") || pd.weatherName.Equals("Haze"))
     {
         return(1.5f);
     }
     else if (pd.weatherName.Equals("Thunderstorm"))
     {
         return(1f);
     }
     else
     {
         return(1f);
     }
 }
Exemplo n.º 15
0
    public void GenerateTerrain(PhysicalData pd)
    {
        Terrain terrain   = GetComponent <Terrain> ();
        float   latitude  = pd.latitude;
        float   longitude = pd.longitude;

//		GetComponent<TerrainToolkit> ().FractalGenerator(0.4f, 1f);

        CalculateClimate(pd);
        GenerateTrees(pd);

        //Generate Terrain Contour
        GetComponent <TerrainToolkit> ().CustomFractalGenerator(0.4f, 1f, CoordinateToSeed(latitude, longitude));
        GetComponent <TerrainToolkit> ().FractalGenerator(0.6f, 0.025f);
        GetComponent <TerrainToolkit> ().SmoothTerrain(1, 1f);

        //Generate Terrain Texture
        minHeight = GetComponent <TerrainToolkit> ().minHeight;
        Debug.Log("minimum height:" + minHeight);
        maxHeight = GetComponent <TerrainToolkit> ().maxHeight;
        Debug.Log("maximum height:" + maxHeight);
        float delta = (maxHeight - minHeight) / 5f;

        float[] hstops = new float[4];
        for (int i = 0; i < 4; i++)
        {
            hstops [i] = minHeight + delta * (i + 1);
        }
        float[] sstops = new float[2];
        sstops [0]       = 15.0f;
        sstops [1]       = 35.0f;
        selectedTextures = new Texture2D[4];
        SelectTextures(pd);
        GetComponent <TerrainToolkit> ().CustomAssignTerrainTexture(selectedTextures);
        GenerateTexture();
        startingAltitude = GetComponent <Terrain> ().terrainData.GetHeight(200, 200) + 10;
    }
Exemplo n.º 16
0
    public void SelectTextures(PhysicalData pd)
    {
        int   tx0, tx1, tx2, tx3;
        float score0, score1, score2, score3;

        //selecting texture[0], base texture
        score0 = climateScore * (baseTextures.Length - 2);
        if (score0 < 0.5f)
        {
            tx0 = 0;
        }
        else if (score0 > baseTextures.Length - 1.5f)
        {
            tx0 = baseTextures.Length - 1;
        }
        else
        {
            tx0 = Mathf.RoundToInt(score0);
        }
        selectedTextures [0] = baseTextures[tx0];
        //selecting texture[1], alternate
        score1 = climateScore * highAltVariantTextures.Length;
        if (score1 < 0)
        {
            tx1 = 0;
        }
        else if (score1 >= highAltVariantTextures.Length)
        {
            tx1 = highAltVariantTextures.Length - 1;
        }
        else
        {
            tx1 = Mathf.FloorToInt(score1);
        }
        selectedTextures [1] = highAltVariantTextures [tx1];
        //selecting texture[2], flat ground/grass, negative=sand, over max = snow
        score2 = climateScore * (flatGrassyTerrain.Length - 2);
        if (score2 < 0)
        {
            tx2 = 0;             //snow
        }
        else if (score2 >= flatGrassyTerrain.Length - 2)
        {
            tx2 = flatGrassyTerrain.Length - 1;
        }
        else
        {
            tx2 = Mathf.CeilToInt(score2);
        }
        selectedTextures [2] = flatGrassyTerrain [tx2];
        //selecting texture[3], cliff
        score3 = climateScore * (cliffTerrain.Length - 1);
        if (score3 < 0.5f)
        {
            tx3 = 0;
        }
        else if (score3 > cliffTerrain.Length - 1.5f)
        {
            tx3 = cliffTerrain.Length - 1;
        }
        else
        {
            tx3 = Mathf.RoundToInt(score3);
        }
        selectedTextures [3] = cliffTerrain[tx3];
        Debug.Log("texture score: " + score0 + ", " + score1 + ", " + score2 + ", " + score3);
        Debug.Log("texture selected: " + tx0 + ", " + tx1 + ", " + tx2 + ", " + tx3);
    }
Exemplo n.º 17
0
    public void GenerateTrees(PhysicalData pd)
    {
        Terrain terrain = GetComponent <Terrain> ();
        float   negTreeScore;
        int     treeCount;

        if (climateScore >= 0.5f)
        {
            negTreeScore = (climateScore - 0.5f) / 0.5f;
        }
        else
        {
            negTreeScore = (0.5f - climateScore) / 0.5f;
        }
        //climate score: max tree count at 0.5, tree count (150-800)
        treeCount = Mathf.Clamp(Mathf.RoundToInt(800 - (negTreeScore * 600)), 0, 800);
        //desert trees
        if (climateScore < 0)
        {
            int treeVar = 2;
            //worse climate, only dead trees
            if (climateScore < -0.8f)
            {
                treeVar = 1;
            }
            TreePrototype[] newTreeProts = new TreePrototype[treeVar];
            int             j            = 0;
            for (int i = 0; i < treeVar; i++)
            {
                newTreeProts [i]            = new TreePrototype();
                newTreeProts [i].prefab     = TropicalTrees [j];
                newTreeProts [i].bendFactor = 1f;
                j++;
            }
            terrain.terrainData.treePrototypes = newTreeProts;
            terrain.terrainData.RefreshPrototypes();
        }
        else
        {
            int treeVar = 4;
            //tropical plants
            if (pd.latitude < 30f && pd.latitude > -30f)
            {
                TreePrototype[] newTreeProts = new TreePrototype[treeVar];
                float           variantScore = climateScore * (TropicalTrees.Length - treeVar);
                int             startidx     = 0;
                if (variantScore < 0)
                {
                    startidx = 0;
                }
                else if (variantScore >= TropicalTrees.Length - treeVar)
                {
                    startidx = TropicalTrees.Length - treeVar;
                }
                else
                {
                    startidx = Mathf.RoundToInt(variantScore);
                }
                Debug.Log("Start index: " + startidx);
                int j = startidx;
                for (int i = 0; i < treeVar; i++)
                {
                    newTreeProts [i]            = new TreePrototype();
                    newTreeProts [i].prefab     = TropicalTrees [j];
                    newTreeProts [i].bendFactor = 1f;
                    j++;
                }
                terrain.terrainData.treePrototypes = newTreeProts;
                terrain.terrainData.RefreshPrototypes();
            }
            //temperate
            else
            {
                TreePrototype[] newTreeProts = new TreePrototype[treeVar];
                float           variantScore = climateScore * TemperateTrees.Length - treeVar;
                int             startidx     = 0;
                if (variantScore < 0)
                {
                    startidx = 0;
                }
                else if (variantScore >= TemperateTrees.Length - treeVar)
                {
                    startidx = TemperateTrees.Length - treeVar;
                }
                else
                {
                    startidx = Mathf.RoundToInt(variantScore);
                }
                Debug.Log("Start index: " + startidx);
                int j = startidx;
                for (int i = 0; i < treeVar; i++)
                {
                    newTreeProts [i]            = new TreePrototype();
                    newTreeProts [i].prefab     = TemperateTrees [j];
                    newTreeProts [i].bendFactor = 1f;
                    j++;
                }
                terrain.terrainData.treePrototypes = newTreeProts;
                terrain.terrainData.RefreshPrototypes();
            }
        }
        GetComponent <MassTreePlacement> ().count = treeCount;
        GetComponent <MassTreePlacement>().GenerateTrees(terrain);
    }
Exemplo n.º 18
0
    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;
            }
            }
        }
    }
Exemplo n.º 19
0
    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);
        }
    }
Exemplo n.º 20
0
    private static SpecificState GetNextState(SpecificState currentState, InputData currentInput, PhysicalData currentPhysicals, float deadzone = float.Epsilon)
    {
        var nextState = currentState;

        switch (currentState)
        {
        case SpecificState.IdleLeft:
            if (currentInput.horizontal > deadzone)
            {
                nextState = SpecificState.IdleRight;
            }
            else if (currentInput.horizontal < -deadzone)
            {
                nextState = SpecificState.RunLeft;
            }
            else if (currentPhysicals.velocity.y < -deadzone)
            {
                nextState = SpecificState.FallFaceLeft;
            }
            else if (currentInput.buttonA)
            {
                nextState = SpecificState.JumpFaceLeft;
            }
            break;

        case SpecificState.IdleRight:
            if (currentInput.horizontal > deadzone)
            {
                nextState = SpecificState.RunRight;
            }
            else if (currentInput.horizontal < -deadzone)
            {
                nextState = SpecificState.IdleLeft;
            }
            else if (currentPhysicals.velocity.y < -deadzone)
            {
                nextState = SpecificState.FallFaceLeft;
            }
            else if (currentInput.buttonA)
            {
                nextState = SpecificState.JumpFaceRight;
            }
            break;

        case SpecificState.RunLeft:
            if (currentInput.horizontal > -deadzone)
            {
                nextState = SpecificState.IdleLeft;
            }
            else if (currentPhysicals.velocity.y < -deadzone)
            {
                nextState = SpecificState.FallMoveLeft;
            }
            else if (currentInput.buttonA)
            {
                nextState = SpecificState.JumpMoveLeft;
            }
            else if (currentPhysicals.leftWall)
            {
                nextState = SpecificState.ClimbLeftIdle;
            }
            break;

        case SpecificState.RunRight:
            if (currentInput.horizontal < deadzone)
            {
                nextState = SpecificState.IdleRight;
            }
            else if (currentPhysicals.velocity.y < -deadzone)
            {
                nextState = SpecificState.FallMoveRight;
            }
            else if (currentInput.buttonA)
            {
                nextState = SpecificState.JumpMoveRight;
            }
            else if (currentPhysicals.rightWall)
            {
                nextState = SpecificState.ClimbRightIdle;
            }
            break;

        case SpecificState.JumpFaceLeft:
            if (currentPhysicals.velocity.y < -deadzone)
            {
                nextState = SpecificState.FallFaceLeft;
            }
            else if (currentInput.horizontal < -deadzone)
            {
                nextState = SpecificState.JumpMoveLeft;
            }
            else if (currentInput.horizontal > deadzone)
            {
                nextState = SpecificState.JumpFaceRight;
            }
            else if (currentPhysicals.botWall)
            {
                nextState = SpecificState.IdleLeft;
            }
            else if (currentPhysicals.topWall && currentInput.vertical > deadzone)
            {
                nextState = SpecificState.ClimbTopIdleLeft;
            }
            break;

        case SpecificState.JumpFaceRight:
            if (currentPhysicals.velocity.y < -deadzone)
            {
                nextState = SpecificState.FallFaceRight;
            }
            else if (currentInput.horizontal > deadzone)
            {
                nextState = SpecificState.JumpMoveRight;
            }
            else if (currentInput.horizontal < -deadzone)
            {
                nextState = SpecificState.JumpFaceLeft;
            }
            else if (currentPhysicals.botWall)
            {
                nextState = SpecificState.IdleRight;
            }
            else if (currentPhysicals.topWall && currentInput.vertical > deadzone)
            {
                nextState = SpecificState.ClimbTopIdleRight;
            }
            break;

        case SpecificState.JumpMoveLeft:
            if (currentPhysicals.velocity.y < -deadzone)
            {
                nextState = SpecificState.FallMoveLeft;
            }
            else if (currentInput.horizontal > -deadzone)
            {
                nextState = SpecificState.JumpFaceLeft;
            }
            else if (currentPhysicals.botWall)
            {
                nextState = SpecificState.RunLeft;
            }
            else if (currentPhysicals.leftWall)
            {
                nextState = SpecificState.ClimbLeftIdle;
            }
            else if (currentPhysicals.topWall && currentInput.vertical > deadzone)
            {
                nextState = SpecificState.ClimbTopMoveLeft;
            }
            break;

        case SpecificState.JumpMoveRight:
            if (currentPhysicals.velocity.y < -deadzone)
            {
                nextState = SpecificState.FallMoveRight;
            }
            else if (currentInput.horizontal < deadzone)
            {
                nextState = SpecificState.JumpFaceRight;
            }
            else if (currentPhysicals.botWall)
            {
                nextState = SpecificState.RunRight;
            }
            else if (currentPhysicals.rightWall)
            {
                nextState = SpecificState.ClimbRightIdle;
            }
            else if (currentPhysicals.topWall && currentInput.vertical > deadzone)
            {
                nextState = SpecificState.ClimbTopMoveRight;
            }
            break;

        case SpecificState.FallFaceLeft:
            if (currentPhysicals.botWall)
            {
                nextState = SpecificState.IdleLeft;
            }
            else if (currentInput.horizontal < -deadzone)
            {
                nextState = SpecificState.FallMoveLeft;
            }
            else if (currentInput.horizontal > deadzone)
            {
                nextState = SpecificState.FallFaceRight;
            }
            break;

        case SpecificState.FallFaceRight:
            if (currentPhysicals.botWall)
            {
                nextState = SpecificState.IdleRight;
            }
            else if (currentInput.horizontal > deadzone)
            {
                nextState = SpecificState.FallMoveRight;
            }
            else if (currentInput.horizontal < -deadzone)
            {
                nextState = SpecificState.FallFaceLeft;
            }
            break;

        case SpecificState.FallMoveLeft:
            if (currentPhysicals.botWall)
            {
                nextState = SpecificState.RunLeft;
            }
            else if (currentInput.horizontal > -deadzone)
            {
                nextState = SpecificState.FallFaceLeft;
            }
            else if (currentPhysicals.leftWall)
            {
                nextState = SpecificState.ClimbLeftIdle;
            }
            break;

        case SpecificState.FallMoveRight:
            if (currentPhysicals.botWall)
            {
                nextState = SpecificState.RunRight;
            }
            else if (currentInput.horizontal < deadzone)
            {
                nextState = SpecificState.FallFaceRight;
            }
            else if (currentPhysicals.rightWall)
            {
                nextState = SpecificState.ClimbRightIdle;
            }
            break;

        case SpecificState.ClimbLeftIdle:
            if (currentInput.horizontal > -deadzone)
            {
                nextState = SpecificState.FallFaceLeft;
            }
            else if (currentInput.vertical > deadzone)
            {
                nextState = SpecificState.ClimbLeftUp;
            }
            else if (currentInput.vertical < -deadzone && !currentPhysicals.botWall)
            {
                nextState = SpecificState.ClimbLeftDown;
            }
            break;

        case SpecificState.ClimbRightIdle:
            if (currentInput.horizontal < deadzone)
            {
                nextState = SpecificState.FallFaceRight;
            }
            else if (currentInput.vertical > deadzone)
            {
                nextState = SpecificState.ClimbRightUp;
            }
            else if (currentInput.vertical < -deadzone && !currentPhysicals.botWall)
            {
                nextState = SpecificState.ClimbRightDown;
            }
            break;

        case SpecificState.ClimbLeftUp:
            if (currentInput.horizontal > -deadzone)
            {
                nextState = SpecificState.FallFaceLeft;
            }
            else if (currentInput.vertical < deadzone)
            {
                nextState = SpecificState.ClimbLeftIdle;
            }
            else if (!currentPhysicals.leftWall)
            {
                nextState = SpecificState.FallMoveLeft;
            }
            else if (currentPhysicals.topWall && currentInput.vertical > deadzone)
            {
                nextState = SpecificState.ClimbTopIdleLeft;
            }
            break;

        case SpecificState.ClimbRightUp:
            if (currentInput.horizontal < deadzone)
            {
                nextState = SpecificState.FallFaceRight;
            }
            else if (currentInput.vertical < deadzone)
            {
                nextState = SpecificState.ClimbRightIdle;
            }
            else if (!currentPhysicals.rightWall)
            {
                nextState = SpecificState.FallMoveRight;
            }
            else if (currentPhysicals.topWall && currentInput.vertical > deadzone)
            {
                nextState = SpecificState.ClimbTopIdleRight;
            }
            break;

        case SpecificState.ClimbLeftDown:
            if (currentInput.horizontal > -deadzone)
            {
                nextState = SpecificState.FallFaceLeft;
            }
            else if (currentInput.vertical > -deadzone)
            {
                nextState = SpecificState.ClimbLeftIdle;
            }
            else if (!currentPhysicals.leftWall)
            {
                nextState = SpecificState.FallMoveLeft;
            }
            else if (currentPhysicals.botWall)
            {
                nextState = SpecificState.ClimbLeftIdle;
            }
            break;

        case SpecificState.ClimbRightDown:
            if (currentInput.horizontal < deadzone)
            {
                nextState = SpecificState.FallFaceRight;
            }
            else if (currentInput.vertical > -deadzone)
            {
                nextState = SpecificState.ClimbRightIdle;
            }
            else if (!currentPhysicals.rightWall)
            {
                nextState = SpecificState.FallMoveRight;
            }
            else if (currentPhysicals.botWall)
            {
                nextState = SpecificState.ClimbRightIdle;
            }
            break;

        case SpecificState.ClimbTopIdleLeft:
            if (currentInput.vertical < deadzone)
            {
                nextState = SpecificState.FallFaceLeft;
            }
            else if (currentInput.horizontal < -deadzone && !currentPhysicals.leftWall)
            {
                nextState = SpecificState.ClimbTopMoveLeft;
            }
            else if (currentInput.horizontal > deadzone)
            {
                nextState = SpecificState.ClimbTopIdleRight;
            }
            break;

        case SpecificState.ClimbTopIdleRight:
            if (currentInput.vertical < deadzone)
            {
                nextState = SpecificState.FallFaceRight;
            }
            else if (currentInput.horizontal > deadzone && !currentPhysicals.rightWall)
            {
                nextState = SpecificState.ClimbTopMoveRight;
            }
            else if (currentInput.horizontal < -deadzone)
            {
                nextState = SpecificState.ClimbTopIdleLeft;
            }
            break;

        case SpecificState.ClimbTopMoveLeft:
            if (currentInput.vertical < deadzone)
            {
                nextState = SpecificState.FallMoveLeft;
            }
            else if (currentInput.horizontal > -deadzone)
            {
                nextState = SpecificState.ClimbTopIdleLeft;
            }
            else if (!currentPhysicals.topWall)
            {
                nextState = SpecificState.FallMoveLeft;
            }
            else if (currentPhysicals.leftWall)
            {
                nextState = SpecificState.ClimbTopIdleLeft;
            }
            break;

        case SpecificState.ClimbTopMoveRight:
            if (currentInput.vertical < deadzone)
            {
                nextState = SpecificState.FallMoveRight;
            }
            else if (currentInput.horizontal < deadzone)
            {
                nextState = SpecificState.ClimbTopIdleRight;
            }
            else if (!currentPhysicals.topWall)
            {
                nextState = SpecificState.FallMoveRight;
            }
            else if (currentPhysicals.rightWall)
            {
                nextState = SpecificState.ClimbTopIdleRight;
            }
            break;
        }
        return(nextState);
    }
Exemplo n.º 21
0
 public SceneObjectBuilder(object data, Vector2 center, float size)
 {
     this.data          = data;
     this.physicalShape = new PhysicalData(center, new Vector2(size));
 }
Exemplo n.º 22
0
    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)
        {
        }
    }