static string StringFromLeafObject(object obj)
        {
            if (obj == null)
            {
                return(string.Empty);
            }

            if (typeof(Component).IsAssignableFrom(obj.GetType()))
            {
                Component c = (Component)obj;
                if (c == null) // Component overrides the == operator, so we have to check
                {
                    return(string.Empty);
                }
                return(ObjectTreeUtil.GetFullName(c.gameObject));
            }
            if (typeof(GameObject).IsAssignableFrom(obj.GetType()))
            {
                GameObject go = (GameObject)obj;
                if (go == null) // GameObject overrides the == operator, so we have to check
                {
                    return(string.Empty);
                }
                return(ObjectTreeUtil.GetFullName(go));
            }
            if (typeof(ScriptableObject).IsAssignableFrom(obj.GetType()))
            {
                return(AssetDatabase.GetAssetPath(obj as ScriptableObject));
            }
            return(obj.ToString());
        }
예제 #2
0
        static string StringFromLeafObject(object obj)
        {
            if (obj == null)
            {
                return(string.Empty);
            }

            if (obj.GetType().IsSubclassOf(typeof(Component)))
            {
                Component c = (Component)obj;
                if (c == null) // Component overrides the == operator, so we have to check
                {
                    return(string.Empty);
                }
                return(ObjectTreeUtil.GetFullName(c.gameObject));
            }
            if (obj.GetType().IsSubclassOf(typeof(GameObject)))
            {
                GameObject go = (GameObject)obj;
                if (go == null) // GameObject overrides the == operator, so we have to check
                {
                    return(string.Empty);
                }
                return(ObjectTreeUtil.GetFullName(go));
            }
            return(obj.ToString());
        }
        /// <summary>
        /// Recursively collect all the field values in the MonoBehaviours
        /// owned by this object and its descendants.  The values are stored
        /// in an internal dictionary.
        /// </summary>
        public void CollectFieldValues(GameObject go)
        {
            mObjectFullPath = ObjectTreeUtil.GetFullName(go);
            GameObjectFieldScanner scanner = new GameObjectFieldScanner();

            scanner.FilterField = FilterField;
            scanner.OnLeafField = (string fullName, Type type, ref object value) =>
            {
                // Save the value in the dictionary
                mValues[fullName] = StringFromLeafObject(value);
                //Debug.Log(mObjectFullPath + "." + fullName + " = " + mValues[fullName]);
                return(false);
            };
            scanner.ScanFields(go);
        }