To add a platform to an effect’s excludedPlatforms
array, you need to add it via the effect’s relationships - for example:
// get current platform
var platform = studio.project.workspace.projectSettings.activePlatform;
// add it to the effect's excluded platforms
eventEffect.relationships.excludedPlatforms.add(platform);
I’ve modified your script to use the effect’s relationships to toggle whether the Oculus Spatializer effect is excluded from the currently selected plaform. Give it a try and let me know whether you run into any issues.
studio.menu.addMenuItem({
name: "Toggle Oculus Spatializers for Current Platform",
execute: function() {
var platform = studio.project.workspace.projectSettings.activePlatform; // get current platform
var selectedEvents = studio.window.browserSelection();
// iterate over browser selection
selectedEvents.forEach(function(event)
{
// check whether event is selected
if (event.isOfExactType("Event"))
{
var effectChain = event.masterTrack.mixerGroup.effectChain;
var effectChainEffects = effectChain.effects;
// iterate over effects in event's master track
effectChainEffects.forEach(function(eventEffect)
{
// if current effect is a plugin effect
if (eventEffect.isOfExactType("PluginEffect"))
{
// if plugin effect is oculus spatializer
if (eventEffect.plugin.identifier === "Oculus Spatializer")
{
// check whether effect is already excluded so exclusion can be toggled
var index = platformsArrayIncludes(eventEffect.excludedPlatforms, platform)
if (index >= 0)
{
eventEffect.relationships.excludedPlatforms.remove(platform);
}
else
{
eventEffect.relationships.excludedPlatforms.add(platform);
}
}
}
});
}
});
},
});
// helper function to check whether platform is already excluded
function platformsArrayIncludes(array, platformToCheck){
var index = -1;
array.forEach(function(platform){
index++;
if (platform.id === platformToCheck.id) return index;
});
return index;
}