public async Task <ActionResult <GoalData> > PostGoalData(GoalData goalData) { _context.GoalData.Add(goalData); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGoalData", new { id = goalData.GoalId }, goalData)); }
private void SetMockGoals() { MockGoals = new Mock <DbSet <Goal> >().SetupData(GoalData.Data()); MockGoals.Setup(x => x.Find(It.IsAny <object[]>())).Returns <object[]>(ids => GoalData.Data().FirstOrDefault(d => d.GoalId == (int)ids[0])); MockGoals.Setup(x => x.FindAsync(It.IsAny <object[]>())).Returns <object[]>(ids => Task.FromResult(GoalData.Data().FirstOrDefault(d => d.GoalId == (int)ids[0]))); MockContext.Setup(x => x.Goals).Returns(MockGoals.Object); }
public async Task <IHttpActionResult> CreateGoalAsync(GoalData goalData) { _log.LogDebug($"Request: {JsonConvert.SerializeObject(goalData)}"); User user; try { user = await ControllerUtils.GetUserForRequestHeaderTokenAsync(this, _tokenStore, _userStore, _log); } catch (AuthenticationException ex) { return(BadRequest(ex.Message)); } catch (InternalServerException) { return(InternalServerError()); } Goal goal = await _goalStore.CreateGoalAsync( user.Id, goalData.Name, goalData.PeriodInHours, goalData.FrequencyWithinPeriod, goalData.StartDate); _log.LogDebug($"Goal created: {goal}"); return(Ok( JsonConvert.SerializeObject( Mapper.Map <GoalData>(goal)))); }
} //NPCか否か /////////////////////////////////////////////////////////////////////////// // 公開関数 /////////////////////////////////////////////////////////////////////////// //データ設定=============================================================== public void Initialize(PlayerCharStateData aData) { //モデル変更 this.ModeChange(Database.obj.GetPlayerModel(aData.modelId)); //アンカー m_AncData = m_CouresAncs.GetAnc(0); m_AncDataGround = m_CouresAncs.GetAnc(0); //ステータス m_wait = aData.wait; m_Gravity = new GravityStatus(); m_Speed = new SpeedStatus(aData.accel, aData.turn, aData.maxSpeed); m_Jump = new JumpStatus(); m_Glider = new GliderStatus(); m_Heat = new HeatStatus(); m_Rack = RackState.READY; m_GoalData = new GoalData(); //ステート m_TrgState = new BoolArray32(false); m_NowState = new BoolArray32(false); InputStart(); //入力 CameraStart(); //カメラ SpeedStart(); //速度・方向 StartPhysics(); //重力やレイキャスト SpwanStart(); //復帰する処理用 TurnnStart(); //ターン GoalStart(); }
public GetGoalDataResponse GetGoal(GetGoalDataRequest request) { GetGoalDataResponse result = null; try { result = new GetGoalDataResponse(); IGoalRepository repo = Factory.GetRepository(request, RepositoryType.Goal); GoalData goalData = repo.FindByID(request.Id) as GoalData; //if (patientGoalData != null) //{ // //Get all barriers for a given goal // patientGoalData.BarriersData = getBarriersByPatientGoalId(request, patientGoalData.Id); // //Get all tasks for a given goal // patientGoalData.TasksData = getTasksByPatientGoalId(request, patientGoalData.Id); // //Get all interventions for a given goal // patientGoalData.InterventionsData = getInterventionsByPatientGoalId(request, patientGoalData.Id); //} result.GoalData = goalData; result.Version = request.Version; return(result); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> PutGoalData(int id, GoalData goalData) { if (id != goalData.GoalId) { return(BadRequest()); } _context.Entry(goalData).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GoalDataExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public GoalData[] GatherGoals() { List <GoalData> allgd = new List <GoalData> (); int ccmax = Registry.only.GetCount <GoalManager> (); for (int cc = 0; cc < ccmax; cc++) { GoalData gd = new GoalData(); GoalManager gm = Registry.only.GetObject <GoalManager> (cc); gd.InitialStatus = GoalStateToStatus(gm.initialState); gd.CurrentStatus = GoalStateToStatus(gm.currentState); gd.IsActive = gm.isActive; gd.RegistryIndex = gm.ListIndex; gd.ActualIndex = cc; allgd.Add(gd); } return(allgd.ToArray()); }
public object FindByID(string entityID) { GoalData goalData = null; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEGoal.IdProperty, ObjectId.Parse(entityID))); queries.Add(Query.EQ(MEGoal.DeleteFlagProperty, false)); queries.Add(Query.EQ(MEGoal.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); MEGoal meG = ctx.Goals.Collection.Find(mQuery).FirstOrDefault(); goalData = AutoMapper.Mapper.Map <GoalData>(meG); } return(goalData); } catch (Exception) { throw; } }
private void RefreshGoalsTab() { IDataReader reader = RunQuery("SELECT goap_goals.* FROM goap_goals"); Dictionary<int, GoalData> goals = new Dictionary<int, GoalData>(); int i = 1; while(reader.Read()) { int c_id = reader.GetInt32(0); string c_desc = reader.GetString(1); GoalData data = new GoalData(); data.ID = c_id; data.Description = c_desc; goals.Add(i, data); i++; } string [] dropDownOptions = new string[goals.Count + 1]; dropDownOptions[0] = "Add New.."; if(goals.Count > 0) { for(int index=1; index <= goals.Count; index++) { dropDownOptions[index] = goals[index].Description; } } GUI.Label(new Rect(10, 40, 200, 20), "Available Goals:"); _tab1Goal = EditorGUI.Popup(new Rect(10, 60, 150, 20), _tab1Goal, dropDownOptions); GUI.Label(new Rect(10, 90, 250, 20), "Description: " + dropDownOptions[_tab1Goal]); _tab1Description = GUI.TextField(new Rect(10, 110, 150, 15), _tab1Description, 100); if(GUI.Button(new Rect(170, 110, 60, 20), "Save")) { if(_tab1Goal > 0) { RunQuery("UPDATE goap_goals SET description = '" + _tab1Description + "' WHERE id = " + goals[_tab1Goal].ID); } else if(_tab1Goal == 0) { RunQuery("INSERT INTO goap_goals (id, description) VALUES (null, '" + _tab1Description + "')"); } } if(_tab1Goal > 0 && GUI.Button(new Rect(240, 110, 60, 20), "Delete")) { RunQuery("DELETE FROM goap_goals WHERE id = " + goals[_tab1Goal].ID); RunQuery("DELETE FROM goal_conditions WHERE goal_id = " + goals[_tab1Goal].ID); RunQuery("DELETE FROM character_goals WHERE goal_id = " + goals[_tab1Goal].ID); _tab1Goal = 0; } if(_tab1Goal > 0) { GUI.Label(new Rect(10, 140, 200, 20), "Conditions:"); IDataReader conditionReader = RunQuery( "SELECT world_states.*, goal_conditions.* " + "FROM goal_conditions INNER JOIN world_states " + "ON goal_conditions.world_state_id = world_states.id AND goal_conditions.goal_id = '" + goals[_tab1Goal].ID + "'"); List<GoapWorldState> conditions = new List<GoapWorldState>(); while(conditionReader.Read()) { GoapWorldState state = ParseWorldStateJoint(conditionReader); conditions.Add(state); } //get all the world states in order to form a drop down list IDataReader worldStatesReader = RunQuery("SELECT world_states.* FROM world_states"); _worldStates = new Dictionary<int, WorldStatesData>(); int stateIndex = 0; while(worldStatesReader.Read()) { int c_id = worldStatesReader.GetInt32(0); string c_desc = worldStatesReader.GetString(1); int isBool = worldStatesReader.GetInt32(2); WorldStatesData data = new WorldStatesData(); data.ID = c_id; data.Description = c_desc; data.IsBool = isBool; _worldStates.Add(stateIndex, data); stateIndex++; } string [] conditionOptions = new string[_worldStates.Count]; int rectHeight = 160; int heightStep = 30; int condIndex = 0; //remove existing goal conditions in db RunQuery("DELETE FROM goal_conditions WHERE goal_id = " + goals[_tab1Goal].ID); foreach(GoapWorldState state in conditions) { int selectedName = 0; if(_worldStates.Count > 0) { for(int index=0; index < _worldStates.Count; index++) { conditionOptions[index] = _worldStates[index].Description; if(state.Name == _worldStates[index].Description) { selectedName = index; } } int height = rectHeight + heightStep * condIndex; selectedName = EditorGUI.Popup(new Rect(10, height, 150, 20), selectedName, conditionOptions); GUI.Label(new Rect(170, height, 40, 20), "Equals"); int selectedValue = EditorGUI.Popup(new Rect(220, height, 60, 20), ((bool)state.Value) == true ? 1 : 0, new string[]{"False", "True"}); bool toBeDeleted = false; if(GUI.Button(new Rect(290, height, 15, 15), "-")) { toBeDeleted = true; } //add new entries to db if(!toBeDeleted) { RunQuery("INSERT INTO goal_conditions (goal_id, world_state_id, operator_id, value) VALUES (" + goals[_tab1Goal].ID + ", " + _worldStates[selectedName].ID + ", 0, " + selectedValue + ")"); } } condIndex ++; } //a button to add new condition if(GUI.Button(new Rect(290, rectHeight + heightStep * conditions.Count, 20, 20), "+")) { RunQuery("INSERT INTO goal_conditions (goal_id, world_state_id, operator_id, value) VALUES (" + goals[_tab1Goal].ID + ", " + _worldStates[0].ID + ", 0, 1)"); } } }
private void RefreshCharactersTab() { IDataReader reader = RunQuery("SELECT characters.* FROM characters"); Dictionary<int, CharacterData> characters = new Dictionary<int, CharacterData>(); int i = 1; while(reader.Read()) { int c_id = reader.GetInt32(0); string c_title = reader.GetString(1); string c_first = reader.GetString(2); string c_last = reader.GetString(3); CharacterData data = new CharacterData(); data.ID = c_id; data.Title = c_title; data.FirstName = c_first; data.LastName = c_last; characters.Add(i, data); i++; } string [] dropDownOptions = new string[characters.Count + 1]; dropDownOptions[0] = "None"; if(characters.Count > 0) { for(int index=1; index <= characters.Count; index++) { dropDownOptions[index] = characters[index].Title + ", " + characters[index].FirstName + " " + characters[index].LastName; } } GUI.Label(new Rect(10, 40, 200, 20), "Characters:"); _tab3Char = EditorGUI.Popup(new Rect(10, 60, 250, 20), _tab3Char, dropDownOptions); if(_tab3Char > 0) { //now we have the character ID, we make a list of character goals IDataReader goalReader = RunQuery( "SELECT goap_goals.*, character_goals.priority " + "FROM goap_goals INNER JOIN character_goals " + "ON goap_goals.id = character_goals.goal_id AND character_goals.character_id = '" + characters[_tab3Char].ID + "'"); List<GoapGoal> goals = new List<GoapGoal>(); while(goalReader.Read()) { int goalID = goalReader.GetInt32(0); string goalName = goalReader.GetString(1); int priority = goalReader.GetInt32(2); GoapGoal goal = new GoapGoal(); goal.Name = goalName; goal.Priority = priority; goals.Add(goal); } IDataReader allGoalsReader = RunQuery("SELECT goap_goals.* FROM goap_goals"); Dictionary<int, GoalData> allGoals = new Dictionary<int, GoalData>(); int goalIndex = 0; while(allGoalsReader.Read()) { int c_id = allGoalsReader.GetInt32(0); string c_desc = allGoalsReader.GetString(1); GoalData data = new GoalData(); data.ID = c_id; data.Description = c_desc; allGoals.Add(goalIndex, data); goalIndex++; } GUI.Label(new Rect(10, 90, 150, 20), "Goals:"); int rectHeight = 110; int heightStep = 20; int gIndex = 0; foreach(GoapGoal goal in goals) { int selectedName = 0; int selectedPriority = 0; string [] options = new string[allGoals.Count]; for(int index=0; index < allGoals.Count; index++) { options[index] = allGoals[index].Description; if(goal.Name == allGoals[index].Description) { selectedName = index; selectedPriority = goal.Priority; } } int height = rectHeight + gIndex * heightStep; int newSelectedName = EditorGUI.Popup(new Rect(10, height, 150, 20), selectedName, options); GUI.Label(new Rect(170, height, 40, 20), "Priority"); int newSelectedPriority = EditorGUI.Popup(new Rect(220, height, 60, 20), selectedPriority, new string[]{"0", "1", "2", "3", "4", "5"}); bool toBeUpdated = false; if(newSelectedName != selectedName || newSelectedPriority != selectedPriority) { toBeUpdated = true; } bool toBeDeleted = false; if(GUI.Button(new Rect(290, height, 15, 15), "-")) { toBeDeleted = true; } if(toBeUpdated) { RunQuery("UPDATE character_goals SET goal_id = " + allGoals[newSelectedName].ID + ", priority = " + newSelectedPriority + " WHERE character_id = " + characters[_tab3Char].ID + " AND goal_id = " + allGoals[selectedName].ID); } if(toBeDeleted) { RunQuery("DELETE FROM character_goals WHERE goal_id = " + allGoals[newSelectedName].ID + " AND character_id = " + characters[_tab3Char].ID); } gIndex ++; } rectHeight = rectHeight + heightStep * goals.Count; //a button to add new condition if(GUI.Button(new Rect(290, rectHeight, 20, 20), "+")) { RunQuery("INSERT INTO character_goals (character_id, goal_id, priority) VALUES (" + characters[_tab3Char].ID + ", " + allGoals[0].ID + ", 0)"); } //now we have the character ID, we make a list of character actions IDataReader actionReader = RunQuery( "SELECT goap_actions.* " + "FROM goap_actions INNER JOIN character_actions " + "ON goap_actions.id = character_actions.action_id AND character_actions.character_id = '" + characters[_tab3Char].ID + "'"); List<ActionData> actions = new List<ActionData>(); while(actionReader.Read()) { int id = actionReader.GetInt32(0); string className = actionReader.GetString(1); string description = actionReader.GetString(2); float cost = actionReader.GetFloat(3); ActionData action = new ActionData(); action.ID = id; action.ClassName = className; action.Description = description; action.DefaultCost = cost; actions.Add(action); } IDataReader allActionsReader = RunQuery("SELECT goap_actions.* FROM goap_actions"); Dictionary<int, ActionData> allActions = new Dictionary<int, ActionData>(); int actionIndex = 0; while(allActionsReader.Read()) { int c_id = allActionsReader.GetInt32(0); string c_desc = allActionsReader.GetString(2); ActionData data = new ActionData(); data.ID = c_id; data.Description = c_desc; allActions.Add(actionIndex, data); actionIndex++; } rectHeight = rectHeight + 30; GUI.Label(new Rect(10, rectHeight, 150, 20), "Actions:"); rectHeight += 20; int aIndex = 0; foreach(ActionData action in actions) { int selectedName = 0; string [] options = new string[allActions.Count]; for(int index=0; index < allActions.Count; index++) { options[index] = allActions[index].Description; if(action.Description == allActions[index].Description) { selectedName = index; } } int height = rectHeight + aIndex * heightStep; int newSelectedName = EditorGUI.Popup(new Rect(10, height, 150, 20), selectedName, options); bool toBeUpdated = false; if(newSelectedName != selectedName) { toBeUpdated = true; } bool toBeDeleted = false; if(GUI.Button(new Rect(290, height, 15, 15), "-")) { toBeDeleted = true; } if(toBeUpdated) { RunQuery("UPDATE character_actions SET action_id = " + allActions[newSelectedName].ID + " WHERE character_id = " + characters[_tab3Char].ID + " AND action_id = " + allActions[selectedName].ID); } if(toBeDeleted) { RunQuery("DELETE FROM character_actions WHERE action_id = " + allActions[newSelectedName].ID + " AND character_id = " + characters[_tab3Char].ID); } aIndex ++; } rectHeight = rectHeight + heightStep * actions.Count; //a button to add new condition if(GUI.Button(new Rect(290, rectHeight, 20, 20), "+")) { RunQuery("INSERT INTO character_actions (character_id, action_id) VALUES (" + characters[_tab3Char].ID + ", " + allActions[0].ID + ")"); } } }
/////////////////////////////////////////////////////////////////////////// // 公開関数 /////////////////////////////////////////////////////////////////////////// //データ設定=============================================================== public void Initialize(PlayerCharStateData aData) { //モデル変更 this.ModeChange(Database.obj.GetPlayerModel(aData.modelId)); //アンカー m_AncData = m_CouresAncs.GetAnc(0); m_AncDataGround = m_CouresAncs.GetAnc(0); //ステータス m_wait = aData.wait; m_Gravity = new GravityStatus(); m_Speed = new SpeedStatus(aData.accel, aData.turn, aData.maxSpeed); m_Jump = new JumpStatus(); m_Glider = new GliderStatus(); m_Heat = new HeatStatus(); m_Rack = RackState.READY; m_GoalData = new GoalData(); //ステート m_TrgState = new BoolArray32(false); m_NowState = new BoolArray32(false); InputStart(); //入力 CameraStart(); //カメラ SpeedStart(); //速度・方向 StartPhysics(); //重力やレイキャスト SpwanStart(); //復帰する処理用 TurnnStart(); //ターン GoalStart(); }
/// <summary> /// Listens for new goal. /// </summary> /// <param name='goalData'> /// Goal data. /// </param> void listenForNewGoal(GoalData goalData) { if (!mCameraMoving) { // Switch state from new goal changeState (goalData.mVisitStateLevel); // Push new goal wanted to stack mGoalsStack.Push (goalData); // Move that f**king cam to the given goal mCameraManager.moveToGoal (goalData); // Desactivate Goal Collider we have touched/clicked // This to avoid to reclick again on // And ensure that stack is not increased with same goal if (goalData.mIniator != null) { goalData.mIniator.GetComponent<Collider>().enabled = false; } } }
private void RefreshCharactersTab() { IDataReader reader = RunQuery("SELECT characters.* FROM characters"); Dictionary <int, CharacterData> characters = new Dictionary <int, CharacterData>(); int i = 1; while (reader.Read()) { int c_id = reader.GetInt32(0); string c_title = reader.GetString(1); string c_first = reader.GetString(2); string c_last = reader.GetString(3); CharacterData data = new CharacterData(); data.ID = c_id; data.Title = c_title; data.FirstName = c_first; data.LastName = c_last; characters.Add(i, data); i++; } string [] dropDownOptions = new string[characters.Count + 1]; dropDownOptions[0] = "None"; if (characters.Count > 0) { for (int index = 1; index <= characters.Count; index++) { dropDownOptions[index] = characters[index].Title + ", " + characters[index].FirstName + " " + characters[index].LastName; } } GUI.Label(new Rect(10, 40, 200, 20), "Characters:"); _tab3Char = EditorGUI.Popup(new Rect(10, 60, 250, 20), _tab3Char, dropDownOptions); if (_tab3Char > 0) { //now we have the character ID, we make a list of character goals IDataReader goalReader = RunQuery( "SELECT goap_goals.*, character_goals.priority " + "FROM goap_goals INNER JOIN character_goals " + "ON goap_goals.id = character_goals.goal_id AND character_goals.character_id = '" + characters[_tab3Char].ID + "'"); List <GoapGoal> goals = new List <GoapGoal>(); while (goalReader.Read()) { int goalID = goalReader.GetInt32(0); string goalName = goalReader.GetString(1); int priority = goalReader.GetInt32(2); GoapGoal goal = new GoapGoal(); goal.Name = goalName; goal.Priority = priority; goals.Add(goal); } IDataReader allGoalsReader = RunQuery("SELECT goap_goals.* FROM goap_goals"); Dictionary <int, GoalData> allGoals = new Dictionary <int, GoalData>(); int goalIndex = 0; while (allGoalsReader.Read()) { int c_id = allGoalsReader.GetInt32(0); string c_desc = allGoalsReader.GetString(1); GoalData data = new GoalData(); data.ID = c_id; data.Description = c_desc; allGoals.Add(goalIndex, data); goalIndex++; } GUI.Label(new Rect(10, 90, 150, 20), "Goals:"); int rectHeight = 110; int heightStep = 20; int gIndex = 0; foreach (GoapGoal goal in goals) { int selectedName = 0; int selectedPriority = 0; string [] options = new string[allGoals.Count]; for (int index = 0; index < allGoals.Count; index++) { options[index] = allGoals[index].Description; if (goal.Name == allGoals[index].Description) { selectedName = index; selectedPriority = goal.Priority; } } int height = rectHeight + gIndex * heightStep; int newSelectedName = EditorGUI.Popup(new Rect(10, height, 150, 20), selectedName, options); GUI.Label(new Rect(170, height, 40, 20), "Priority"); int newSelectedPriority = EditorGUI.Popup(new Rect(220, height, 60, 20), selectedPriority, new string[] { "0", "1", "2", "3", "4", "5" }); bool toBeUpdated = false; if (newSelectedName != selectedName || newSelectedPriority != selectedPriority) { toBeUpdated = true; } bool toBeDeleted = false; if (GUI.Button(new Rect(290, height, 15, 15), "-")) { toBeDeleted = true; } if (toBeUpdated) { RunQuery("UPDATE character_goals SET goal_id = " + allGoals[newSelectedName].ID + ", priority = " + newSelectedPriority + " WHERE character_id = " + characters[_tab3Char].ID + " AND goal_id = " + allGoals[selectedName].ID); } if (toBeDeleted) { RunQuery("DELETE FROM character_goals WHERE goal_id = " + allGoals[newSelectedName].ID + " AND character_id = " + characters[_tab3Char].ID); } gIndex++; } rectHeight = rectHeight + heightStep * goals.Count; //a button to add new condition if (GUI.Button(new Rect(290, rectHeight, 20, 20), "+")) { RunQuery("INSERT INTO character_goals (character_id, goal_id, priority) VALUES (" + characters[_tab3Char].ID + ", " + allGoals[0].ID + ", 0)"); } //now we have the character ID, we make a list of character actions IDataReader actionReader = RunQuery( "SELECT goap_actions.* " + "FROM goap_actions INNER JOIN character_actions " + "ON goap_actions.id = character_actions.action_id AND character_actions.character_id = '" + characters[_tab3Char].ID + "'"); List <ActionData> actions = new List <ActionData>(); while (actionReader.Read()) { int id = actionReader.GetInt32(0); string className = actionReader.GetString(1); string description = actionReader.GetString(2); float cost = actionReader.GetFloat(3); ActionData action = new ActionData(); action.ID = id; action.ClassName = className; action.Description = description; action.DefaultCost = cost; actions.Add(action); } IDataReader allActionsReader = RunQuery("SELECT goap_actions.* FROM goap_actions"); Dictionary <int, ActionData> allActions = new Dictionary <int, ActionData>(); int actionIndex = 0; while (allActionsReader.Read()) { int c_id = allActionsReader.GetInt32(0); string c_desc = allActionsReader.GetString(2); ActionData data = new ActionData(); data.ID = c_id; data.Description = c_desc; allActions.Add(actionIndex, data); actionIndex++; } rectHeight = rectHeight + 30; GUI.Label(new Rect(10, rectHeight, 150, 20), "Actions:"); rectHeight += 20; int aIndex = 0; foreach (ActionData action in actions) { int selectedName = 0; string [] options = new string[allActions.Count]; for (int index = 0; index < allActions.Count; index++) { options[index] = allActions[index].Description; if (action.Description == allActions[index].Description) { selectedName = index; } } int height = rectHeight + aIndex * heightStep; int newSelectedName = EditorGUI.Popup(new Rect(10, height, 150, 20), selectedName, options); bool toBeUpdated = false; if (newSelectedName != selectedName) { toBeUpdated = true; } bool toBeDeleted = false; if (GUI.Button(new Rect(290, height, 15, 15), "-")) { toBeDeleted = true; } if (toBeUpdated) { RunQuery("UPDATE character_actions SET action_id = " + allActions[newSelectedName].ID + " WHERE character_id = " + characters[_tab3Char].ID + " AND action_id = " + allActions[selectedName].ID); } if (toBeDeleted) { RunQuery("DELETE FROM character_actions WHERE action_id = " + allActions[newSelectedName].ID + " AND character_id = " + characters[_tab3Char].ID); } aIndex++; } rectHeight = rectHeight + heightStep * actions.Count; //a button to add new condition if (GUI.Button(new Rect(290, rectHeight, 20, 20), "+")) { RunQuery("INSERT INTO character_actions (character_id, action_id) VALUES (" + characters[_tab3Char].ID + ", " + allActions[0].ID + ")"); } } }
private void RefreshGoalsTab() { IDataReader reader = RunQuery("SELECT goap_goals.* FROM goap_goals"); Dictionary <int, GoalData> goals = new Dictionary <int, GoalData>(); int i = 1; while (reader.Read()) { int c_id = reader.GetInt32(0); string c_desc = reader.GetString(1); GoalData data = new GoalData(); data.ID = c_id; data.Description = c_desc; goals.Add(i, data); i++; } string [] dropDownOptions = new string[goals.Count + 1]; dropDownOptions[0] = "Add New.."; if (goals.Count > 0) { for (int index = 1; index <= goals.Count; index++) { dropDownOptions[index] = goals[index].Description; } } GUI.Label(new Rect(10, 40, 200, 20), "Available Goals:"); _tab1Goal = EditorGUI.Popup(new Rect(10, 60, 150, 20), _tab1Goal, dropDownOptions); GUI.Label(new Rect(10, 90, 250, 20), "Description: " + dropDownOptions[_tab1Goal]); _tab1Description = GUI.TextField(new Rect(10, 110, 150, 15), _tab1Description, 100); if (GUI.Button(new Rect(170, 110, 60, 20), "Save")) { if (_tab1Goal > 0) { RunQuery("UPDATE goap_goals SET description = '" + _tab1Description + "' WHERE id = " + goals[_tab1Goal].ID); } else if (_tab1Goal == 0) { RunQuery("INSERT INTO goap_goals (id, description) VALUES (null, '" + _tab1Description + "')"); } } if (_tab1Goal > 0 && GUI.Button(new Rect(240, 110, 60, 20), "Delete")) { RunQuery("DELETE FROM goap_goals WHERE id = " + goals[_tab1Goal].ID); RunQuery("DELETE FROM goal_conditions WHERE goal_id = " + goals[_tab1Goal].ID); RunQuery("DELETE FROM character_goals WHERE goal_id = " + goals[_tab1Goal].ID); _tab1Goal = 0; } if (_tab1Goal > 0) { GUI.Label(new Rect(10, 140, 200, 20), "Conditions:"); IDataReader conditionReader = RunQuery( "SELECT world_states.*, goal_conditions.* " + "FROM goal_conditions INNER JOIN world_states " + "ON goal_conditions.world_state_id = world_states.id AND goal_conditions.goal_id = '" + goals[_tab1Goal].ID + "'"); List <GoapWorldState> conditions = new List <GoapWorldState>(); while (conditionReader.Read()) { GoapWorldState state = ParseWorldStateJoint(conditionReader); conditions.Add(state); } //get all the world states in order to form a drop down list IDataReader worldStatesReader = RunQuery("SELECT world_states.* FROM world_states"); _worldStates = new Dictionary <int, WorldStatesData>(); int stateIndex = 0; while (worldStatesReader.Read()) { int c_id = worldStatesReader.GetInt32(0); string c_desc = worldStatesReader.GetString(1); int isBool = worldStatesReader.GetInt32(2); WorldStatesData data = new WorldStatesData(); data.ID = c_id; data.Description = c_desc; data.IsBool = isBool; _worldStates.Add(stateIndex, data); stateIndex++; } string [] conditionOptions = new string[_worldStates.Count]; int rectHeight = 160; int heightStep = 30; int condIndex = 0; //remove existing goal conditions in db RunQuery("DELETE FROM goal_conditions WHERE goal_id = " + goals[_tab1Goal].ID); foreach (GoapWorldState state in conditions) { int selectedName = 0; if (_worldStates.Count > 0) { for (int index = 0; index < _worldStates.Count; index++) { conditionOptions[index] = _worldStates[index].Description; if (state.Name == _worldStates[index].Description) { selectedName = index; } } int height = rectHeight + heightStep * condIndex; selectedName = EditorGUI.Popup(new Rect(10, height, 150, 20), selectedName, conditionOptions); GUI.Label(new Rect(170, height, 40, 20), "Equals"); int selectedValue = EditorGUI.Popup(new Rect(220, height, 60, 20), ((bool)state.Value) == true ? 1 : 0, new string[] { "False", "True" }); bool toBeDeleted = false; if (GUI.Button(new Rect(290, height, 15, 15), "-")) { toBeDeleted = true; } //add new entries to db if (!toBeDeleted) { RunQuery("INSERT INTO goal_conditions (goal_id, world_state_id, operator_id, value) VALUES (" + goals[_tab1Goal].ID + ", " + _worldStates[selectedName].ID + ", 0, " + selectedValue + ")"); } } condIndex++; } //a button to add new condition if (GUI.Button(new Rect(290, rectHeight + heightStep * conditions.Count, 20, 20), "+")) { RunQuery("INSERT INTO goal_conditions (goal_id, world_state_id, operator_id, value) VALUES (" + goals[_tab1Goal].ID + ", " + _worldStates[0].ID + ", 0, 1)"); } } }
public void moveToGoal(GoalData goalData) { tweenTransformFromTo(transform, goalData.mTransform, goalData.mMoveTime); }