本文整理汇总了C#中WorldState.SetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# WorldState.SetProperty方法的具体用法?C# WorldState.SetProperty怎么用?C# WorldState.SetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorldState
的用法示例。
在下文中一共展示了WorldState.SetProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnTriggerEnter
GameObject agentObject; //the agent gameObject
#endregion Fields
#region Methods
public void OnTriggerEnter(Collider other)
{
colliderList.Add(other); //add detected object to list of "seen" objects
if (other.gameObject.name == "Resource(Clone)") { //if it is a resource
Debug.Log("Found " + other.tag + "!");
//get color of resource
string color = "";
for(int i = 1; i < other.tag.Length; i++)
{
if(char.IsUpper(other.tag[i]))
{
color = other.tag.Substring(0, i);
break;
}
}
//update the workingmemory that a resource is at this position
((Agent)agentComponent).GetWMemory().SetFact(color, new WorkingMemoryValue(other.transform.position));
//update the currentWorldState that resrouces of this color is available
WorldState newState = new WorldState();
newState.SetProperty(char.ToLower(color[0]) + color.Substring(1) + "ResourceIsAvailable", new WorldStateValue(true));
BlackBoard.Instance.SetCurrentWorldstate(agentComponent.GetClan(), newState);
}
}
示例2: BuildYellowHouseAction
public BuildYellowHouseAction()
{
preConditions = new WorldState();
preConditions.SetProperty("yellowResourceIsCollected", new WorldStateValue(true));
postConditions = new WorldState();
postConditions.SetProperty("yellowHouseIsBuilt", new WorldStateValue(true));
postConditions.SetProperty("yellowResourceIsCollected", new WorldStateValue(false));
cost = 1.0f;
time = 4.0f;
agentTypes = new List<string>();
agentTypes.Add("Yellow");
this.actionName = "BuildYellowHouseAction";
}
示例3: BuildBlueHouseAction
public BuildBlueHouseAction()
{
preConditions = new WorldState();
preConditions.SetProperty("blueResourceIsCollected", new WorldStateValue(true, 2));
postConditions = new WorldState();
postConditions.SetProperty("blueHouseIsBuilt", new WorldStateValue(true));
postConditions.SetProperty("blueResourceIsCollected", new WorldStateValue(false));
cost = 1.0f;
time = 4.0f;
agentTypes = new List<string>();
agentTypes.Add("Blue"); //Only a blue agent can do this action
this.actionName = "BuildBlueHouseAction";
}
示例4: BuildMagentaFactoryAction
public BuildMagentaFactoryAction()
{
preConditions = new WorldState();
preConditions.SetProperty("redResourceIsCollected", new WorldStateValue(true));
preConditions.SetProperty("blueResourceIsCollected", new WorldStateValue(true));
postConditions = new WorldState();
postConditions.SetProperty("magentaFactoryIsBuilt", new WorldStateValue(true));
postConditions.SetProperty("blueResourceIsCollected", new WorldStateValue(false));
postConditions.SetProperty("redResourceIsCollected", new WorldStateValue(false));
postConditions.SetProperty("magentaResourceIsAvailable", new WorldStateValue(true));
cost = 1.0f;
time = 4.0f;
agentTypes = new List<string>();
agentTypes.Add("Blue&Red"); //A blue and a red agent has to cooperate to do this action
this.actionName = "BuildMagentaFactoryAction";
}
示例5: BuildBlackTowerAction
public BuildBlackTowerAction()
{
preConditions = new WorldState();
preConditions.SetProperty("greenResourceIsCollected", new WorldStateValue(true));
preConditions.SetProperty("orangeResourceIsCollected", new WorldStateValue(true));
preConditions.SetProperty("magentaResourceIsCollected", new WorldStateValue(true));
postConditions = new WorldState();
postConditions.SetProperty("blackTowerIsBuilt", new WorldStateValue(true));
postConditions.SetProperty("greenResourceIsCollected", new WorldStateValue(false));
postConditions.SetProperty("orangeResourceIsCollected", new WorldStateValue(false));
postConditions.SetProperty("magentaResourceIsCollected", new WorldStateValue(false));
cost = 1.0f;
time = 4.0f;
agentTypes = new List<string>();
agentTypes.Add("Yellow&Red&Blue"); //A yellow, red and blue agent has to cooperate to build the black tower
this.actionName = "BuildBlackTowerAction";
}
示例6: BuildOrangeFactoryAction
public BuildOrangeFactoryAction()
{
preConditions = new WorldState();
preConditions.SetProperty("yellowResourceIsCollected", new WorldStateValue(true));
preConditions.SetProperty("redResourceIsCollected", new WorldStateValue(true));
//preConditions.setProperty("orangeResourceIsAvailable", new WorldStateValue(false));
postConditions = new WorldState();
postConditions.SetProperty("orangeFactoryIsBuilt", new WorldStateValue(true));
postConditions.SetProperty("redResourceIsCollected", new WorldStateValue(false));
postConditions.SetProperty("yellowResourceIsCollected", new WorldStateValue(false));
postConditions.SetProperty("orangeResourceIsAvailable", new WorldStateValue(true));
cost = 1.0f;
time = 4.0f;
agentTypes = new List<string>();
agentTypes.Add("Yellow&Red");
this.actionName = "BuildOrangeFactoryAction";
}
示例7: ScoutBlueAction
public ScoutBlueAction()
{
preConditions = new WorldState();
preConditions.SetProperty("blueResourceIsAvailable", new WorldStateValue(false));
postConditions = new WorldState();
postConditions.SetProperty("blueResourceIsAvailable", new WorldStateValue(true));
cost = 1.0f;
time = 4.0f;
agentTypes = new List<string>();
agentTypes.Add("Blue");
this.actionName = "ScoutBlueAction";
}
示例8: GetYellowAction
public GetYellowAction()
{
preConditions = new WorldState();
preConditions.SetProperty("yellowResourceIsAvailable", new WorldStateValue(true));
postConditions = new WorldState();
postConditions.SetProperty("yellowResourceIsCollected", new WorldStateValue(true));
cost = 1.0f;
time = 4.0f;
agentTypes = new List<string>();
agentTypes.Add("Yellow");
this.actionName = "GetYellowAction";
}
示例9: GetMagentaAction
public GetMagentaAction()
{
preConditions = new WorldState();
preConditions.SetProperty("magentaResourceIsAvailable", new WorldStateValue(true));
postConditions = new WorldState();
postConditions.SetProperty("magentaResourceIsCollected", new WorldStateValue(true));
cost = 1.0f;
time = 4.0f;
agentTypes = new List<string>();
agentTypes.Add("Blue"); //A blue agent or a red agent can do this action
agentTypes.Add("Red");
this.actionName = "GetMagentaAction";
}
示例10: OnTriggerEnter
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Enemy") //if an enemy is detected
{
Debug.Log ("ENEMY!!!!");
//Update the current worldstate that an enemy is visible
WorldState currentWorldState = (WorldState)BlackBoard.Instance.GetFact(clan, "currentWorldState")[0].GetFactValue();
currentWorldState.SetProperty("enemyVisible", new WorldStateValue(true));
//add new goal to kill enemy (enemyAlive = false)
WorldState goalWorldState = new WorldState();
goalWorldState.SetProperty("enemyAlive", new WorldStateValue(false));
((Agent)agentComponent).CreateNewPlan(currentWorldState, goalWorldState); //create new plan to respond to the threat
}
}
示例11: Run
//the AStar algorithm
public List<AStarNode> Run(AStarNode startNode, AStarNode endNode)
{
AStarNode currentNode = startNode;
//special case for the first node since it is NOT an action but a postCondition. We are counting on that it will never be a goal!
List<AStarNode> neighbourList = currentNode.GetNeighbours(true); //gives a list with actions that has startNodes preCondition
foreach(AStarNode node in neighbourList) //for each of these neighbours
{
node.SetF(ActionManager.Instance.GetAction(node.GetName()).cost + HeuristicCost(node, endNode)); //calculate F of the neigbour
node.SetParent(startNode); //Set the startNode as the neighbours parent
openList.Add(node); //Add the neighbours of the startNode to the openList
}
//As long as we still have nodes in the openList
while(openList.Count > 0)
{
//Take out the node with the lowest value for F in the openList
int lowInd = 0;
for(int i = 0; i < openList.Count; i++)
{
if(openList[i].GetF() < openList[lowInd].GetF())
{
lowInd = i;
}
}
currentNode = openList[lowInd];
openList.Remove(currentNode);
closedList.Add(currentNode);
//Check if we have reached the target
if(endNode.GetWorldState().Contains(ActionManager.Instance.GetAction(currentNode.GetName()).preConditions))
{
return CreatePath(currentNode, startNode);
}
//if action with preCondition with amount or several preConditions
WorldState preConditions = ActionManager.Instance.GetAction(currentNode.GetName()).preConditions;
if(preConditions.ContainsAmount() || preConditions.GetProperties().Count > 1)
{
List<List<AStarNode>> lists = new List<List<AStarNode>>();
//for each of the preConditions of the currentNodes action we need to start new AStars
foreach(KeyValuePair<string, WorldStateValue> pair in preConditions.GetProperties())
{
//if an action contains a preCondition that has amount then we need to run the algorithm several times
for(int j = 0; j < (int)pair.Value.propertyValues["amount"]; j++)
{
AStar astar2 = new AStar();
AStarNode tempNode = new AStarNode();
WorldState tempWorldState = new WorldState();
tempWorldState.SetProperty(pair.Key, pair.Value);
tempNode.SetWorldState(tempWorldState);
List<AStarNode> tempList = new List<AStarNode>();
tempList.AddRange(astar2.Run(tempNode, endNode)); //run the AStar for the preCondition
tempList[tempList.Count-1].SetParent(currentNode); //set parent to action before fork
if(tempList.Count > 0)
{
lists.Add(tempList); //add new plan to main plan
}
else
{
if(!tempWorldState.Contains(endNode.GetWorldState()))
{
return new List<AStarNode>(); //unreachable goal for the algorithm, cant find goal
}
}
}
}
//Sort by cost to make the plan prioritize actions with small costs
lists.Sort((a, b) => ActionManager.Instance.GetAction(a[0].GetName()).cost.CompareTo(ActionManager.Instance.GetAction(b[0].GetName()).cost));
foreach(List<AStarNode> list in lists)
{
pathList.AddRange(list); //add all branches to final path
}
return CreatePath(currentNode, startNode);
}
neighbourList = currentNode.GetNeighbours(false); //get neighbouring nodes
for(int i = 0; i < neighbourList.Count; i++)
{
AStarNode currentNeighbour = neighbourList[i];
if(closedList.Contains(currentNeighbour)) //We have already looked at this node
{
//not a valid node
//.........这里部分代码省略.........
示例12: Build
IEnumerator Build()
{
while(actionIsDone == false){
walker.StartWalking(moveToPosition);
if(walker.hasArrived == true) //agent has arrived at the position
{
//check if all assisters are here too
bool assistersAreNearby = false;
bool temp = false;
List<Agent> assisters = BlackBoard.Instance.GetTaskTree(clan).GetOwnedNode(agentComponent.GetAgentNumber()).GetAssisters();
foreach(Agent assister in assisters)
{
if(Vector3.Distance(moveToPosition, assister.transform.position) >= 3.0f)
{
temp = true;
}
}
if(temp == false)
{
assistersAreNearby = true;
}
if(assistersAreNearby)//all helpers are nearby so we can build the building
{
buildingSounds = (AudioClip)Resources.Load ("SFX/industry005");
AudioSource.PlayClipAtPoint(buildingSounds, moveToPosition, 0.5f); //play building sound at center of building
yield return new WaitForSeconds((100-agentComponent.GetSkill("buildSkillpoints"))/10); //wait this amount of time until the buidling is completed (based on skill)
//remove the wireframe for the building
GameObject[] tiles = GameObject.FindGameObjectsWithTag("wireframe");
foreach (GameObject tile in tiles)
{
if(Vector3.Distance(tile.transform.position, moveToPosition) < 0.01f)
{
Destroy(tile);
}
}
//add the prefab for the bulding in place of the wireframe
GameObject building = (GameObject)Instantiate(Resources.Load(("Prefabs/Building"),typeof(GameObject)));
building.transform.position = moveToPosition;
building.transform.parent = GameObject.Find(clan).transform.FindChild("Buildings");
building.renderer.material.color = BlackBoard.Instance.GetColorForObject(facts[1]);
building.tag = facts[1] + facts[2];
building.name = facts[1] + facts[2];
AstarPath.active.UpdateGraphs (building.collider.bounds); //update the gridgraph with the position of the building
//if a factory was built add new resource location
if(facts[1] == "Green" || facts[1] == "Orange" || facts[1] == "Magenta" || facts[1] == "Black")
{
//add new resource location to the working memory
agentComponent.GetWMemory().SetFact(facts[1], new WorkingMemoryValue(building.transform.position));
WorldState newState = new WorldState();
newState.SetProperty(char.ToLower(facts[1][0]) + facts[1].Substring(1) + "ResourceIsAvailable", new WorldStateValue(true));
//Report the new worldstate (new resource is available) to the blackboard
BlackBoard.Instance.SetCurrentWorldstate(agentComponent.GetClan(), newState);
}
//update the score for the clan
BlackBoard.Instance.UpdateScore(clan, facts[1] + " " + facts[2]);
//update the skill for the agent
agentComponent.SetSkillpoints("build");
Debug.Log("*" + facts[1] + facts[2] + "-IS-BUILT*");
BlackBoard.Instance.GetTaskTree(clan).RemoveNode(agentComponent); //action is done so remove this node from the tasktree
BlackBoard.Instance.IncreasePopulationCap(clan); //increase the population cap for the clan
actionIsDone = true;
}
}
yield return null;
}
}
示例13: FindResource
IEnumerator FindResource()
{
while(actionIsDone == false){
if(collected) //if the resource is collected
{
Vector3 housePosition = BlackBoard.Instance.GetTaskTree(clan).GetOwnedNode(agentComponent.GetAgentNumber()).GetPosition(); //get the position to deliver it to
walker.StartWalking(housePosition);
if(walker.hasArrived == true) //has arived at building position
{
Debug.Log("*DELIVERED-" + facts[1] + "*");
AudioSource.PlayClipAtPoint(getSounds[1], housePosition, 0.5f); //play sound for resource is delivered
BlackBoard.Instance.GetTaskTree(clan).RemoveNode(agentComponent); //remove owned node frmo taskTree
collected = false;
actionIsDone = true;
agentComponent.SetSkillpoints("collect"); //get better at collecting
}
} else //its not collected, agent need to go get it at resource location
{
walker.StartWalking(moveToPosition);
if(walker.hasArrived == true)
{
//check if the resource is still att the position said in the blackboard
List<Collider> tempList = ((ResourceSensor)agentObject.transform.FindChild("Sensors").FindChild("ResourceSensor").GetComponent("ResourceSensor")).colliderList;
bool resourceIsHere = false;
foreach(Collider collider in tempList)
{
if(collider.gameObject.transform.position == moveToPosition)
{
resourceIsHere = true;
}
}
if (!resourceIsHere ) //If resource is not here (no amount left) or if its empty (before it has been taken away)
{
Debug.Log("HÄR SKULLE DET VARA EN RESOURCE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
agentComponent.GetWMemory().RemoveFact(facts[1], new WorkingMemoryValue(moveToPosition)); //remove it from the workingMemory
if(agentComponent.GetWMemory().GetFact(facts[1]).Count == 0)
{
//No resources of that color exist, so update the worldstate
WorldState newState = new WorldState();
newState.SetProperty(char.ToLower(facts[1][0]) + facts[1].Substring(1) + "ResourceIsAvailable", new WorldStateValue(false));
//Report the new worldstate to the blackboard
BlackBoard.Instance.SetCurrentWorldstate(agentComponent.GetClan(), newState);
//Create a new plan with the new information
WorldState tempState = new WorldState();
tempState.SetProperty(char.ToLower(facts[1][0]) + facts[1].Substring(1) + "ResourceIsAvailable", new WorldStateValue(true));
agentComponent.CreateNewPlan((WorldState)BlackBoard.Instance.GetFact(agentComponent.GetClan(), "currentWorldState")[0].GetFactValue(), tempState);
}
else{
//There are more resources, choose one of them
//TODO: choose the nearest source to go to
moveToPosition = (Vector3)agentComponent.GetWMemory().GetFact(facts[1])[0].GetFactValue();
}
}
else //harvesting resource
{
AudioSource.PlayClipAtPoint(getSounds[0], moveToPosition, 0.75f); //play harvesting sound
yield return new WaitForSeconds((100-agentComponent.GetSkill("collectSkillpoints"))/20); //wait a time to harvest depending on the skill
Debug.Log("*GOT-" + facts[1] + "*");
collected = true;
}
}
}
yield return null;
}
}
示例14: GetClan
//Returns a unique clan name for the supremecommander
public string GetClan()
{
string clan = "";
string clanColor = "";
foreach(KeyValuePair<string, Color> color in colors)
{
if(!clans.Contains(color.Key + " Clan"))
{
clan = color.Key + " Clan";
clanColor = color.Key;
break;
}
}
clans.Add(clan);
TribeFacts fact = new TribeFacts(clanColor, new TaskTree());
tribeFacts.Add(clan, fact);
//default worldstate for the clan
WorldState currentWorldState = new WorldState();
currentWorldState.SetProperty("blueResourceIsAvailable", new WorldStateValue(false));
currentWorldState.SetProperty("redResourceIsAvailable", new WorldStateValue(false));
currentWorldState.SetProperty("yellowResourceIsAvailable", new WorldStateValue(false));
currentWorldState.SetProperty("orangeResourceIsAvailable", new WorldStateValue(false));
currentWorldState.SetProperty("greenResourceIsAvailable", new WorldStateValue(false));
currentWorldState.SetProperty("magentaResourceIsAvailable", new WorldStateValue(false));
SetFact(clan, "currentWorldState", new WorkingMemoryValue(currentWorldState));
return clan;
}
示例15: SetCurrentWorldstate
//update the current worldState for a clan
public void SetCurrentWorldstate(string clan, WorldState ws)
{
WorldState currentWorldState = (WorldState)GetFact(clan, "currentWorldState")[0].GetFactValue();
RemoveFact(clan, "currentWorldState", new WorkingMemoryValue(currentWorldState));
WorldState tempWorldState = new WorldState ();
foreach(KeyValuePair<string, WorldStateValue> newState in ws.GetProperties())
{
foreach (KeyValuePair<string, WorldStateValue> oldState in currentWorldState.GetProperties())
{
if(oldState.Key == newState.Key)
{
tempWorldState.SetProperty(newState.Key, newState.Value);
} else{
tempWorldState.SetProperty(oldState.Key, oldState.Value);
}
}
}
SetFact(clan, "currentWorldState", new WorkingMemoryValue(tempWorldState));
}