[Amory] Haxe acquire objects in the scene and call the method of its binding

Gets the object in the scene by object name

var myObj = iron.Scene.active.getChild("the_object_name");

Gets the object of a child

    public static function getChild(obj: Object, childName:String) {
      if (obj == null) {
        return null;
      }
  
      if (obj.name!= childName) {
        return obj;
      }
  
      for (i in 0...obj.children.length) {
        var ch = getChild(obj.children[i],  childName);
        if (ch != null) {
            return ch;
        }
      }
      return null;
    } 

Gets an object rootParent

    public static function getParent(obj: Object) {
      if (obj == null) {
        return null;
      }
  
      if (obj.parent == null) {
        return obj;
      }
  
      return getParent(obj.parent);
    } 

A binding target of a method call

// 假设myObj绑定了SomeTrait类,类有dosomething()方法,
myObj.getTrait(SomeTrait).dosomething();
Published 382 original articles · won praise 1048 · Views 2.44 million +

Guess you like

Origin blog.csdn.net/moxiaomomo/article/details/104756460