public GemCell GetOneGemCell(int id) { GemCell gemCellObject = null; var poolItem = GemCellPoolItems.Find(pool => pool.Id == id); if (poolItem != null && poolItem.GemCells.Count > 0) { var gemCell = poolItem.GemCells[0]; gemCellObject = gemCell.GetComponent <GemCell>(); gemCellObject.gameObject.transform.parent = null; gemCellObject.gameObject.transform.localPosition = Vector3.zero; poolItem.GemCells.RemoveAt(0); gemCellObject.gameObject.SetActive(true); } else { var name = GemConverter.GetGemName(id); var prefabItem = PrefabList.Find(a => a.Name.Equals(name)); var gObject = Instantiate(prefabItem.Prefab) as GameObject; gemCellObject = gObject.GetComponent <GemCell>(); gemCellObject.gameObject.transform.parent = null; gemCellObject.gameObject.transform.localPosition = Vector3.zero; } gemCellObject.OnActivate(); return(gemCellObject); }
private void Start() { gemNumber = gameObject.GetComponentInChildren<Text>(); animator = gameObject.GetComponent<Animator>(); wizard = FindObjectOfType<Wizard>(); gemConverter = FindObjectOfType<GemConverter>(); inventory = FindObjectOfType<Inventory>(); mana = FindObjectOfType<Mana>(); currentGemNumber = 0; }
void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } Instance = this; // Furthermore we make sure that we don't destroy between scenes (this is optional) DontDestroyOnLoad(gameObject); }
private GemCell ConvertToGemCell(SpawnItem spawn) { int gem = GemConverter.GetGemInt(spawn.GemName); GemCell newGemCell = GemCellPool.Instance.GetOneGemCell(gem); newGemCell.InitGem(); var thisGem = newGemCell.Gem; if (thisGem.AllowBG) { int bg = GemBGConverter.GetGemInt(spawn.BgName); newGemCell.InitBgGem(bg); } if (thisGem.AllowFG) { int fg = GemFGConverter.GetGemInt(spawn.FgName); newGemCell.InitFgGem(fg); } return(newGemCell); }
// Use this for initialization public void Init() { Type = GemConverter.GetGemInt(Id); }