Lớp công cụ
Pose
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Thuộc Tính
Phương Pháp
AddSubPose(pose: Instance):() |
GetSubPoses():Instances |
RemoveSubPose(pose: Instance):() |
Mẫu mã
Sinh động Khung Hình Tạo Poses
local function generateKeyframe(model)
if not model.PrimaryPart then
warn("Không có phần chính được thiết lập")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Không tìm thấy phần gốc")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part, parentPose)
-- lấy tất cả các khớp nối gắn liền với phần
for _, joint in pairs(part:GetJoints()) do
-- chúng tôi chỉ quan tâm đến Motor6Ds
if joint:IsA("Motor6D") then
-- tìm phần kết nối
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- đảm bảo rằng chúng tôi chưa thêm phần này
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
-- tạo một pose
local pose = Instance.new("Pose")
pose.Name = connectedPart.Name
parentPose:AddSubPose(pose)
-- tiếp tục
addPoses(connectedPart, pose)
end
end
end
end
end
local keyframe = Instance.new("Keyframe")
-- điền thông tin vào keyframe
local rootPose = Instance.new("Pose")
rootPose.Name = rootPart.Name
addPoses(rootPart, rootPose)
keyframe:AddPose(rootPose)
return keyframe
end
local character = script.Parent
local keyframe = generateKeyframe(character)
print(keyframe)Đặt lại Poses Khung khóa
local function resetPoses(parent)
-- cả hai hàm đều tương đương với GetChildren
local poses = parent:IsA("Keyframe") and parent:GetPoses() or parent:IsA("Pose") and parent:GetSubPoses()
for _, pose in pairs(poses) do
if pose:IsA("Pose") then
pose.CFrame = CFrame.new()
-- đệ quy
resetPoses(pose)
end
end
endTài Liệu Tham Khảo API
Thuộc Tính
MaskWeight
Phương Pháp
AddSubPose
Tham Số
Lợi Nhuận
()
Mẫu mã
Thêm/Bỏ tư thế Keyframe
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local pose = Instance.new("Pose")
pose.EasingStyle = Enum.PoseEasingStyle.Cubic
pose.EasingDirection = Enum.PoseEasingDirection.Out
local pose2 = Instance.new("Pose")
pose2.EasingStyle = Enum.PoseEasingStyle.Cubic
pose2.EasingDirection = Enum.PoseEasingDirection.Out
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
keyframe:RemovePose(pose) -- pose.Parent = nil
task.wait(2)
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
pose:AddSubPose(pose2) -- pose2.Parent = pose
task.wait(2)
pose:RemoveSubPose(pose2) -- pose2.Parent = nilGetSubPoses
Pose:GetSubPoses():Instances
Lợi Nhuận
Instances
Mẫu mã
Đặt lại Poses Khung khóa
local function resetPoses(parent)
-- cả hai hàm đều tương đương với GetChildren
local poses = parent:IsA("Keyframe") and parent:GetPoses() or parent:IsA("Pose") and parent:GetSubPoses()
for _, pose in pairs(poses) do
if pose:IsA("Pose") then
pose.CFrame = CFrame.new()
-- đệ quy
resetPoses(pose)
end
end
endRemoveSubPose
Tham Số
Lợi Nhuận
()
Mẫu mã
Thêm/Bỏ tư thế Keyframe
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local pose = Instance.new("Pose")
pose.EasingStyle = Enum.PoseEasingStyle.Cubic
pose.EasingDirection = Enum.PoseEasingDirection.Out
local pose2 = Instance.new("Pose")
pose2.EasingStyle = Enum.PoseEasingStyle.Cubic
pose2.EasingDirection = Enum.PoseEasingDirection.Out
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
keyframe:RemovePose(pose) -- pose.Parent = nil
task.wait(2)
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
pose:AddSubPose(pose2) -- pose2.Parent = pose
task.wait(2)
pose:RemoveSubPose(pose2) -- pose2.Parent = nil