Exemplo n.º 1
0
    /// <summary>
    /// Create a JSON Data for template save.
    /// </summary>
    /// <returns></returns>
    public JsonObject buildJSONData()
    {
        if (ConfigurationAsset == null)
        {
            return(null);
        }

        string jsonContent = SpeedometerUIHelper.ReadJSONFile(ConfigurationAsset.name);

        JsonObject oJson = new JsonObject(jsonContent);

        if (oJson == null)
        {
            Debug.LogWarning("SPEEDOMETER UI WARNING \r\nImproper JSon File! Please use speedometerui-template.txt for creating your own configuration");
            return(null);
        }


        oJson.GetField("SpeedometerUIData").GetField("ControlName").str                = this.ControlName.ToString();
        oJson.GetField("SpeedometerUIData").GetField("GaugeSize").str                  = GaugeSize.x.ToString() + "," + GaugeSize.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("GaugePosition").str              = Convert.ToInt16(this.GaugePosition).ToString();
        oJson.GetField("SpeedometerUIData").GetField("GaugePositonOffset").str         = GaugePositionOffset.x.ToString() + "," + GaugePositionOffset.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleOffset").str         = SpeedoNeedleOffset.x.ToString() + "," + SpeedoNeedleOffset.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleSize").str           = SpeedoNeedleSize.x.ToString() + "," + SpeedoNeedleSize.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedoCapSize").str              = SpeedoCapSize.x.ToString() + "," + SpeedoCapSize.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleCenterDistance").str = SpeedoNeedleCenterDistance.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleMinValueAngle").str  = SpeedoNeedleMinValueAngle.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleMaxValueAngle").str  = SpeedoNeedleMaxValueAngle.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleMaxValue").str       = SpeedoNeedleMaxValue.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedTextOffset").str            = SpeedTextOffset.x.ToString() + "," + SpeedTextOffset.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("EnableRpm").str                  = EnableRPM.ToString();
        oJson.GetField("SpeedometerUIData").GetField("RpmNeedleOffset").str            = RPMNeedleOffset.x.ToString() + "," + RPMNeedleOffset.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("RpmNeedleCenterDistance").str    = RPMNeedleCenterDistance.ToString();
        oJson.GetField("SpeedometerUIData").GetField("RpmNeedleMinValueAngle").str     = RPMNeedleMinValueAngle.ToString();
        oJson.GetField("SpeedometerUIData").GetField("RpmNeedleMaxValueAngle").str     = RPMNeedleMaxValueAngle.ToString();
        oJson.GetField("SpeedometerUIData").GetField("RpmNeedleMaxValue").str          = RPMNeedleMaxValue.ToString();
        oJson.GetField("SpeedometerUIData").GetField("RpmCapSize").str                 = RPMCapSize.x.ToString() + "," + RPMCapSize.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("RPMNeedleSize").str              = RPMNeedleSize.x.ToString() + "," + RPMNeedleSize.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("RpmTextOffset").str              = RPMTextOffset.x.ToString() + "," + RPMTextOffset.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("GearTextOffset").str             = GearTextOffset.x.ToString() + "," + GearTextOffset.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("ShowSpeedText").str              = ShowSpeedText.ToString();
        oJson.GetField("SpeedometerUIData").GetField("ShowSpeedUnitText").str          = ShowSpeedUnitText.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedUnitText").str              = SpeedUnitText.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedUnitTextOffset").str        = SpeedUnitTextOffset.x.ToString() + "," + SpeedUnitTextOffset.y.ToString();
        oJson.GetField("SpeedometerUIData").GetField("ShowRpmText").str                = ShowRPMText.ToString();
        oJson.GetField("SpeedometerUIData").GetField("ShowGearText").str               = ShowGearText.ToString();
        oJson.GetField("SpeedometerUIData").GetField("SpeedoSkin").str                 = SpeedoSkin.name.ToString();

        oJson.GetField("SpeedometerUIData").GetField("GaugeDialTexture").str = GaugeDial.name.ToString();

        if (SpeedoCapTexture != null)
        {
            oJson.GetField("SpeedometerUIData").GetField("SpeedoCapTexture").str = SpeedoCapTexture.name.ToString();
        }
        else
        {
            oJson.GetField("SpeedometerUIData").GetField("SpeedoCapTexture").str = "";
        }

        if (SpeedoNeedleTexture != null)
        {
            oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleTexture").str = SpeedoNeedleTexture.name.ToString();
        }
        else
        {
            oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleTexture").str = "";
        }

        if (RPMCapTexture != null)
        {
            oJson.GetField("SpeedometerUIData").GetField("RpmCapTexture").str = RPMCapTexture.name.ToString();
        }
        else
        {
            oJson.GetField("SpeedometerUIData").GetField("RpmCapTexture").str = "";
        }

        if (RPMNeedleTexture != null)
        {
            oJson.GetField("SpeedometerUIData").GetField("RpmNeedleTexture").str = RPMNeedleTexture.name.ToString();
        }
        else
        {
            oJson.GetField("SpeedometerUIData").GetField("RpmNeedleTexture").str = "";
        }


        return(oJson);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Loads the values from given json documents.
    /// </summary>
    public void loadJSONData()
    {
        if (ConfigurationAsset == null)
        {
            return;
        }
        string jsonContent = SpeedometerUIHelper.ReadJSONFile(ConfigurationAsset.name);

        JsonObject oJson = new JsonObject(jsonContent);

        if (oJson == null)
        {
            return;
        }

        if (oJson.GetField("SpeedometerUIData").GetField("GaugePosition").str == "")
        {
            Debug.LogWarning("SPEEDOMETER UI WARNING \r\nJSON File valid but its empty. Please save your settings before loading template.");
            return;
        }

        this.ControlName = oJson.GetField("SpeedometerUIData").GetField("ControlName").str;
        string[] sizeGauge = oJson.GetField("SpeedometerUIData").GetField("GaugeSize").str.Split(new char[] { ',' });
        this.GaugeSize     = new Vector2(float.Parse(sizeGauge[0]), float.Parse(sizeGauge[1]));
        this.GaugePosition = (GaugePositionEnum)float.Parse(oJson.GetField("SpeedometerUIData").GetField("GaugePosition").str);
        string[] offGauge = oJson.GetField("SpeedometerUIData").GetField("GaugePositonOffset").str.Split(new char[] { ',' });
        this.GaugePositionOffset = new Vector2(float.Parse(offGauge[0]), float.Parse(offGauge[1]));
        string[] offSpeedoNeedle = oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleOffset").str.Split(new char[] { ',' });
        this.SpeedoNeedleOffset = new Vector2(float.Parse(offSpeedoNeedle[0]), float.Parse(offSpeedoNeedle[1]));
        string[] sizeSpeedoNeedle = oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleSize").str.Split(new char[] { ',' });
        this.SpeedoNeedleSize           = new Vector2(float.Parse(sizeSpeedoNeedle[0]), float.Parse(sizeSpeedoNeedle[1]));
        this.SpeedoNeedleCenterDistance = float.Parse(oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleCenterDistance").str);

        string[] sizeSpeedoCap = oJson.GetField("SpeedometerUIData").GetField("SpeedoCapSize").str.Split(new char[] { ',' });
        this.SpeedoCapSize = new Vector2(float.Parse(sizeSpeedoCap[0]), float.Parse(sizeSpeedoCap[1]));

        this.SpeedoNeedleMinValueAngle = float.Parse(oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleMinValueAngle").str);
        this.SpeedoNeedleMaxValueAngle = float.Parse(oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleMaxValueAngle").str);
        this.SpeedoNeedleMaxValue      = Convert.ToInt16(oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleMaxValue").str);
        this.GaugePositionOffset       = new Vector2(float.Parse(offGauge[0]), float.Parse(offGauge[1]));
        string[] offSpeedTextOffset = oJson.GetField("SpeedometerUIData").GetField("SpeedTextOffset").str.Split(new char[] { ',' });
        this.SpeedTextOffset = new Vector2(float.Parse(offSpeedTextOffset[0]), float.Parse(offSpeedTextOffset[1]));
        this.EnableRPM       = Convert.ToBoolean(oJson.GetField("SpeedometerUIData").GetField("EnableRpm").str);
        string[] offRPMNeedle = oJson.GetField("SpeedometerUIData").GetField("RpmNeedleOffset").str.Split(new char[] { ',' });

        string[] sizeRPMNeedle = oJson.GetField("SpeedometerUIData").GetField("RPMNeedleSize").str.Split(new char[] { ',' });
        this.RPMNeedleSize = new Vector2(float.Parse(sizeRPMNeedle[0]), float.Parse(sizeRPMNeedle[1]));

        string[] sizeRPMCap = oJson.GetField("SpeedometerUIData").GetField("RpmCapSize").str.Split(new char[] { ',' });
        this.RPMCapSize = new Vector2(float.Parse(sizeRPMCap[0]), float.Parse(sizeRPMCap[1]));

        this.RPMNeedleOffset         = new Vector2(float.Parse(offRPMNeedle[0]), float.Parse(offRPMNeedle[1]));
        this.RPMNeedleCenterDistance = float.Parse(oJson.GetField("SpeedometerUIData").GetField("RpmNeedleCenterDistance").str);
        this.RPMNeedleMinValueAngle  = float.Parse(oJson.GetField("SpeedometerUIData").GetField("RpmNeedleMinValueAngle").str);
        this.RPMNeedleMaxValueAngle  = float.Parse(oJson.GetField("SpeedometerUIData").GetField("RpmNeedleMaxValueAngle").str);
        this.RPMNeedleMaxValue       = float.Parse(oJson.GetField("SpeedometerUIData").GetField("RpmNeedleMaxValue").str);
        string[] offRPMText = oJson.GetField("SpeedometerUIData").GetField("RpmTextOffset").str.Split(new char[] { ',' });
        this.RPMTextOffset = new Vector2(float.Parse(offRPMText[0]), float.Parse(offRPMText[1]));
        string[] offGearText = oJson.GetField("SpeedometerUIData").GetField("GearTextOffset").str.Split(new char[] { ',' });
        this.GearTextOffset = new Vector2(float.Parse(offGearText[0]), float.Parse(offGearText[1]));
        this.ShowSpeedText  = Convert.ToBoolean(oJson.GetField("SpeedometerUIData").GetField("ShowSpeedText").str);

        this.ShowSpeedUnitText = Convert.ToBoolean(oJson.GetField("SpeedometerUIData").GetField("ShowSpeedUnitText").str);
        this.SpeedUnitText     = oJson.GetField("SpeedometerUIData").GetField("SpeedUnitText").str;
        string[] offSpeedUnitText = oJson.GetField("SpeedometerUIData").GetField("SpeedUnitTextOffset").str.Split(new char[] { ',' });
        this.SpeedUnitTextOffset = new Vector2(float.Parse(offSpeedUnitText[0]), float.Parse(offSpeedUnitText[1]));


        this.ShowRPMText  = Convert.ToBoolean(oJson.GetField("SpeedometerUIData").GetField("ShowRpmText").str);
        this.ShowGearText = Convert.ToBoolean(oJson.GetField("SpeedometerUIData").GetField("ShowGearText").str);
        this.SpeedoSkin   = (GUISkin)Resources.Load(oJson.GetField("SpeedometerUIData").GetField("SpeedoSkin").str);

        this.GaugeDial = (Texture2D)Resources.Load(oJson.GetField("SpeedometerUIData").GetField("GaugeDialTexture").str);
        if (oJson.GetField("SpeedometerUIData").GetField("SpeedoCapTexture").str != "")
        {
            this.SpeedoCapTexture = (Texture2D)Resources.Load(oJson.GetField("SpeedometerUIData").GetField("SpeedoCapTexture").str);
        }
        else
        {
            this.SpeedoCapTexture = null;
        };
        if (oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleTexture").str != "")
        {
            this.SpeedoNeedleTexture = (Texture2D)Resources.Load(oJson.GetField("SpeedometerUIData").GetField("SpeedoNeedleTexture").str);
        }
        else
        {
            this.SpeedoNeedleTexture = null;
        };
        if (oJson.GetField("SpeedometerUIData").GetField("RpmCapTexture").str != "")
        {
            this.RPMCapTexture = (Texture2D)Resources.Load(oJson.GetField("SpeedometerUIData").GetField("RpmCapTexture").str);
        }
        else
        {
            this.RPMCapTexture = null;
        };
        if (oJson.GetField("SpeedometerUIData").GetField("RpmNeedleTexture").str != "")
        {
            this.RPMNeedleTexture = (Texture2D)Resources.Load(oJson.GetField("SpeedometerUIData").GetField("RpmNeedleTexture").str);
        }
        else
        {
            this.RPMNeedleTexture = null;
        };

        RefreshScreenPosition();
    }