示例#1
0
        void ShowAnimatorController()
        {
            _controller = (RuntimeAnimatorController)CreateObjectField("animator", _controller, typeof(RuntimeAnimatorController));

            if (null != _controller)
            {
                EditorGUILayout.BeginHorizontal();
                CreateLabel("clip");
                CreateLabel("duration");
                CreateLabel("isloop");
                EditorGUILayout.EndHorizontal();

                if (_controller is UnityEditor.Animations.AnimatorController)
                {
                    UnityEditor.Animations.AnimatorController controller = _controller as UnityEditor.Animations.AnimatorController;
#if UNITY_4_6
                    ShowAnimatorControllerLayer(controller.GetLayer(0));
#endif

                    for (int i = 0; i < controller.layers.Length; i++)
                    {
                        ShowAnimatorControllerLayer(controller.layers[i]);
                    }
                }
                else if (_controller is AnimatorOverrideController)
                {
                    AnimatorOverrideController overrideController = _controller as AnimatorOverrideController;
                    //				AnimationClipPair[] clips = (AnimationClipPair[])_controller.GetType().BaseType.GetProperty("clips").GetValue(_controller, null);
                    //ShowAnimatorOverrideControllerClips(overrideController.clips);
                }
            }
        }
示例#2
0
    /// <summary>
    /// 动画控制器比较特殊,不能通过序列化得到
    /// </summary>
    /// <param name="info"></param>
    /// <param name="o"></param>
    private void AnalyzeObjectReference2(Object o, AssetBundle ab)
    {
        UnityEditor.Animations.AnimatorController ac = o as UnityEditor.Animations.AnimatorController;
        if (ac)
        {
#if UNITY_5 || UNITY_5_3_OR_NEWER
            foreach (var clip in ac.animationClips)
            {
                AnalyzeObjectReference(o, ab);
            }
#else
            List <State> list = new List <State>();
            for (int i = 0; i < ac.layerCount; i++)
            {
                AnimatorControllerLayer layer = ac.GetLayer(i);
                list.AddRange(AnimatorStateMachine_StatesRecursive(layer.stateMachine));
            }
            foreach (State state in list)
            {
                var clip = state.GetMotion() as AnimationClip;
                if (clip)
                {
                    AnalyzeObjectReference(clip, ab);
                }
            }
#endif
        }
    }
    private void FixPositions(GameObject gameObj, float deltaScaleX, float deltaScaleY)
    {
        Vector3 newPos = gameObj.transform.localPosition;

        newPos.x *= deltaScaleX;
        newPos.y *= deltaScaleY;
        gameObj.transform.localPosition = newPos;

        // fix Animation components
        Animation[] animations = gameObj.GetComponents <Animation>();
        foreach (Animation animation in animations)
        {
            foreach (AnimationState animState in animation)
            {
                if (animState.clip != null)
                {
                    this.FixAnimationClip(animState.clip, deltaScaleX, deltaScaleY);
                }
            }
        }

        // fix Animator components
        Animator[] animators = gameObj.GetComponents <Animator>();
        foreach (Animator animator in animators)
        {
            UnityEditor.Animations.AnimatorController animController = animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
        #if UNITY_5_PLUS
            for (int i = 0; i < animController.layers.Length; i++)
        #else
            for (int i = 0; i < animator.layerCount; i++)
        #endif
            {
            #if UNITY_5_PLUS
                UnityEditor.Animations.AnimatorStateMachine stateMachine = animController.layers[i].stateMachine;
                for (int j = 0; j < stateMachine.states.Length; j++)
            #else
                UnityEditor.Animations.AnimatorStateMachine stateMachine = animController.GetLayer(i).stateMachine;
                for (int j = 0; j < stateMachine.stateCount; j++)
            #endif
                {
                #if UNITY_5_PLUS
                    UnityEditor.Animations.ChildAnimatorState state = stateMachine.states[j];
                    Motion mtn = state.state.motion;
                #else
                    UnityEditor.Animations.AnimatorState state = stateMachine.GetState(j);
                    Motion mtn = state.GetMotion();
                #endif

                    if (mtn != null)
                    {
                        AnimationClip clip = mtn as AnimationClip;
                        this.FixAnimationClip(clip, deltaScaleX, deltaScaleY);
                    }
                }
            }
        }
    }
