瀏覽代碼

Use node instead of GetNode() in lua samples
Also simplified sample 15 for lua

Mike3D 10 年之前
父節點
當前提交
3fbb34f406

+ 1 - 1
bin/Data/LuaScripts/06_SkeletalAnimation.lua

@@ -201,7 +201,7 @@ function Mover:SetParameters(moveSpeed, rotationSpeed, bounds)
 end
 end
 
 
 function Mover:Update(timeStep)
 function Mover:Update(timeStep)
-    local node = self:GetNode()
+    local node = self.node
     node:Translate(Vector3(0.0, 0.0, 1.0) * self.moveSpeed * timeStep)
     node:Translate(Vector3(0.0, 0.0, 1.0) * self.moveSpeed * timeStep)
 
 
     -- If in risk of going outside the plane, rotate the model right
     -- If in risk of going outside the plane, rotate the model right

+ 1 - 1
bin/Data/LuaScripts/08_Decals.lua

@@ -194,7 +194,7 @@ function PaintDecal()
     local hitPos, hitDrawable = Raycast(250.0)
     local hitPos, hitDrawable = Raycast(250.0)
     if hitDrawable ~= nil then
     if hitDrawable ~= nil then
         -- Check if target scene node already has a DecalSet component. If not, create now
         -- Check if target scene node already has a DecalSet component. If not, create now
-        local targetNode = hitDrawable:GetNode()
+        local targetNode = hitDrawable.node
         local decal = targetNode:GetComponent("DecalSet")
         local decal = targetNode:GetComponent("DecalSet")
         if decal == nil then
         if decal == nil then
             decal = targetNode:CreateComponent("DecalSet")
             decal = targetNode:CreateComponent("DecalSet")

+ 8 - 13
bin/Data/LuaScripts/15_Navigation.lua

@@ -210,9 +210,9 @@ function MoveCamera(timeStep)
 end
 end
 
 
 function SetPathPoint()
 function SetPathPoint()
-    local result, hitPos, hitDrawable = Raycast(250.0)
+    local hitPos, hitDrawable = Raycast(250.0)
     local navMesh = scene_:GetComponent("NavigationMesh")
     local navMesh = scene_:GetComponent("NavigationMesh")
-    if result then
+    if hitPos then
         local pathPos = navMesh:FindNearestPoint(hitPos, Vector3.ONE)
         local pathPos = navMesh:FindNearestPoint(hitPos, Vector3.ONE)
 
 
         if input:GetQualifierDown(QUAL_SHIFT) then
         if input:GetQualifierDown(QUAL_SHIFT) then
@@ -230,13 +230,13 @@ end
 
 
 function AddOrRemoveObject()
 function AddOrRemoveObject()
     -- Raycast and check if we hit a mushroom node. If yes, remove it, if no, create a new one
     -- Raycast and check if we hit a mushroom node. If yes, remove it, if no, create a new one
-    local result, hitPos, hitDrawable = Raycast(250.0)
-    if result then
+    local hitPos, hitDrawable = Raycast(250.0)
+    if hitDrawable then
         -- The part of the navigation mesh we must update, which is the world bounding box of the associated
         -- The part of the navigation mesh we must update, which is the world bounding box of the associated
         -- drawable component
         -- drawable component
         local updateBox = nil
         local updateBox = nil
 
 
-        local hitNode = hitDrawable:GetNode()
+        local hitNode = hitDrawable.node
         if hitNode.name == "Mushroom" then
         if hitNode.name == "Mushroom" then
             updateBox = hitDrawable.worldBoundingBox
             updateBox = hitDrawable.worldBoundingBox
             hitNode:Remove()
             hitNode:Remove()
@@ -268,13 +268,11 @@ function CreateMushroom(pos)
 end
 end
 
 
 function Raycast(maxDistance)
 function Raycast(maxDistance)
-    local hitPos = nil
-    local hitDrawable = nil
 
 
     local pos = ui.cursorPosition
     local pos = ui.cursorPosition
     -- Check the cursor is visible and there is no UI element in front of the cursor
     -- Check the cursor is visible and there is no UI element in front of the cursor
     if (not ui.cursor.visible) or (ui:GetElementAt(pos, true) ~= nil) then
     if (not ui.cursor.visible) or (ui:GetElementAt(pos, true) ~= nil) then
