示例#1
0
        private static void AddReferenceForStateMachine(AssetData assetData, AnimatorStateMachine stateMachine)
        {
            foreach (var stateMachineBehaviour in stateMachine.states
                     .SelectMany(childAnimatorState => childAnimatorState.state.behaviours))
            {
                AddReferenceForObject(assetData, stateMachineBehaviour);
            }

            foreach (var stateMachineBehaviour in stateMachine.behaviours)
            {
                AddReferenceForObject(assetData, stateMachineBehaviour);
            }

            foreach (var childAnimatorStateMachine in stateMachine.stateMachines)
            {
                AddReferenceForStateMachine(assetData, childAnimatorStateMachine.stateMachine);
            }
        }
示例#2
0
        private static void AddAttachedAssets(Object component, object value, AssetData assetData, bool isScene)
        {
            var values = new List <Object>();

            if (value.GetType().IsArray)
            {
                values.AddRange(((Array)value).Cast <object>()
                                .Where(v => v != null)
                                .Select(v => v as Object));
            }
            else
            {
                values.Add(value as Object);
            }

            foreach (var v in values)
            {
                AddAttachedAsset(component, v, assetData, isScene);
            }
        }
示例#3
0
        private static void SearchProperty(Object component, object val, AssetData assetData, bool isScene)
        {
            var properties = val.GetType().GetProperties(flags);

            foreach (var info in properties.Where(info => info.CanRead))
            {
                var isObject = info.PropertyType.IsSubclassOf(typeof(Object)) ||
                               info.PropertyType == typeof(Object);

                if (!isObject || Ignore(val.GetType(), info.Name))
                {
                    continue;
                }

                var value = info.GetValue(val, new object[0]);
                if (value != null)
                {
                    AddAttachedAssets(component, value, assetData, isScene);
                }
            }
        }
示例#4
0
        private static void AddSceneData(Object component, Object value, AssetData assetData)
        {
            var _path = AssetDatabase.GetAssetPath(value);

            if (!string.IsNullOrEmpty(_path))
            {
                var name       = value.name;
                var gameObject = GetGameObject(component, value);

                if (gameObject)
                {
                    name = GetName(gameObject.transform);
                }

                assetData.sceneData.Add(new SceneData
                {
                    name     = name,
                    typeName = value.GetType().FullName,
                    guid     = AssetDatabase.AssetPathToGUID(_path)
                });
            }
        }
示例#5
0
        private static void SearchProperty(Object component, object val, AssetData assetData, bool isScene)
        {
            var properties = val.GetType().GetProperties(flags);

            foreach (var info in properties.Where(info => info.CanRead))
            {
                var isObject = info.PropertyType.IsSubclassOf(typeof(Object)) ||
                               info.PropertyType == typeof(Object);

                if (!isObject || Ignore(val.GetType(), info.Name)) continue;

                var value = info.GetValue(val, new object[0]);
                if (value != null)
                {
                    AddAttachedAssets(component, value, assetData, isScene);
                }
            }
        }
