コード例 #1
0
ファイル: PartsManager.cs プロジェクト: tmoritaa/JunkMetal
    private void loadWeaponParts()
    {
        Dictionary <string, PartSchematic> schematics = new Dictionary <string, PartSchematic>();

        TextAsset jsonText = Resources.Load("WeaponPartList") as TextAsset;

        JObject root = JObject.Parse(jsonText.text);

        foreach (var partInfo in root)
        {
            string name = partInfo.Key;

            JObject info = (JObject)partInfo.Value;

            float  reloadTime             = info.Value <float>("reload_time");
            int    energyUsage            = info.Value <int>("energy_usage");
            string tierStr                = info.Value <string>("tier");
            PartSchematic.WeaponTier tier = PartSchematic.WeaponTier.Light;
            if (tierStr.Equals("L"))
            {
                tier = PartSchematic.WeaponTier.Light;
            }
            else if (tierStr.Equals("M"))
            {
                tier = PartSchematic.WeaponTier.Medium;
            }
            else if (tierStr.Equals("H"))
            {
                tier = PartSchematic.WeaponTier.Heavy;
            }

            Bullet.BulletTypes bType = (Bullet.BulletTypes)Enum.Parse(typeof(Bullet.BulletTypes), info.Value <string>("bullet_type"));

            Dictionary <string, object> bulletInfoDict = parseBulletInfoJson(bType, info.Value <JObject>("bullet_info"));

            WeaponPartSchematic part = TankParSchematictFactory.CreateWeaponPartSchematic(name, reloadTime, energyUsage, tier, bType, bulletInfoDict);

            schematics.Add(part.Name, part);
        }

        partSchematicDics.Add(PartSchematic.PartType.Weapon, schematics);
    }
コード例 #2
0
ファイル: PartsManager.cs プロジェクト: tmoritaa/JunkMetal
    private void loadHullParts()
    {
        Dictionary <string, PartSchematic> schematics = new Dictionary <string, PartSchematic>();

        TextAsset jsonText = Resources.Load("HullPartList") as TextAsset;

        JObject root = JObject.Parse(jsonText.text);

        foreach (var partInfo in root)
        {
            string name = partInfo.Key;

            JObject info        = (JObject)partInfo.Value;
            int     weight      = info.Value <int>("weight");
            int     armour      = info.Value <int>("armor");
            int     enginePower = info.Value <int>("engine_pow");

            Vector2 size = new Vector2();
            size.x = info.Value <float>("size_x");
            size.y = info.Value <float>("size_y");

            float angularDrag = info.Value <float>("angular_drag");

            float energy         = info.Value <float>("energy");
            float energyRefresh  = info.Value <float>("energy_refresh");
            float jetImpulse     = info.Value <float>("jet_impulse");
            float jetEnergyUsage = info.Value <float>("jet_energy_usage");

            List <Vector2> weaponDirs = new List <Vector2>();
            List <Vector2> weaponPos  = new List <Vector2>();
            List <PartSchematic.WeaponTier> tierRestrictions = new List <PartSchematic.WeaponTier>();
            foreach (JObject jo in info.Value <JArray>("weapons"))
            {
                Vector2 dir = new Vector2();
                dir.x = jo.Value <float>("x_dir");
                dir.y = jo.Value <float>("y_dir");
                weaponDirs.Add(dir);

                Vector2 pos = new Vector2();
                pos.x = jo.Value <float>("x_pos");
                pos.y = jo.Value <float>("y_pos");
                weaponPos.Add(pos);

                string weaponTier = jo.Value <string>("tier");

                PartSchematic.WeaponTier tier = PartSchematic.WeaponTier.Light;
                if (weaponTier.Equals("L"))
                {
                    tier = PartSchematic.WeaponTier.Light;
                }
                else if (weaponTier.Equals("M"))
                {
                    tier = PartSchematic.WeaponTier.Medium;
                }
                else if (weaponTier.Equals("H"))
                {
                    tier = PartSchematic.WeaponTier.Heavy;
                }
                tierRestrictions.Add(tier);
            }

            HullPartSchematic part = TankParSchematictFactory.CreateHullPartSchematic(name, armour, enginePower, size, weight, angularDrag, energy, energyRefresh, jetImpulse, jetEnergyUsage, weaponDirs.ToArray(), weaponPos.ToArray(), tierRestrictions.ToArray());

            schematics.Add(part.Name, part);
        }

        partSchematicDics.Add(PartSchematic.PartType.Hull, schematics);
    }