/* * GameObject.AddComponent<T>() */ public static bool GameObject_AddComponentT1(JSVCall vc, int count) { help_getGoAndType(vc); if (typeInfo.IsCSMonoBehaviour) { Component com = go.AddComponent(type); JSMgr.datax.setObject((int)JSApi.SetType.Rval, com); } else { string jsComponentName = JSCache.GetMonoBehaviourJSComponentName(typeString); Type jsComponentType = typeof(JSComponent); if (string.IsNullOrEmpty(jsComponentName)) { Debug.LogWarning(string.Format("\"{0}\" has no JSComponent_XX. Use JSComponent instead.", typeString)); } else { jsComponentType = JSDataExchangeMgr.GetTypeByName(jsComponentName, jsComponentType); } JSComponent jsComp = (JSComponent)go.AddComponent(jsComponentType); jsComp.jsClassName = typeString; jsComp.jsFail = false; jsComp.init(true); jsComp.callAwake(); // Òªµ÷Óà js µÄ Awake //JSApi.JSh_SetRvalObject(vc.cx, vc.vp, jsComp.jsObj); JSApi.setObject((int)JSApi.SetType.Rval, jsComp.GetJSObjID(false)); } return(true); }
// GameObject.AddComponent<T>() public static bool GameObject_AddComponentT1(JSVCall vc, int count) { help_getGoAndType(vc); if (typeInfo.IsCSMonoBehaviour) { Component com = go.AddComponent(type); JSMgr.datax.setObject((int)JSApi.SetType.Rval, com); } else { // TODO JSComponent jsComp = go.AddComponent <JSComponent>(); jsComp.jsClassName = typeString; jsComp.jsFail = false; jsComp.init(true); if (go.activeInHierarchy) { jsComp.callAwake(); // Òªµ÷Óà js µÄ Awake jsComp.callOnAwake(); jsComp.callOnEnable(); } //JSApi.JSh_SetRvalObject(vc.cx, vc.vp, jsComp.jsObj); JSApi.setObject((int)JSApi.SetType.Rval, jsComp.GetJSObjID(false)); } return(true); }
public static JSComponent s_AddComponent(GameObject go, string jsName) { JSComponent jsComp = go.AddComponent <JSComponent>(); jsComp.jsClassName = jsName; jsComp.jsFail = false; jsComp.init(true); jsComp.callAwake(); // 要调用 js 的 Awake return(jsComp); }
public void InitAndDestroy() { if (!inited) { inited = true; JSComponent script = gameObject.AddComponent <JSComponent>(); script.jsClassName = ScriptName; script.jsFail = false; script.init(true); SerializeData(script); script.callAwake(); script.callOnAwake(); script.callOnEnable(); Destroy(this); } }
void Start() { // 这个函数是一个演示,他是整个应用程序的入口 // 逻辑代码不能直接在Inspector中挂上去,那么总得有一个入口点,就是这里 // // GameObject prefab = (GameObject)EditorEnv.LoadMainAssetAtPath("Assets/Prefabs/Login.prefab"); GameObject go = (GameObject)Instantiate(prefab); go.transform.SetParent(transform, false); #if JS Instantiate(AssetDatabase.LoadMainAssetAtPath("Assets/Scripts/JSBinding/_JSEngine.prefab")); JSComponent jsComp = go.AddComponent <JSComponent>(); jsComp.jsClassName = "Login"; jsComp.jsFail = false; jsComp.init(true); jsComp.callAwake(); // 要调用 js 的 Awake #else go.AddComponent <Login>(); #endif }