示例#6
0
        public static void Build(string[] assetPaths, Action<AssetData[]> callback = null)
        {
            var result = new AssetData[0];
            for (var i = 0; i < assetPaths.Length; i++)
            {
                var assetPath = assetPaths[i];
                var assetData = new AssetData
                {
                    path = assetPath,
                    guid = AssetDatabase.AssetPathToGUID(assetPath)
                };

                var progress = (float)i / assetPaths.Length;
                switch (Path.GetExtension(assetPath))
                {
                    case ".prefab":
                        {
                            DisplayProgressBar(assetData.path, progress);
                            var prefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject;

                            var go = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
                            go.hideFlags = HideFlags.HideAndDontSave;

                            SearchGameObject(go, assetData);
                            Object.DestroyImmediate(go);
                        }
                        break;
                    case ".unity":
                        DisplayProgressBar(assetData.path, progress);
                        if (EditorApplication.OpenScene(assetPath))
                        {
                            foreach (GameObject go in Object.FindObjectsOfType(typeof(GameObject)))
                            {
                                SearchGameObject(go, assetData, true);
                            }
                        }
                        break;
                    case ".controller":
                        var animator =
                            (AnimatorController)
                                AssetDatabase.LoadAssetAtPath(assetPath, typeof(AnimatorController));
                        var layerCount = 0;
                        if (isUnity41)
                        {
                            layerCount = (int)animator.GetType().GetMethod("GetLayerCount").Invoke(animator, new object[0]);
                        }
                        else
                        {
                            layerCount = (int)animator.GetType().GetProperty("layerCount").GetValue(animator, new object[0]);
                        }
                        for (var j = 0; j < layerCount; j++)
                        {
                            StateMachine stateMachine = null;

                            if (isUnity41)
                            {
                                stateMachine =
                                    (StateMachine)
                                        animator.GetType()
                                            .GetMethod("GetLayerStateMachine")
                                            .Invoke(animator, new object[] { j });
                            }
                            else
                            {
                                var layer =
                                        animator.GetType().GetMethod("GetLayer").Invoke(animator, new object[] { j });
                                stateMachine = (StateMachine)layer.GetType().GetProperty("stateMachine").GetValue(layer, new object[0]);
                            }
                            SearchMotion(animator, stateMachine, assetData);
                            var stateMachineCount = 0;
                            if (isUnity41)
                            {
                                stateMachineCount = (int)stateMachine.GetType().GetMethod("GetStateMachineCount").Invoke(stateMachine, new object[0]);
                            }
                            else
                            {
                                stateMachineCount =
                                    (int)stateMachine.GetType().GetProperty("stateMachineCount").GetValue(stateMachine, new object[0]);
                            }

                            for (var s = 0; s < stateMachineCount; s++)
                            {
                                SearchMotion(animator, stateMachine.GetStateMachine(s), assetData);
                            }
                        }
                        break;
                    case ".mat":

                        var material = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Material)) as Material;

                        AddAttachedAsset(material, material.shader, assetData, false);

                        var propertyCount = ShaderUtil.GetPropertyCount(material.shader);

                        for (var j = 0; j < propertyCount; j++)
                        {
                            if (ShaderUtil.GetPropertyType(material.shader, j) != ShaderUtil.ShaderPropertyType.TexEnv)
                                continue;
                            var propertyName = ShaderUtil.GetPropertyName(material.shader, j);
                            AddAttachedAsset(material, material.GetTexture(propertyName), assetData, false);
                        }
                        break;
                    default:
                        SearchFieldAndProperty(AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)), assetData);
                        break;
                }
                ArrayUtility.Add(ref result, assetData);
            }
            callback(result);
            depths.Clear();
            EditorUtility.ClearProgressBar();
        }
示例#7
0
        private static void SearchGameObject(GameObject go, AssetData assetData, bool isScene = false)
        {
            foreach (var obj in go.GetComponentsInChildren<Component>().Where(obj => obj))
            {
                AddAttachedAsset(obj, obj, assetData, isScene);

                SearchFieldAndProperty(obj, assetData, isScene);
            }
        }
示例#8
0
        private static void SearchMotion(AnimatorController animator, StateMachine stateMachine, AssetData assetData)
        {
            var stateCount = 0;

            if (isUnity41)
            {
                stateCount = (int)stateMachine.GetType().GetMethod("GetStateCount").Invoke(stateMachine, new object[0]);
            }
            else
            {
                stateCount =
                    (int)stateMachine.GetType().GetProperty("stateCount").GetValue(stateMachine, new object[0]);
            }
            for (var k = 0; k < stateCount; k++)
            {
                var state = stateMachine.GetState(k);
                var parameters = new object[0];
                var types = new Type[0];
                if (isUnity41)
                {
                    ArrayUtility.Add(ref parameters, 0);
                    ArrayUtility.Add(ref types, typeof(int));
                }
                var motion = state.GetType().GetMethod("GetMotion", types).Invoke(state, parameters) as Motion;
                if (motion)
                    SearchBlendTreeMotion(animator, motion, assetData);
            }
        }
