protected void VisitUrlFunction(PrimitiveTerm term) { string path = (string)term.Value; string projectRelativePath, errorMessage; URIValidationResult result = URIHelpers.ValidAssetURL(assetPath, path, out errorMessage, out projectRelativePath); if (result != URIValidationResult.OK) { m_Builder.AddValue(path, StyleValueType.MissingAssetReference); m_Errors.AddValidationWarning(errorMessage, m_Builder.currentProperty.line); } else { UnityEngine.Object asset = DeclareDependencyAndLoad(projectRelativePath); bool isTexture = asset is Texture2D; if (isTexture || asset is Font || asset is VectorImage) { // Looking suffixed images files only if (isTexture) { string hiResImageLocation = URIHelpers.InjectFileNameSuffix(projectRelativePath, "@2x"); if (File.Exists(hiResImageLocation)) { UnityEngine.Object hiResImage = DeclareDependencyAndLoad(hiResImageLocation); if (hiResImage is Texture2D) { m_Builder.AddValue(new ScalableImage() { normalImage = asset as Texture2D, highResolutionImage = hiResImage as Texture2D }); } else { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidHighResolutionImage, string.Format("Invalid asset type {0}, only Texture2D is supported for variants with @2x suffix", asset.GetType().Name)); } return; } // If we didn't find an high res variant, tell ADB we depend on that potential file existing DeclareDependencyAndLoad(hiResImageLocation); } m_Builder.AddValue(asset); } else { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidURIProjectAssetType, string.Format("Invalid asset type {0}, only Font, Texture2D and VectorImage are supported", asset.GetType().Name)); } } }
private bool ValidateFunction(GenericFunction term, out StyleValueFunction func) { func = StyleValueFunction.Unknown; if (term.Arguments.Length == 0) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.MissingFunctionArgument, term.Name); return(false); } if (term.Name == k_VariableFunctionName) { func = StyleValueFunction.Var; return(ValidateVarFunction(term)); } try { func = StyleValueFunctionExtension.FromUssString(term.Name); } catch (Exception) { var prop = m_Builder.currentProperty; m_Errors.AddValidationWarning($"Unknown function {term.Name} in declaration {prop.name}: {term.Name}", prop.line); return(false); } return(true); }