Skip to content

Instantly share code, notes, and snippets.

@314pies
Created November 25, 2018 15:54
Show Gist options
  • Save 314pies/10fd51b40fc8153c006b9c13c1483118 to your computer and use it in GitHub Desktop.
Save 314pies/10fd51b40fc8153c006b9c13c1483118 to your computer and use it in GitHub Desktop.
ItemIdToLoadout.cs
```cs
using LWWeaponSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dazad : MonoBehaviour
{
public enum ItemTypes
{
w,
wa,
ws,
wr,
c,
cs,
ab
}
Dictionary<string, ItemTypes> _strToItemtype = null;
Dictionary<string, ItemTypes> strToItemtype
{
get
{
if (_strToItemtype == null)
foreach (ItemTypes _item in Enum.GetValues(typeof(ItemTypes)))
_strToItemtype.Add(_item.ToString(), _item);
return _strToItemtype;
}
}
public ItemTypes IdentifySingleItemType(string singleItemType)
{
char[] delimiterChars = { '_' };
string[] itemIDs = singleItemType.Split(delimiterChars);
if (strToItemtype.ContainsKey(itemIDs[0]))
{
return strToItemtype[itemIDs[0]];
}
else
{
throw new Exception("singleItemType is not in correct format");
}
}
public object GetType(string itemId)
{
char[] delimiterChars = { '.' };
string[] itemIDs = itemId.Split(delimiterChars);
if (IdentifySingleItemType(itemIDs[0]) == ItemTypes.w)
{
Loadout_Weapon _loadoutWeapon = new Loadout_Weapon() { WeaponIndex = itemIDs[0] };
if (itemIDs.Length > 1)
{
if (IdentifySingleItemType(itemIDs[1]) == ItemTypes.ws)
_loadoutWeapon.SkinId = itemIDs[1];
else if (IdentifySingleItemType(itemIDs[1]) == ItemTypes.wr)
_loadoutWeapon.ReloadAnimation = itemIDs[1];
return _loadoutWeapon;
}
}
else if (IdentifySingleItemType(itemIDs[0]) == ItemTypes.c)
{
Loadout_Character _loadoutCharacter = new Loadout_Character() { CharacterId = itemIDs[0] };
if (itemIDs.Length > 1)
_loadoutCharacter.SkinId = itemIDs[1];
return _loadoutCharacter;
}else if(IdentifySingleItemType(itemIDs[0]) == ItemTypes.ab)
{
return itemIDs[0];
}
return null;
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment