「iniファイルを使ったセーブシステム」の編集履歴(バックアップ)一覧はこちら
追加された行は緑色になります。
削除された行は赤色になります。
*概要
iniファイルを使って変数をセーブするコードです。
iniを使う事によって例えばマップを移動した時にヘスル値やイベントリ等を次のマップに引き継げます。
*リンク
http://udn.epicgames.com/Three/ConfigSavegameSystem.html
http://udn.epicgames.com/Three/ConfigSavegameSystemJP.html
*シンプルなコード
#pre{{
class MyGame extends UTGame
config(Test)
notplaceable;
var config int CallNum;
function PostBeginPlay()
{
SetTimer(1, true, 'AddNum');//ゲーム開始から1秒毎にAddNum()を実行
super.PostBeginPlay();
}
function AddNum()
{
WorldInfo.Game.Broadcast(self, CallNum); //数字をHUDに表示
CallNum++; //実行毎に+1
SaveConfig(); //iniをセーブ
}
defaultproperties
{
MapPrefixes[0]="MY"
}
}}
上記のコードは1秒毎に数字を読み上げていき、数字をUDKTest.iniに保存して行きます。
*ヘルス値の保存
#pre{{
class MyPawn extends UTPawn
config(Test)
notplaceable;
var config int CurrentHealth;
simulated function PostBeginPlay()
{
LoadHealth();
super.PostBeginPlay();
}
simulated function SaveHealth()
{
CurrentHealth=Health;
SaveConfig();
}
simulated function LoadHealth()
{
if( CurrentHealth <= 0 )
{
CurrentHealth=Health;
}
Health=CurrentHealth;
}
defaultproperties
{
}
}}
#pre{{
class MySaveZone extends UTGameObjective
placeable;
var() Volume CalcZone;
var() float CheckInterval;
auto state Active
{
event BeginState(Name PreviousStateName)
{
SetTimer(CheckInterval, true, 'CheckZone');
super.BeginState(PreviousStateName);
}
function CheckZone()
{
NumPawnInZone();
}
function NumPawnInZone()
{
local MyPawn P;
P=MyPawn(Instigator);
foreach CalcZone.TouchingActors(class'MyPawn', P)
{
if(P.Health >=0)
{
P.SaveHealth();
WorldInfo.Game.Broadcast(self, 'Saved');
gotostate('Complete');
}
}
}
}
state Complete
{
event BeginState(Name PreviousStateName)
{
super.BeginState(PreviousStateName);
}
}
defaultproperties
{
bStatic=false
bHidden=false
bAlwaysRelevant=true
Physics=PHYS_None
bOrientOnSlope=true
bReplicateMovement=true
bIgnoreRigidBodyPawns=true
CheckInterval=0.1
}
}}
上記のコードはマップが始まった時にUDKTest.iniから現在のヘルス値をロードして、
MySaveZoneで指定されたボリュームにタッチするとセーブします。
~
*概要
iniファイルを使って変数をセーブするコードです。
iniを使う事によって例えばマップを移動した時にヘスル値やイベントリ等を次のマップに引き継げます。
*リンク
http://udn.epicgames.com/Three/ConfigSavegameSystem.html
http://udn.epicgames.com/Three/ConfigSavegameSystemJP.html
*シンプルなコード
#pre{{
class MyGame extends UTGame
config(Test)
notplaceable;
var config int CallNum;
function PostBeginPlay()
{
SetTimer(1, true, 'AddNum');//ゲーム開始から1秒毎にAddNum()を実行
super.PostBeginPlay();
}
function AddNum()
{
WorldInfo.Game.Broadcast(self, CallNum); //数字をHUDに表示
CallNum++; //実行毎に+1
SaveConfig(); //iniをセーブ
}
defaultproperties
{
MapPrefixes[0]="MY"
}
}}
上記のコードは1秒毎に数字を読み上げていき、数字をUDKTest.iniに保存して行きます。
*ヘルス値の保存
#pre{{
class MyPawn extends UTPawn
config(Test)
notplaceable;
var config int CurrentHealth;
simulated function PostBeginPlay()
{
LoadHealth();
super.PostBeginPlay();
}
simulated function SaveHealth()
{
CurrentHealth=Health;
SaveConfig();
}
simulated function LoadHealth()
{
if( CurrentHealth <= 0 )
{
CurrentHealth=Health;
}
Health=CurrentHealth;
}
defaultproperties
{
}
}}
#pre{{
class MySaveZone extends UTGameObjective
placeable;
var() Volume CalcZone;
var() float CheckInterval;
auto state Active
{
event BeginState(Name PreviousStateName)
{
SetTimer(CheckInterval, true, 'CheckZone');
super.BeginState(PreviousStateName);
}
function CheckZone()
{
NumPawnInZone();
}
function NumPawnInZone()
{
local MyPawn P;
P=MyPawn(Instigator);
foreach CalcZone.TouchingActors(class'MyPawn', P)
{
if(P.Health >=0)
{
P.SaveHealth();
WorldInfo.Game.Broadcast(self, 'Saved');
gotostate('Complete');
}
}
}
}
state Complete
{
event BeginState(Name PreviousStateName)
{
super.BeginState(PreviousStateName);
}
}
defaultproperties
{
bStatic=false
bHidden=false
bAlwaysRelevant=true
Physics=PHYS_None
bOrientOnSlope=true
bReplicateMovement=true
bIgnoreRigidBodyPawns=true
CheckInterval=0.1
}
}}
上記のコードはマップが始まった時にUDKTest.iniから現在のヘルス値をロードして、
MySaveZoneで指定されたボリュームにタッチするとセーブします。
[[ダウンロード>http://www20.atwiki.jp/udk_tips?cmd=upload&act=open&pageid=85&file=saveini.zip]]
~