示例#9
0
        public static void Build(string[] assetPaths, Action <AssetData[]> callback = null)
        {
            var result = new AssetData[0];

            EditorApplication.LockReloadAssemblies();
            assetPaths = assetPaths.OrderBy(path => Path.GetExtension(path)).ToArray();
            for (int i = 0; i < assetPaths.Length; i++)
            {
                var assetPath = assetPaths[i];

                if (assetPath.StartsWith("Assets/") == false)
                {
                    continue;
                }

                var assetData = new AssetData
                {
                    path = assetPath,
                    guid = AssetDatabase.AssetPathToGUID(assetPath)
                };
                progress = (float)i / assetPaths.Length;

                var obj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));
                DisplayProgressBar(assetData.path, progress);
                switch (Path.GetExtension(assetPath))
                {
                case ".prefab":
                    AddReferenceForPrefab(assetData, obj);
                    break;

                case ".unity":

                    if (EditorApplication.OpenScene(assetPath))
                    {
                        foreach (GameObject go in Object.FindObjectsOfType(typeof(GameObject)))
                        {
                            if (go.transform.parent != null)
                            {
                                continue;
                            }

                            DisplayProgressBar(assetData.path + " - " + go.name, progress);
                            AddReferenceForObject(assetData, go);
                            AddReferenceForObject(assetData, go, true);
                        }
                    }
                    break;

                case ".controller":
                    var animatorController = AssetDatabase.LoadAssetAtPath(assetPath, typeof(AnimatorController)) as AnimatorController;
                    foreach (var animationClip in animatorController.animationClips)
                    {
                        AddReferenceForObject(assetData, animationClip);
                    }

                    foreach (var animatorControllerLayer in animatorController.layers)
                    {
                        AddReferenceForStateMachine(assetData, animatorControllerLayer.stateMachine);
                    }
                    break;

                default:

                    AddReferenceForObject(assetData, obj);
                    break;
                }
                ArrayUtility.Add(ref result, assetData);
            }
            callback(result);
            EditorApplication.UnlockReloadAssemblies();
            EditorUtility.ClearProgressBar();
        }
示例#10
0
        private static void SearchFieldAndProperty(Object obj, object val, AssetData assetData, bool isScene = false)
        {
            if (!obj || obj is NavMeshAgent || ignoreTypes.Contains(obj.GetType().Name))
                return;

            SearchField(obj, val, assetData, isScene);
            SearchProperty(obj, val, assetData, isScene);
        }
示例#11
0
        private static void AddReferenceForStateMachine(AssetData assetData, AnimatorStateMachine stateMachine)
        {
            foreach (var stateMachineBehaviour in stateMachine.states
                .SelectMany(childAnimatorState => childAnimatorState.state.behaviours))
            {
                AddReferenceForObject(assetData, stateMachineBehaviour);
            }

            foreach (var stateMachineBehaviour in stateMachine.behaviours)
            {
                AddReferenceForObject(assetData, stateMachineBehaviour);
            }

            foreach (var childAnimatorStateMachine in stateMachine.stateMachines)
            {
                AddReferenceForStateMachine(assetData, childAnimatorStateMachine.stateMachine);
            }
        }
示例#12
0
 private static void SearchFieldAndProperty(Object obj, AssetData assetData, bool isScene = false)
 {
     SearchFieldAndProperty(obj, obj, assetData, isScene);
 }
示例#13
0
        private static void AddAttachedAssets(Object component, object value, AssetData assetData, bool isScene)
        {
            var values = new List<Object>();
            if (value.GetType().IsArray)
            {
                values.AddRange(((Array)value).Cast<object>()
                    .Where(v => v != null)
                    .Select(v => v as Object));
            }
            else
            {
                values.Add(value as Object);
            }

            foreach (var v in values)
            {
                AddAttachedAsset(component, v, assetData, isScene);
            }
        }
