示例#1
0
        private static void GetDependantAssets(Component asset, List <Component> assets, List <Component> transforms, List <Component> containerRelated)
        {
            if (asset != null && !assets.Contains(asset))
            {
                assets.Add(asset);
                switch (asset.classID1)
                {
                case UnityClassID.Animator:
                    Animator animator = (Animator)asset;
                    GetDependantAssets(animator.m_Avatar.asset, assets, transforms, containerRelated);
                    GetDependantAssets(animator.m_Controller.asset, assets, transforms, containerRelated);
                    foreach (Component ren in containerRelated)
                    {
                        GetDependantAssets(ren, assets, null, null);
                        if (ren is MeshRenderer)
                        {
                            MeshRenderer meshR   = (MeshRenderer)ren;
                            PPtr <Mesh>  meshPtr = Operations.GetMeshPtr(meshR);
                            if (meshPtr != null)
                            {
                                if (meshPtr.m_FileID != 0)
                                {
                                    Component found = assets.Find
                                                      (
                                        delegate(Component c)
                                    {
                                        if (c is ExternalAsset)
                                        {
                                            ExternalAsset e = (ExternalAsset)c;
                                            return(e.FileID == meshPtr.m_FileID && e.PathID == meshPtr.m_PathID);
                                        }
                                        return(false);
                                    }
                                                      );
                                    if (found == null)
                                    {
                                        ExternalAsset extMesh = new ExternalAsset();
                                        extMesh.FileID = meshPtr.m_FileID;
                                        extMesh.PathID = meshPtr.m_PathID;
                                        assets.Add(extMesh);
                                    }
                                }
                                else if (meshPtr.instance != null && !assets.Contains(meshPtr.instance))
                                {
                                    assets.Add(meshPtr.instance);
                                }
                            }
                            foreach (PPtr <Material> matPtr in meshR.m_Materials)
                            {
                                if (!assets.Contains(matPtr.asset))
                                {
                                    GetDependantAssets(matPtr.asset, assets, null, null);
                                }
                            }
                        }
                    }
                    assets.Sort
                    (
                        delegate(Component c1, Component c2)
                    {
                        if (c1 is ExternalAsset)
                        {
                            ExternalAsset e1 = (ExternalAsset)c1;
                            if (c2 is ExternalAsset)
                            {
                                ExternalAsset e2 = (ExternalAsset)c2;
                                return(e1.FileID != e2.FileID ? e1.FileID.CompareTo(e2.FileID)
                                                                                : e1.PathID.CompareTo(e2.PathID));
                            }
                            return(-1);
                        }
                        else if (c2 is ExternalAsset)
                        {
                            return(1);
                        }
                        return(c1.pathID.CompareTo(c2.pathID));
                    }
                    );
                    break;

                case UnityClassID.Avatar:
                    break;

                case UnityClassID.AnimatorController:
                    AnimatorController aCon = (AnimatorController)asset;
                    for (int i = 0; i < aCon.m_AnimationClips.Count; i++)
                    {
                        assets.Add(aCon.m_AnimationClips[i].asset);
                        containerRelated.Add(aCon.m_AnimationClips[i].asset);
                    }
                    break;

                case UnityClassID.AnimationClip:
                    break;

                case UnityClassID.GameObject:
                    GameObject gameObj = (GameObject)asset;
                    animator = null;
                    foreach (var compPair in gameObj.m_Component)
                    {
                        switch (compPair.Key)
                        {
                        case UnityClassID.Transform:
                            Transform trans = (Transform)compPair.Value.instance;
                            transforms.Add(trans);
                            foreach (Transform child in trans)
                            {
                                GetDependantAssets(child.m_GameObject.asset, assets, transforms, containerRelated);
                            }
                            break;

                        case UnityClassID.Animator:
                            animator = (Animator)compPair.Value.asset;
                            break;

                        case UnityClassID.MeshRenderer:
                        case UnityClassID.MeshFilter:
                        case UnityClassID.SkinnedMeshRenderer:
                            containerRelated.Add(compPair.Value.asset);
                            break;

                        case UnityClassID.MonoBehaviour:
                            GetDependantAssets(compPair.Value.asset, assets, transforms, containerRelated);
                            break;

                        default:
                            if (!assets.Contains(compPair.Value.asset))
                            {
                                assets.Add(compPair.Value.asset);
                            }
                            break;
                        }
                    }
                    if (animator != null)
                    {
                        foreach (Component trans in transforms)
                        {
                            GetDependantAssets(trans, assets, null, null);
                        }
                        GetDependantAssets(animator, assets, transforms, containerRelated);
                    }
                    break;

                case UnityClassID.Light:
                    break;

                default:
                    if (asset.classID2 == UnityClassID.MonoBehaviour)
                    {
                        MonoBehaviour monoB = (MonoBehaviour)asset;
                        if (!assets.Contains(monoB.m_MonoScript.asset))
                        {
                            assets.Add(monoB.m_MonoScript.asset);
                        }
                    }
                    break;

                case UnityClassID.MonoScript:
                    break;

                case UnityClassID.Transform:
                    break;

                case UnityClassID.MeshRenderer:
                case UnityClassID.MeshFilter:
                case UnityClassID.SkinnedMeshRenderer:
                    break;

                case UnityClassID.Material:
                    Material mat = (Material)asset;
                    foreach (var texVal in mat.m_SavedProperties.m_TexEnvs)
                    {
                        GetDependantAssets(texVal.Value.m_Texture.asset, assets, transforms, containerRelated);
                    }
                    if (mat.m_Shader.m_FileID != 0)
                    {
                        AddExternalAsset(assets, mat.m_Shader);
                    }
                    else if (mat.m_Shader.instance != null)
                    {
                        GetDependantAssets(mat.m_Shader.asset, assets, transforms, containerRelated);
                    }
                    break;

                case UnityClassID.Shader:
                    Shader shader = (Shader)asset;
                    foreach (PPtr <Shader> dep in shader.m_Dependencies)
                    {
                        if (dep.m_FileID != 0)
                        {
                            AddExternalAsset(assets, dep);
                        }
                        else if (dep.asset != null)
                        {
                            GetDependantAssets(dep.asset, assets, transforms, containerRelated);
                        }
                    }
                    break;

                case UnityClassID.Sprite:
                    assets.Remove(asset);
                    Sprite sprite = (Sprite)asset;
                    assets.Add(sprite.m_RD.texture.asset);
                    assets.Add(sprite);
                    break;

                case UnityClassID.Texture2D:
                    break;
                }
            }
        }