示例#4
0
    /// <summary>
    /// 动画控制器比较特殊,不能通过序列化得到
    /// </summary>
    /// <param name="info"></param>
    /// <param name="o"></param>
    private void SettingObjectReference2(UnityEngine.Object o)
    {
        UnityEditor.Animations.AnimatorController ac = o as UnityEditor.Animations.AnimatorController;
        if (ac)
        {
#if UNITY_5 || UNITY_5_3_OR_NEWER
            for (int i = 0; i < ac.animationClips.Length; i++)
            {
                var clip = ac.animationClips[i];
                if (clip)
                {
                    if (new_asset_obj_Dict.ContainsKey(clip))
                    {
                        ac.animationClips[i] = (AnimationClip)new_asset_obj_Dict[clip];
                    }
                    else
                    {
                        Object uo = GetUnityAssset(clip);
                        if (uo != null)
                        {
                            ac.animationClips[i] = (AnimationClip)uo;
                        }
                    }
                }
            }
#else
            List <State> list = new List <State>();
            for (int i = 0; i < ac.layerCount; i++)
            {
                AnimatorControllerLayer layer = ac.GetLayer(i);
                list.AddRange(AnimatorStateMachine_StatesRecursive(layer.stateMachine));
            }
            foreach (State state in list)
            {
                var clip = state.GetMotion() as AnimationClip;

                if (clip)
                {
                    if (new_asset_obj_Dict.ContainsKey(clip))
                    {
                        state.SetAnimationClip((AnimationClip)new_asset_obj_Dict[clip]);
                    }

                    else
                    {
                        Object uo = GetUnityAssset(clip);
                        if (uo != null)
                        {
                            state.SetAnimationClip((AnimationClip)uo);
                        }
                    }
                }
            }
#endif
        }
    }