示例#14
0
        private static void AddSceneData(Object component, Object value, AssetData assetData)
        {
            var _path = AssetDatabase.GetAssetPath(value);
            if (!string.IsNullOrEmpty(_path))
            {
                var name = value.name;
                var gameObject = GetGameObject(component, value);

                if (gameObject)
                    name = GetName(gameObject.transform);

                assetData.sceneData.Add(new SceneData
                {
                    name = name,
                    typeName = value.GetType().FullName,
                    guid = AssetDatabase.AssetPathToGUID(_path)
                });
            }
        }
示例#15
0
        private static void AddAttachedAsset(Object component, Object value, AssetData assetData, bool isScene)
        {
            if (!value) return;

            if (value as MonoBehaviour)
            {

                value = MonoScript.FromMonoBehaviour(value as MonoBehaviour);

                if (isScene)
                {
                    AddSceneData(component, value, assetData);
                }

            }
            else if (value as ScriptableObject)
            {
                value = MonoScript.FromScriptableObject(value as ScriptableObject);

                if (isScene)
                {
                    AddSceneData(component, value, assetData);
                }
            }
            else if (isScene && PrefabUtility.GetPrefabType(value) == PrefabType.PrefabInstance)
            {
                var name = "";
                var gameObject = GetGameObject(component, value);

                if (gameObject)
                    name = GetName(PrefabUtility.FindPrefabRoot(gameObject).transform);

                value = PrefabUtility.GetPrefabParent(value);
                if (string.IsNullOrEmpty(name))
                    name = value.name;

                assetData.sceneData.Add(new SceneData
                {
                    name = name,
                    typeName = value.GetType().FullName,
                    guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value))
                });
            }
            else if (isScene)
            {
                AddSceneData(component, value, assetData);
            }

            var path = AssetDatabase.GetAssetPath(value);

            if (string.IsNullOrEmpty(path)) return;

            var guid = AssetDatabase.AssetPathToGUID(path);
            if (!assetData.reference.Contains(guid))
                assetData.reference.Add(guid);
        }
示例#16
0
        public static void Build(string[] assetPaths, Action<AssetData[]> callback = null)
        {
            var result = new AssetData[0];
            EditorApplication.LockReloadAssemblies();
            assetPaths = assetPaths.OrderBy(path => Path.GetExtension(path)).ToArray();
            for (int i = 0; i < assetPaths.Length; i++)
            {
                var assetPath = assetPaths[i];

                if (assetPath.StartsWith("Assets/") == false)
                    continue;

                var assetData = new AssetData
                {
                    path = assetPath,
                    guid = AssetDatabase.AssetPathToGUID(assetPath)
                };
                progress = (float)i / assetPaths.Length;

                var obj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));
                DisplayProgressBar(assetData.path, progress);
                switch (Path.GetExtension(assetPath))
                {
                    case ".prefab":
                        AddReferenceForPrefab(assetData, obj);
                        break;
                    case ".unity":

                        if (EditorApplication.OpenScene(assetPath))
                        {
                            foreach (GameObject go in Object.FindObjectsOfType(typeof(GameObject)))
                            {
                                if(go.transform.parent != null)continue;

                                DisplayProgressBar(assetData.path + " - " + go.name, progress);
                                AddReferenceForObject(assetData, go);
                                AddReferenceForObject(assetData, go, true);
                            }
                        }
                        break;
                    case ".controller":
                        var animatorController = AssetDatabase.LoadAssetAtPath(assetPath, typeof(AnimatorController)) as AnimatorController;
                        foreach (var animationClip in animatorController.animationClips)
                        {
                            AddReferenceForObject(assetData, animationClip);
                        }

                        foreach (var animatorControllerLayer in animatorController.layers)
                        {
                            AddReferenceForStateMachine(assetData, animatorControllerLayer.stateMachine);
                        }
                        break;
                    default:

                        AddReferenceForObject(assetData, obj);
                        break;
                }
                ArrayUtility.Add(ref result, assetData);
            }
            callback(result);
            EditorApplication.UnlockReloadAssemblies();
            EditorUtility.ClearProgressBar();
        }
示例#17
0
        private static void AddReference(AssetData assetData, Object obj, bool isSceneObject)
        {
            var guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(obj));

            if (string.IsNullOrEmpty(guid))
            {
                return;
            }

            if (isSceneObject)
            {
                Transform transform = null;

                var go = obj as GameObject;

                if (go)
                {
                    transform = go.transform;
                }
                else
                {
                    //                        var component = o as Component;
                    //                        if (component)
                    //                            transform = component.transform;
                }

                if (transform == null)
                {
                    return;
                }

                assetData.sceneData.Add(new SceneData
                {
                    guid     = guid,
                    name     = GetPathName(transform),
                    typeName = obj.GetType().FullName
                });
            }
            else
            {
                if (string.IsNullOrEmpty(guid))
                {
                    return;
                }


                if (AssetDatabase.IsSubAsset(obj))
                {
                    var sub = new SubAssetData
                    {
                        name     = obj.name,
                        guid     = guid,
                        typeName = obj.GetType().FullName
                    };
                    if (assetData.subAssets.Count(s => s.guid == sub.guid && s.name == sub.name && s.typeName == sub.typeName) == 0)
                    {
                        assetData.subAssets.Add(sub);
                    }
                }
                else
                {
                    if (assetData.reference.Contains(guid) == false)
                    {
                        assetData.reference.Add(guid);
                    }
                }
            }
        }
示例#18
0
        private static void SearchMotion(AnimatorController animator, StateMachine stateMachine, AssetData assetData)
        {
            var stateCount = 0;

            if (isUnity41)
            {
                stateCount = (int)stateMachine.GetType().GetMethod("GetStateCount").Invoke(stateMachine, new object[0]);
            }
            else
            {
                stateCount =
                    (int)stateMachine.GetType().GetProperty("stateCount").GetValue(stateMachine, new object[0]);
            }
            for (var k = 0; k < stateCount; k++)
            {
                var state      = stateMachine.GetState(k);
                var parameters = new object[0];
                var types      = new Type[0];
                if (isUnity41)
                {
                    ArrayUtility.Add(ref parameters, 0);
                    ArrayUtility.Add(ref types, typeof(int));
                }
                var motion = state.GetType().GetMethod("GetMotion", types).Invoke(state, parameters) as Motion;
                if (motion)
                {
                    SearchBlendTreeMotion(animator, motion, assetData);
                }
            }
        }
示例#19
0
        private static void AddAttachedAsset(Object component, Object value, AssetData assetData, bool isScene)
        {
            if (!value)
            {
                return;
            }

            if (value as MonoBehaviour)
            {
                value = MonoScript.FromMonoBehaviour(value as MonoBehaviour);

                if (isScene)
                {
                    AddSceneData(component, value, assetData);
                }
            }
            else if (value as ScriptableObject)
            {
                value = MonoScript.FromScriptableObject(value as ScriptableObject);

                if (isScene)
                {
                    AddSceneData(component, value, assetData);
                }
            }
            else if (isScene && PrefabUtility.GetPrefabType(value) == PrefabType.PrefabInstance)
            {
                var name       = "";
                var gameObject = GetGameObject(component, value);

                if (gameObject)
                {
                    name = GetName(PrefabUtility.FindPrefabRoot(gameObject).transform);
                }

                value = PrefabUtility.GetPrefabParent(value);
                if (string.IsNullOrEmpty(name))
                {
                    name = value.name;
                }

                assetData.sceneData.Add(new SceneData
                {
                    name     = name,
                    typeName = value.GetType().FullName,
                    guid     = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value))
                });
            }
            else if (isScene)
            {
                AddSceneData(component, value, assetData);
            }

            var path = AssetDatabase.GetAssetPath(value);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var guid = AssetDatabase.AssetPathToGUID(path);

            if (!assetData.reference.Contains(guid))
            {
                assetData.reference.Add(guid);
            }
        }
