• Chicken的代码解剖 :4 ChickenPawn


      该类继承了GamePawn意味着简化,对于iOS的性能是最好不过了。

    class ChickenPawn extends GamePawn implements(Interface_DraggableItem);

      实现了一个接口。

    enum PawnType
    {
     CHICKEN_PEN,
     ROOSTER_PEN,
     FOX_PEN  
    };
    var PawnType myType;

      老规矩,从活体编译器开始看看代码的执行。

    event PostBeginPlay()
    {
     super.PostBeginPlay();
    
     //生成一个controller并且该controller占有他
     if(Controller==none)
     SpawnDefaultController();
    
     //调用一个动画状态
     SetAnimState(STATE_MOVEMENT);
    
     //设置碰撞
     SetCollisionType(COLLIDE_TouchAll);
    
     //0.3s后重新设置碰撞,为什么呢。后面将其碰撞设为COLLIDE_BlockAll,因为才生成的生物害怕和别的撞在一起。给一定的时间Bump
     SetTimer(0.3f,false,'ResetCollision');
     //该函数只不过在这个类中声明,后边会定义。目前不去看
     BeginTimeOut();
    }

      进入动画树状态SetAnimState(STATE_MOVEMENT);让我们更清晰的看看他们的动画树,无论是狐狸,小鸡和公鸡都是这种动画树。    

    PrimaryBlender是一个AnimNodeBlendList在其NodeName中命名其为PrimaryBlender。在使用该节点前先进行初始化。

    //初始化节点
    simulated function CacheAnimNodes()
    {
     if(PrimaryBlender==none)
     PrimaryBlender==AnimNodeBlendList(Mesh.FindAnimNode('PrimaryBlender'));
    }

    接下来就是动画的主要执行了,非常的一目了然

    //该节点应该可以实现持有枪支的方式
    function SetAnimState(AnimState newAnimState)
    {
        local int newActiveChild;
    
        if(PrimaryBlender==none)
        CacheAnimNodes();
    
        switch(newAnimState)
        {
         case  STATE_CARRY:
         //此时将BlendList的newActiveChild的节点赋予
         newActiveChild=PrimaryBlender.Children.Find('Name','Carry');
         break;
    
         case STATE_DRAGGED:
         newActiveChild=PrimaryBlendr.Children.Find('Name','Drag');
         break;
    
         default:
         //传统情况是运动状态
         newActiveChild=PrimaryBlender.Children.Find('Name','Movement');
        }
        PrimaryBlender.SetActiveChild(newActiveChild,0.1f);
    }

     我在pawn中注意了一个变量,然后再UnCodeX中队该变量进行了搜索,现在分析一下该变量的运用地方。包括其他Controller中

    var Controller TargetedBy;

    下面有一个使用该变量的函数,随后我们看看该函数都在哪些地方被调用。

    function SetTargeted(Controller newTargeter)
    {
     TargetedBy=newTargeter;
    }

    想一想,好像在狐狸的controller中我们用到过。以及什么地方调用该函数。好吧我回忆到在ChickenAIController_Fox中使用function bool FindPrey()在这里面

    回头查查这个函数,遍历了所有的actor然后查找距离最近的一个ChickenPawn选为目标,然后将其controller设为狐狸,这样他将被狐狸的controller所控制,造成的假象是鸡被狐狸叼着走。

    if(currentBestTarget!=none)
    {
     ChickenPawn(currentBestTarget).SetTargeted(self);
    }

    后边还有一段在HuntPrey的状态EndState

    ChickenPawn(currentPrey)!=none

    咱们下节ChickenPawn_Fox和ChickenPawn_Chicken见

      

  • 相关阅读:
    【转】WPF DataGridComboBoxColumn使用
    【转】CAD 二次开发--属性块 Block和BlockReference
    【转】【Revit】Revit二次开发——读取cad中的文字信息
    【转】【Centos】Linux(Centos7)下搭建SVN服务器
    现代php编程
    drone实践记录
    PHP拆分YAPI导出的swagjson文件
    pydantic验证器Validator
    利用notion打造读书追逐系统
    opencv马赛克python实现
  • 原文地址:https://www.cnblogs.com/NEOCSL/p/2761117.html
Copyright © 2020-2023  润新知