• 大小: 53KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: 其他
  • 标签: GOAP  AI  

资源简介

一个 GOAP AI Unity 实现Demo,包含行为 买菜,做饭,吃饭。根据自身变化以及世界状态,自动执行行为

资源截图

代码片段和文件信息

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Goap;

public class GoapActionBuyVegetables : GoapAction {

public GoapActionBuyVegetables(GoapGoal goapGoal):base(goapGoal)
    {

    }

    public override void InitStatus()
    {
        base.InitStatus();

        preconditionsStatus.AddState(GoapCondition.hasSellVegetables true);
        preconditionsStatus.AddState(GoapCondition.hasVegetables false);

        effectsStatus.AddState(GoapCondition.hasVegetables true);
    }

    public override bool CheckProceduralPrecondition()
    {
        Gameobject Vegetables = Gameobject.Find(“Vegetables“);
        target = Vegetables.transform;
        return Vegetables != null;
    }

    public override void Run()
    {
        if (!IsInRange())
        {
            MoveController.instance.Move(goapGoal.transform target.position 6);
            return;
        }
        base.Run();

        if (target == null)
        {
            Fail();
            return;
        }

        if (goapGoal.GetType() == typeof(Person))
        {
            Person person = (Person)goapGoal;
            person.AddVegetables(1);

            if (person.VegetablesEnougth())
            {
                Finish();
            }
        }
    }


}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-23 15:16  GoapDemo\
     目录           0  2018-01-16 11:37  GoapDemo\Assets\
     目录           0  2018-01-16 11:37  GoapDemo\Assets\Material\
     文件         200  2018-01-10 20:03  GoapDemo\Assets\Material.meta
     文件        5020  2018-01-10 20:03  GoapDemo\Assets\Material\Person.mat
     文件         187  2018-01-10 20:03  GoapDemo\Assets\Material\Person.mat.meta
     目录           0  2018-01-16 12:00  GoapDemo\Assets\Scene\
     文件         191  2018-01-16 11:37  GoapDemo\Assets\Scene.meta
     文件       40480  2018-01-16 12:00  GoapDemo\Assets\Scene\Test.unity
     文件         182  2018-01-10 20:03  GoapDemo\Assets\Scene\Test.unity.meta
     目录           0  2018-01-16 11:37  GoapDemo\Assets\script\
     文件         200  2018-01-10 20:03  GoapDemo\Assets\script.meta
     目录           0  2018-01-16 12:22  GoapDemo\Assets\script\Action\
     文件         200  2018-01-10 20:03  GoapDemo\Assets\script\Action.meta
     文件        1333  2018-01-16 12:22  GoapDemo\Assets\script\Action\GoapActionBuyVegetables.cs
     文件         262  2018-01-16 11:57  GoapDemo\Assets\script\Action\GoapActionBuyVegetables.cs.meta
     文件        1374  2018-01-16 12:12  GoapDemo\Assets\script\Action\GoapActionCook.cs
     文件         262  2018-01-11 18:49  GoapDemo\Assets\script\Action\GoapActionCook.cs.meta
     文件        1464  2018-01-16 11:56  GoapDemo\Assets\script\Action\GoapActionEat.cs
     文件         274  2018-01-10 20:03  GoapDemo\Assets\script\Action\GoapActionEat.cs.meta
     目录           0  2018-01-16 12:24  GoapDemo\Assets\script\Goap\
     文件         200  2018-01-10 20:03  GoapDemo\Assets\script\Goap.meta
     文件        2632  2018-01-11 19:58  GoapDemo\Assets\script\Goap\GoapAction.cs
     文件         274  2018-01-10 20:03  GoapDemo\Assets\script\Goap\GoapAction.cs.meta
     文件        1758  2018-01-11 19:37  GoapDemo\Assets\script\Goap\GoapAgent.cs
     文件         274  2018-01-10 20:03  GoapDemo\Assets\script\Goap\GoapAgent.cs.meta
     文件        1301  2018-01-11 19:40  GoapDemo\Assets\script\Goap\GoapGoal.cs
     文件         274  2018-01-10 20:03  GoapDemo\Assets\script\Goap\GoapGoal.cs.meta
     文件         827  2018-01-10 20:03  GoapDemo\Assets\script\Goap\GoapNode.cs
     文件         274  2018-01-10 20:03  GoapDemo\Assets\script\Goap\GoapNode.cs.meta
     文件        4229  2018-01-16 12:24  GoapDemo\Assets\script\Goap\GoapPlan.cs
............此处省略40个文件信息

评论

共有 条评论