示例#20
0
        private static void SearchBlendTreeMotion(AnimatorController animator, Motion motion, AssetData assetData)
        {
            AddAttachedAsset(animator, motion, assetData, false);

            var blendTree = motion as BlendTree;

            if (!blendTree)
            {
                return;
            }
            int childCount = 0;

            if (isUnity41)
            {
                childCount = (int)blendTree.GetType().GetMethod("GetChildCount").Invoke(blendTree, new object[0]);
            }
            else
            {
                childCount = (int)blendTree.GetType().GetProperty("childCount").GetValue(blendTree, new object[0]);
            }
            for (var i = 0; i < childCount; i++)
            {
                SearchBlendTreeMotion(animator, blendTree.GetMotion(i), assetData);
            }
        }
示例#21
0
 private static void AddReferenceForPrefab(AssetData assetData, Object obj, int depth = 0)
 {
     foreach (var o in EditorUtility.CollectDependencies(new[] { obj }))
     {
         if(o == null)continue;
         DisplayProgressBar(assetData.path + " - " + o.name, progress);
         AddReference(assetData, o, false);
     }
 }
示例#22
0
        private static void SearchBlendTreeMotion(AnimatorController animator, Motion motion, AssetData assetData)
        {
            AddAttachedAsset(animator, motion, assetData, false);

            var blendTree = motion as BlendTree;

            if (!blendTree) return;
            int childCount = 0;

            if (isUnity41)
            {
                childCount = (int)blendTree.GetType().GetMethod("GetChildCount").Invoke(blendTree, new object[0]);
            }
            else
            {
                childCount = (int)blendTree.GetType().GetProperty("childCount").GetValue(blendTree, new object[0]);
            }
            for (var i = 0; i < childCount; i++)
            {
                SearchBlendTreeMotion(animator, blendTree.GetMotion(i), assetData);
            }
        }
示例#23
0
        private static void AddReference(AssetData assetData, Object obj, bool isSceneObject)
        {
            var guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(obj));
            if (string.IsNullOrEmpty(guid))
                return;

            if (isSceneObject)
            {
                Transform transform = null;

                var go = obj as GameObject;

                if (go)
                    transform = go.transform;
                else
                {
                    //                        var component = o as Component;
                    //                        if (component)
                    //                            transform = component.transform;
                }

                if (transform == null)
                    return;

                assetData.sceneData.Add(new SceneData
                {
                    guid = guid,
                    name = GetPathName(transform),
                    typeName = obj.GetType().FullName
                });
            }
            else
            {
                if (string.IsNullOrEmpty(guid))
                    return;

                if (AssetDatabase.IsSubAsset(obj))
                {
                    var sub = new SubAssetData
                    {
                        name = obj.name,
                        guid = guid,
                        typeName = obj.GetType().FullName
                    };
                    if (assetData.subAssets.Count(s => s.guid == sub.guid && s.name == sub.name && s.typeName == sub.typeName) == 0)
                    {
                        assetData.subAssets.Add(sub);
                    }
                }
                else
                {
                    if (assetData.reference.Contains(guid) == false)
                        assetData.reference.Add(guid);
                }
            }
        }
