Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        internal static void IndexColor(string propertyName, Color c, ObjectIndexer indexer, int documentIndex)
        {
            var colorHex = c.a < 1f ? ColorUtility.ToHtmlStringRGBA(c) : ColorUtility.ToHtmlStringRGB(c);

            indexer.AddProperty(propertyName, colorHex.ToLowerInvariant(), documentIndex, exact: true, saveKeyword: false);
        }
Пример #6
0
        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;
                }
            }
        }