2
0

39_CrowdNavigation.as 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. // Navigation example.
  2. // This sample demonstrates:
  3. // - Generating a navigation mesh into the scene
  4. // - Performing path queries to the navigation mesh
  5. // - Rebuilding the navigation mesh partially when adding or removing objects
  6. // - Visualizing custom debug geometry
  7. // - Raycasting drawable components
  8. // - Making a node follow the Detour path
  9. #include "Scripts/Utilities/Sample.as"
  10. Vector3 endPos;
  11. Array<Vector3> currentPath;
  12. Array<Node@> jackNodes;
  13. Array<Node@> mushroomNodes;
  14. void Start()
  15. {
  16. // Execute the common startup for samples
  17. SampleStart();
  18. // Create the scene content
  19. CreateScene();
  20. // Create the UI content
  21. CreateUI();
  22. // Setup the viewport for displaying the scene
  23. SetupViewport();
  24. // Hook up to the frame update and render post-update events
  25. SubscribeToEvents();
  26. }
  27. void CreateScene()
  28. {
  29. scene_ = Scene();
  30. // Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
  31. // Also create a DebugRenderer component so that we can draw debug geometry
  32. scene_.CreateComponent("Octree");
  33. scene_.CreateComponent("DebugRenderer");
  34. // Create scene node & StaticModel component for showing a static plane
  35. Node@ planeNode = scene_.CreateChild("Plane");
  36. planeNode.scale = Vector3(100.0f, 1.0f, 100.0f);
  37. StaticModel@ planeObject = planeNode.CreateComponent("StaticModel");
  38. planeObject.model = cache.GetResource("Model", "Models/Plane.mdl");
  39. planeObject.material = cache.GetResource("Material", "Materials/StoneTiled.xml");
  40. // Create a Zone component for ambient lighting & fog control
  41. Node@ zoneNode = scene_.CreateChild("Zone");
  42. Zone@ zone = zoneNode.CreateComponent("Zone");
  43. zone.boundingBox = BoundingBox(-1000.0f, 1000.0f);
  44. zone.ambientColor = Color(0.15f, 0.15f, 0.15f);
  45. zone.fogColor = Color(0.5f, 0.5f, 0.7f);
  46. zone.fogStart = 100.0f;
  47. zone.fogEnd = 300.0f;
  48. // Create a directional light to the world. Enable cascaded shadows on it
  49. Node@ lightNode = scene_.CreateChild("DirectionalLight");
  50. lightNode.direction = Vector3(0.6f, -1.0f, 0.8f);
  51. Light@ light = lightNode.CreateComponent("Light");
  52. light.lightType = LIGHT_DIRECTIONAL;
  53. light.castShadows = true;
  54. light.shadowBias = BiasParameters(0.00025f, 0.5f);
  55. // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
  56. light.shadowCascade = CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f);
  57. // Create randomly sized boxes. If boxes are big enough, make them occluders. Occluders will be software rasterized before
  58. // rendering to a low-resolution depth-only buffer to test the objects in the view frustum for visibility
  59. const uint NUM_BOXES = 20;
  60. for (uint i = 0; i < NUM_BOXES; ++i)
  61. {
  62. Node@ boxNode = scene_.CreateChild("Box");
  63. float size = 1.0f + Random(10.0f);
  64. boxNode.position = Vector3(Random(80.0f) - 40.0f, size * 0.5f, Random(80.0f) - 40.0f);
  65. boxNode.SetScale(size);
  66. StaticModel@ boxObject = boxNode.CreateComponent("StaticModel");
  67. boxObject.model = cache.GetResource("Model", "Models/Box.mdl");
  68. boxObject.material = cache.GetResource("Material", "Materials/Stone.xml");
  69. boxObject.castShadows = true;
  70. //if (size >= 3.0f)
  71. // boxObject.occluder = true;
  72. }
  73. // Create a DynamicNavigationMesh component to the scene root
  74. DynamicNavigationMesh@ navMesh = scene_.CreateComponent("DynamicNavigationMesh");
  75. // Set the agent height large enough to exclude the layers under boxes
  76. navMesh.agentHeight = 10;
  77. navMesh.tileSize = 64;
  78. // Create a Navigable component to the scene root. This tags all of the geometry in the scene as being part of the
  79. // navigation mesh. By default this is recursive, but the recursion could be turned off from Navigable
  80. scene_.CreateComponent("Navigable");
  81. // Add padding to the navigation mesh in Y-direction so that we can add objects on top of the tallest boxes
  82. // in the scene and still update the mesh correctly
  83. navMesh.padding = Vector3(0.0f, 10.0f, 0.0f);
  84. // Now build the navigation geometry. This will take some time. Note that the navigation mesh will prefer to use
  85. // physics geometry from the scene nodes, as it often is simpler, but if it can not find any (like in this example)
  86. // it will use renderable geometry instead
  87. navMesh.Build();
  88. // Create a detour crowd manager component
  89. DetourCrowdManager@ crowdManager = scene_.CreateComponent("DetourCrowdManager");
  90. //crowdManager.navMesh = navMesh;
  91. //crowdManager.CreateCrowd();
  92. // Create Jack node that will follow the path
  93. Node@ jackNode = SpawnJack(Vector3(-5.0f, 0, -20.0f));
  94. // Because the navigation mesh is a cache the mushrooms can be created after building
  95. // Create some mushrooms
  96. const uint NUM_MUSHROOMS = 100;
  97. for (uint i = 0; i < NUM_MUSHROOMS; ++i)
  98. CreateMushroom(Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f));
  99. //navMesh.ForceUpdate();
  100. // Create the camera. Limit far clip distance to match the fog
  101. cameraNode = scene_.CreateChild("Camera");
  102. Camera@ camera = cameraNode.CreateComponent("Camera");
  103. camera.farClip = 300.0f;
  104. // Set an initial position for the camera scene node above the plane
  105. cameraNode.position = Vector3(0.0f, 5.0f, 0.0f);
  106. }
  107. void CreateUI()
  108. {
  109. // Create a Cursor UI element because we want to be able to hide and show it at will. When hidden, the mouse cursor will
  110. // control the camera, and when visible, it will point the raycast target
  111. XMLFile@ style = cache.GetResource("XMLFile", "UI/DefaultStyle.xml");
  112. Cursor@ cursor = Cursor();
  113. cursor.SetStyleAuto(style);
  114. ui.cursor = cursor;
  115. // Set starting position of the cursor at the rendering window center
  116. cursor.SetPosition(graphics.width / 2, graphics.height / 2);
  117. // Construct new Text object, set string to display and font to use
  118. Text@ instructionText = ui.root.CreateChild("Text");
  119. instructionText.text =
  120. "Use WASD keys to move, RMB to rotate view\n"
  121. "LMB to set destination, SHIFT+LMB to spawn a Jack\n"
  122. "MMB to add or remove obstacles\n"
  123. "F5 To Save The Scene, F7 to Reload the Scene\n"
  124. "Space to toggle debug geometry";
  125. instructionText.SetFont(cache.GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15);
  126. // The text has multiple rows. Center them in relation to each other
  127. instructionText.textAlignment = HA_CENTER;
  128. // Position the text relative to the screen center
  129. instructionText.horizontalAlignment = HA_CENTER;
  130. instructionText.verticalAlignment = VA_CENTER;
  131. instructionText.SetPosition(0, ui.root.height / 4);
  132. }
  133. void SetupViewport()
  134. {
  135. // Set up a viewport to the Renderer subsystem so that the 3D scene can be seen
  136. Viewport@ viewport = Viewport(scene_, cameraNode.GetComponent("Camera"));
  137. renderer.viewports[0] = viewport;
  138. }
  139. void SubscribeToEvents()
  140. {
  141. // Subscribe HandleUpdate() function for processing update events
  142. SubscribeToEvent("Update", "HandleUpdate");
  143. // Subscribe HandlePostRenderUpdate() function for processing the post-render update event, during which we request
  144. // debug geometry
  145. SubscribeToEvent("PostRenderUpdate", "HandlePostRenderUpdate");
  146. // Subscribe HandleCrowdAgentFailure() function for resolving invalidation issues with agents, during which we
  147. // use a larger extents for finding a point on the navmesh to fix the agent's position
  148. SubscribeToEvent("CrowdAgentFailure", "HandleCrowdAgentFailure");
  149. }
  150. void MoveCamera(float timeStep)
  151. {
  152. // Right mouse button controls mouse cursor visibility: hide when pressed
  153. ui.cursor.visible = !input.mouseButtonDown[MOUSEB_RIGHT];
  154. // Do not move if the UI has a focused element (the console)
  155. if (ui.focusElement !is null)
  156. return;
  157. // Movement speed as world units per second
  158. const float MOVE_SPEED = 20.0f;
  159. // Mouse sensitivity as degrees per pixel
  160. const float MOUSE_SENSITIVITY = 0.1f;
  161. // Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the pitch between -90 and 90 degrees
  162. // Only move the camera when the cursor is hidden
  163. if (!ui.cursor.visible)
  164. {
  165. IntVector2 mouseMove = input.mouseMove;
  166. yaw += MOUSE_SENSITIVITY * mouseMove.x;
  167. pitch += MOUSE_SENSITIVITY * mouseMove.y;
  168. pitch = Clamp(pitch, -90.0f, 90.0f);
  169. // Construct new orientation for the camera scene node from yaw and pitch. Roll is fixed to zero
  170. cameraNode.rotation = Quaternion(pitch, yaw, 0.0f);
  171. }
  172. // Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
  173. if (input.keyDown['W'])
  174. cameraNode.Translate(Vector3(0.0f, 0.0f, 1.0f) * MOVE_SPEED * timeStep);
  175. if (input.keyDown['S'])
  176. cameraNode.Translate(Vector3(0.0f, 0.0f, -1.0f) * MOVE_SPEED * timeStep);
  177. if (input.keyDown['A'])
  178. cameraNode.Translate(Vector3(-1.0f, 0.0f, 0.0f) * MOVE_SPEED * timeStep);
  179. if (input.keyDown['D'])
  180. cameraNode.Translate(Vector3(1.0f, 0.0f, 0.0f) * MOVE_SPEED * timeStep);
  181. // Set destination or spawn a jack with left mouse button
  182. if (input.mouseButtonPress[MOUSEB_LEFT])
  183. SetPathPoint();
  184. // Add or remove objects with middle mouse button, then rebuild navigation mesh partially
  185. if (input.mouseButtonPress[MOUSEB_MIDDLE])
  186. AddOrRemoveObject();
  187. // Toggle debug geometry with space
  188. if (input.keyPress[KEY_SPACE])
  189. drawDebug = !drawDebug;
  190. }
  191. void SetPathPoint()
  192. {
  193. Vector3 hitPos;
  194. Drawable@ hitDrawable;
  195. DynamicNavigationMesh@ navMesh = scene_.GetComponent("DynamicNavigationMesh");
  196. if (Raycast(250.0f, hitPos, hitDrawable))
  197. {
  198. Vector3 pathPos = navMesh.FindNearestPoint(hitPos, Vector3(1.0f, 1.0f, 1.0f));
  199. if (input.qualifierDown[QUAL_SHIFT])
  200. {
  201. // Spawn a jack
  202. SpawnJack(pathPos);
  203. }
  204. else
  205. {
  206. // Calculate path from Jack's current position to the end point
  207. endPos = pathPos;
  208. for (uint i = 0; i < jackNodes.length; ++i)
  209. {
  210. CrowdAgent@ agent = jackNodes[i].GetComponent("CrowdAgent");
  211. agent.enabled = true;
  212. if (i == 0)
  213. {
  214. // The first agent will always move to the exact target
  215. agent.SetMoveTarget(endPos);
  216. }
  217. else
  218. {
  219. // Keep the random point on the navigation mesh
  220. Vector3 targetPos = navMesh.FindNearestPoint(endPos + Vector3(Random(-4.5f,4.5f), 0.0f, Random(-4.5, 4.5f)), Vector3(1.0f, 1.0f, 1.0f));
  221. agent.SetMoveTarget(targetPos);
  222. }
  223. }
  224. }
  225. }
  226. }
  227. void AddOrRemoveObject()
  228. {
  229. // Raycast and check if we hit a mushroom node. If yes, remove it, if no, create a new one
  230. Vector3 hitPos;
  231. Drawable@ hitDrawable;
  232. if (Raycast(250.0f, hitPos, hitDrawable))
  233. {
  234. // The part of the navigation mesh we must update, which is the world bounding box of the associated
  235. // drawable component
  236. BoundingBox updateBox;
  237. Node@ hitNode = hitDrawable.node;
  238. if (hitNode.name == "Mushroom")
  239. {
  240. updateBox = hitDrawable.worldBoundingBox;
  241. hitNode.Remove();
  242. mushroomNodes.Erase(mushroomNodes.FindByRef(hitNode));
  243. }
  244. else
  245. {
  246. Node@ newNode = CreateMushroom(hitPos);
  247. StaticModel@ newObject = newNode.GetComponent("StaticModel");
  248. updateBox = newObject.worldBoundingBox;
  249. }
  250. }
  251. }
  252. Node@ CreateMushroom(const Vector3& pos)
  253. {
  254. Node@ mushroomNode = scene_.CreateChild("Mushroom");
  255. mushroomNode.position = pos;
  256. mushroomNode.rotation = Quaternion(0.0f, Random(360.0f), 0.0f);
  257. mushroomNode.SetScale(2.0f + Random(0.5f));
  258. StaticModel@ mushroomObject = mushroomNode.CreateComponent("StaticModel");
  259. mushroomObject.model = cache.GetResource("Model", "Models/Mushroom.mdl");
  260. mushroomObject.material = cache.GetResource("Material", "Materials/Mushroom.xml");
  261. mushroomObject.castShadows = true;
  262. Obstacle@ obstacleObject = mushroomNode.CreateComponent("Obstacle");
  263. obstacleObject.radius = mushroomNode.scale.x;
  264. mushroomNodes.Push(mushroomNode);
  265. return mushroomNode;
  266. }
  267. Node@ SpawnJack(const Vector3& pos)
  268. {
  269. Node@ jackNode = scene_.CreateChild("Jack");
  270. jackNodes.Push(jackNode);
  271. jackNode.position = pos;
  272. AnimatedModel@ modelObject = jackNode.CreateComponent("AnimatedModel");
  273. modelObject.model = cache.GetResource("Model", "Models/Jack.mdl");
  274. modelObject.material = cache.GetResource("Material", "Materials/Jack.xml");
  275. modelObject.castShadows = true;
  276. CrowdAgent@ navAgent = jackNode.CreateComponent("CrowdAgent");
  277. navAgent.height = 2.0f;
  278. navAgent.enabled = false;
  279. return jackNode;
  280. }
  281. bool Raycast(float maxDistance, Vector3& hitPos, Drawable@& hitDrawable)
  282. {
  283. hitDrawable = null;
  284. IntVector2 pos = ui.cursorPosition;
  285. // Check the cursor is visible and there is no UI element in front of the cursor
  286. if (!ui.cursor.visible || ui.GetElementAt(pos, true) !is null)
  287. return false;
  288. Camera@ camera = cameraNode.GetComponent("Camera");
  289. Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
  290. // Pick only geometry objects, not eg. zones or lights, only get the first (closest) hit
  291. // Note the convenience accessor to scene's Octree component
  292. RayQueryResult result = scene_.octree.RaycastSingle(cameraRay, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY);
  293. if (result.drawable !is null)
  294. {
  295. hitPos = result.position;
  296. hitDrawable = result.drawable;
  297. return true;
  298. }
  299. return false;
  300. }
  301. void HandleUpdate(StringHash eventType, VariantMap& eventData)
  302. {
  303. // Take the frame time step, which is stored as a float
  304. float timeStep = eventData["TimeStep"].GetFloat();
  305. // Move the camera, scale movement with time step
  306. MoveCamera(timeStep);
  307. // Make the CrowdAgents face the direction of their velocity
  308. for (uint i = 0; i < jackNodes.length; ++i)
  309. {
  310. CrowdAgent@ agent = jackNodes[i].GetComponent("CrowdAgent");
  311. jackNodes[i].worldDirection = agent.actualVelocity;
  312. }
  313. if (input.keyPress[KEY_F5])
  314. {
  315. File saveFile(fileSystem.programDir + "Data/Scenes/CrowdDemo.xml", FILE_WRITE);
  316. scene_.SaveXML(saveFile);
  317. }
  318. if (input.keyPress[KEY_F7])
  319. {
  320. File loadFile(fileSystem.programDir + "Data/Scenes/CrowdDemo.xml", FILE_READ);
  321. scene_.LoadXML(loadFile);
  322. // After loading we have to reacquire the character scene node, as it has been recreated
  323. // Simply find by name as there's only one of them
  324. jackNodes.Clear();
  325. Array<Node@> jacks = scene_.GetChildrenWithComponent("CrowdAgent", true);
  326. for (uint i = 0; i < jacks.length; ++i)
  327. {
  328. jackNodes.Push(jacks[i]);
  329. }
  330. mushroomNodes.Clear();
  331. Array<Node@> mushrooms = scene_.GetChildrenWithComponent("Obstacle", true);
  332. for (uint i = 0; i < mushrooms.length; ++i)
  333. {
  334. mushroomNodes.Push(mushrooms[i]);
  335. }
  336. }
  337. }
  338. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
  339. {
  340. // If draw debug mode is enabled, draw navigation mesh debug geometry
  341. if (drawDebug)
  342. {
  343. DynamicNavigationMesh@ navMesh = scene_.GetComponent("DynamicNavigationMesh");
  344. navMesh.DrawDebugGeometry(true);
  345. for (uint i = 0; i < jackNodes.length; ++i)
  346. {
  347. CrowdAgent@ agent = jackNodes[i].GetComponent("CrowdAgent");
  348. agent.DrawDebugGeometry(true);
  349. }
  350. for (uint i = 0; i < mushroomNodes.length; ++i)
  351. {
  352. Obstacle@ obstacle = mushroomNodes[i].GetComponent("Obstacle");
  353. obstacle.DrawDebugGeometry(true);
  354. }
  355. }
  356. }
  357. void HandleCrowdAgentFailure(StringHash eventType, VariantMap& eventData)
  358. {
  359. Node@ node = eventData["Node"].GetPtr();
  360. int state = eventData["CrowdAgentState"].GetInt();
  361. // If the agent's state is invalid, likely from spawning on the side of a box, find a point in a larger area
  362. if (state == CrowdAgentState::CROWD_AGENT_INVALID)
  363. {
  364. DynamicNavigationMesh@ navMesh = scene_.GetComponent("DynamicNavigationMesh");
  365. // Get a point on the navmesh using more generous extents
  366. Vector3 newPos = navMesh.FindNearestPoint(node.position, Vector3(5.0f,5.0f,5.0f));
  367. // Set the new node position, CrowdAgent component will automatically reset the state of the agent
  368. node.position = newPos;
  369. }
  370. }
  371. // Create XML patch instructions for screen joystick layout specific to this sample app
  372. String patchInstructions =
  373. "<patch>" +
  374. " <add sel=\"/element\">" +
  375. " <element type=\"Button\">" +
  376. " <attribute name=\"Name\" value=\"Button3\" />" +
  377. " <attribute name=\"Position\" value=\"-120 -120\" />" +
  378. " <attribute name=\"Size\" value=\"96 96\" />" +
  379. " <attribute name=\"Horiz Alignment\" value=\"Right\" />" +
  380. " <attribute name=\"Vert Alignment\" value=\"Bottom\" />" +
  381. " <attribute name=\"Texture\" value=\"Texture2D;Textures/TouchInput.png\" />" +
  382. " <attribute name=\"Image Rect\" value=\"96 0 192 96\" />" +
  383. " <attribute name=\"Hover Image Offset\" value=\"0 0\" />" +
  384. " <attribute name=\"Pressed Image Offset\" value=\"0 0\" />" +
  385. " <element type=\"Text\">" +
  386. " <attribute name=\"Name\" value=\"Label\" />" +
  387. " <attribute name=\"Horiz Alignment\" value=\"Center\" />" +
  388. " <attribute name=\"Vert Alignment\" value=\"Center\" />" +
  389. " <attribute name=\"Color\" value=\"0 0 0 1\" />" +
  390. " <attribute name=\"Text\" value=\"Spawn A jack\" />" +
  391. " </element>" +
  392. " <element type=\"Text\">" +
  393. " <attribute name=\"Name\" value=\"KeyBinding\" />" +
  394. " <attribute name=\"Text\" value=\"LSHIFT\" />" +
  395. " </element>" +
  396. " <element type=\"Text\">" +
  397. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />" +
  398. " <attribute name=\"Text\" value=\"LEFT\" />" +
  399. " </element>" +
  400. " </element>" +
  401. " <element type=\"Button\">" +
  402. " <attribute name=\"Name\" value=\"Button4\" />" +
  403. " <attribute name=\"Position\" value=\"-120 -12\" />" +
  404. " <attribute name=\"Size\" value=\"96 96\" />" +
  405. " <attribute name=\"Horiz Alignment\" value=\"Right\" />" +
  406. " <attribute name=\"Vert Alignment\" value=\"Bottom\" />" +
  407. " <attribute name=\"Texture\" value=\"Texture2D;Textures/TouchInput.png\" />" +
  408. " <attribute name=\"Image Rect\" value=\"96 0 192 96\" />" +
  409. " <attribute name=\"Hover Image Offset\" value=\"0 0\" />" +
  410. " <attribute name=\"Pressed Image Offset\" value=\"0 0\" />" +
  411. " <element type=\"Text\">" +
  412. " <attribute name=\"Name\" value=\"Label\" />" +
  413. " <attribute name=\"Horiz Alignment\" value=\"Center\" />" +
  414. " <attribute name=\"Vert Alignment\" value=\"Center\" />" +
  415. " <attribute name=\"Color\" value=\"0 0 0 1\" />" +
  416. " <attribute name=\"Text\" value=\"Obstacles\" />" +
  417. " </element>" +
  418. " <element type=\"Text\">" +
  419. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />" +
  420. " <attribute name=\"Text\" value=\"MIDDLE\" />" +
  421. " </element>" +
  422. " </element>" +
  423. " </add>" +
  424. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />" +
  425. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Set</replace>" +
  426. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">" +
  427. " <element type=\"Text\">" +
  428. " <attribute name=\"Name\" value=\"MouseButtonBinding\" />" +
  429. " <attribute name=\"Text\" value=\"LEFT\" />" +
  430. " </element>" +
  431. " </add>" +
  432. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />" +
  433. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Debug</replace>" +
  434. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">" +
  435. " <element type=\"Text\">" +
  436. " <attribute name=\"Name\" value=\"KeyBinding\" />" +
  437. " <attribute name=\"Text\" value=\"SPACE\" />" +
  438. " </element>" +
  439. " </add>" +
  440. "</patch>";