當前位置: 首頁>>代碼示例>>C#>>正文


C# Agent.getNextPercept方法代碼示例

本文整理匯總了C#中Agent.getNextPercept方法的典型用法代碼示例。如果您正苦於以下問題:C# Agent.getNextPercept方法的具體用法?C# Agent.getNextPercept怎麽用?C# Agent.getNextPercept使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Agent的用法示例。


在下文中一共展示了Agent.getNextPercept方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: getPercepts

    // Agent perceives world through this function alone.
    public void getPercepts(Agent agent, float perfectVisionRange)
    {
        float startTime = Time.realtimeSinceStartup;
        agent.resetPercepts();

        AgentPercept tempPercept;

        List<Agent> nearbyAgents = new List<Agent>();
        Vector2 loc = agent.Location;
        float radius = agent.SightRange;
        Quad visibleArea = new Quad( loc.x-radius, loc.y-radius, loc.x+radius, loc.y+radius );

        agentTree.SearchArea(visibleArea, ref nearbyAgents);

        for(int i=0; i<nearbyAgents.Count; i++)
        {
            // For now not doing self-aware. No Skynet on *my* watch!
            if(agent.Guid == nearbyAgents[i].Guid)
            {
                continue;
            }
            if(canPerceivePosition(agent, nearbyAgents[i].Location, perfectVisionRange))
            {
                tempPercept 		= agent.getNextPercept();// new AgentPercept();
                tempPercept.type 	= AgentPercept.PerceptType.AGENT;
                tempPercept.locOne 	= nearbyAgents[i].Location;
                tempPercept.living 	= nearbyAgents[i].LivingState;
                tempPercept.facingDirection = nearbyAgents[i].Direction;

                // TODO: Agent object should not be part of percept, fix!
                // See AgentPercept.perceivedAgent for more.
                tempPercept.perceivedAgent = nearbyAgents[i];

                tempPercept 		= null;
            }
        }

        List<Rect> nearbyStructures = new List<Rect>();
        buildingTree.SearchArea(visibleArea, ref nearbyStructures);

        List<AgentPercept> structureList = null;
        for(int i=0; i<nearbyStructures.Count; i++)
        {
            perceiveStructure(agent, nearbyStructures[i]);
        }

        // TODO: Work out a smarter way to handle WorldObjects than point-based
        if(agent.Type == Agent.AgentType.HUMAN || agent.Type == Agent.AgentType.HUMAN_PLAYER)
        {
            for(int wo=0; wo<worldObjects.Count; wo++)
            {
                if(canPerceivePosition(agent, worldObjects[wo].Location, perfectVisionRange))
                {
                    tempPercept = agent.getNextPercept();// new AgentPercept();
                    tempPercept.type = AgentPercept.PerceptType.EXTRACT;
                    tempPercept.locOne = worldObjects[wo].Location;
                    tempPercept.living = AgentPercept.LivingState.INANIMATE;

                    tempPercept = null;
                }
            }
        }
        _perceptTotalTime += (Time.realtimeSinceStartup-startTime);
        _perceptTotalCount++;
    }
開發者ID:futurechris,項目名稱:zombai,代碼行數:66,代碼來源:WorldMap.cs


注:本文中的Agent.getNextPercept方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。