示例#5
0
    void CheckResources()
    {
        ActiveTextures.Clear();
        ActiveMaterials.Clear();
        ActiveMeshDetails.Clear();

        Renderer[] renderers = FindObjects <Renderer>();

        //Debug.Log("Total renderers "+renderers.Length);
        foreach (Renderer renderer in renderers)
        {
            //Debug.Log("Renderer is "+renderer.name);
            foreach (Material material in renderer.sharedMaterials)
            {
                MaterialDetails tMaterialDetails = FindMaterialDetails(material);
                if (tMaterialDetails == null)
                {
                    tMaterialDetails          = new MaterialDetails();
                    tMaterialDetails.material = material;
                    ActiveMaterials.Add(tMaterialDetails);
                }
                tMaterialDetails.FoundInRenderers.Add(renderer);
            }

            if (renderer is SpriteRenderer)
            {
                SpriteRenderer tSpriteRenderer = (SpriteRenderer)renderer;

                if (tSpriteRenderer.sprite != null)
                {
                    var tSpriteTextureDetail = GetTextureDetail(tSpriteRenderer.sprite.texture, renderer);
                    if (!ActiveTextures.Contains(tSpriteTextureDetail))
                    {
                        ActiveTextures.Add(tSpriteTextureDetail);
                    }
                }
            }
        }

        if (IncludeGuiElements)
        {
            Graphic[] graphics = FindObjects <Graphic>();

            foreach (Graphic graphic in graphics)
            {
                if (graphic.mainTexture)
                {
                    var tSpriteTextureDetail = GetTextureDetail(graphic.mainTexture, graphic);
                    if (!ActiveTextures.Contains(tSpriteTextureDetail))
                    {
                        ActiveTextures.Add(tSpriteTextureDetail);
                    }
                }

                if (graphic.materialForRendering)
                {
                    MaterialDetails tMaterialDetails = FindMaterialDetails(graphic.materialForRendering);
                    if (tMaterialDetails == null)
                    {
                        tMaterialDetails          = new MaterialDetails();
                        tMaterialDetails.material = graphic.materialForRendering;
                        ActiveMaterials.Add(tMaterialDetails);
                    }
                    tMaterialDetails.FoundInGraphics.Add(graphic);
                }
            }
        }

        foreach (MaterialDetails tMaterialDetails in ActiveMaterials)
        {
            Material tMaterial = tMaterialDetails.material;
            if (tMaterial != null)
            {
                var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial });
                foreach (Object obj in dependencies)
                {
                    if (obj is Texture)
                    {
                        Texture tTexture       = obj as Texture;
                        var     tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMaterialDetails);
                        ActiveTextures.Add(tTextureDetail);
                    }
                }

                //if the texture was downloaded, it won't be included in the editor dependencies
                if (tMaterial.mainTexture != null && !dependencies.Contains(tMaterial.mainTexture))
                {
                    var tTextureDetail = GetTextureDetail(tMaterial.mainTexture, tMaterial, tMaterialDetails);
                    ActiveTextures.Add(tTextureDetail);
                }
            }
        }


        MeshFilter[] meshFilters = FindObjects <MeshFilter>();

        foreach (MeshFilter tMeshFilter in meshFilters)
        {
            Mesh tMesh = tMeshFilter.sharedMesh;
            if (tMesh != null)
            {
                MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                if (tMeshDetails == null)
                {
                    tMeshDetails      = new MeshDetails();
                    tMeshDetails.mesh = tMesh;
                    ActiveMeshDetails.Add(tMeshDetails);
                }
                tMeshDetails.FoundInMeshFilters.Add(tMeshFilter);
            }
        }

        SkinnedMeshRenderer[] skinnedMeshRenderers = FindObjects <SkinnedMeshRenderer>();

        foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers)
        {
            Mesh tMesh = tSkinnedMeshRenderer.sharedMesh;
            if (tMesh != null)
            {
                MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                if (tMeshDetails == null)
                {
                    tMeshDetails      = new MeshDetails();
                    tMeshDetails.mesh = tMesh;
                    ActiveMeshDetails.Add(tMeshDetails);
                }
                tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer);
            }
        }

        if (IncludeSpriteAnimations)
        {
            Animator[] animators = FindObjects <Animator>();
            foreach (Animator anim in animators)
            {
                                #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                UnityEditorInternal.AnimatorController ac = anim.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
                                #elif UNITY_5
                UnityEditor.Animations.AnimatorController ac = anim.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
                                #endif

                //Skip animators without layers, this can happen if they don't have an animator controller.
                if (!ac || ac.layers == null || ac.layers.Length == 0)
                {
                    continue;
                }

                for (int x = 0; x < anim.layerCount; x++)
                {
                                        #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                    UnityEditorInternal.StateMachine sm = ac.GetLayer(x).stateMachine;
                    int cnt = sm.stateCount;
                                        #elif UNITY_5
                    UnityEditor.Animations.AnimatorStateMachine sm = ac.layers[x].stateMachine;
                    int cnt = sm.states.Length;
                                        #endif

                    for (int i = 0; i < cnt; i++)
                    {
                                                #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                        UnityEditorInternal.State state = sm.GetState(i);
                        Motion m = state.GetMotion();
                                                #elif UNITY_5
                        UnityEditor.Animations.AnimatorState state = sm.states[i].state;
                        Motion m = state.motion;
                                                #endif
                        if (m != null)
                        {
                            AnimationClip clip = m as AnimationClip;

                            EditorCurveBinding[] ecbs = AnimationUtility.GetObjectReferenceCurveBindings(clip);

                            foreach (EditorCurveBinding ecb in ecbs)
                            {
                                if (ecb.propertyName == "m_Sprite")
                                {
                                    foreach (ObjectReferenceKeyframe keyframe in AnimationUtility.GetObjectReferenceCurve(clip, ecb))
                                    {
                                        Sprite tSprite = keyframe.value as Sprite;

                                        if (tSprite != null)
                                        {
                                            var tTextureDetail = GetTextureDetail(tSprite.texture, anim);
                                            if (!ActiveTextures.Contains(tTextureDetail))
                                            {
                                                ActiveTextures.Add(tTextureDetail);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if (IncludeScriptReferences)
        {
            MonoBehaviour[] scripts = FindObjects <MonoBehaviour>();
            foreach (MonoBehaviour script in scripts)
            {
                BindingFlags flags  = BindingFlags.Public | BindingFlags.Instance;                // only public non-static fields are bound to by Unity.
                FieldInfo[]  fields = script.GetType().GetFields(flags);

                foreach (FieldInfo field in fields)
                {
                    System.Type fieldType = field.FieldType;
                    if (fieldType == typeof(Sprite))
                    {
                        Sprite tSprite = field.GetValue(script) as Sprite;
                        if (tSprite != null)
                        {
                            var tSpriteTextureDetail = GetTextureDetail(tSprite.texture, script);
                            if (!ActiveTextures.Contains(tSpriteTextureDetail))
                            {
                                ActiveTextures.Add(tSpriteTextureDetail);
                            }
                        }
                    }
                }
            }
        }

        TotalTextureMemory = 0;
        foreach (TextureDetails tTextureDetails in ActiveTextures)
        {
            TotalTextureMemory += tTextureDetails.memSizeKB;
        }

        TotalMeshVertices = 0;
        foreach (MeshDetails tMeshDetails in ActiveMeshDetails)
        {
            TotalMeshVertices += tMeshDetails.mesh.vertexCount;
        }

        // Sort by size, descending
        ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeKB - details1.memSizeKB); });
        ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); });

        collectedInPlayingMode = Application.isPlaying;
    }
    void ListTextures()
    {
        textureListScrollPos = EditorGUILayout.BeginScrollView(textureListScrollPos);

        foreach (TextureDetails tDetails in ActiveTextures)
        {
            GUILayout.BeginHorizontal();
            Texture tex = new Texture();
            tex = tDetails.texture;
                        #if !UNITY_EDITOR_OSX
            if (tDetails.texture.GetType() == typeof(Texture2DArray) || tDetails.texture.GetType() == typeof(Cubemap))
            {
                        #else
            if (tDetails.texture.GetType() == typeof(Cubemap))
            {
                        #endif
                tex = AssetPreview.GetMiniThumbnail(tDetails.texture);
            }
            GUILayout.Box(tex, GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight));

            if (tDetails.instance == true)
            {
                GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f);
            }
            if (tDetails.isgui == true)
            {
                GUI.color = new Color(defColor.r, 0.95f, 0.8f, 1.0f);
            }
            if (tDetails.isSky)
            {
                GUI.color = new Color(0.9f, defColor.g, defColor.b, 1.0f);
            }
            if (GUILayout.Button(tDetails.texture.name, GUILayout.Width(150)))
            {
                SelectObject(tDetails.texture, ctrlPressed);
            }
            GUI.color = defColor;

            string sizeLabel = "" + tDetails.texture.width + "x" + tDetails.texture.height;
            if (tDetails.isCubeMap)
            {
                sizeLabel += "x6";
            }
                        #if !UNITY_EDITOR_OSX
            if (tDetails.texture.GetType() == typeof(Texture2DArray))
            {
                sizeLabel += "[]\n" + ((Texture2DArray)tDetails.texture).depth + "depths";
            }
                        #endif
            sizeLabel += " - " + tDetails.mipMapCount + "mip\n" + FormatSizeString(tDetails.memSizeKB) + " - " + tDetails.format;

            GUILayout.Label(sizeLabel, GUILayout.Width(120));

            if (GUILayout.Button(tDetails.FoundInMaterials.Count + " Mat", GUILayout.Width(50)))
            {
                SelectObjects(tDetails.FoundInMaterials, ctrlPressed);
            }

            HashSet <Object> FoundObjects = new HashSet <Object>();
            foreach (Renderer renderer in tDetails.FoundInRenderers)
            {
                FoundObjects.Add(renderer.gameObject);
            }
            foreach (Animator animator in tDetails.FoundInAnimators)
            {
                FoundObjects.Add(animator.gameObject);
            }
            foreach (Graphic graphic in tDetails.FoundInGraphics)
            {
                FoundObjects.Add(graphic.gameObject);
            }
            foreach (MonoBehaviour script in tDetails.FoundInScripts)
            {
                FoundObjects.Add(script.gameObject);
            }
            if (GUILayout.Button(FoundObjects.Count + " GO", GUILayout.Width(50)))
            {
                SelectObjects(new List <Object>(FoundObjects), ctrlPressed);
            }

            GUILayout.EndHorizontal();
        }
        if (ActiveTextures.Count > 0)
        {
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            //GUILayout.Box(" ",GUILayout.Width(ThumbnailWidth),GUILayout.Height(ThumbnailHeight));
            if (GUILayout.Button("Select \n All", GUILayout.Width(ThumbnailWidth * 2)))
            {
                List <Object> AllTextures = new List <Object>();
                foreach (TextureDetails tDetails in ActiveTextures)
                {
                    AllTextures.Add(tDetails.texture);
                }
                SelectObjects(AllTextures, ctrlPressed);
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.EndScrollView();
    }

    void ListMaterials()
    {
        materialListScrollPos = EditorGUILayout.BeginScrollView(materialListScrollPos);

        foreach (MaterialDetails tDetails in ActiveMaterials)
        {
            if (tDetails.material != null)
            {
                GUILayout.BeginHorizontal();

                GUILayout.Box(AssetPreview.GetAssetPreview(tDetails.material), GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight));

                if (tDetails.instance == true)
                {
                    GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f);
                }
                if (tDetails.isgui == true)
                {
                    GUI.color = new Color(defColor.r, 0.95f, 0.8f, 1.0f);
                }
                if (tDetails.isSky)
                {
                    GUI.color = new Color(0.9f, defColor.g, defColor.b, 1.0f);
                }
                if (GUILayout.Button(tDetails.material.name, GUILayout.Width(150)))
                {
                    SelectObject(tDetails.material, ctrlPressed);
                }
                GUI.color = defColor;

                string shaderLabel = tDetails.material.shader != null ? tDetails.material.shader.name : "no shader";
                GUILayout.Label(shaderLabel, GUILayout.Width(200));

                if (GUILayout.Button((tDetails.FoundInRenderers.Count + tDetails.FoundInGraphics.Count) + " GO", GUILayout.Width(50)))
                {
                    List <Object> FoundObjects = new List <Object>();
                    foreach (Renderer renderer in tDetails.FoundInRenderers)
                    {
                        FoundObjects.Add(renderer.gameObject);
                    }
                    foreach (Graphic graphic in tDetails.FoundInGraphics)
                    {
                        FoundObjects.Add(graphic.gameObject);
                    }
                    SelectObjects(FoundObjects, ctrlPressed);
                }


                GUILayout.EndHorizontal();
            }
        }
        EditorGUILayout.EndScrollView();
    }

    void ListMeshes()
    {
        meshListScrollPos = EditorGUILayout.BeginScrollView(meshListScrollPos);

        foreach (MeshDetails tDetails in ActiveMeshDetails)
        {
            if (tDetails.mesh != null)
            {
                GUILayout.BeginHorizontal();
                string name = tDetails.mesh.name;
                if (name == null || name.Count() < 1)
                {
                    name = tDetails.FoundInMeshFilters[0].gameObject.name;
                }
                if (tDetails.instance == true)
                {
                    GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f);
                }
                if (GUILayout.Button(name, GUILayout.Width(150)))
                {
                    SelectObject(tDetails.mesh, ctrlPressed);
                }
                GUI.color = defColor;
                string sizeLabel = "" + tDetails.mesh.vertexCount + " vert";

                GUILayout.Label(sizeLabel, GUILayout.Width(100));


                if (GUILayout.Button(tDetails.FoundInMeshFilters.Count + " GO", GUILayout.Width(50)))
                {
                    List <Object> FoundObjects = new List <Object>();
                    foreach (MeshFilter meshFilter in tDetails.FoundInMeshFilters)
                    {
                        FoundObjects.Add(meshFilter.gameObject);
                    }
                    SelectObjects(FoundObjects, ctrlPressed);
                }
                if (tDetails.FoundInSkinnedMeshRenderer.Count > 0)
                {
                    if (GUILayout.Button(tDetails.FoundInSkinnedMeshRenderer.Count + " skinned mesh GO", GUILayout.Width(140)))
                    {
                        List <Object> FoundObjects = new List <Object> ();
                        foreach (SkinnedMeshRenderer skinnedMeshRenderer in tDetails.FoundInSkinnedMeshRenderer)
                        {
                            FoundObjects.Add(skinnedMeshRenderer.gameObject);
                        }
                        SelectObjects(FoundObjects, ctrlPressed);
                    }
                }
                else
                {
                    GUI.color = new Color(defColor.r, defColor.g, defColor.b, 0.5f);
                    GUILayout.Label("   0 skinned mesh");
                    GUI.color = defColor;
                }


                GUILayout.EndHorizontal();
            }
        }
        EditorGUILayout.EndScrollView();
    }

    void ListMissing()
    {
        missingListScrollPos = EditorGUILayout.BeginScrollView(missingListScrollPos);
        foreach (MissingGraphic dMissing in MissingObjects)
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(dMissing.name, GUILayout.Width(150)))
            {
                SelectObject(dMissing.Object, ctrlPressed);
            }
            GUILayout.Label("missing ", GUILayout.Width(48));
            switch (dMissing.type)
            {
            case "mesh":
                GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f);
                break;

            case "sprite":
                GUI.color = new Color(defColor.r, 0.8f, 0.8f, 1.0f);
                break;

            case "material":
                GUI.color = new Color(0.8f, defColor.g, 0.8f, 1.0f);
                break;
            }
            GUILayout.Label(dMissing.type);
            GUI.color = defColor;
            GUILayout.EndHorizontal();
        }
        EditorGUILayout.EndScrollView();
    }

    string FormatSizeString(int memSizeKB)
    {
        if (memSizeKB < 1024)
        {
            return("" + memSizeKB + "k");
        }
        else
        {
            float memSizeMB = ((float)memSizeKB) / 1024.0f;
            return(memSizeMB.ToString("0.00") + "Mb");
        }
    }

    TextureDetails FindTextureDetails(Texture tTexture)
    {
        foreach (TextureDetails tTextureDetails in ActiveTextures)
        {
            if (tTextureDetails.texture == tTexture)
            {
                return(tTextureDetails);
            }
        }
        return(null);
    }

    MaterialDetails FindMaterialDetails(Material tMaterial)
    {
        foreach (MaterialDetails tMaterialDetails in ActiveMaterials)
        {
            if (tMaterialDetails.material == tMaterial)
            {
                return(tMaterialDetails);
            }
        }
        return(null);
    }

    MeshDetails FindMeshDetails(Mesh tMesh)
    {
        foreach (MeshDetails tMeshDetails in ActiveMeshDetails)
        {
            if (tMeshDetails.mesh == tMesh)
            {
                return(tMeshDetails);
            }
        }
        return(null);
    }

    void CheckResources()
    {
        ActiveTextures.Clear();
        ActiveMaterials.Clear();
        ActiveMeshDetails.Clear();
        MissingObjects.Clear();
        thingsMissing = false;

        Renderer[] renderers = FindObjects <Renderer>();

        MaterialDetails skyMat = new MaterialDetails();

        skyMat.material = RenderSettings.skybox;
        skyMat.isSky    = true;
        ActiveMaterials.Add(skyMat);

        //Debug.Log("Total renderers "+renderers.Length);
        foreach (Renderer renderer in renderers)
        {
            //Debug.Log("Renderer is "+renderer.name);
            foreach (Material material in renderer.sharedMaterials)
            {
                MaterialDetails tMaterialDetails = FindMaterialDetails(material);
                if (tMaterialDetails == null)
                {
                    tMaterialDetails          = new MaterialDetails();
                    tMaterialDetails.material = material;
                    ActiveMaterials.Add(tMaterialDetails);
                }
                tMaterialDetails.FoundInRenderers.Add(renderer);
            }

            if (renderer is SpriteRenderer)
            {
                SpriteRenderer tSpriteRenderer = (SpriteRenderer)renderer;

                if (tSpriteRenderer.sprite != null)
                {
                    var tSpriteTextureDetail = GetTextureDetail(tSpriteRenderer.sprite.texture, renderer);
                    if (!ActiveTextures.Contains(tSpriteTextureDetail))
                    {
                        ActiveTextures.Add(tSpriteTextureDetail);
                    }
                }
                else if (tSpriteRenderer.sprite == null)
                {
                    MissingGraphic tMissing = new MissingGraphic();
                    tMissing.Object = tSpriteRenderer.transform;
                    tMissing.type   = "sprite";
                    tMissing.name   = tSpriteRenderer.transform.name;
                    MissingObjects.Add(tMissing);
                    thingsMissing = true;
                }
            }
        }

        if (IncludeGuiElements)
        {
            Graphic[] graphics = FindObjects <Graphic>();

            foreach (Graphic graphic in graphics)
            {
                if (graphic.mainTexture)
                {
                    var tSpriteTextureDetail = GetTextureDetail(graphic.mainTexture, graphic);
                    if (!ActiveTextures.Contains(tSpriteTextureDetail))
                    {
                        ActiveTextures.Add(tSpriteTextureDetail);
                    }
                }

                if (graphic.materialForRendering)
                {
                    MaterialDetails tMaterialDetails = FindMaterialDetails(graphic.materialForRendering);
                    if (tMaterialDetails == null)
                    {
                        tMaterialDetails          = new MaterialDetails();
                        tMaterialDetails.material = graphic.materialForRendering;
                        tMaterialDetails.isgui    = true;
                        ActiveMaterials.Add(tMaterialDetails);
                    }
                    tMaterialDetails.FoundInGraphics.Add(graphic);
                }
            }
        }

        foreach (MaterialDetails tMaterialDetails in ActiveMaterials)
        {
            Material tMaterial = tMaterialDetails.material;
            if (tMaterial != null)
            {
                var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial });
                foreach (Object obj in dependencies)
                {
                    if (obj is Texture)
                    {
                        Texture tTexture       = obj as Texture;
                        var     tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMaterialDetails);
                        tTextureDetail.isSky    = tMaterialDetails.isSky;
                        tTextureDetail.instance = tMaterialDetails.instance;
                        tTextureDetail.isgui    = tMaterialDetails.isgui;
                        ActiveTextures.Add(tTextureDetail);
                    }
                }

                //if the texture was downloaded, it won't be included in the editor dependencies
                if (tMaterial.HasProperty("_MainTex"))
                {
                    if (tMaterial.mainTexture != null && !dependencies.Contains(tMaterial.mainTexture))
                    {
                        var tTextureDetail = GetTextureDetail(tMaterial.mainTexture, tMaterial, tMaterialDetails);
                        ActiveTextures.Add(tTextureDetail);
                    }
                }
            }
        }


        MeshFilter[] meshFilters = FindObjects <MeshFilter>();

        foreach (MeshFilter tMeshFilter in meshFilters)
        {
            Mesh tMesh = tMeshFilter.sharedMesh;
            if (tMesh != null)
            {
                MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                if (tMeshDetails == null)
                {
                    tMeshDetails      = new MeshDetails();
                    tMeshDetails.mesh = tMesh;
                    ActiveMeshDetails.Add(tMeshDetails);
                }
                tMeshDetails.FoundInMeshFilters.Add(tMeshFilter);
            }
            else if (tMesh == null && tMeshFilter.transform.GetComponent("TextContainer") == null)
            {
                MissingGraphic tMissing = new MissingGraphic();
                tMissing.Object = tMeshFilter.transform;
                tMissing.type   = "mesh";
                tMissing.name   = tMeshFilter.transform.name;
                MissingObjects.Add(tMissing);
                thingsMissing = true;
            }
            if (tMeshFilter.transform.GetComponent <MeshRenderer>().sharedMaterial == null)
            {
                MissingGraphic tMissing = new MissingGraphic();
                tMissing.Object = tMeshFilter.transform;
                tMissing.type   = "material";
                tMissing.name   = tMeshFilter.transform.name;
                MissingObjects.Add(tMissing);
                thingsMissing = true;
            }
        }

        SkinnedMeshRenderer[] skinnedMeshRenderers = FindObjects <SkinnedMeshRenderer>();

        foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers)
        {
            Mesh tMesh = tSkinnedMeshRenderer.sharedMesh;
            if (tMesh != null)
            {
                MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                if (tMeshDetails == null)
                {
                    tMeshDetails      = new MeshDetails();
                    tMeshDetails.mesh = tMesh;
                    ActiveMeshDetails.Add(tMeshDetails);
                }
                tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer);
            }
            else if (tMesh == null)
            {
                MissingGraphic tMissing = new MissingGraphic();
                tMissing.Object = tSkinnedMeshRenderer.transform;
                tMissing.type   = "mesh";
                tMissing.name   = tSkinnedMeshRenderer.transform.name;
                MissingObjects.Add(tMissing);
                thingsMissing = true;
            }
            if (tSkinnedMeshRenderer.sharedMaterial == null)
            {
                MissingGraphic tMissing = new MissingGraphic();
                tMissing.Object = tSkinnedMeshRenderer.transform;
                tMissing.type   = "material";
                tMissing.name   = tSkinnedMeshRenderer.transform.name;
                MissingObjects.Add(tMissing);
                thingsMissing = true;
            }
        }

        if (IncludeSpriteAnimations)
        {
            Animator[] animators = FindObjects <Animator>();
            foreach (Animator anim in animators)
            {
                                #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                UnityEditorInternal.AnimatorController ac = anim.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
                                #elif UNITY_5
                UnityEditor.Animations.AnimatorController ac = anim.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
                                #endif

                //Skip animators without layers, this can happen if they don't have an animator controller.
                if (!ac || ac.layers == null || ac.layers.Length == 0)
                {
                    continue;
                }

                for (int x = 0; x < anim.layerCount; x++)
                {
                                        #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                    UnityEditorInternal.StateMachine sm = ac.GetLayer(x).stateMachine;
                    int cnt = sm.stateCount;
                                        #elif UNITY_5
                    UnityEditor.Animations.AnimatorStateMachine sm = ac.layers[x].stateMachine;
                    int cnt = sm.states.Length;
                                        #endif

                    for (int i = 0; i < cnt; i++)
                    {
                                                #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                        UnityEditorInternal.State state = sm.GetState(i);
                        Motion m = state.GetMotion();
                                                #elif UNITY_5
                        UnityEditor.Animations.AnimatorState state = sm.states[i].state;
                        Motion m = state.motion;
                                                #endif
                        if (m != null)
                        {
                            AnimationClip clip = m as AnimationClip;

                            if (clip != null)
                            {
                                EditorCurveBinding[] ecbs = AnimationUtility.GetObjectReferenceCurveBindings(clip);

                                foreach (EditorCurveBinding ecb in ecbs)
                                {
                                    if (ecb.propertyName == "m_Sprite")
                                    {
                                        foreach (ObjectReferenceKeyframe keyframe in AnimationUtility.GetObjectReferenceCurve(clip, ecb))
                                        {
                                            Sprite tSprite = keyframe.value as Sprite;

                                            if (tSprite != null)
                                            {
                                                var tTextureDetail = GetTextureDetail(tSprite.texture, anim);
                                                if (!ActiveTextures.Contains(tTextureDetail))
                                                {
                                                    ActiveTextures.Add(tTextureDetail);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if (IncludeScriptReferences)
        {
            MonoBehaviour[] scripts = FindObjects <MonoBehaviour>();
            foreach (MonoBehaviour script in scripts)
            {
                BindingFlags flags  = BindingFlags.Public | BindingFlags.Instance;                // only public non-static fields are bound to by Unity.
                FieldInfo[]  fields = script.GetType().GetFields(flags);

                foreach (FieldInfo field in fields)
                {
                    System.Type fieldType = field.FieldType;
                    if (fieldType == typeof(Sprite))
                    {
                        Sprite tSprite = field.GetValue(script) as Sprite;
                        if (tSprite != null)
                        {
                            var tSpriteTextureDetail = GetTextureDetail(tSprite.texture, script);
                            if (!ActiveTextures.Contains(tSpriteTextureDetail))
                            {
                                ActiveTextures.Add(tSpriteTextureDetail);
                            }
                        }
                    }
                    if (fieldType == typeof(Mesh))
                    {
                        Mesh tMesh = field.GetValue(script) as Mesh;
                        if (tMesh != null)
                        {
                            MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                            if (tMeshDetails == null)
                            {
                                tMeshDetails          = new MeshDetails();
                                tMeshDetails.mesh     = tMesh;
                                tMeshDetails.instance = true;
                                ActiveMeshDetails.Add(tMeshDetails);
                            }
                        }
                    }
                    if (fieldType == typeof(Material))
                    {
                        Material tMaterial = field.GetValue(script) as Material;
                        if (tMaterial != null)
                        {
                            MaterialDetails tMatDetails = FindMaterialDetails(tMaterial);
                            if (tMatDetails == null)
                            {
                                tMatDetails          = new MaterialDetails();
                                tMatDetails.instance = true;
                                tMatDetails.material = tMaterial;
                                if (!ActiveMaterials.Contains(tMatDetails))
                                {
                                    ActiveMaterials.Add(tMatDetails);
                                }
                            }
                            if (tMaterial.mainTexture)
                            {
                                var tSpriteTextureDetail = GetTextureDetail(tMaterial.mainTexture);
                                if (!ActiveTextures.Contains(tSpriteTextureDetail))
                                {
                                    ActiveTextures.Add(tSpriteTextureDetail);
                                }
                            }
                            var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial });
                            foreach (Object obj in dependencies)
                            {
                                if (obj is Texture)
                                {
                                    Texture tTexture       = obj as Texture;
                                    var     tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMatDetails);
                                    if (!ActiveTextures.Contains(tTextureDetail))
                                    {
                                        ActiveTextures.Add(tTextureDetail);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        TotalTextureMemory = 0;
        foreach (TextureDetails tTextureDetails in ActiveTextures)
        {
            TotalTextureMemory += tTextureDetails.memSizeKB;
        }

        TotalMeshVertices = 0;
        foreach (MeshDetails tMeshDetails in ActiveMeshDetails)
        {
            TotalMeshVertices += tMeshDetails.mesh.vertexCount;
        }

        // Sort by size, descending
        ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeKB - details1.memSizeKB); });
        ActiveTextures = ActiveTextures.Distinct().ToList();
        ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); });

        collectedInPlayingMode = Application.isPlaying;
    }