• JSBinding / Code Snippets


    new a gameobject & overloaded methds

    var go1 = new UnityEngine.GameObject.ctor();
    var go2 = new UnityEngine.GameObject.ctor$$String("Hello");

     

    add/get c# component

    var trans = go.GddComponent$1(UnityEngine.Transform.ctor);
    var image = go.AddComponent$1(UnityEngine.UI.Image.ctor);
    image.set_color(new UnityEngine.Color.ctor$$Single$$Single$$Single(125/255, 78/255, 3/255));

     

     

    add/get javascript component

    // a javascript monobehaviour
    jss.define_mb("Dog", function () {
        this.Eat = function () {
            print("EAT!");
        }
    });
    
    // some function
    function fun(goDog) {
        goDog.AddComponent$1(jss.Dog);
        var dog = goDog.GetComponent$1(jss.Dog);
        dog.Eat();
    }

     

    define a javascript monobehaviour

    jss.define_mb("UIController", function () {
    
        // UnityEngine.Object
        // add this variable to Unity Inspector and drag something to it
        this.oTileRoot = null;
        
        this.oScore = null;
        this.oBestScore = null;
    
        // auto called from c#
        this.Start = function () {
        }
    
        // auto called from c#
        this.Update = function () {
        }
    });

     

    static methods & enum

    if (UnityEngine.Input.GetKeyDown$$KeyCode(UnityEngine.KeyCode.UpArrow)) {
        inputMgr.emit("move", 0);
        break;
    }

     

    properties (get_, set_)

    var e = this.animator.get_enabled();
    this.animator.set_enabled(!e);
    var pos = this.trans.get_position();
    other.trans.set_position(pos);

     

    ref/out

    var $cv = { Value: UnityEngine.Vector3.get_zero() };
    var newPos = UnityEngine.Vector3.SmoothDamp$$Vector3$$Vector3$$Vector3$$Single(
        this.trans.get_position(),
        this.toPos,
        $cv,
        0.07);
    
    print("new pos: " + $cv.Value);

     

    delegates & properties & overloaded functions

    btn.get_onClick().RemoveAllListeners();
    btn.get_onClick().AddListener$$UnityAction(function () {
        print("button clicked!");
    });

     

    Coroutine

    jss.define_mb("CorutineTest", function() {
    
        // called from c#
        this.Start = function () {
            this.StartCoroutine$$IEnumerator(this.SayHello());
        }
    
        // notice syntax here!
        this.SayHello = function*() {
            var i = 10;
    
            while (i > 0) {
                print("hello jsb " + i);
                i--;
                yield new UE.WaitForSeconds.ctor(1);
            }
        }
    
        this.Update = function () {
            var elapsed = UE.Time.get_deltaTime();
            
            // update coroutines and invokes manually!
            this.$UpdateAllCoroutines(elapsed);
            this.$UpdateAllInvokes(elapsed);
        }
    }

     

     

    back to JSBinding / Home

  • 相关阅读:
    android中获取某段程序的执行时间
    图像位宽对齐
    使用 ssh 连接github的方法说明(gitub的官方说法)
    转:程序员必须知道的几个Git代码托管平台
    转:webRTC的前世今生
    Eclipse c++头文件问题(未完)
    [原创] NetBean开发c++程序指南1- 加入c++项目文件夹
    xshell5 启动显示 mfc110.dll msvcp110.dll 未找到问题 解决办法
    vmware12安装vmtools
    转: EclipseIDE开发 for C++
  • 原文地址:https://www.cnblogs.com/answerwinner/p/5644493.html
Copyright © 2020-2023  润新知