尝试根据本地时间补间Color3值

时间:2015-07-03 17:48:12

标签: lua roblox

所以我在www.roblox.com上制作插件并且我遇到了一个问题,尽管我成功地花了他们的时间,但这段代码似乎没有正确调整脚本编辑器颜色。我想我的数学可能会被关闭? (注意:我使用内置函数:lerp用于Vector3值,只需从Vector3和Color3转换为避免创建我自己的自定义lerp函数。)

代码:

local S = settings().Studio
local toolbar = plugin:CreateToolbar("Time of day Script Editor")
local Toggle = toolbar:CreateButton("Enable", "Enable Time of day Script Editor", "")
local Options = {"Background Color", "Comment Color", "Error Color", "Keyword Color", "Number Color", "Operator Color", "Preprocessor Color", "Selection Background Color", "Selection Color", "String Color","Text Color", "Warning Color"}
local Original = {["Background Color"] = Color3.new(1, 1, 1), ["Comment Color"] = Color3.new(0, 127/255, 0), ["Error Color"] = Color3.new(1, 0, 0), ["Keyword Color"] = Color3.new(0, 0, 127/255), ["Number Color"] = Color3.new(0, 127/255, 127/255), ["Operator Color"] = Color3.new(127/255, 127/255, 0), ["Preprocessor Color"] = Color3.new(127/255, 0, 0), ["Selection Background Color"] = Color3.new(110/255, 161/255, 241/255), ["Selection Color"] = Color3.new(1, 1, 1), ["String Color"] = Color3.new(127/255, 0, 127/255),["Text Color"] = Color3.new(0, 0, 0), ["Warning Color"] = Color3.new(0, 0, 1)}
local Active = false

local Lighting = game.Lighting

local function C3V3(c3) --Convert a Color3 into Vector3
    return Vector3.new(c3.r, c3.g, c3.b)
end

local function V3C3(v3) --Convert a Vector3 into a Color3
    return Color3.new(v3.x, v3.y, v3.z)
end

local function Color3Lerp(start, fin, decimal) --Return a lerped Color3
    return V3C3(C3V3(start):lerp(C3V3(fin), decimal))
end

local function GetLocalTime() --Get their local time
    local t = tick()
    local hour = math.floor(t/60/60%24)
    local minute = math.floor(t/60%60)
    return hour .. ":" .. minute .. ":00"
end

local function GetMinutes(T) --Get minutes
    local Orig = Lighting.TimeOfDay --Original .TimeOfDay property
    local Minutes = nil
    Lighting.TimeOfDay = T --Set to time
    Minutes = Lighting:GetMinutesAfterMidnight() --Get minutes after midnight
    Lighting.TimeOfDay = Orig --Set back to original so user doesn't notice
    return Minutes
end

local function GetDecimal(minutes) --Get decimal used for lerping
    return minutes < 720 and  minutes/720 or (minutes-720)/720
end

local function DeterminePoints(start, fin, minutes) --Determine start and end values of the lerp based on the local time
    if minutes >= 720 then
        return start,fin
    else
        return fin,start
    end
end

local function Invert(Color) --Invert a color
    return Color3.new(1 - Color.r, 1 - Color.g, 1 - Color.b)
end

Toggle.Click:connect(function() --When the plugin is used
    Active = not Active
    Toggle:SetActive(Active)
    while Active do
        for i = 1,#Options do
            local Min = GetMinutes(GetLocalTime()) --Get minutes
            local start, fin = DeterminePoints(Original[Options[i]], Invert(Original[Options[i]]), Min) --Get start and finish points
            S[Options[i]] = Color3Lerp(start, fin, GetDecimal(Min)) --Lerp it
        end
        wait(60) --Wait a minute before repeating
    end
end)

它确实会改变颜色,并且不会出错,但它不会改变为正确的颜色。

非常感谢任何帮助,谢谢。

1 个答案:

答案 0 :(得分:-1)

据我所知,您无法通过插件更改脚本编辑器的设置。我对插件不是很熟练,但是我相信它仅限于无法编辑脚本编辑器设置。