示例#24
0
        public static void Build(string[] assetPaths, Action <AssetData[]> callback = null)
        {
            var result = new AssetData[0];

            for (var i = 0; i < assetPaths.Length; i++)
            {
                var assetPath = assetPaths[i];
                var assetData = new AssetData
                {
                    path = assetPath,
                    guid = AssetDatabase.AssetPathToGUID(assetPath)
                };

                var progress = (float)i / assetPaths.Length;
                switch (Path.GetExtension(assetPath))
                {
                case ".prefab":
                {
                    DisplayProgressBar(assetData.path, progress);
                    var prefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject;

                    var go = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
                    go.hideFlags = HideFlags.HideAndDontSave;

                    SearchGameObject(go, assetData);
                    Object.DestroyImmediate(go);
                }
                break;

                case ".unity":
                    DisplayProgressBar(assetData.path, progress);
                    if (EditorApplication.OpenScene(assetPath))
                    {
                        foreach (GameObject go in Object.FindObjectsOfType(typeof(GameObject)))
                        {
                            SearchGameObject(go, assetData, true);
                        }
                    }
                    break;

                case ".controller":
                    var animator =
                        (AnimatorController)
                        AssetDatabase.LoadAssetAtPath(assetPath, typeof(AnimatorController));
                    var layerCount = 0;
                    if (isUnity41)
                    {
                        layerCount = (int)animator.GetType().GetMethod("GetLayerCount").Invoke(animator, new object[0]);
                    }
                    else
                    {
                        layerCount = (int)animator.GetType().GetProperty("layerCount").GetValue(animator, new object[0]);
                    }
                    for (var j = 0; j < layerCount; j++)
                    {
                        StateMachine stateMachine = null;

                        if (isUnity41)
                        {
                            stateMachine =
                                (StateMachine)
                                animator.GetType()
                                .GetMethod("GetLayerStateMachine")
                                .Invoke(animator, new object[] { j });
                        }
                        else
                        {
                            var layer =
                                animator.GetType().GetMethod("GetLayer").Invoke(animator, new object[] { j });
                            stateMachine = (StateMachine)layer.GetType().GetProperty("stateMachine").GetValue(layer, new object[0]);
                        }
                        SearchMotion(animator, stateMachine, assetData);
                        var stateMachineCount = 0;
                        if (isUnity41)
                        {
                            stateMachineCount = (int)stateMachine.GetType().GetMethod("GetStateMachineCount").Invoke(stateMachine, new object[0]);
                        }
                        else
                        {
                            stateMachineCount =
                                (int)stateMachine.GetType().GetProperty("stateMachineCount").GetValue(stateMachine, new object[0]);
                        }

                        for (var s = 0; s < stateMachineCount; s++)
                        {
                            SearchMotion(animator, stateMachine.GetStateMachine(s), assetData);
                        }
                    }
                    break;

                case ".mat":

                    var material = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Material)) as Material;

                    AddAttachedAsset(material, material.shader, assetData, false);

                    var propertyCount = ShaderUtil.GetPropertyCount(material.shader);

                    for (var j = 0; j < propertyCount; j++)
                    {
                        if (ShaderUtil.GetPropertyType(material.shader, j) != ShaderUtil.ShaderPropertyType.TexEnv)
                        {
                            continue;
                        }
                        var propertyName = ShaderUtil.GetPropertyName(material.shader, j);
                        AddAttachedAsset(material, material.GetTexture(propertyName), assetData, false);
                    }
                    break;

                default:
                    SearchFieldAndProperty(AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)), assetData);
                    break;
                }
                ArrayUtility.Add(ref result, assetData);
            }
            callback(result);
            depths.Clear();
            EditorUtility.ClearProgressBar();
        }
示例#25
0
        private static void SearchField(Object component, object val, AssetData assetData, bool isScene)
        {
            var fields = val.GetType().GetFields(flags);
            foreach (var info in fields)
            {

                var isObject = info.FieldType.IsSubclassOf(typeof(Object)) ||
                               info.FieldType == typeof(Object) ||
                               info.FieldType.IsSerializable &&
                               info.FieldType.IsClass;

                if (!isObject || Ignore(val.GetType(), info.Name)) continue;

                var value = info.GetValue(val);
                if (value != null)
                {

                    AddAttachedAssets(component, value, assetData, isScene);

                    if (!depths.ContainsKey(value))
                    {
                        depths.Add(value, 0);
                    }

                    if (!ignoreTypes.Contains(value.GetType().Name) && depths[value]++ <= 100)
                    {
                        SearchField(component, value, assetData, isScene);
                    }
                }
            }
        }
示例#26
0
 private static void SearchFieldAndProperty(Object obj, AssetData assetData, bool isScene = false)
 {
     SearchFieldAndProperty(obj, obj, assetData, isScene);
 }
示例#27
0
 private static void AddReferenceForObject(AssetData assetData, Object obj, bool isSceneObject = false)
 {
     AddReference(assetData, obj, isSceneObject);
     foreach (var o in EditorUtility.CollectDependencies(new[] { obj }))
     {
         AddReference(assetData, o, isSceneObject);
     }
 }