private void LoadEffects(Package package, EffectsDefinition effectsDef) { if (effectsDef?.Effects == null || effectsDef.Effects.Count == 0) { _assetErrors.Add($"{package.packageName} - effects list is null or empty."); return; } foreach (var effectDef in effectsDef.Effects) { if (effectDef?.Name == null) { _assetErrors.Add($"{package.packageName} - Effect name missing."); continue; } if (_effects.Any(e => e.name == effectDef.Name) || EffectCollection.FindEffect(effectDef.Name) != null) { //_assetErrors.Add($"{package.packageName} - {effectDef.Name} - Duplicate effect name!"); continue; } if (effectDef is EffectsDefinition.LightEffect lightEffectDef) { LoadLightEffect(package, lightEffectDef); } // TODO add support for other asset types! } }
private void DumpExampleDefFile() { var def = new EffectsDefinition { Effects = new List <EffectsDefinition.Effect> { new EffectsDefinition.LightEffect { Name = "MY CUSTOM EFFECT", Type = "Spot", VariationColors = new List <EffectsDefinition.Color> { new EffectsDefinition.Color { R = 255, G = 255, B = 255, A = 255 } } } } }; try { var xmlSerializer = new XmlSerializer(typeof(EffectsDefinition)); using (var streamWriter = new StreamWriter("EffectsDefinition.xml")) { xmlSerializer.Serialize(streamWriter, def); } } catch (Exception e) { Debug.LogError(e); } }
private void LoadEffects() { try { var checkedPaths = new List <string>(); var packages = PackageManager.allPackages.Where((Package p) => p.FilterAssets(UserAssetType.CustomAssetMetaData).Any()).ToArray(); foreach (var package in packages) { if (package == null) { continue; } var crpPath = package.packagePath; if (crpPath == null) { continue; } var effectsDefPath = Path.Combine(Path.GetDirectoryName(crpPath) ?? "", EffectsDefinitionFileName); // skip files which were already parsed if (checkedPaths.Contains(effectsDefPath)) { continue; } checkedPaths.Add(effectsDefPath); if (!File.Exists(effectsDefPath)) { continue; } EffectsDefinition effectsDef = null; var xmlSerializer = new XmlSerializer(typeof(EffectsDefinition)); try { using (var streamReader = new StreamReader(effectsDefPath)) { effectsDef = xmlSerializer.Deserialize(streamReader) as EffectsDefinition; } } catch (Exception e) { Debug.LogException(e); _assetErrors.Add($"{package.packageName} - {e.Message}"); continue; } LoadEffects(package, effectsDef); } } catch (Exception e) { Debug.LogException(e); } EffectCollection.InitializeEffects(_effects.ToArray()); }