Thursday, October 4, 2012

Appendix A-Import Custom Model With Script

1.SetUp CustomGameInfo.
2.Using RestartPlayer(Controller) Function.
3.Seting variable(SkeletalMesh MaterialInterface
   AnimTree array<AnimSet> AnimNodeSequence PhysicsAsset).
4.Call the function.

設定玩家自行匯入的模型當人物,要有自定義GameInfo和PlayerController,
先從GameInfo開始:
class FunnyGameInfo extends UTDeathmatch;

var CustomTopDownController currentPlayer;

simulated function PostBeginPlay()
{

}
function RestartPlayer(Controller aPlayer)
{
super.RestartPlayer(aPlayer);
currentPlayer=CustomTopDownController(aPlayer);
currentPlayer.ResetPlayerMesh();
}

DefaultProperties
{

PlayerControllerClass = class'Tutorial.CustomTopDownController'
DefaultPawnClass=class'Tutorial.CustomTopDownPawn'
}
RestartPlayer()是定義在GameInfo.uc,在遊戲剛開始時會執行,所以要在這進行override,可以取得Controller便執行自行定義的PlayerController裡的function(RestPlayerMesh)。
接下來便是修改CustomTopDownController.uc:
class CustomTopDownController extends UTPlayerController;
var SkeletalMesh myCustomMesh;
var MaterialInterface myCustomMaterial0;
var AnimTree myCustomAnimTree;
var array<AnimSet> myCustomAnimSets;
var AnimNodeSequence myCustomAnimSeq;
var PhysicsAsset myCustomPhysicsAsset;
simulated function PostBeginPlay()
{

ResetPlayerMesh();
}
function ResetPlayerMesh()
{
if(Pawn != none)
{
Pawn.Mesh.SetSkeletalMesh(myCustomMesh);
Pawn.Mesh.SetMaterial(0,myCustomMaterial0);
Pawn.Mesh.SetPhysicsAsset(myCustomPhysicsAsset);
Pawn.Mesh.AnimSets=myCustomAnimSets;
Pawn.Mesh.SetAnimTreeTemplate(myCustomAnimTree);
}
}

DefaultProperties
{
myCustomMesh=SkeletalMesh'KismetGame_Assets.Anims.SK_Jazz'
myCustomAnimTree=AnimTree'KismetGame_Assets.Anims.Jazz_AnimTree'
myCustomAnimSets(0)=AnimSet'KismetGame_Assets.Anims.SK_Jazz_Anims'
//myCustomPhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
}
宣告變數,一個標準的skeletalMesh必須有SkeletalMesh MaterialInterface
AnimTree array<AnimSet> AnimNodeSequence PhysicsAsset包含這些才能夠完整表現出來,在這裡使用UDK內附的Jazz的兔子,因為他沒包含PhysicsAsset在這裡設定成none,如果PhysicsAsset沒有符合模型骨架,在遊玩時log會顯示缺少那些骨架未定義且人物會不段閃爍,可以把PhysicsAsset設定成none,DefaultProperties必須設定好Package位置,在FunnyGameInfo.uc有呼叫ResetPlayerMesh(),因此要新增ResetPlayerMesh()在playerController,這樣即可完成設定成自行的模型給玩家操作。
clip_image002

File:CustomModel.7z

No comments:

Post a Comment