public static ItemObjectWorldElement SpawnFromPrefabPath(Item item) { try { int id = item.itemId; if (ExistsInCache(id)) { Debug.Log("Spawning from cache!"); ItemObjectWorldElement i = CreateItemObjectBehavior(id, (itemGameObjectCache[id])); return(i); } GameObject gameObject = (GameObject)AssetDatabase.LoadAssetAtPath(item.prefabName, typeof(GameObject)); ItemObjectWorldElement itemObj = CreateItemObjectBehavior(id, gameObject); itemGameObjectCache.Add(id, gameObject); return(itemObj); } catch (ArgumentException) { return(new GameObject("Invalid_Item_Object", typeof(ItemObjectWorldElement)).GetComponent <ItemObjectWorldElement>()); } }
private static ItemObjectWorldElement CreateItemObjectBehavior(int id, GameObject toClone) { ItemObjectWorldElement itemObj = GameObject.Instantiate(toClone).GetOrAddComponent <ItemObjectWorldElement>(); itemObj.SetItemFromId(id); return(itemObj); }
private void OnEnable() { parentFocusAreaContainer = GetComponentInParent<ItemObjectWorldElement>(); sphereCollider = GetComponent<SphereCollider>(); spriteRenderer = GetComponent<SpriteRenderer>(); numberDisplay = GetComponentInChildren<TextMeshPro>(); originalScale = transform.localScale; SetNumberDisplay(); CraftingManager.AddFocusAreaScreenIndicator(this); }