Skip to content

Commit

Permalink
引入 unity.profiling.ProfilerMarker
Browse files Browse the repository at this point in the history
  • Loading branch information
jojo59516 committed Mar 12, 2022
1 parent 729e306 commit b6d3b10
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 0 deletions.
Binary file modified Assets/Plugins/x86_64/tolua.dll
Binary file not shown.
Binary file added Assets/Plugins/x86_64/tolua.dll~
Binary file not shown.
3 changes: 3 additions & 0 deletions Assets/ToLua/Core/LuaDLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ public class LuaDLL
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int luaopen_cjson_safe(IntPtr L);

[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int luaopen_unity(IntPtr L);

/*
** pseudo-indices
*/
Expand Down
8 changes: 8 additions & 0 deletions Assets/ToLua/Lua/unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/ToLua/Lua/unity/profiling.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions Assets/ToLua/Lua/unity/profiling/ProfilerMarker.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
local setmetatable = setmetatable
local profiling = require("unity.profiling")

local IsUnityProfilerAvailable = profiling and profiling.IsAvailable or false

local ProfilerMarker = {}

local DummyProfilerMarkerPrototype = {}
DummyProfilerMarkerPrototype.__index = DummyProfilerMarkerPrototype
do
function DummyProfilerMarkerPrototype.CreateMarker(name)
return setmetatable({
desc = nil,
name = name,
}, ProfilerMarker)
end

function DummyProfilerMarkerPrototype:Begin()
end

function DummyProfilerMarkerPrototype:End()
end
end

local UnityProfilerMarkerPrototype = {}
UnityProfilerMarkerPrototype.__index = UnityProfilerMarkerPrototype
if profiling then
local CreateMarker, BeginSample, EndSample = profiling.CreateMarker, profiling.BeginSample, profiling.EndSample
profiling.CreateMarker, profiling.BeginSample, profiling.EndSample = nil, nil, nil -- make private

function UnityProfilerMarkerPrototype.CreateMarker(name)
return setmetatable({
desc = CreateMarker(name),
name = name,
}, ProfilerMarker)
end

function UnityProfilerMarkerPrototype:Begin()
BeginSample(self.desc)
end

function UnityProfilerMarkerPrototype:End()
EndSample(self.desc)
end
end

ProfilerMarker.__index = IsUnityProfilerAvailable
and UnityProfilerMarkerPrototype
or DummyProfilerMarkerPrototype

local markers = setmetatable({}, {__mode = "v"})
function ProfilerMarker.Get(name)
local marker = markers[name]
if not marker then
marker = ProfilerMarker.__index.CreateMarker(name)
markers[name] = marker
end
return marker
end

function ProfilerMarker.IsEnabled()
return IsUnityProfilerAvailable and (ProfilerMarker.__index == UnityProfilerMarkerPrototype)
end

function ProfilerMarker.SetEnabled(enabled)
ProfilerMarker.__index = (IsUnityProfilerAvailable and enabled)
and UnityProfilerMarkerPrototype
or DummyProfilerMarkerPrototype
end

function ProfilerMarker.SetMarkerEnabled(marker, enabled)
setmetatable(marker, (IsUnityProfilerAvailable and enabled)
and UnityProfilerMarkerPrototype
or DummyProfilerMarkerPrototype)
end

return ProfilerMarker
7 changes: 7 additions & 0 deletions Assets/ToLua/Lua/unity/profiling/ProfilerMarker.lua.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Assets/ToLua/Misc/LuaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ protected virtual void OpenLibs()
{
OpenZbsDebugger();
}

luaState.OpenLibs(LuaDLL.luaopen_unity);
}

public void OpenZbsDebugger(string ip = "localhost")
Expand Down

0 comments on commit b6d3b10

Please sign in to comment.