StyleRule
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
Selector プロパティに影響を受けるインスタンスのプロパティをオーバーライドするスタイルプロパティを定義します。
概要
プロパティ
A number that determines how properties of the StyleRule が他の StyleRules の同じプロパティに対して適用されるかを決定する数。優先度の高い値は、低い値より優先されます。
StyleRule が影響するインスタンスを指定する文字列。
Selector プロパティからのエラーを表示する読み込み専用の文字列。
方法
StyleRule のプロパティを説明するキー-バリューペアの辞書を返します。
StyleRule に特定のプロパティの値を返します。
一度に複数の StyleRule のプロパティを宣言して設定できます。
関連する StyleRules のアレイを返します。
新しい StyleRule を規則の配列に挿入します。
InsertStyleRule() と似ていますが、一度に複数の StyleRules を宣言して設定できます。
プロパティ
Priority
A number that determines how properties of the StyleRule が他の StyleRules の同じプロパティに対して適用されるかを決定する数。優先度の高い値は、低い値より優先されます。たとえば、優先度が StyleRule の 10 を持つ AnchorPoint プロパティが
Selector
StyleRule が影響するインスタンスを指定する文字列。これは、クラス名、インスタンス名、階層関係などの特徴に一致する選択者と結合者の混合になる可能性があります。
たとえば、 効果的には、スタイルルールがすべての をオーバーライドし、インスタンスタグが でタグ付けされた子のすべての をオーバーライドし、 は でタグ付けされ、 は 状態にあり、 は でタグ付けされています ( ) です。
セレクター
<th>説明</th><th>例</th></tr></thead><tbody><tr><td><code>[class]</code></td><td><code>Class.GuiObject</code> または <code>Class.UIComponent</code> クラスのインスタンスと一致します。</td><td><code>"フレーム"</code><code>"画像ボタン"</code><code>"UICorner"</code></td></tr><tr><td><code>.[タグ]</code></td><td>マッチインスタンス <a href="/studio/properties#instance-tags">タグ付き</a> を <code>Class.CollectionService</code> タグでタグ付きにします。</td><td><code>".コンテナ"</code><code>".ブルーオンホバ"</code></td></tr><tr><td><code>#name</code></td><td>特定の <code>Class.Instance.Name</code> のインスタンスと一致します。</td><td><code>"#ModalFrame"</code><code>="#閉じるボタン"</code></td></tr><tr><td><code>:[状態]</code></td><td>現在 <code>Enum.GuiState</code> に存在するインスタンスと一致します。</td><td><code>":ホバリング"</code></td></tr></tbody>
選択者 |
---|
結合子
<th>説明</th><th>例</th></tr></thead><tbody><tr><td><code>></code></td><td>前のフィルターマッチの <b>直接の子供</b> であるインスタンスと一致する。</td><td width="40%"><code>「フレーム > .Inventory」</code></td></tr><tr><td><code>>></code></td><td>前のフィルターマッチの <b>子孫</b> であるインスタンスと一致します。</td><td><code>「画像ボタン >> .BlueOnHover」</code></td></tr><tr><td><code>,</code></td><td>スタイルルールの複数の独立した選択者のリストを指定します。</td><td><code>「Frame.TagA、TextLabel.TagA」</code></td></tr><tr><td><code>::</code></td><td>以前のフィルター一致の下でファントム <code>Class.UIComponent</code> インスタンスを作成し、スタイルルールのプロパティを適用します。</td><td><code>「Frame::UICorner」</code></td></tr></tbody>
コンビネータ |
---|
コードサンプル
The following example shows how to define a class selector which targets all TextButton instances and styles them with blue background and light grey text. To test, paste the code into a LocalScript which is a child of a ScreenGui located inside the StarterGui container.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local screenGui = script.Parent
local coreSheet = Instance.new("StyleSheet")
coreSheet.Parent = ReplicatedStorage
local styleLink = Instance.new("StyleLink")
styleLink.StyleSheet = coreSheet
styleLink.Parent = screenGui
local rule = Instance.new("StyleRule")
rule.Parent = coreSheet
-- Class selector
rule.Selector = "TextButton"
-- Set rule properties
rule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("335FFF"),
["TextColor3"] = Color3.fromHex("E1E1E1"),
["Size"] = UDim2.new(0.15, 0, 0, 40),
["BorderSizePixel"] = 0
})
local button = Instance.new("TextButton")
button.Text = "Main Menu"
button.Parent = screenGui
The following example shows how to define a tag selector which utilizes tags applied through CollectionService to target a TextButton tagged with ButtonPrimary. To test, paste the code into a LocalScript which is a child of a ScreenGui located inside the StarterGui container.
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local screenGui = script.Parent
local coreSheet = Instance.new("StyleSheet")
coreSheet.Parent = ReplicatedStorage
local styleLink = Instance.new("StyleLink")
styleLink.StyleSheet = coreSheet
styleLink.Parent = screenGui
local rule = Instance.new("StyleRule")
rule.Parent = coreSheet
-- Tag selector
rule.Selector = ".ButtonPrimary"
-- Set rule properties
rule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("FF0099"),
["TextColor3"] = Color3.fromHex("E1E1E1"),
["Size"] = UDim2.new(0.15, 0, 0, 40),
["BorderSizePixel"] = 0
})
local button = Instance.new("TextButton")
button.Text = "Main Menu"
button.Parent = screenGui
-- Apply tag to button
CollectionService:AddTag(button, "ButtonPrimary")
The following example shows how to define a UI modifier selector which applies a phantom UICorner instance to a Frame tagged with RoundedCorner20. To test, paste the code into a LocalScript which is a child of a ScreenGui located inside the StarterGui container.
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local screenGui = script.Parent
local coreSheet = Instance.new("StyleSheet")
coreSheet.Parent = ReplicatedStorage
local styleLink = Instance.new("StyleLink")
styleLink.StyleSheet = coreSheet
styleLink.Parent = screenGui
local rule = Instance.new("StyleRule")
rule.Parent = coreSheet
-- UI component selector
rule.Selector = "Frame.RoundedCorner20::UICorner"
-- Set rule property
rule:SetProperty("CornerRadius", UDim.new(0, 20))
-- Create frame
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0.4, 0, 0.2, 0)
frame.Parent = screenGui
-- Apply tag to frame
CollectionService:AddTag(frame, "RoundedCorner20")
方法
GetProperties
返すのは、StyleRule のプロパティを説明するキー-バリューペアの辞書です:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- スタイルルールの参照を取得local frameRule = coreSheet.Framelocal props = frameRule:GetProperties()print(props)--[[{["AnchorPoint"] = 0.5, 0,["BackgroundColor3"] = 1, 0, 0.25}]]
戻り値
StyleRule のプロパティを説明するキー-バリューペアの辞書。
GetProperty
StyleRule に特定のプロパティの値を返します。
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- スタイルルールの参照を取得local frameRule = coreSheet.Framelocal prop = frameRule:GetProperty("AnchorPoint")print(prop) --> 0.5, 0
パラメータ
プロパティのストリング名、例えば "AnchorPoint" または "BackgroundColor3" 。
戻り値
プロパティの値。
SetProperties
SetProperty() と似ていますが、一度に複数の StyleRule のプロパティを宣言して設定できます。各割り当ては、影響を受けた または ( 、 > など)の有効なプロパティであり、割り当てられた値はそのプロパティの値タイプに一致する必要があります。例えば、 は または のため、値がその値タイプに一致します。
"AnchorPt" または "BkColor" のような無効なプロパティ名の割り当て試みは、無音で失敗します。タイプミスマッチは、CFrame で AnchorPoint または UDim2 で BackgroundColor3 や、出力ウィンドウ にエラーが表示され、失敗します。
To set/update just one property of a StyleRule 、 see SetProperty() 。
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- スタイルルールの参照を取得local frameRule = coreSheet.Frame-- 規則プロパティを設定frameRule:SetProperties({["AnchorPoint"] = Vector2.new(0.5, 0),["BackgroundColor3"] = Color3.new(1, 0, 0.25)})
トークン をプロパティ値として割り当てることができるのは、$ プレフィックスを通じて:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")-- トークン(属性)をトークンシートに設定するtokensSheet:SetAttribute("TopCenterAnchor", Vector2.new(0.5, 0))tokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))-- スタイルルールの参照を取得local frameRule = coreSheet.Frame-- 規則プロパティを設定frameRule:SetProperties({["AnchorPoint"] = "$TopCenterAnchor",["BackgroundColor3"] = "$MainBackgroundColor"})
パラメータ
設定するプロパティを定義するキー-値ペアの辞書。 Dictionary of key-value pairs defining the properties to set.
戻り値
SetProperty
新しいプロパティ (または既存のプロパティを変更)を StyleRule に設定します。パラメータ name は、影響を受けた GuiObject または UIComponent ( UICorner , UIGradient , など) の有効なプロパティであり、割り当てられた値は、例えば Vector2 で AnchorPoint または Color3 で BackgroundColor3 のプロパティの値タイプに一致する必要があります。
"AnchorPt" または "BkColor" のような無効なプロパティ名の割り当て試みは、無音で失敗します。タイプミスマッチは、CFrame で AnchorPoint または UDim2 で BackgroundColor3 や、出力ウィンドウ にエラーが表示され、失敗します。
一度に複数のプロパティを StyleRule に設定するには、SetProperties() を参照してください。
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")-- スタイルルールの参照を取得local frameRule = coreSheet.Frame-- ルールプロパティを設定frameRule:SetProperty("BackgroundColor3", Color3.new(1, 0, 0.25))
トークン をプロパティ値として割り当てることができるのは、$ プレフィックスを通じて:
local ReplicatedStorage = game:GetService("ReplicatedStorage")local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")-- トークンシートに新しいトークン (属性) を設定するtokensSheet:SetAttribute("MainBackgroundColor", Color3.new(0.2, 0.2, 0.3))-- スタイルルールの参照を取得local frameRule = coreSheet.Frame-- ルールプロパティを設定して、トークンを値として使用するframeRule:SetProperty("BackgroundColor3, "$MainBackgroundColor")
パラメータ
設定するプロパティ名、例えば "BackgroundColor3" 。
設定するプロパティ値、例えば Color3.new(1, 0, 0.25) 。