Exemple #1
0
        internal static void ShaderIndexing(CustomObjectIndexerTarget context, ObjectIndexer indexer)
        {
            if (!(context.target is Shader shader) ||
                !indexer.settings.options.properties ||
                !indexer.settings.type.Equals("asset", System.StringComparison.Ordinal))
            {
                return;
            }

            for (int i = 0, end = shader.GetPropertyCount(); i != end; ++i)
            {
                var name = shader.GetPropertyName(i).ToLowerInvariant();
                if (name.Length > 0 && name[0] == '_')
                {
                    name = name.Substring(1);
                }
                switch (shader.GetPropertyType(i))
                {
                case UnityEngine.Rendering.ShaderPropertyType.Color:
                    var v = shader.GetPropertyDefaultVectorValue(i);
                    IndexColor(name, new Color(v.x, v.y, v.z, v.w), indexer, context.documentIndex);
                    break;

                case UnityEngine.Rendering.ShaderPropertyType.Vector:
                    v = shader.GetPropertyDefaultVectorValue(i);
                    IndexVector(name, v, indexer, context.documentIndex);
                    break;

                case UnityEngine.Rendering.ShaderPropertyType.Float:
                    indexer.IndexNumber(context.documentIndex, name, shader.GetPropertyDefaultFloatValue(i));
                    break;
                }
            }
        }
Exemple #2
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);
                }
            }
        }
Exemple #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);
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
0
        protected void CallCustomIndexers(string id, Object obj, int documentIndex, SerializedObject so, bool multiLevel = true)
        {
            var objectType = obj.GetType();
            List <Action <CustomObjectIndexerTarget, ObjectIndexer> > customIndexers;

            if (!multiLevel)
            {
                if (!m_CustomObjectIndexers.TryGetValue(objectType, out customIndexers))
                {
                    return;
                }
            }
            else
            {
                customIndexers = new List <Action <CustomObjectIndexerTarget, ObjectIndexer> >();
                var indexerTypes = m_CustomObjectIndexers.Keys;
                foreach (var indexerType in indexerTypes)
                {
                    if (indexerType.IsAssignableFrom(objectType))
                    {
                        customIndexers.AddRange(m_CustomObjectIndexers[indexerType]);
                    }
                }
            }

            var indexerTarget = new CustomObjectIndexerTarget
            {
                id               = id,
                documentIndex    = documentIndex,
                target           = obj,
                serializedObject = so,
                targetType       = objectType
            };

            foreach (var customIndexer in customIndexers)
            {
                customIndexer(indexerTarget, this);
            }
        }
        /// <summary>
        /// Call all the registered custom indexer for an object of a specific type. See <see cref="CustomObjectIndexerAttribute"/>.
        /// </summary>
        /// <param name="documentId">Document id.</param>
        /// <param name="obj">Object to index.</param>
        /// <param name="documentIndex">Document where the indexed object was found.</param>
        /// <param name="so">SerializedObject representation of obj.</param>
        /// <param name="multiLevel">If true, calls all the indexer that would fit the type of the object (all assignable type). If false only check for an indexer registered for the exact type of the Object.</param>
        protected void CallCustomIndexers(string documentId, int documentIndex, Object obj, SerializedObject so, bool multiLevel = true)
        {
            var objectType = obj.GetType();
            List <CustomIndexerHandler> customIndexers;

            if (!multiLevel)
            {
                if (!CustomIndexers.TryGetValue(objectType, out customIndexers))
                {
                    return;
                }
            }
            else
            {
                customIndexers = new List <CustomIndexerHandler>();
                foreach (var indexerType in CustomIndexers.types)
                {
                    if (indexerType.IsAssignableFrom(objectType))
                    {
                        customIndexers.AddRange(CustomIndexers.GetHandlers(indexerType));
                    }
                }
            }

            var indexerTarget = new CustomObjectIndexerTarget
            {
                id               = documentId,
                documentIndex    = documentIndex,
                target           = obj,
                serializedObject = so,
                targetType       = objectType
            };

            foreach (var customIndexer in customIndexers)
            {
                customIndexer(indexerTarget, this);
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
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();
                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;
                }
            }
        }
Exemple #9
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;
                }
            }
        }