State:
E:/udnweb/udn script/udn.epicgames.com/Three/MasteringUnrealScriptStatesCH.html
指南 11.1 – 状态触发器, 第一部分:函数重载
前期准备
原文件地图文件扩展名为ut3,UDK2013.07编译时地图要另存为扩展名为udk,添加一个PlayerStart否则提示找不到地图文件
新建文本文档在项目中添加现有项
UDKGame\Config目录下的DefaultEngine.ini文件中没有添加Chapte11_State文件包,编译后脚本中不产生相关的.u文件。
DefaultEngine.ini文件中添加Chapte11_State文件包后,在Editor的Contenbrowser中才可以找到MU_StateTrigger,否则在Contenbrowser中不会显示出MU_StateTrigger
class MU_StateTrigger extends Actor
placeable;
defaultproperties中Translation=(X=0.000000,Y=0.000000,Z=-40.000000)意味着网格物体在Editor中位置处于坐标下方40个单位处
函数重载测试完成的代码:
CH_State:
Class CH_State extends utGame;
MU_StateTrigger:
class MU_StateTrigger extends Actor
placeable;
event Touch(Actor Other, PrimitiveComponent OtherComp,vector HitLocation,vector HitNormal)
{
WorldInfo.Game.Broadcast(self,"This is theStateTigger class.");
GotoState('Dialog'); //碰撞发生后,把当前面Actor放到Dialog状态下(让它处在Dialog状态)
}
state Dialog
{
eventTouch(ActorOther, PrimitiveComponentOtherComp, vectorHitLocation, vectorHitNormal)
{
WorldInfo.Game.Broadcast(self,"This is thebase dialog state's output");
}
}
defaultproperties
{ //defaultproperties代码块为Actor提供了网格物体和碰撞几何体。由用于达到actor的可视化效果的StaticMeshComponent子对象和用于作为actor碰撞的CylinderComponent子对象构成。
//定义三个子对象StaticMeshComponent(组件),CollideActors=false;定义了一个CylinderComponent组件CollideActors=true
BeginObject Class=StaticMeshComponent Name=StaticMeshComponent0
//StaticMesh=StaticMesh'LT_Deco.SM.Mesh.S_LT_Deco_SM_PodiumScorpion'
StaticMesh=StaticMesh'Chapter_06_Functions.ClownFish'
Translation=(X=0.000000,Y=0.000000,Z=-20.000000)
Scale3D=(X=0.50000,Y=0.50000,Z=0.5000)
CollideActors=false
bAllowApproximateOcclusion=True
bForceDirectLightMap=True
bCastDynamicShadow=False
LightingChannels=(Dynamic=False,Static=True)
EndObject
Components.Add(StaticMeshComponent0)
BeginObject Class=StaticMeshComponent Name=StaticMeshComponent1
StaticMesh=StaticMesh'LT_Deco.SM.Mesh.S_LT_Walls_SM_FlexRing'
Translation=(X=0.000000,Y=0.000000,Z=-40.000000)
Scale3D=(X=0.500000,Y=0.500000,Z=0.500000)
CollideActors=false
bAllowApproximateOcclusion=True
bForceDirectLightMap=True
bCastDynamicShadow=False
LightingChannels=(Dynamic=False,Static=True)
EndObject
Components.Add(StaticMeshComponent1)
BeginObject Class=StaticMeshComponent Name=StaticMeshComponent2
//StaticMesh=StaticMesh'LT_Light.SM.Mesh.S_LT_Light_SM_LightCone01'
StaticMesh=StaticMesh'LT_Light.SM.Mesh.S_LT_Light_SM_Light01' //UDK2013.07中contenbrowser中自带的文件
Translation=(X=0.000000,Y=0.000000,Z=-40.000000)
//Scale3D=(X=2.000000,Y=2.000000,Z=-1.000000)
Scale3D=(X=2.000000,Y=2.000000,Z=1.000000)
CollideActors=false
bAllowApproximateOcclusion=True
bAcceptsLights=True
CastShadow=False
EndObject
Components.Add(StaticMeshComponent2)
//BeginObject Class=DrawCylinderComponent NAME=CollisionCylinder 先用Draw,把Component在Editor中看一下效果。测试发现,Draw出来的东西不具备计算碰撞的功能。
BeginObject Class=CylinderComponent NAME=CollisionCylinder
CollideActors=true
CollisionRadius=+0040.000000
CollisionHeight=+0040.000000
EndObject
CollisionComponent=CollisionCylinder
Components.Add(CollisionCylinder)
bCollideActors=true
bStatic=true
bMovable=False
bEdShouldSnap=True
}
指南 11.2 –状态触发器, 第二部分:状态继承