internal static void IndexVector(string propertyName, Vector4 v, ObjectIndexer indexer, int documentIndex) { indexer.AddNumber(propertyName + ".x", v.x, indexer.settings.baseScore, documentIndex); indexer.AddNumber(propertyName + ".y", v.y, indexer.settings.baseScore, documentIndex); indexer.AddNumber(propertyName + ".z", v.z, indexer.settings.baseScore, documentIndex); indexer.AddNumber(propertyName + ".w", v.w, indexer.settings.baseScore, documentIndex); }
internal static void AnimationClipEventsIndexing(CustomObjectIndexerTarget context, ObjectIndexer indexer) { if (!(context.target is AnimationClip clip) || !indexer.settings.options.properties) { return; } indexer.AddNumber("events", clip.events.Length, indexer.settings.baseScore, context.documentIndex); foreach (var e in clip.events) { indexer.AddNumber("time", e.time, indexer.settings.baseScore, context.documentIndex); indexer.AddProperty("function", e.functionName.ToLowerInvariant(), context.documentIndex, saveKeyword: true, exact: false); } }
internal static void IndexMeshRendererMaterials(CustomObjectIndexerTarget context, ObjectIndexer indexer) { if (indexer.settings.type != "asset") { return; } var c = context.target as MeshRenderer; if (c == null) { return; } indexer.AddNumber("materialcount", c.sharedMaterials.Length, indexer.settings.baseScore + 2, context.documentIndex); foreach (var m in c.sharedMaterials) { indexer.AddProperty("material", m.name.Replace(" (Instance)", "").ToLowerInvariant(), context.documentIndex, saveKeyword: true); var mp = AssetDatabase.GetAssetPath(m); if (!string.IsNullOrEmpty(mp)) { indexer.AddProperty("material", mp.ToLowerInvariant(), context.documentIndex, saveKeyword: false, exact: true); } } }
internal static void Texture2DIndexing(CustomObjectIndexerTarget context, ObjectIndexer indexer) { if (!(context.target is Texture2D texture) || !indexer.settings.options.properties) { return; } indexer.AddProperty("format", texture.format.ToString().ToLowerInvariant(), context.documentIndex, saveKeyword: true, exact: true); indexer.AddProperty("filtermode", texture.filterMode.ToString().ToLowerInvariant(), context.documentIndex, saveKeyword: true, exact: true); indexer.AddProperty("dimension", texture.dimension.ToString().ToLowerInvariant(), context.documentIndex, saveKeyword: true, exact: true); var ti = AssetImporter.GetAtPath(context.id) as TextureImporter; if (ti) { indexer.AddProperty("type", ti.textureType.ToString().ToLowerInvariant(), context.documentIndex, saveKeyword: true, exact: true); indexer.AddProperty("shape", ti.textureShape.ToString().ToLowerInvariant(), context.documentIndex, saveKeyword: true, exact: true); indexer.AddProperty("readable", ti.isReadable.ToString().ToLowerInvariant(), context.documentIndex, saveKeyword: false, exact: true); indexer.AddProperty("srgb", ti.sRGBTexture.ToString().ToLowerInvariant(), context.documentIndex, saveKeyword: false, exact: true); indexer.AddProperty("compression", ti.textureCompression.ToString().ToLowerInvariant(), context.documentIndex, saveKeyword: true, exact: true); indexer.AddNumber("compressionquality", ti.compressionQuality, indexer.settings.baseScore, context.documentIndex); } }
internal static void MaterialShaderReferences(CustomObjectIndexerTarget context, ObjectIndexer indexer) { var material = context.target as Material; if (material == null) { return; } if (material.shader) { var fullShaderName = material.shader.name.ToLowerInvariant(); indexer.AddReference(context.documentIndex, fullShaderName); } if (!indexer.settings.type.Equals("asset", System.StringComparison.Ordinal)) { return; } if (!indexer.settings.options.properties) { return; } var properties = MaterialEditor.GetMaterialProperties(new Material[] { material }); foreach (var property in properties) { var propertyName = property.name.ToLowerInvariant(); if (propertyName.Length > 0 && propertyName[0] == '_') { propertyName = propertyName.Substring(1); } switch (property.type) { case MaterialProperty.PropType.Color: IndexColor(propertyName, property.colorValue, indexer, context.documentIndex); break; case MaterialProperty.PropType.Vector: IndexVector(propertyName, property.vectorValue, indexer, context.documentIndex); break; case MaterialProperty.PropType.Float: indexer.AddNumber(propertyName, property.floatValue, indexer.settings.baseScore, context.documentIndex); break; case MaterialProperty.PropType.Range: IndexVector(propertyName, property.rangeLimits, indexer, context.documentIndex); break; case MaterialProperty.PropType.Texture: if (property.textureValue) { indexer.AddReference(context.documentIndex, AssetDatabase.GetAssetPath(property.textureValue)); } break; } } }
internal static void MaterialShaderReferences(CustomObjectIndexerTarget context, ObjectIndexer indexer) { var material = context.target as Material; if (material == null) { return; } if (material.shader) { var fullShaderName = material.shader.name.ToLowerInvariant(); var shortShaderName = System.IO.Path.GetFileNameWithoutExtension(fullShaderName); indexer.AddProperty("ref", shortShaderName, context.documentIndex, saveKeyword: false); indexer.AddProperty("ref", fullShaderName, context.documentIndex, saveKeyword: false); } if (!indexer.settings.options.properties) { return; } var properties = MaterialEditor.GetMaterialProperties(new Material[] { material }); foreach (var property in properties) { var propertyName = property.name; if (propertyName.Length > 0 && propertyName[0] == '_') { propertyName = propertyName.Substring(1).ToLowerInvariant(); } switch (property.type) { case MaterialProperty.PropType.Color: indexer.AddProperty(propertyName, ColorUtility.ToHtmlStringRGB(property.colorValue).ToLowerInvariant(), context.documentIndex, exact: true, saveKeyword: true); break; case MaterialProperty.PropType.Vector: indexer.AddNumber(propertyName + "x", property.vectorValue.x, indexer.settings.baseScore, context.documentIndex); indexer.AddNumber(propertyName + "y", property.vectorValue.y, indexer.settings.baseScore, context.documentIndex); indexer.AddNumber(propertyName + "z", property.vectorValue.z, indexer.settings.baseScore, context.documentIndex); indexer.AddNumber(propertyName + "w", property.vectorValue.w, indexer.settings.baseScore, context.documentIndex); break; case MaterialProperty.PropType.Float: indexer.AddNumber(propertyName, property.floatValue, indexer.settings.baseScore, context.documentIndex); break; case MaterialProperty.PropType.Range: indexer.AddNumber(propertyName + "x", property.rangeLimits.x, indexer.settings.baseScore, context.documentIndex); indexer.AddNumber(propertyName + "y", property.rangeLimits.x, indexer.settings.baseScore, context.documentIndex); break; case MaterialProperty.PropType.Texture: if (property.textureValue) { indexer.AddProperty(propertyName, property.textureValue.name.ToLowerInvariant(), context.documentIndex, saveKeyword: true); indexer.AddProperty("ref", AssetDatabase.GetAssetPath(property.textureValue).ToLowerInvariant(), context.documentIndex, exact: true, saveKeyword: true); } break; default: break; } } }