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
}