UDN
Search public documentation:
UnrealScriptDefaultPropertiesJP
English Translation
中国翻译
한국어
Interested in the Unreal Engine?
Visit the Unreal Technology site.
Looking for jobs and company info?
Check out the Epic games site.
Questions about support via UDN?
Contact the UDN Staff
中国翻译
한국어
Interested in the Unreal Engine?
Visit the Unreal Technology site.
Looking for jobs and company info?
Check out the Epic games site.
Questions about support via UDN?
Contact the UDN Staff
UnrealScript のデフォルトプロパティ
概要
defaultproperties
ブロックという特別なコードブロックが使用されます。これを使用すると、クラスのインスタンスが生成される際に、初期化のために使われるそのクラスの一部または全部のインスタンス変数に、値をセットすることができます。このコードブロックは、常に、すべての関数およびステートが宣言された後で、スクリプトの最後に置かれます。このコードブロックは UnrealScript の一部でありながらも、そのブロック内部にあるコードは、標準的な UnrealScript ではなく、若干異なる規則に従います。
デフォルトプロパティ値を指定する
defaultproperties
ブロックの規則は、標準的な UnrealScript のシンタックスとやや異なります。以下は相違点の概略です。
- defaultproperties ブロックでは、動的配列の操作を除いて、文の記述が許されていません。つまり、計算の実行または関数の呼び出しなどができないことになります。
defaultproperties
ブロックは、リテラル値をインスタンス変数に割り当てることしか行いません。 - セミコロンは各行末に置くことができますが、必須ではありません。
- スペースは入れないようにします。(たとえば、変数名、代入演算子、値の間に)。
-
defaultproperties
ブロックの開き波括弧は、新しい行に置かれなければなりません。
VarName=Value
ArrayProp(0)=Value1 ArrayProp(1)=Value2
ArrayProp[0]=Value1 ArrayProp[1]=Value2
ArrayProp=(Value1,Value2,Value3)
ArrayProp(0)=Value1 ArrayProp(1)=Value2 ArrayProp(2)=Value3
ArrayProp.Add(Value1) ArrayProp.Add(Value2) ArrayProp.Add(Value3)
NameProp='Value'
NameProp=Value
ObjectProp=ObjectClass'ObjectName'
Begin Object Class=ObjectClass Name=ObjectName VarName=Value ... End Object ObjectProperty=ObjectName
StructProperty=(InnerStructPropertyA=Value1,InnerStructPropertyB=Value2)
StructProperty={( InnerStructPropertyA=Value1, InnerStructPropertyB=Value2 )}
- インラインの静的配列は、次のように宣言する必要があります。(配列の区切り文字が、丸括弧 ( ) ではなく、角括弧 [ ] になっていることに注意してください)。
StructProperty=(StaticArray[0]=Value,StaticArrayProp[1]=Value)
- インラインの動的配列は、一行構文を使用して次のように宣言しなければなりません。
StructProperty=(DynamicArray=(Value,Value))</code>
- インラインの名前変数は、引用符の中に入れる必要があります。
StructProperty=(NameProperty="Value")
- Empty - 配列全体を空にします。
Array.Empty
- Add(element) -
element
(要素) を配列の最後に追加します。Array.Add(element)
- Remove(element) - 配列から
element
を削除します。これによって、element
のすべての出現が削除されます。Array.Remove(element)
- RemoveIndex(index) - 指定された
index
(インデックス) の要素を削除します。Array.RemoveIndex(index)
- Replace(element1, element2) -
element1
をelement2
に置き換えます。すべての出現が置き換えられます。element1
が見つからない場合は、警告が出されます。Array.Replace(element1, element2)
次は、完結したdefaultproperties
ブロックの例です。(Actor.uc
に基づいています)。defaultproperties { // objects MessageClass=class'LocalMessage' // declare an inline subobject of class SpriteComponent named "Sprite" Begin Object Class=SpriteComponent Name=Sprite // values specified here override SpriteComponent's own defaultproperties Sprite=Texture2D'EngineResources.S_Actor' HiddenGame=true End Object //todo Components.Add(Sprite) // declare an inline subobject of class CylinderComponent named "CollisionCylinder" Begin Object Class=CylinderComponent Name=CollisionCylinder // values specified here override CylinderComponent's own defaultproperties CollisionRadius=10 CollisionHeight=10 AlwaysLoadOnClient=True AlwaysLoadOnServer=True End Object //todo Components.Add(CollisionCylinder) CollisionComponent=CollisionCylinder // floats (leading '+' and trailing 'f' characters are ignored) DrawScale=00001.000000 Mass=+00100.000000 NetPriority=00001.f // ints NetUpdateFrequency=100 // enumerations Role=ROLE_Authority RemoteRole=ROLE_None // structs DrawScale3D=(X=1,Y=1,Z=1) // bools bJustTeleported=true bMovable=true bHiddenEdGroup=false bReplicateMovement=true // names InitialState=None // dynamic array (in this case, a dynamic class array) SupportedEvents(0)=class'SeqEvent_Touch' SupportedEvents(1)=class'SeqEvent_UnTouch' SupportedEvents(2)=class'SeqEvent_Destroyed' SupportedEvents(3)=class'SeqEvent_TakeDamage' }
構造体のデフォルト
UnrealScript で構造体を宣言する場合、その構造体のプロパティにデフォルトの値を指定することができます (オプション)。この構造体が UnrealScript で使用される場合はいつでも、そのメンバーがデフォルト値で初期化されることになります。シンタックスは、クラスの defaultproperties ブロックの場合と同じです。ただし、ブロックの名前は、 structdefaultproperties としなければなりません。 例 :struct LinearColor { var() config float R, G, B, A; structdefaultproperties { A=1.f } };
var LinearColor NormalColor, DarkColor; defaultproperties { NormalColor=(R=1.f,B=1.f,G=1.f) // value of A will be 1.0f for this property DarkColor=(R=1.f,B=1.f,G=1.f,A=0.2f) // value of A will be 0.2f for this property }
変数のデフォルト値にアクセスする
レベルデザイナーは、「Unreal」エディタを使用して、オブジェクトのクラスがもつ「デフォルト」の変数を編集することができます。 クラスから新たなアクタがスポーンすると、その変数はすべてデフォルト値に初期化されます。ただし、コードから変数をデフォルト値にリセットするのが便利な場合があります。たとえば、プレイヤーがインベントリのアイテムをドロップした場合は、インベントリのコードによって、アクタの値のいくつかをデフォルト値にリセットする必要があります。UnrealScript では、Default
というキーワードを使用すると、クラスがもつデフォルトの変数にアクセスすることができます。例 :var() float Health, Stamina; ... // Reset some variables to their defaults. function ResetToDefaults() { // Reset health, and stamina. Health = Default.Health; Stamina = Default.Stamina; }
クラスの参照によって変数のデフォルト値にアクセスする
クラスの参照 (class
型またはclass<classlimitor>
型の変数) がある場合は、クラスのオブジェクトがなくても、参照されるクラスがもつデフォルトのプロパティにアクセスすることができます。このシンタックスは、クラス型と評価されるあらゆる式で使用することができます。var class C; var class
PC; Health = class'Spotlight'.default.LightBrightness; // Access the default value of // LightBrightness in the Spotlight class. Health = PC.default.Health; // Access the default value of Health in // a variable class identified by PC. Health = class (C).default.Health; // Access the default value // of Health in a casted class // expression. - Add(element) -