When I add a script and write the content, it will automatically be excluded. Hope for help. Thanks a lot.
var ArtworkObject = pc.createScript('artworkObject');
ArtworkObject.attributes.add('data', {
type: 'json', array: true,
schema: [{
name: 'id', type: 'number'
}, {
name: 'anchorId', type: 'string'
}, {
name: 'src', type: 'string'
}, {
name: 'type', type: 'string'
}]
});
// initialize code called once per entity
ArtworkObject.prototype.initialize = function() {
this.globalCommunication = this.app.root.findByName('Feature').script.globalCommunication
this.sceneName = this.globalCommunication.sceneName;
this.artworkGroup = this.app.root.findByTag("Artwork");
this.getSceneArtworkData()
this.on('attr:data', function (value, prev) {
this.onDataChange()
}, this);
};
ArtworkObject.prototype.loadJsonFromRemote = function (url, callback) {
console.log(url);
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function () {
callback(JSON.parse(this.response));
});
xhr.open("GET", url);
xhr.send();
};
ArtworkObject.prototype.getSceneArtworkData = function() {
let self = this;
this.sceneName = this.globalCommunication.sceneName;
this.loadJsonFromRemote(`https://xxx/1139101/testing/artworks/${this.sceneName}.json`, function (data) {
self.initDisplay(data);
console.log(data);
});
}
ArtworkObject.prototype.initDisplay = async function (data) {
this.data = data.json;
console.log(this.data)
};
ArtworkObject.prototype.onDataChange = async function () {
this.artworkGroup = this.app.root.findByTag("Artwork");
console.log(this.artworkGroup)
};
// update code called every frame
ArtworkObject.prototype.update = function(dt) {
};