public static void SetData(PlayerFormation data) { if (data == null || string.IsNullOrEmpty(data.characterGuid)) { return; } DataMap[data.characterGuid] = data; }
void Start() { Camera camera = Camera.main; float distance = transform.position.z - camera.transform.position.z; xmin = camera.ViewportToWorldPoint(new Vector3(0, 0, distance)).x + padding; xmax = camera.ViewportToWorldPoint(new Vector3(1, 1, distance)).x - padding; formation = GameObject.Find("PlayerFormation").GetComponent <PlayerFormation>(); }
public static bool TryGetData(string playerId, string dataId, int position, out PlayerFormation data) { foreach (var item in DataMap.Values) { if (item.GetFormationID().Equals(playerId + "_" + dataId + "_" + position)) { data = item; return(true); } } data = null; return(false); }
private void HelperSetFormation(string itemguid, string playerId, string characterId, string formationName, int position) { PlayerFormation oldFormation = null; if (!string.IsNullOrEmpty(characterId)) { var oldFormations = GameInstance.dbDataUtils.ExecuteReader(@"SELECT * FROM playerFormation WHERE playerId=@playerId AND Guid=@Guid AND position=@position LIMIT 1", new SqliteParameter("@playerId", playerId), new SqliteParameter("@Guid", formationName), new SqliteParameter("@position", position)); if (oldFormations.Read()) { oldFormation = new PlayerFormation(); oldFormation.PlayerId = oldFormations.GetString(1); oldFormation.formationId = oldFormations.GetString(2); oldFormation.Position = oldFormations.GetInt32(3); oldFormation.ItemId = oldFormations.GetString(4); oldFormation.characterGuid = oldFormations.GetString(5); } if (oldFormation != null) { GameInstance.dbDataUtils.ExecuteNonQuery(@"DELETE FROM playerFormation WHERE playerId=@playerId AND Guid=@Guid AND position=@position", new SqliteParameter("@playerId", playerId), new SqliteParameter("@Guid", formationName), new SqliteParameter("@position", position)); } } PlayerFormation formation = null; var targetFormations = GameInstance.dbDataUtils.ExecuteReader(@"SELECT * FROM playerFormation WHERE playerId=@playerId AND Guid=@Guid AND itemguid=@itemguid LIMIT 1", new SqliteParameter("@itemguid", itemguid), new SqliteParameter("@playerId", playerId), new SqliteParameter("@Guid", formationName)); if (targetFormations.Read()) { formation = new PlayerFormation(); formation.PlayerId = targetFormations.GetString(1); formation.formationId = targetFormations.GetString(2); formation.Position = targetFormations.GetInt32(3); formation.ItemId = targetFormations.GetString(4); formation.characterGuid = targetFormations.GetString(5); } if (formation == null) { formation = new PlayerFormation(); formation.characterGuid = itemguid; formation.PlayerId = playerId; formation.formationId = formationName; formation.Position = position; formation.ItemId = characterId; GameInstance.dbDataUtils.ExecuteNonQuery(@"INSERT INTO playerFormation (itemguid, playerId, Guid, position, itemId,id) VALUES (@itemguid, @playerId, @Guid, @position, @itemId,@id)", new SqliteParameter("@itemguid", formation.characterGuid), new SqliteParameter("@playerId", formation.PlayerId), new SqliteParameter("@Guid", formation.formationId), new SqliteParameter("@position", formation.Position), new SqliteParameter("@itemId", formation.ItemId), new SqliteParameter("@id", 0)); } else { Debug.LogError("find this item" + formation.characterGuid); formation.Position = position; GameInstance.dbDataUtils.ExecuteNonQuery(@"UPDATE playerFormation SET position=@position WHERE itemguid=@itemguid", new SqliteParameter("@position", formation.Position), new SqliteParameter("@itemguid", formation.characterGuid)); } }
public static bool TryGetData(string dataId, int position, out PlayerFormation data) { return(TryGetData(IPlayer.CurrentPlayer.guid, dataId, position, out data)); }