/// <summary> /// Sets up the manager and creates all the selectable items. /// Makes sure one of the items is the correct one to complete the row. /// </summary> public void SetUp() { DestroyOldItems(); // List to make sure that the items on the bar are from different themes. m_currentThemes = new List <string>(); // int to pick one of the four items that will match with current row. int randomItemPosition = Random.Range(0, Constants.NUMBER_OF_SELECTABLE_ITEMS); m_currentRowScript = m_rowsManager.GetCurrentRowScript(); // What is the current theme name? string currentTheme = m_currentRowScript.GetThemeName(); // Add it on used themes. List <string> itemThemes = new List <string>(); for (int i = 0; i < Constants.NUMBER_OF_SELECTABLE_ITEMS; i++) { string itemName; string selectTheme = currentTheme; GameObject item = (GameObject)Instantiate(m_itemHolder); item.AddComponent <SelectItemScript>(); // selectable item. // this is the item that matches. if (randomItemPosition == i) { itemName = m_currentRowScript.GetMissingElement(); item.GetComponent <SelectItemScript>().SetUpItem(itemName, selectTheme, i, m_currentRowScript.gameObject.transform, m_showReel); m_selectItemsNames.Add(itemName); correctItemPos = item.transform.position; } // this is a random item. else { GameObject pictureLoaderObject = GameObject.Find(Constants.PICTURE_LOADER_NAME); PictureLoader pictureLoader = pictureLoaderObject.GetComponent <PictureLoader>(); // Make sure it's not an item of the same theme! Item should be unique. if (Game.SuperMode != Game.Difficulty.Hard) { do { selectTheme = pictureLoader.SelectRandomTheme(); }while (selectTheme == currentTheme || itemThemes.IndexOf(selectTheme) != -1); itemName = pictureLoader.SelectRandomURL(selectTheme); } else { selectTheme = currentTheme; do { itemName = pictureLoader.SelectRandomURL(selectTheme); }while (m_selectItemsNames.IndexOf(itemName) != -1 || itemName == m_currentRowScript.GetMissingElement()); } item.GetComponent <SelectItemScript>().SetUpItem(itemName, selectTheme, i, gameObject.transform, m_showReel); itemThemes.Add(selectTheme); m_selectItems.Add(item); m_selectItemsNames.Add(itemName); } } }
/// <summary> /// Returns true if the manager has the selectable item. /// </summary> public bool Contains(GameObject item) { return(m_selectItems.IndexOf(item) != -1 || item.name == m_currentRowScript.GetMissingElement()); }