public Sprite getSprite(string spriteSheet, string unityName) { //if it's a proper unityName with offset int uOffset = DmiIcon.getOffsetFromUnityName(unityName); if (!uOffset.Equals(-1)) { return(getSprite(spriteSheet, uOffset)); } //if it's something custom ,like tileconnect handwritten stuff DmiIcon icon = getIconBySheet(spriteSheet); if (!icon.getName().Equals("")) { DmiState dmiState = icon.states.Find(state => state.unityName.Equals(unityName)); if (dmiState != null) { int offset = dmiState.offset; if (icon.spriteSheet.Length > offset && !offset.Equals(-1)) { return(icon.spriteSheet[offset]); } } Logger.LogErrorFormat("Couldn't find sprite by UN: {0}({1}) in {2}", Category.DmMetadata, spriteSheet, unityName, icon.icon); } return(new Sprite()); }
public Sprite getSprite(string spriteSheet, int offset) { DmiIcon icon = getIconBySheet(spriteSheet); if (!icon.getName().Equals("") && offset >= 0 && offset < icon.spriteSheet.Length) { return(icon.spriteSheet[offset]); } Logger.LogErrorFormat("Couldn't find sprite by offset: {0}({1}) in {2}", Category.DmMetadata, spriteSheet, offset, icon.icon); return(new Sprite()); }
private static Sprite tryGetStateSprite(DmiIcon dmiIcon, string icon_state) { if (dmiIcon == null || dmiIcon.getName().Equals("")) { Debug.LogErrorFormat("DmiIcon '{0}' is null, unable to get state '{1}'", dmiIcon, icon_state); return(new Sprite()); } DmiState iState = dmiIcon.getState(icon_state); if (!iState.state.Equals("")) { return(dmiIcon.spriteSheet[iState.offset]); } Debug.LogErrorFormat("Failed to find inventory sprite '{1}' in icon '{0}'", dmiIcon.icon, icon_state); return(new Sprite()); }
private static Sprite tryGetStateSprite(DmiIcon dmiIcon, string icon_state) { if (dmiIcon == null || dmiIcon.getName().Equals("")) { Logger.Log($"DmiIcon '{dmiIcon}' is null, unable to get state '{icon_state}'", Category.DmMetadata); return(new Sprite()); } DmiState iState = dmiIcon.getState(icon_state); if (!iState.state.Equals("")) { return(dmiIcon.spriteSheet[iState.offset]); } Logger.Log($"Failed to find inventory sprite '{icon_state}' in icon '{dmiIcon.icon}'", Category.DmMetadata); return(new Sprite()); }
// Enum test: // // private void OnEnable() // { // if (hierarchy == null || hierarchy.Equals("")) // { // hierarchy = cloth.GetDescription(); // } // ConstructItem(hierarchy); // } public void ConstructItem(string hierString) { //randomize clothing! uncomment only if you spawn without any clothes on! // randomizeClothHierIfEmpty(); //don't do anything if hierarchy string is empty hier = hierString.Trim(); if (hier.Length == 0) { return; } //init datafiles if (!dmi) { // Debug.Log("Item DMI data loading..."); dmi = Resources.Load("DmiIconData") as DmiIconData; } if (!dm) { // Debug.Log("Item DM data loading..."); dm = Resources.Load("DmObjectData") as DmObjectData; } //raw dictionary of attributes dmDic = dm.getObject(hier); //basic attributes name = tryGetAttr("name"); desc = tryGetAttr("desc"); //custom inventory(?) icon, if present icon = tryGetAttr("icon"); // states icon_state = tryGetAttr("icon_state"); item_color = tryGetAttr("item_color"); //also a state item_state = tryGetAttr("item_state"); var states = new[] { icon_state, item_color, item_state }; masterType = getMasterType(hier);// aka SpriteType itemType = getItemType(hier, getInvIconPrefix(masterType)); invSheetPaths = getItemClothSheetHier(itemType); // size = getItemSize(tryGetAttr("w_class")); int[] inHandOffsets = tryGetInHand(); inHandLeft = inHandOffsets[0]; inHandRight = inHandOffsets[1]; inventoryIcon = tryGetInventoryIcon(); clothingOffset = tryGetClothingOffset(states); //determine item type via sheet name if hier name failed if (itemType == ItemType.None) { itemType = getItemType(inventoryIcon.getName()); } //inventory item sprite Sprite stateSprite = tryGetStateSprite(inventoryIcon, icon_state); //finally setting things inHandReferenceLeft = inHandLeft; inHandReferenceRight = inHandRight; clothingReference = clothingOffset; type = itemType; itemName = name; itemDescription = desc; GetComponentInChildren <SpriteRenderer>().sprite = stateSprite; // Debug.Log(name + " size=" + size + " type=" + type + " spriteType=" // + spriteType + " (" + desc + ") : " // + icon_state + " / " + item_state + " / C: " + clothingReference // + ", L: " + inHandReferenceLeft + ", R: " + inHandReferenceRight + ", I: " + inventoryIcon.icon + '\n' // + dmDic.Keys.Aggregate("", (current, key) => current + (key + ": ") + dmDic[key] + "\n")); }
public void ConstructItem(string hierString) { //randomize clothing! randomizeClothHierIfEmpty(); //don't do anything if hierarchy string is empty hier = hierString.Trim(); if (hier.Length == 0) { return; } //init datafiles if (!dmi) { // Logger.Log("Item DMI data loading..."); dmi = Resources.Load("DmiIconData") as DmiIconData; } if (!dm) { // Logger.Log("Item DM data loading..."); dm = Resources.Load("DmObjectData") as DmObjectData; } //raw dictionary of attributes dmDic = dm.getObject(hier); //basic attributes name = tryGetAttr("name"); desc = tryGetAttr("desc"); //custom inventory(?) icon, if present icon = tryGetAttr("icon"); // states icon_state = tryGetAttr("icon_state"); item_color = tryGetAttr("item_color"); //also a state item_state = tryGetAttr("item_state"); string[] states = { icon_state, item_color, item_state }; throwDamage = TryParseFloat("throwforce") ?? throwDamage; throwSpeed = TryParseFloat("throw_speed") ?? throwSpeed; throwRange = TryParseFloat("throw_range") ?? throwRange; hitDamage = TryParseFloat("force") ?? hitDamage; attackVerb = TryParseList("attack_verb") ?? attackVerb; masterType = getMasterType(hier); // aka SpriteType itemType = getItemType(hier, getInvIconPrefix(masterType)); invSheetPaths = getItemClothSheetHier(itemType); // size = getItemSize(tryGetAttr("w_class")); int[] inHandOffsets = tryGetInHand(); inHandLeft = inHandOffsets[0]; inHandRight = inHandOffsets[1]; inventoryIcon = tryGetInventoryIcon(); clothingOffset = tryGetClothingOffset(states); //determine item type via sheet name if hier name failed if (itemType == ItemType.None) { itemType = getItemType(inventoryIcon.getName()); } //inventory item sprite Sprite stateSprite = tryGetStateSprite(inventoryIcon, icon_state); //finally setting things inHandReferenceLeft = inHandLeft; inHandReferenceRight = inHandRight; clothingReference = clothingOffset; type = itemType; itemName = name; itemDescription = desc; spriteType = masterType; GetComponentInChildren <SpriteRenderer>().sprite = stateSprite; //assign an order in layer so we don't have arbitrary ordering GetComponentInChildren <SpriteRenderer>().sortingOrder = clothingOffset; // Logger.Log(name + " size=" + size + " type=" + type + " spriteType=" // + spriteType + " (" + desc + ") : " // + icon_state + " / " + item_state + " / C: " + clothingReference // + ", L: " + inHandReferenceLeft + ", R: " + inHandReferenceRight + ", I: " + inventoryIcon.icon + '\n' // + dmDic.Keys.Aggregate("", (current, key) => current + (key + ": ") + dmDic[key] + "\n")); CheckEvaCapatibility(); }
public void ConstructItem(string hierString) { //randomize clothing! RandomizeClothHierIfEmpty(); //don't do anything if hierarchy string is empty hier = hierString.Trim(); if (hier.Length == 0) { return; } //init datafiles if (!dmi) { dmi = Resources.Load("DmiIconData") as DmiIconData; } if (!dm) { dm = Resources.Load("DmObjectData") as DmObjectData; } dmDic = dm.getObject(hier); //basic attributes itemName = TryGetAttr("name"); itemDescription = TryGetAttr("desc"); icon = TryGetAttr("icon"); //states icon_state = TryGetAttr("icon_state"); item_color = TryGetAttr("item_color"); //also a state item_state = TryGetAttr("item_state"); string[] states = { icon_state, item_color, item_state }; throwDamage = TryParseFloat("throwforce") ?? throwDamage; throwSpeed = TryParseFloat("throw_speed") ?? throwSpeed; throwRange = TryParseFloat("throw_range") ?? throwRange; hitDamage = TryParseFloat("force") ?? hitDamage; attackVerb = TryParseList("attack_verb") ?? attackVerb; spriteType = UniItemUtils.GetMasterType(hier); itemType = UniItemUtils.GetItemType(hier); invSheetPaths = UniItemUtils.GetItemClothSheetHier(itemType); int[] inHandOffsets = TryGetInHand(); inHandReferenceLeft = inHandOffsets[0]; inHandReferenceRight = inHandOffsets[1]; inventoryIcon = UniItemUtils.GetInventoryIcon(hier, invSheetPaths, icon, icon_state); clothingReference = TryGetClothingOffset(states); //determine item type via sheet name if hier name failed if (itemType == ItemType.None) { itemType = UniItemUtils.GetItemType(inventoryIcon.getName()); } CanConnectToTank = TryGetConnectedToTank(); //inventory item sprite Sprite stateSprite = UniItemUtils.TryGetStateSprite(inventoryIcon, icon_state); var childSpriteRenderer = GetComponentInChildren <SpriteRenderer>(); childSpriteRenderer.sprite = stateSprite; //assign an order in layer so we don't have arbitrary ordering childSpriteRenderer.sortingOrder = clothingReference; CheckEvaCapatibility(); }
private void OnEnable() { //todo: make more methods static //randomize clothing! uncomment only if you spawn without any clothes on! randomizeClothHierIfEmpty(); //don't do anything if hierarchy string is empty hier = hierarchy.Trim(); if (hier.Length == 0) { return; } //init datafiles if (!dmi) { Debug.Log("Item DMI data loading..."); dmi = Resources.Load("DmiIconData") as DmiIconData; } if (!dm) { Debug.Log("Item DM data loading..."); dm = Resources.Load("DmObjectData") as DmObjectData; } //raw dictionary of attributes dmDic = dm.getObject(hier); //basic attributes name = tryGetAttr("name"); desc = tryGetAttr("desc"); icon_state = tryGetAttr("icon_state"); item_state = tryGetAttr("item_state"); icon = tryGetAttr("icon"); masterType = getMasterType(hier); iType = getItemType(hier, getInvIconPrefix(masterType)); invSheetPaths = getItemClothSheetHier(iType); // size = getItemSize(tryGetAttr("w_class")); int[] inHandOffsets = tryGetInHand(); inHandLeft = inHandOffsets[0]; inHandRight = inHandOffsets[1]; inventoryIcon = tryGetInventoryIcon(); clothingOffset = tryGetClothingOffset(); //determine item type via sheet name if hier name failed if (iType == ItemType.None) { iType = getItemType(inventoryIcon.getName()); } //inventory item sprite DmiState iState = inventoryIcon.getState(icon_state); Sprite stateSprite = inventoryIcon.spriteSheet[iState.offset]; //finally setting things inHandReferenceLeft = inHandLeft; inHandReferenceRight = inHandRight; clothingReference = clothingOffset; type = iType; itemName = name; itemDescription = desc; GetComponentInChildren <SpriteRenderer>().sprite = stateSprite; Debug.Log(name + " size=" + size + " type=" + type + " spriteType=" + spriteType + " (" + desc + ") : " + icon_state + " / " + item_state + " / C: " + clothingReference + ", L: " + inHandReferenceLeft + ", R: " + inHandReferenceRight + ", I: " + inventoryIcon.icon + '\n' + dmDic.Keys.Aggregate("", (current, key) => current + (key + ": ") + dmDic[key] + "\n")); }