オブジェクトを順番に表示するボタンを作成する方法はありますか。

質問:

1 度に 1 つのオブジェクトだけを表示し、他のオブジェクトはすべて非表示にするボタンを作成したいと考えています。ボタンを押すごとに、シーン オブジェクトを巡回し、次のオブジェクトを表示させる必要があります。

回答:

次に解決方法を示します。

スクリプト:

    macroScript showNext category: "MXS Help"
    (
      local current_object = 0 --this is local to the macroScript
      on execute do
      (
        allObjects = objects as array --collect all objects
        hide $* --hide all objects
        current_object += 1 --increment the counter
        if current_object > allObjects.count do --loop if necessary
          current_object = 1
        if allObjects.count > 0 do --if anything in the scene...
          unhide allObjects[current_object]
        -- then unhide the current object
      )
    )

次のスクリプトも同じですが、アルファベット順にオブジェクトを表示するように変更されています。

スクリプト:

    macroScript showNextABC category:"MXS Help"
    (
      local current_object = 0 --this is local to the macroScript
      on execute do
      (
        -- collect all names and sort them:
        allObjectNames = sort( for i in objects collect i.name )
        hide $* --hide all objects
        current_object += 1 --increment counter
        if current_object > allObjectNames.count do --loop if necessary
          current_object = 1
        if allObjectNames.count > 0 do --if anything in the scene...
          unhide getNodeByName allObjectNames[current_object]
        -- then get the object by name and unhide it
      )
    )