{ if (err) { console.error(err); } else { // 1. 普通函数可以直接调用 Print("Hello World"); // 2. 继承cc.Component的类 let clsNam._cocos creat">
赞
踩
- // 加载代码
- let url = "http://远程域名或ip地址/路径/TestRemote.js";
- cc.loader.load(url, (err, res) => {
- if (err) {
- console.error(err);
- } else {
- // 1. 普通函数可以直接调用
- Print("Hello World");
-
- // 2. 继承cc.Component的类
- let clsName = "TestRemote";// 自己定义,需要和TestRemote.js文件中类名一致
- let cls = cc.js.getClassByName(clsName);
- if (!cls) {
- let remoteCls: any = window[clsName];
- if (window.__modular) {
- // preview
- window.__modular.modules[clsName] = {
- file: clsName
- };
- window.__modular.nameMap[clsName] = clsName;
- }
- if (window.__require) {
- // build
- }
- let o = function (r) {
- var u = {
- exports: {}
- };
- remoteCls[0].call(u.exports, function (t) {
- return o(remoteCls[1][t] || t)
- }, u, u.exports);
- return u.exports
- }
- o(clsName);
- }
- let node = new cc.Node();
- node.parent = this.node;
- node.setPosition(0, 100);
- let com = node.addComponent("TestRemote");
- let labelNode = new cc.Node();
- labelNode.parent = node;
- com.label = labelNode.addComponent(cc.Label);
- com.setLabel("Hahaha");
-
- console.log('done');
- }
- });
- // 远程代码: 下面3种任选一种
- // 1.普通js代码
- function Print(msg) {
- console.log('Print', msg);
- }
- // =====================================================
- // 2.cocos creator 继承cc.Component的js类编译后版本:
- // build版本之后获取到的,"37c8fTvEXFFTJXIilra/hLt"为随机生成的uuid,由编辑器生成
- var TestRemote = [function (t, e, i) {
- "use strict";
- cc._RF.push(e, "37c8fTvEXFFTJXIilra/hLt", "TestRemote", "TestRemote");
- cc.Class({
- extends: cc.Component,
- properties: {
- label: cc.Label
- },
- start: function () { },
- setLabel: function (t) {
- this.label.string = t
- }
- });
- cc._RF.pop()
- }, {}]
- // =====================================================
- // 2.cocos creator 继承cc.Component的ts类编译后版本:
- // build版本之后获取到的,"19b791y98xIZLnToPi/DNyb"为随机生成的uuid,由编辑器生成
- var TestRemote = [function(t, e, i) {
- "use strict";
- cc._RF.push(e, "19b791y98xIZLnToPi/DNyb", "TestRemote", "TestRemote");
- var n = this && this.__extends || function() {
- var t = function(e, i) {
- return (t = Object.setPrototypeOf || {
- __proto__: []
- }instanceof Array && function(t, e) {
- t.__proto__ = e
- }
- || function(t, e) {
- for (var i in e)
- e.hasOwnProperty(i) && (t[i] = e[i])
- }
- )(e, i)
- };
- return function(e, i) {
- function n() {
- this.constructor = e
- }
- t(e, i),
- e.prototype = null === i ? Object.create(i) : (n.prototype = i.prototype,
- new n)
- }
- }()
- , o = this && this.__decorate || function(t, e, i, n) {
- var o, s = arguments.length, r = s < 3 ? e : null === n ? n = Object.getOwnPropertyDescriptor(e, i) : n;
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate)
- r = Reflect.decorate(t, e, i, n);
- else
- for (var a = t.length - 1; a >= 0; a--)
- (o = t[a]) && (r = (s < 3 ? o(r) : s > 3 ? o(e, i, r) : o(e, i)) || r);
- return s > 3 && r && Object.defineProperty(e, i, r),
- r
- }
- ;
- Object.defineProperty(i, "__esModule", {
- value: !0
- });
- var s = cc._decorator
- , r = s.ccclass
- , a = s.property
- , c = function(t) {
- function e() {
- var e = null !== t && t.apply(this, arguments) || this;
- return e.label = null,
- e
- }
- return n(e, t),
- e.prototype.onLoad = function() {}
- ,
- e.prototype.start = function() {}
- ,
- e.prototype.setLabel = function(t) {
- this.label.string = t
- }
- ,
- o([a(cc.Label)], e.prototype, "label", void 0),
- e = o([r], e)
- }(cc.Component);
- i.TestRemote = c,
- cc._RF.pop()
- }
- , {}]
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。