public static bool GetTokenInDB() { var DBtoken = SQLiteBD.ExecuteQueryWithAnswer($"SELECT token FROM players where id = {GameController.PlayerID}"); if (!(DBtoken == string.Empty || DBtoken == null)) { token = DBtoken; return(true); } return(false); }
private IEnumerator GetStatsInBD() { // new Thread(new ThreadStart(() => // { statsText.text = SQLiteBD.ExecuteQueryWithAnswer($"SELECT itemCount FROM PlayersItems WHERE itemId = {itemId} AND playerId = {GameController.PlayerID}"); // })).Start(); //Debug.Log(statsText.text); yield return(new WaitForSeconds(1.0f)); StartCoroutine(GetStatsInBD()); }
private void Start() { try { maxCratID = int.Parse(SQLiteBD.ExecuteQueryWithAnswer("SELECT MAX(craftID) FROM CraftItems")); } catch (FormatException) { Debug.LogError("FormatE"); maxCratID = 0; } catch (ArgumentNullException) { Debug.LogError("ArgNULL"); maxCratID = 0; } }
void Start() { _deltaX = 1.3f; _deltaY = -1.3f; int workshopLVL = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT workshopLVL FROM players WHERE selectedPlayer = 1")); int x = 0; int y = 0; for (int i = 0; i < itemsRecipes.Length; i++) { if (itemsRecipes[i].AccessLevel <= workshopLVL) { var newItem = Instantiate(itemPrefab, new Vector3(startPos.x + _deltaX * x, startPos.y + _deltaY * y, transform.position.z), Quaternion.identity, transform); newItem.name = $"{itemPrefab.name} {transform.childCount}"; StartCoroutine(GetComponent <LoadItem>().LoadIemIconFromWorkshop( itemsRecipes[i].ItemID, newItem)); newItem.GetComponent <ClickToItem>().recipe = itemsRecipes[i]; //newItem.GetComponent<LoadItemRecipeOnBoard>().Recipe = itemsRecipes[i]; x++; if (x > 2) { x = 0; y++; } } } if (y > 3) { RectTransform contentRect = GetComponent <RectTransform>(); contentRect.sizeDelta = new Vector2(contentRect.sizeDelta.x, //distance between 2 item * rows.count * yOffset 60 * y + 40); //RectTransform contentRect = GetComponent<RectTransform>(); //contentRect.offsetMax += new Vector2(0, -50); //contentRect.offsetMin -= new Vector2(0, 50); } }
public void UpdateLVL() { int sawmillLVL = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT sawmillLVL FROM Players WHERE id = {GameController.PlayerID}")); int mineLVL = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT mineLVL FROM Players WHERE id = {GameController.PlayerID}")); if (ChoppersRecipes.Length < sawmillLVL) { ChoppersRecipes = new UpgradeRecipes[0]; } else if (sawmillLVL > 1) { ChoppersRecipes = RemoveItems(ChoppersRecipes, ChoppersRecipes.Length - (sawmillLVL - 1), sawmillLVL - 1); } if (MinersRecipes.Length < mineLVL) { MinersRecipes = new UpgradeRecipes[0]; } else if (mineLVL > 1) { MinersRecipes = RemoveItems(MinersRecipes, MinersRecipes.Length - (mineLVL - 1), mineLVL - 1); } }
private void Start() { string unitType = ""; if (isChopper) { unitType = "1"; } else { unitType = "2"; } DataTable data = SQLiteBD.GetTable($"SELECT TimeToEnd,speed,effectivity,unitID FROM Units WHERE playerId = {GameController.PlayerID} AND unitType = {unitType} ORDER BY unitID"); maxUnitID = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT MAX(unitID) FROM Units")) + 1; if (data.Rows.Count > 0) { for (int i = 0; i < data.Rows.Count; i++) { TimeSpan second; DateTime unitTime = DateTime.ParseExact(data.Rows[i][0].ToString(), "u", CultureInfo.InvariantCulture).AddHours(2); if (unitTime > DateTime.UtcNow) { second = unitTime - System.DateTime.UtcNow; } else { second = TimeSpan.Zero; } AddUnitInDB(Mathf.RoundToInt(float.Parse(second.TotalSeconds.ToString())), //seconds float.Parse(data.Rows[i][1].ToString()), // speed int.Parse(data.Rows[i][2].ToString()), // effectivity int.Parse(data.Rows[i][3].ToString()) ); } } }
private void Awake() { GameController.PlayerID = int.Parse(SQLiteBD.ExecuteQueryWithAnswer("SELECT id FROM Players WHERE selectedPlayer = 1")); }
IEnumerator LoadItemIcon(string uri, int childNumber, int currentID) { using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture($"{uri}/{SQLiteBD.ExecuteQueryWithAnswer($"SELECT pathToSprite FROM Items WHERE itemID = {currentID}")}")) { yield return(webRequest.SendWebRequest()); if (webRequest.isNetworkError) { Debug.Log("Error: " + webRequest.error); } else { //Debug.Log("Received: " + webRequest.downloadHandler); Texture2D texture = DownloadHandlerTexture.GetContent(webRequest); transform.GetChild(childNumber).GetChild(0).GetComponent <Image>().sprite = Sprite.Create( texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); } } yield break; }
//[SerializeField] private UpgradeRecipes currentRecipe; private void OnEnable() { UpgradeRecipes currentRecipe = GetComponent <AddRecipeOnScript>().CurrentUpgradeRecipe; if (currentRecipe == null) { currentRecipe = GetComponent <AddRecipeOnScript>().CurrentItemRecipe; } bool allResourcesAvailable = false; if (currentRecipe != null) { byte countAvailable = 0; for (int i = 0; i < currentRecipe.RecipesItemsID.Length; i++) { var child = transform.GetChild(i); var currentID = currentRecipe.RecipesItemsID[i]; //set sprite #if UNITY_EDITOR DirectoryInfo directoryInfo = new DirectoryInfo(Application.streamingAssetsPath + "/ItemsIcons"); print(directoryInfo); FileInfo[] allFiles = directoryInfo.GetFiles("*.*"); foreach (var file in allFiles) { if (file.Name.Contains(SQLiteBD.ExecuteQueryWithAnswer($"SELECT pathToSprite FROM Items WHERE itemID = {currentID}"))) { StartCoroutine(LoadItemIcon(file, i)); } } #endif #if UNITY_ANDROID //DirectoryInfo direcrotyInfo = new DirectoryInfo(Application.persistentDataPath); //DirectoryInfo direcrotyInfo = new DirectoryInfo() StartCoroutine(LoadItemIcon(Application.streamingAssetsPath + "/ItemsIcons", i, currentID)); #endif int playerCount = int.Parse(SQLiteBD.ExecuteQueryWithAnswer($"SELECT ItemCount FROM PlayersItems WHERE itemId = {currentID} AND playerId = {GameController.PlayerID}")); TextMeshProUGUI childTMP = child.GetChild(1).GetComponent <TextMeshProUGUI>(); //set text color if (playerCount >= currentRecipe.RecipesCountItems[i]) { Debug.Log($"{gameObject.name} {countAvailable}//{currentRecipe.RecipesItemsID.Length}"); childTMP.color = Color.green; countAvailable++; } else { childTMP.color = Color.red; } if (countAvailable >= currentRecipe.RecipesItemsID.Length) { allResourcesAvailable = true; } //Debug.Log($"{gameObject.name} {allResourcesAvailable}//{countAvailable}"); childTMP.text = $"" + $"{playerCount}" + $"/{currentRecipe.RecipesCountItems[i]}"; child.gameObject.SetActive(true); } } else { Debug.LogError("Not have a recipe"); } if (allResourcesAvailable) { transform.GetChild(6).GetComponent <Button>().interactable = true; } else { transform.GetChild(6).GetComponent <Button>().interactable = false; } }
public IEnumerator LoadIemIconFromWorkshop(int itemID, GameObject go) { if (itemID > 0 && go != null) { using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture($"{Application.streamingAssetsPath + "/ItemsIcons"}" + $"/{SQLiteBD.ExecuteQueryWithAnswer($"SELECT pathToSprite FROM Items WHERE itemID = {itemID}")}")) { yield return(webRequest.SendWebRequest()); if (webRequest.isNetworkError) { Debug.Log("Error: " + webRequest.error); } else { //Debug.Log("Received: " + webRequest.downloadHandler); Texture2D texture = DownloadHandlerTexture.GetContent(webRequest); go.transform.GetChild(1).GetComponent <Image>().sprite = Sprite.Create( texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); } } } else { Debug.LogError("Error: Load Item Sprite"); } yield break; }