예제 #1
0
 // Use this for initialization
 void Start()
 {
     myLeftLimit = gameVars.leftWall + Mathf.Abs(tail.transform.position.x - transform.position.x);
     if (hitAvatar == null)
     {
         Debug.Log("Warning no hit avatar set");
     }
     else
     {
         hitAvatarSpriteStore = hitAvatar.GetComponent <SpriteStore>();
         if (hitAvatarSpriteStore == null)
         {
             Debug.Log("Warning no sprite Store for hit avatar set");
         }
     }
 }
예제 #2
0
        private void DeserializeItemTypes()
        {
            //todo store the sprite names associated with the item types in a dictionary for easy access

            _itemTypes = new Dictionary <string, ItemType>();

            var settings = new DeserializeSettings {
                RequireAllFieldsArePopulated = false
            };

            SpriteStore spriteStore = FindObjectOfType <SpriteStore>();

            foreach (var itemTypesFile in ItemTypesFiles)
            {
                var json = JSON.ParseString(itemTypesFile.text);

                foreach (var key in json.Keys)
                {
                    var itemTypeJson = json.GetJSON(key);

                    var itemType = new ItemType();

                    itemType.Name = key;

                    itemType.Description = itemTypeJson.GetString("Description")?.Trim();

                    itemType.Parent = itemTypeJson.GetString("Parent")?.Trim();

                    itemType.Melee = itemTypeJson.GetJSON("Melee").Deserialize <Attack>(settings);

                    itemType.Ranged = itemTypeJson.GetJSON("Ranged").Deserialize <Attack>(settings);

                    itemType.Defense = itemTypeJson.GetJSON("Defense").Deserialize <Defense>(settings);

                    itemType.Abilities = new List <string>(itemTypeJson.GetJArray("Abilities").AsStringArray());

                    itemType.Range = itemTypeJson.GetInt("Range");

                    var spriteKey = itemTypeJson.GetString("Sprite")?.Trim();

                    itemType.Sprite = spriteStore.GetItemSpriteByKey(spriteKey);

                    var slotString = itemTypeJson.GetString("Slot")?.Trim();

                    itemType.Stackable = itemTypeJson.GetBool("Stackable");

                    itemType.Price = itemTypeJson.GetInt("Price");

                    itemType.TwoHanded = itemTypeJson.GetBool("TwoHanded");

                    itemType.Group = GetItemGroupFromFilename(itemTypesFile.name);

                    AddSpriteNameForGroup(itemType.Group, spriteKey);

                    if (string.IsNullOrEmpty(slotString))
                    {
                        itemType.Slot = null;
                    }
                    else
                    {
                        itemType.Slot = (EquipLocation)Enum.Parse(typeof(EquipLocation), slotString, true);
                    }

                    _itemTypes.Add(key.ToLower(), itemType);
                }
            }
        }