iniファイルを使ったセーブシステム

概要

iniファイルを使って変数をセーブするコードです。
iniを使う事によって例えばマップを移動した時にヘスル値やイベントリ等を次のマップに引き継げます。

リンク


シンプルなコード

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に保存して行きます。

ヘルス値の保存

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
{
}

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で指定されたボリュームにタッチするとセーブします。
ダウンロード

~

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2011年06月27日 06:40
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。
添付ファイル