public override void ExportMaterial(Material material, PrefabContext prefabContext) { var urhoPath = EvaluateMaterialName(material); using (var writer = Engine.TryCreateXml(material.GetKey(), urhoPath, ExportUtils.GetLastWriteTimeUtc(material))) { if (writer == null) { return; } var urhoMaterial = new UrhoPBRMaterial(); urhoMaterial.Technique = "Techniques/PBR/PBRWater.xml"; var metallicGlossinessShaderArguments = new MetallicGlossinessShaderArguments(); var _SlowWaterNormal = GetTexture(material, "_SlowWaterNormal"); var _SlowNormalScale = GetFloat(material, "_SlowNormalScale", 1); metallicGlossinessShaderArguments.Bump = _SlowWaterNormal; metallicGlossinessShaderArguments.BumpScale = _SlowNormalScale; urhoMaterial.NormalTexture = GetScaledNormalTextureName(_SlowWaterNormal, _SlowNormalScale); urhoMaterial.ExtraParameters.Add("WaterMetallic", 1); urhoMaterial.ExtraParameters.Add("WaterRoughness", 1.0f - 1); urhoMaterial.ExtraParameters.Add("WaterFlowSpeed", 0.2); urhoMaterial.ExtraParameters.Add("WaterTimeScale", 1); urhoMaterial.ExtraParameters.Add("WaterFresnelPower", 4); Engine.SchedulePBRTextures(metallicGlossinessShaderArguments, urhoMaterial); WriteMaterial(writer, urhoMaterial, prefabContext); } }
public IEnumerable <ProgressBarReport> ExportAssets(string[] assetGUIDs, PrefabContext prefabContext) { yield return("Preparing " + assetGUIDs.Length + " assets to export"); foreach (var guid in assetGUIDs) { EditorTaskScheduler.Default.ScheduleForegroundTask(() => ExportAssetsAtPath(AssetDatabase.GUIDToAssetPath(guid), prefabContext)); } }
private IEnumerable <ProgressBarReport> ExportAsset(Object asset, PrefabContext prefabContext) { var assetPath = AssetDatabase.GetAssetPath(asset); if (string.IsNullOrWhiteSpace(assetPath)) { return(ExportDynamicAsset(asset, prefabContext)); } if (assetPath == "Library/unity default resources" || assetPath == "Resources/unity_builtin_extra") { return(ExportUnityDefaultResource(asset, assetPath)); } return(ExportAssetsAtPath(assetPath, prefabContext)); }
private IEnumerable <ProgressBarReport> ExportAssetsAtPath(string assetPath, PrefabContext prefabContext) { if (string.IsNullOrWhiteSpace(assetPath)) { yield break; } if (_cancellationToken.IsCancellationRequested) { yield break; } if (!_visitedAssetPaths.Add(assetPath)) { yield break; } if (!File.Exists(assetPath) && !Directory.Exists(assetPath)) { yield break; } var attrs = File.GetAttributes(assetPath); if (attrs.HasFlag(FileAttributes.Directory)) { foreach (var guid in AssetDatabase.FindAssets("", new[] { assetPath })) { EditorTaskScheduler.Default.ScheduleForegroundTask(() => ExportAssetsAtPath(AssetDatabase.GUIDToAssetPath(guid), prefabContext)); } yield break; } yield return("Loading " + assetPath); var assets = AssetDatabase.LoadAllAssetsAtPath(assetPath); yield return("Exporting " + assetPath); ExportAssetBlock(assetPath, AssetDatabase.GetMainAssetTypeAtPath(assetPath), assets, prefabContext); }
private void AssignUnityProperties(TmxHasProperties tmxHasProperties, XElement xml, PrefabContext context) { var properties = TmxHelper.GetPropertiesWithTypeDefaults(tmxHasProperties, this.tmxMap.ObjectTypes); // Only the root of the prefab can have a scale { string unityScale = properties.GetPropertyValueAsString("unity:scale", ""); if (!String.IsNullOrEmpty(unityScale)) { float scale = 1.0f; if (context != PrefabContext.Root) { Logger.WriteWarning("unity:scale only applies to map properties\n{0}", xml.ToString()); } else if (!Single.TryParse(unityScale, out scale)) { Logger.WriteError("unity:scale property value '{0}' could not be converted to a float", unityScale); } else { xml.SetAttributeValue("scale", unityScale); } } } // Only the root of the prefab can be marked a resource { string unityResource = properties.GetPropertyValueAsString("unity:resource", ""); if (!String.IsNullOrEmpty(unityResource)) { bool resource = false; if (context != PrefabContext.Root) { Logger.WriteWarning("unity:resource only applies to map properties\n{0}", xml.ToString()); } else if (!Boolean.TryParse(unityResource, out resource)) { Logger.WriteError("unity:resource property value '{0}' could not be converted to a boolean", unityResource); } else { xml.SetAttributeValue("resource", unityResource); } } } // Some users may want resource prefabs to be saved to a particular path { string unityResourcePath = properties.GetPropertyValueAsString("unity:resourcePath", ""); if (!String.IsNullOrEmpty(unityResourcePath)) { if (context != PrefabContext.Root) { Logger.WriteWarning("unity:resourcePath only applies to map properties\n{0}", xml.ToString()); } else { bool isInvalid = Path.GetInvalidPathChars().Any(c => unityResourcePath.Contains(c)); if (isInvalid) { Logger.WriteError("unity:resourcePath has invalid path characters: {0}", unityResourcePath); } else { xml.SetAttributeValue("resourcePath", unityResourcePath); } } } } // Any object can carry the 'isTrigger' setting and we assume any children to inherit the setting { string unityIsTrigger = properties.GetPropertyValueAsString("unity:isTrigger", ""); if (!String.IsNullOrEmpty(unityIsTrigger)) { bool isTrigger = false; if (!Boolean.TryParse(unityIsTrigger, out isTrigger)) { Logger.WriteError("unity:isTrigger property value '{0}' cound not be converted to a boolean", unityIsTrigger); } else { xml.SetAttributeValue("isTrigger", unityIsTrigger); } } } // Any part of the prefab can be assigned a 'layer' { string unityLayer = properties.GetPropertyValueAsString("unity:layer", ""); if (!String.IsNullOrEmpty(unityLayer)) { xml.SetAttributeValue("layer", unityLayer); } } // Any part of the prefab can be assigned a 'tag' { string unityTag = properties.GetPropertyValueAsString("unity:tag", ""); if (!String.IsNullOrEmpty(unityTag)) { xml.SetAttributeValue("tag", unityTag); } } List <String> knownProperties = new List <string>(); knownProperties.Add("unity:layer"); knownProperties.Add("unity:tag"); knownProperties.Add("unity:sortingLayerName"); knownProperties.Add("unity:sortingOrder"); knownProperties.Add("unity:scale"); knownProperties.Add("unity:isTrigger"); knownProperties.Add("unity:convex"); knownProperties.Add("unity:ignore"); knownProperties.Add("unity:resource"); knownProperties.Add("unity:resourcePath"); var unknown = from p in properties.PropertyMap where p.Key.StartsWith("unity:") where knownProperties.Contains(p.Key) == false select p.Key; foreach (var p in unknown) { Logger.WriteWarning("Unknown unity property '{0}' in GameObject '{1}'", p, tmxHasProperties.ToString()); } }
protected abstract IEnumerable <ProgressBarReport> ExportDynamicAsset(Object asset, PrefabContext prefabContext);
protected abstract void ExportAssetBlock(string assetPath, Type mainType, Object[] assets, PrefabContext prefabContext);
public void ScheduleAssetExportAtPath(string assetPath, PrefabContext prefabContext) { EditorTaskScheduler.Default.ScheduleForegroundTask(() => ExportAssetsAtPath(assetPath, prefabContext)); }
public void ScheduleAssetExport(Object asset, PrefabContext prefabContext) { EditorTaskScheduler.Default.ScheduleForegroundTask(() => ExportAsset(asset, prefabContext)); }
public PrefabLocator() { _context = Resources.Load <PrefabContext>(PrefabContextPath); }
private void AssignUnityProperties <T>(T tmx, XElement xml, PrefabContext context) where T : TmxHasProperties { // Only the root of the prefab can have a scale { string unityScale = tmx.Properties.GetPropertyValueAsString("unity:scale", ""); if (!String.IsNullOrEmpty(unityScale)) { float scale = 1.0f; if (context != PrefabContext.Root) { Program.WriteWarning("unity:scale only applies to map properties\n{0}", xml.ToString()); } else if (!Single.TryParse(unityScale, out scale)) { Program.WriteError("unity:scale property value '{0}' could not be converted to a float", unityScale); } else { xml.SetAttributeValue("scale", unityScale); } } } // Only the root of the prefab can be marked a resource { string unityResource = tmx.Properties.GetPropertyValueAsString("unity:resource", ""); if (!String.IsNullOrEmpty(unityResource)) { bool resource = false; if (context != PrefabContext.Root) { Program.WriteWarning("unity:resource only applies to map properties\n{0}", xml.ToString()); } else if (!Boolean.TryParse(unityResource, out resource)) { Program.WriteError("unity:resource property value '{0}' could not be converted to a boolean", unityResource); } else { xml.SetAttributeValue("resource", unityResource); } } } // Any object can carry the 'isTrigger' setting and we assume any children to inherit the setting { string unityIsTrigger = tmx.Properties.GetPropertyValueAsString("unity:isTrigger", ""); if (!String.IsNullOrEmpty(unityIsTrigger)) { bool isTrigger = false; if (!Boolean.TryParse(unityIsTrigger, out isTrigger)) { Program.WriteError("unity:isTrigger property value '{0}' cound not be converted to a boolean", unityIsTrigger); } else { xml.SetAttributeValue("isTrigger", unityIsTrigger); } } } // Any part of the prefab can be assigned a 'layer' { string unityLayer = tmx.Properties.GetPropertyValueAsString("unity:layer", ""); if (!String.IsNullOrEmpty(unityLayer)) { xml.SetAttributeValue("layer", unityLayer); } } // Any part of the prefab can be assigned a 'tag' { string unityTag = tmx.Properties.GetPropertyValueAsString("unity:tag", ""); if (!String.IsNullOrEmpty(unityTag)) { xml.SetAttributeValue("tag", unityTag); } } List <String> knownProperties = new List <string>(); knownProperties.Add("unity:layer"); knownProperties.Add("unity:tag"); knownProperties.Add("unity:sortingLayerName"); knownProperties.Add("unity:sortingOrder"); knownProperties.Add("unity:scale"); knownProperties.Add("unity:isTrigger"); knownProperties.Add("unity:ignore"); knownProperties.Add("unity:collisionOnly"); knownProperties.Add("unity:resource"); var unknown = from p in tmx.Properties.PropertyMap where p.Key.StartsWith("unity:") where knownProperties.Contains(p.Key) == false select p.Key; foreach (var p in unknown) { Program.WriteWarning("Unknown unity property '{0}' in GameObject '{1}'", p, tmx.ToString()); } }
private void StartExportAssets(string[] assetGuiDs, PrefabContext prefabContext) { _engine = CreateEngine(); EditorTaskScheduler.Default.ScheduleForegroundTask(() => _engine.ExportAssets(assetGuiDs, prefabContext)); }
private void Construct(PrefabContext prefabContext) { _prefabContext = prefabContext; }
private void AssignUnityProperties(TmxHasProperties tmxHasProperties, XElement xml, PrefabContext context) { var properties = TmxHelper.GetPropertiesWithTypeDefaults(tmxHasProperties, this.tmxMap.ObjectTypes); // Only the root of the prefab can have a scale { string unityScale = properties.GetPropertyValueAsString("unity:scale", ""); if (!String.IsNullOrEmpty(unityScale)) { float scale = 1.0f; if (context != PrefabContext.Root) { Logger.WriteWarning("unity:scale only applies to map properties\n{0}", xml.ToString()); } else if (!Single.TryParse(unityScale, out scale)) { Logger.WriteError("unity:scale property value '{0}' could not be converted to a float", unityScale); } else { xml.SetAttributeValue("scale", unityScale); } } } // Only the root of the prefab can be marked a resource { string unityResource = properties.GetPropertyValueAsString("unity:resource", ""); if (!String.IsNullOrEmpty(unityResource)) { bool resource = false; if (context != PrefabContext.Root) { Logger.WriteWarning("unity:resource only applies to map properties\n{0}", xml.ToString()); } else if (!Boolean.TryParse(unityResource, out resource)) { Logger.WriteError("unity:resource property value '{0}' could not be converted to a boolean", unityResource); } else { xml.SetAttributeValue("resource", unityResource); } } } // Some users may want resource prefabs to be saved to a particular path { string unityResourcePath = properties.GetPropertyValueAsString("unity:resourcePath", ""); if (!String.IsNullOrEmpty(unityResourcePath)) { if (context != PrefabContext.Root) { Logger.WriteWarning("unity:resourcePath only applies to map properties\n{0}", xml.ToString()); } else { bool isInvalid = Path.GetInvalidPathChars().Any(c => unityResourcePath.Contains(c)); if (isInvalid) { Logger.WriteError("unity:resourcePath has invalid path characters: {0}", unityResourcePath); } else { xml.SetAttributeValue("resourcePath", unityResourcePath); } } } } // Any object can carry the 'isTrigger' setting and we assume any children to inherit the setting { string unityIsTrigger = properties.GetPropertyValueAsString("unity:isTrigger", ""); if (!String.IsNullOrEmpty(unityIsTrigger)) { bool isTrigger = false; if (!Boolean.TryParse(unityIsTrigger, out isTrigger)) { Logger.WriteError("unity:isTrigger property value '{0}' cound not be converted to a boolean", unityIsTrigger); } else { xml.SetAttributeValue("isTrigger", unityIsTrigger); } } } // Any part of the prefab can be assigned a 'layer' { string unityLayer = properties.GetPropertyValueAsString("unity:layer", ""); if (!String.IsNullOrEmpty(unityLayer)) { xml.SetAttributeValue("layer", unityLayer); } } // Any part of the prefab can be assigned a 'tag' { string unityTag = properties.GetPropertyValueAsString("unity:tag", ""); if (!String.IsNullOrEmpty(unityTag)) { xml.SetAttributeValue("tag", unityTag); } } List<String> knownProperties = new List<string>(); knownProperties.Add("unity:layer"); knownProperties.Add("unity:tag"); knownProperties.Add("unity:sortingLayerName"); knownProperties.Add("unity:sortingOrder"); knownProperties.Add("unity:scale"); knownProperties.Add("unity:isTrigger"); knownProperties.Add("unity:convex"); knownProperties.Add("unity:ignore"); knownProperties.Add("unity:resource"); knownProperties.Add("unity:resourcePath"); var unknown = from p in properties.PropertyMap where p.Key.StartsWith("unity:") where knownProperties.Contains(p.Key) == false select p.Key; foreach (var p in unknown) { Logger.WriteWarning("Unknown unity property '{0}' in GameObject '{1}'", p, tmxHasProperties.ToString()); } }