概要
方法
GetDefaultPropertyTransition():Variant |
GetProperty(name: string):Variant |
SetDefaultPropertyTransition(transitionParams: Variant):() |
SetProperties(styleProperties: Dictionary):() |
SetProperty(name: string,value: Variant):() |
SetPropertyTransition(property: string,transitionParams: Variant):() |
SetPropertyTransitions(properties: Dictionary):() |
API 参考
属性
Selector
代码示例
用户界面类选择器
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
-- 类选择器
rule.Selector = "TextButton"
-- 设置规则属性
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 = "主菜单"
button.Parent = screenGuiUI 标签选择器
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
-- 标签选择器
rule.Selector = ".ButtonPrimary"
-- 设置规则属性
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 = "主菜单"
button.Parent = screenGui
-- 将标签应用于按钮
CollectionService:AddTag(button, "ButtonPrimary")UI 修改器选择器
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 组件选择器
rule.Selector = "Frame.RoundedCorner20::UICorner"
-- 设置规则属性
rule:SetProperty("CornerRadius", UDim.new(0, 20))
-- 创建框架
local frame = Instance.new("Frame")
frame.Size = UDim2.new(0.4, 0, 0.2, 0)
frame.Parent = screenGui
-- 将标签应用于框架
CollectionService:AddTag(frame, "RoundedCorner20")UI 样式查询选择器
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 smallRule = Instance.new("StyleRule")
smallRule.Parent = coreSheet
local mediumRule = Instance.new("StyleRule")
mediumRule.Parent = coreSheet
-- 声明样式查询选择器
smallRule.Selector = "@Small"
mediumRule.Selector = "@Medium"
-- 设置规则属性
smallRule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("FF0099"),
["Text"] = "小容器",
["TextColor3"] = Color3.fromHex("E1E1E1"),
["TextSize"] = 12,
})
mediumRule:SetProperties({
["BackgroundColor3"] = Color3.fromHex("F0F0F0"),
["Text"] = "中型容器",
["TextColor3"] = Color3.fromHex("0022FC"),
["TextSize"] = 24,
})
local button = Instance.new("TextButton")
button.Text = "主菜单"
button.Parent = screenGui
button.Size = UDim2.fromScale(0.5, 0.2)
-- 创建样式查询,名称与样式规则选择器匹配
local mediumSQ = Instance.new("StyleQuery")
mediumSQ.Parent = button
mediumSQ.Name = "Medium"
mediumSQ:SetConditions({
["MinSize"] = Vector2.new(200, 0),
})
local smallSQ = Instance.new("StyleQuery")
smallSQ.Parent = button
smallSQ.Name = "Small"
smallSQ:SetConditions({
["MaxSize"] = Vector2.new(200, math.huge),
["MinSize"] = Vector2.new(0, 0),
})方法
GetDefaultPropertyTransition
StyleRule:GetDefaultPropertyTransition():Variant
返回
Variant
GetPropertyTransitions
代码示例
获取属性过渡()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
-- 设置一些过渡
frameRule:SetPropertyTransition("BackgroundColor3", TweenInfo.new(1, Enum.EasingStyle.Linear))
frameRule:SetPropertyTransition("BackgroundTransparency", "$DefaultTransition")
local transitions = frameRule:GetPropertyTransitions()
print(transitions)SetDefaultPropertyTransition
StyleRule:SetDefaultPropertyTransition(transitionParams:Variant):()
参数
transitionParams:Variant |
返回
()
SetPropertyTransition
参数
transitionParams:Variant |
返回
()
代码示例
设置属性过渡(SetPropertyTransition)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
-- 对 BackgroundColor3 设置 1 秒的线性过渡
frameRule:SetPropertyTransition("BackgroundColor3", TweenInfo.new(
1, -- 时间
Enum.EasingStyle.Linear -- 缓动样式
))
-- 移除过渡
frameRule:SetPropertyTransition("BackgroundColor3", nil)使用令牌的 SetPropertyTransition()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
local tokensSheet = ReplicatedStorage:FindFirstChild("Tokens")
-- 在令牌表上设置令牌(属性)
tokensSheet:SetAttribute("LinearTransition", TweenInfo.new(1, Enum.EasingStyle.Linear))
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
frameRule:SetPropertyTransition("BackgroundColor3", "$LinearTransition")SetPropertyTransitions
参数
返回
()
代码示例
设置属性过渡()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
-- 同时设置两个属性的过渡
frameRule:SetPropertyTransitions({
["BackgroundColor3"] = TweenInfo.new(1, Enum.EasingStyle.Linear),
["BackgroundTransparency"] = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
})
-- 移除所有过渡
frameRule:SetPropertyTransitions({})使用令牌的 SetPropertyTransitions()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coreSheet = ReplicatedStorage:FindFirstChild("CoreSheet")
local tokenSheet = ReplicatedStorage:FindFirstChild("Tokens")
-- 在令牌表上设置令牌(属性)
tokenSheet:SetAttribute("LinearTransition", TweenInfo.new(1, Enum.EasingStyle.Linear))
tokenSheet:SetAttribute("QuadTransition", TweenInfo.new(0.25, Enum.EasingStyle.Quad))
-- 获取样式规则的引用
local frameRule = coreSheet.Frame
-- 同时设置多个属性的过渡
frameRule:SetPropertyTransitions({
["BackgroundColor3"] = "$LinearTransition",
["BackgroundTransparency"] = "$QuadTransition",
})