Exemplo n.º 1
0
        /// <summary>
        /// Index all the properties of an object.
        /// </summary>
        /// <param name="id">Object id.</param>
        /// <param name="obj">Object to index.</param>
        /// <param name="documentIndex">Document where the indexed object was found.</param>
        /// <param name="dependencies">Index dependencies.</param>
        protected void IndexObject(string id, Object obj, int documentIndex, bool dependencies = false)
        {
            using (var so = new SerializedObject(obj))
            {
                var p    = so.GetIterator();
                var next = p.Next(true);
                while (next)
                {
                    bool   saveKeyword = true;
                    var    fieldName   = p.displayName.Replace("m_", "").Replace(" ", "").ToLowerInvariant();
                    var    scc         = SearchUtils.SplitCamelCase(fieldName);
                    var    fcc         = scc.Length > 1 && fieldName.Length > 10 ? scc.Aggregate("", (current, s) => current + s[0]) : fieldName;
                    object fieldValue  = GetPropertyValue(p, ref saveKeyword);

                    // Some property names are not worth indexing and take to much spaces.
                    if (k_FieldNamesNoKeywords.Contains(fieldName))
                    {
                        saveKeyword = false;
                    }

                    if (fieldValue != null)
                    {
                        var sfv = fieldValue as string;
                        if (sfv != null)
                        {
                            if (sfv != "")
                            {
                                IndexProperty(id, fcc, sfv.Replace(" ", "").ToLowerInvariant(), documentIndex, saveKeyword);
                            }
                            else
                            {
                                IndexWord(id, $"@{fcc}", documentIndex);
                            }
                        }
                        else if (fieldValue is double)
                        {
                            var nfv = (double)fieldValue;
                            IndexNumber(id, fcc.ToLowerInvariant(), nfv, documentIndex);
                        }

                        IndexDebugMatch(id, fcc, fieldValue.ToString());
                    }

                    if (dependencies)
                    {
                        AddReference(id, p, documentIndex);
                    }

                    next = p.Next(p.hasVisibleChildren);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Index all the properties of an object.
        /// </summary>
        /// <param name="obj">Object to index.</param>
        /// <param name="documentIndex">Document where the indexed object was found.</param>
        /// <param name="dependencies">Index dependencies.</param>
        protected void IndexObject(int documentIndex, Object obj, bool dependencies = false)
        {
            using (var so = new SerializedObject(obj))
            {
                var p    = so.GetIterator();
                var next = p.Next(true);
                while (next)
                {
                    var fieldName = p.displayName.Replace("m_", "").Replace(" ", "").ToLowerInvariant();
                    var scc       = SearchUtils.SplitCamelCase(fieldName);
                    var fcc       = scc.Length > 1 && fieldName.Length > 10 ? scc.Aggregate("", (current, s) => current + s[0]) : fieldName;

                    switch (p.propertyType)
                    {
                    case SerializedPropertyType.Integer:
                        IndexNumber(documentIndex, fcc, (double)p.intValue);
                        break;

                    case SerializedPropertyType.Boolean:
                        IndexProperty(documentIndex, fcc, p.boolValue.ToString().ToLowerInvariant(), saveKeyword: false, exact: true);
                        break;

                    case SerializedPropertyType.Float:
                        IndexNumber(documentIndex, fcc, (double)p.floatValue);
                        break;

                    case SerializedPropertyType.String:
                        if (!string.IsNullOrEmpty(p.stringValue))
                        {
                            IndexProperty(documentIndex, fcc, p.stringValue.ToLowerInvariant(), saveKeyword: false, exact: p.stringValue.Length >= 16);
                        }
                        break;

                    case SerializedPropertyType.Enum:
                        if (p.enumValueIndex >= 0 && p.type == "Enum")
                        {
                            IndexProperty(documentIndex, fcc, p.enumNames[p.enumValueIndex].Replace(" ", "").ToLowerInvariant(), saveKeyword: true, exact: false);
                        }
                        break;

                    case SerializedPropertyType.Color:
                        IndexProperty(documentIndex, fcc, ColorUtility.ToHtmlStringRGB(p.colorValue).ToLowerInvariant(), saveKeyword: false, exact: true);
                        break;

                    case SerializedPropertyType.Vector2:
                        IndexProperty(documentIndex, fcc, V2S(p.vector2Value), saveKeyword: false, exact: true);
                        break;

                    case SerializedPropertyType.Vector3:
                        IndexProperty(documentIndex, fcc, V2S(p.vector3Value), saveKeyword: false, exact: true);
                        break;

                    case SerializedPropertyType.Vector4:
                        IndexProperty(documentIndex, fcc, V2S(p.vector4Value), saveKeyword: false, exact: true);
                        break;

                    case SerializedPropertyType.ObjectReference:
                        if (p.objectReferenceValue && !string.IsNullOrEmpty(p.objectReferenceValue.name))
                        {
                            IndexProperty(documentIndex, fcc, p.objectReferenceValue.name.ToLowerInvariant(), saveKeyword: false, exact: true);
                        }
                        break;
                    }

                    if (dependencies)
                    {
                        AddReference(documentIndex, p);
                    }

                    next = p.Next(p.hasVisibleChildren && !p.isArray);
                }
            }
        }