function OnAfterSceneLoaded(self)
-- 建立单一关键行为和触摸输入
Input:SetKeyAsSingleHit(Vision.KEY_SPACE)
Input:SetKeyAsSingleHit(Vision.KEY_O)
self.map = Input:CreateMap("TouchInput")
local width, height = Screen:GetViewportSize()
local hGrid = height * .15
self.map:MapTrigger("Paint", {0,0, width, height}, "CT_TOUCH_DOUBLE_TAP", { once = true })
self.map:MapTrigger("CurX", "MOUSE", "CT_MOUSE_ABS_DELTA_X", { sensitivity = 1.0f / Screen:GetDeviceDpi() } )
self.map:MapTrigger("CurY", "MOUSE", "CT_MOUSE_ABS_DELTA_Y", { sensitivity = 1.0f / Screen:GetDeviceDpi() } )
if (Application:GetPlatformName() == "ANDROID") or (Application:GetPlatformName() == "IOS") or (Application:GetPlatformName() == "TIZEN") then
self.icons = Game:CreateScreenMask(64, 64, "Samples\\Textures\\icons\\debug.tga")
self.icons:SetBlending(Vision.BLEND_ALPHA)
self.icons:SetTargetSize(hGrid, hGrid)
self.icons:SetPos(width - hGrid, 0)
self.map:MapTrigger("CurX", {0,0, width, height}, "CT_TOUCH_ABS_DELTA_X", { sensitivity = 3.0f / Screen:GetDeviceDpi() } )
self.map:MapTrigger("CurY", {0,0, width, height}, "CT_TOUCH_ABS_DELTA_Y", { sensitivity = 3.0f / Screen:GetDeviceDpi() } )
self.map:MapTrigger("Toggle_Debug", { width - hGrid, 0, width, hGrid }, "CT_TOUCH_ANY", {once = true})
end
-- 启用调试输出
-- 任何画或输出调用“调试”将被无效时禁用
Debug:Enable(true)
Debug:SetupLines(10,10)
-- 记住其他实体
-- (代替你可以附上一个Lua脚本这个实体了)
self.path = Game:GetPath("DemoPath")
Vision.Assert(self.path~=nil)
self.character = Game:GetEntity("DemoEntity")
Vision.Assert(self.character~=nil)
if Application:IsInEditor() and Application:GetEditorMode()~=Vision.EDITOR_PLAY then
Debug:PrintLine("Please use 'Play the Game' mode!")
self:SetThinkFunctionStatus(false)
elseif (Application:GetPlatformName() == "ANDROID") or (Application:GetPlatformName() == "IOS") or (Application:GetPlatformName() == "TIZEN") then
Debug:PrintLine("Use touch to move drop point, then double tap to place icon. Tap Debug Icon to Enable/Disable Debugging")
else
Debug:PrintLine("Use your mouse and press 'SPACE' or 'O'")
if not Application:IsInEditor() then
--固定摄像头的光标,否则现场观众将创建自己的鼠标相机
local cam = Game:GetCamera()
cam:SetPosition(0,-3750,2800)
cam:AttachToEntity(self, cam:GetPosition())
cam:LookAt(self:GetPosition())
end
end
end
function OnThink(self)
local pos = self:GetPosition()
-- 切换调试和渲染
if Input:IsKeyPressed(Vision.KEY_O) or self.map:GetTrigger("Toggle_Debug")>0 then
local status = not Debug:IsEnabled()
Debug:Enable(status)
end
-- 在地板上盖章 (direction 0,0,-1)
if Input:IsKeyPressed(Vision.KEY_SPACE) or self.map:GetTrigger("Paint")>0 then
local dir = Vision.hkvVec3(0,0,-1)
-- 你也可以使用blend_opaque,blend_additive或blend_multiply为混合模式
Debug.Draw:Wallmark(pos,dir, "Samples/Textures/havok_vision.tga", Vision.BLEND_ALPHA, 180, 90)
-- 注:已创建的wallmarks将保持即使调试禁用
end
-- 根据鼠标的位置改变光标对象的位置
local deltaX = self.map:GetTrigger("CurX")
local deltaY = self.map:GetTrigger("CurY")
self:IncPosition(deltaX*200, -deltaY*200, 0)
-- 做一些额外的调试输出
Debug:PrintAt(pos, "Cursor X: ".. pos.x .." Y: ".. pos.y)
-- 一些样品绘制接口:
local color = Vision.V_RGBA_GREEN
Debug.Draw:Line( Vision.hkvVec3(-1000,1000,0), Vision.hkvVec3(1000,-1000,0), color)
Debug.Draw:Line( Vision.hkvVec3(-1000,-1000,0), Vision.hkvVec3(1000,1000,0), color)
color = Vision.V_RGBA_RED
Debug.Draw:Box( Vision.hkvVec3(-1000,1000,0), 50, color)
Debug.Draw:Box( Vision.hkvVec3(1000,-1000,0), 50, color)
--画线
color = Vision.V_RGBA_BLUE
Debug.Draw:Path(self.path, color)
-- 画骨和OBB包围盒
color = Vision.V_RGBA_YELLOW
Debug.Draw:BoneBoundingBox(self.character, "skeleton1:Head", color)
Debug.Draw:OrientedBoundingBox(self.character, color)
-- 在一个特定的位置输出文本
if self.character ~= nil then
local warriorPos = self.character:GetPosition()
Debug:PrintAt(warriorPos, "I'm floating at " .. tostring(warriorPos))
end
--draw aabbox
Debug.Draw:BoundingBox(self)
-- 或者你也可以操纵包围盒在画:
--[[
local box = self:GetBoundingBox()
box.m_vMin = box.m_vMin * 3
box.m_vMax = box.m_vMax * 3
Debug.Draw:BoundingBox(box)
]]--
-- 或得到的角落
--[[
local corners = self:GetBoundingBox():GetCorners()
for i=1,#corners do
Debug.Draw:Box(corners[i], 30, Vision.V_RGBA_PURPLE)
end
]]--
end
function OnBeforeSceneUnloaded(self)
Input:DestroyMap(self.map)
self.map = nil
Game:DeleteAllUnrefScreenMasks()
end