-        return false, nil, nil
+        return nil, nil
     end
     end
 
 
     local camera = cameraNode:GetComponent("Camera")
     local camera = cameraNode:GetComponent("Camera")
@@ -283,13 +281,10 @@ function Raycast(maxDistance)
     local octree = scene_:GetComponent("Octree")
     local octree = scene_:GetComponent("Octree")
     local result = octree:RaycastSingle(cameraRay, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY)
     local result = octree:RaycastSingle(cameraRay, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY)
     if result.drawable ~= nil then
     if result.drawable ~= nil then
-        -- Calculate hit position in world space
-        hitPos = cameraRay.origin + cameraRay.direction * result.distance
-        hitDrawable = result.drawable
-        return true, hitPos, hitDrawable
+        return result.position, result.drawable
     end
     end
 
 
-    return false, nil, nil
+    return nil, nil
 end
 end
 
 
 function HandleUpdate(eventType, eventData)
 function HandleUpdate(eventType, eventData)

+ 2 - 2
bin/Data/LuaScripts/32_Urho2DConstraints.lua

@@ -364,7 +364,7 @@ end
 function HandleMouseButtonDown(eventType, eventData)
 function HandleMouseButtonDown(eventType, eventData)
     local rigidBody = physicsWorld:GetRigidBody(input.mousePosition.x, input.mousePosition.y) -- Raycast for RigidBody2Ds to pick
     local rigidBody = physicsWorld:GetRigidBody(input.mousePosition.x, input.mousePosition.y) -- Raycast for RigidBody2Ds to pick
     if rigidBody ~= nil then
     if rigidBody ~= nil then
-        pickedNode = rigidBody:GetNode()
+        pickedNode = rigidBody.node
         local staticSprite = pickedNode:GetComponent("StaticSprite2D")
         local staticSprite = pickedNode:GetComponent("StaticSprite2D")
         staticSprite.color = Color(1, 0, 0, 1) -- Temporary modify color of the picked sprite
         staticSprite.color = Color(1, 0, 0, 1) -- Temporary modify color of the picked sprite
 
 
@@ -408,7 +408,7 @@ end
 function HandleTouchBegin3(eventType, eventData)
 function HandleTouchBegin3(eventType, eventData)
     local rigidBody = physicsWorld:GetRigidBody(eventData:GetInt("X"), eventData:GetInt("Y")) -- Raycast for RigidBody2Ds to pick
     local rigidBody = physicsWorld:GetRigidBody(eventData:GetInt("X"), eventData:GetInt("Y")) -- Raycast for RigidBody2Ds to pick
     if rigidBody ~= nil then
     if rigidBody ~= nil then
-        pickedNode = rigidBody:GetNode()
+        pickedNode = rigidBody.node
         local staticSprite = pickedNode:GetComponent("StaticSprite2D")
         local staticSprite = pickedNode:GetComponent("StaticSprite2D")
         staticSprite.color = Color(1, 0, 0, 1) -- Temporary modify color of the picked sprite
         staticSprite.color = Color(1, 0, 0, 1) -- Temporary modify color of the picked sprite
         local rigidBody = pickedNode:GetComponent("RigidBody2D")
         local rigidBody = pickedNode:GetComponent("RigidBody2D")

+ 2 - 2
bin/Data/LuaScripts/39_CrowdNavigation.lua

@@ -231,7 +231,7 @@ function AddOrRemoveObject()
     local hitPos, hitDrawable = Raycast(250.0)
     local hitPos, hitDrawable = Raycast(250.0)
     if hitDrawable then
     if hitDrawable then
 
 
-        local hitNode = hitDrawable:GetNode()
+        local hitNode = hitDrawable.node
         if hitNode.name == "Mushroom" then
         if hitNode.name == "Mushroom" then
             hitNode:Remove()
             hitNode:Remove()
         elseif hitNode.name == "Jack" then
         elseif hitNode.name == "Jack" then
@@ -345,7 +345,7 @@ function HandleUpdate(eventType, eventData)
     -- Make the CrowdAgents face the direction of their velocity
     -- Make the CrowdAgents face the direction of their velocity
     for i = 1, table.maxn(agents) do
     for i = 1, table.maxn(agents) do
         local agent = agents[i]
         local agent = agents[i]
-        agent:GetNode().worldDirection = agent.actualVelocity
+        agent.node.worldDirection = agent.actualVelocity
     end
     end
 end
 end