美文网首页我爱编程
Level Object Placement Limitatio

Level Object Placement Limitatio

作者: Bonging | 来源:发表于2018-04-08 10:16 被阅读0次

    Level Object Placement Limitation

    概要

    可以限制放置物体的区域。也可以设置其他标准​​,而不仅仅是位置。例如,可以防止房屋建在陡峭的地形上。要限制对象放置,您需要注册对象编辑器的on drag事件。当某个对象被拖到关卡中的某个对象上时,该事件将在每帧触发。测试当前位置是否匹配定义的标准应在事件处理程序实现中执行。如果位置不合适,您可以选择向用户显示一条解释性信息,该消息将显示在对象图标旁边。

    第1步:事件注册

    注册“ LE_EventInterface.OnObjectDragged ”事件。这个事件将在用户尝试通过拖动放置一个对象到正确的位置的每一帧中执行。请记住,当脚本被销毁时,您也应该注销事件,否则可能会发生内存泄漏。

    using LE_LevelEditor.Events;

    // Register for the load event, which is called when the level is loaded

    LE_EventInterface.OnObjectDragged += OnObjectDragged;

    第2步:事件处理

    下面的事件处理程序将检查当前位置是否适合要放置的对象。如果不适合,p_args.IsObjectPlaceable属性将被设置为false。可以向玩家显示信息,以便使他知道为什么该物体不能放置在特定位置。

    private void OnObjectDragged(object p_sender, LE_ObjectDragEvent p_args)

    {

        // in this example we will check if the cursor position (the place where the object will be placed)

        // is too far away from the center of the level (outside a square with side length 200)

        // you can replace this with the check that you need to perform

        // take a look at the other members of LE_ObjectDragEvent

        // for example the object prefab is also passed within the event args

        if (Mathf.Abs(p_args.CursorHitInfo.point.x) > 100 ||

            Mathf.Abs(p_args.CursorHitInfo.point.z) > 100)

        {

          // tell the level editor that this object cannot be placed at the current cursor position

          p_args.IsObjectPlaceable = false;

          // check if there is already a message that will be shown to the player

          // this can be the case if some other listener of this event has added a message

          // or if the instance count of this objects has reached its maximum

          if (p_args.Message.Length > 0)

          {

              // add a line break if the message is not empty

              p_args.Message += "\n";

          }

          // add your message here in this example the object is simply out of bounds

          p_args.Message += "Object is out of bounds!";

        }

    };

    原文链接:http://www.freebord-game.com/index.php/multiplatform-runtime-level-editor/documentation/level-object-placement-limitation

    相关文章

      网友评论

        本文标题:Level Object Placement Limitatio

        本文链接:https://www.haomeiwen.com/subject/nrlphftx.html