Beispiel #1
0
    //递归枚举通过这个目录读出来的某个GObject以及其子节的gameobject
    public static IEnumerable <GameObject> EunmAllGameObjectRecursiveAtPath(string Path)
    {
        if (Path.Contains(".asset"))
        {
            yield break;
        }
        var objects = AssetDatabase.LoadAssetAtPath(Path, typeof(GameObject));


        if (objects != null)
        {
            if (objects.GetType().ToString() == "UnityEngine.GameObject")
            {
                GameObject mpGameObject = objects as GameObject;
                {
                    // foreach(var aa in EnumAssets.EnumGameObjectRecursive(mpGameObject))
                    var __enumerator13 = (EnumAssets.EnumGameObjectRecursive(mpGameObject)).GetEnumerator();
                    while (__enumerator13.MoveNext())
                    {
                        var aa = __enumerator13.Current;
                        {
                            if (aa != null)
                            {
                                yield return(aa);
                            }
                        }
                    }
                }
            }
        }

        yield break;
    }
Beispiel #2
0
    //递归枚举GameObject以及其子节点所依赖的gameobject
    public static IEnumerable <GameObject> EnumAllGameObjectDependenciesRecursive(IEnumerable <UnityEngine.Object> gos)
    {
        int c          = gos.Count();
        var modelArray = new string[c];
        int i          = 0;
        {
            // foreach(var go in gos)
            var __enumerator14 = (gos).GetEnumerator();
            while (__enumerator14.MoveNext())
            {
                var go = __enumerator14.Current;
                {
                    modelArray[i++] = AssetDatabase.GetAssetPath(go.GetInstanceID());
                }
            }
        }
        string log       = "";
        var    dep       = AssetDatabase.GetDependencies(modelArray);
        var    processed = 0;
        var    count     = dep.Length;

        for (i = 0; i < count; i++)
        {
            var path = dep[i];

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

            if (path.Contains(".asset"))
            {
                continue;
            }

            var objects = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));

            if (objects != null)
            {
                GameObject mpGameObject = objects as GameObject;
                var        temp         = EnumAssets.EnumGameObjectRecursive(mpGameObject);
                {
                    // foreach(var aa in temp)
                    var __enumerator15 = (temp).GetEnumerator();
                    while (__enumerator15.MoveNext())
                    {
                        var aa = __enumerator15.Current;
                        {
                            if (aa != null)
                            {
                                yield return(aa);
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #3
0
    private static void getPath(string path)
    {
        List <string> mpathList = new List <string>();

        if (path != null)
        {
            string[] f1 = Directory.GetFiles(path, "*");
            ;
            string[] d1;
            {
                var __array1       = f1;
                var __arrayLength1 = __array1.Length;
                for (int __i1 = 0; __i1 < __arrayLength1; ++__i1)
                {
                    var f11 = (string)__array1[__i1];
                    {
                        string[] s   = f11.Split(new char[] { '\\' });
                        string   sss = "";
                        for (int i = 4; i < s.Length; i++)
                        {
                            if (i != s.Length - 1)
                            {
                                sss += s[i];
                                sss += '/';
                            }
                            else
                            {
                                sss += s[i];
                            }
                        }
                        if (!sss.Contains("meta") && sss.Contains("prefab"))
                        {
                            mpathList.Add(sss);
                        }
                    }
                }
            }
            d1 = Directory.GetDirectories(path);
            {
                var __array2       = d1;
                var __arrayLength2 = __array2.Length;
                for (int __i2 = 0; __i2 < __arrayLength2; ++__i2)
                {
                    var d11 = (string)__array2[__i2];
                    {
                        getPath(d11);
                    }
                }
            }
        }
        {
            var __list5      = mpathList;
            var __listCount5 = __list5.Count;
            for (int __i5 = 0; __i5 < __listCount5; ++__i5)
            {
                var data = __list5[__i5];
                {
                    int k = 0;
                    UnityEngine.Object[] objects = AssetDatabase.LoadAllAssetsAtPath(data);

                    foreach (var VARIABLE in objects)
                    {
                        if (objects != null && VARIABLE != null)
                        {
                            EditorUtility.DisplayProgressBar("ShadowsCloseTools", VARIABLE.name, k * 1.0f / objects.Length);
                        }
                        if (objects != null && VARIABLE != null)
                        {
                            if (VARIABLE.GetType().ToString() == "UnityEngine.GameObject")
                            {
                                GameObject mpGameObject = VARIABLE as GameObject;
                                foreach (var aa in EnumAssets.EnumGameObjectRecursive(mpGameObject))
                                {
                                    if (aa.GetComponent <Renderer>() != null)
                                    {
                                        var MymeshRenderer = aa.GetComponent <Renderer>();
                                        MymeshRenderer.castShadows    = false;
                                        MymeshRenderer.receiveShadows = false;
                                    }
                                }
                            }
                        }
                        k++;
                    }
                }
            }
        }
        EditorUtility.ClearProgressBar();
        AssetDatabase.Refresh();
    }
Beispiel #4
0
        private static void getPath(string path)
        {
            List <string> fbxList    = new List <string>();
            List <string> PrefabList = new List <string>();

            if (path != null)
            {
                string[] f1 = Directory.GetFiles(path, "*");

                string[] d1;
                {
                    var __array1       = f1;
                    var __arrayLength1 = __array1.Length;
                    for (int __i1 = 0; __i1 < __arrayLength1; ++__i1)
                    {
                        var f11 = (string)__array1[__i1];
                        {
                            string[] s   = f11.Split(new char[] { '\\' });
                            string   sss = "";
                            sss += "Assets/";
                            for (int i = 1; i < s.Length; i++)
                            {
                                if (i != s.Length - 1)
                                {
                                    sss += s[i];
                                    sss += '/';
                                }
                                else
                                {
                                    sss += s[i];
                                }
                            }

                            if (sss.Contains("prefab") && !sss.Contains("meta"))
                            {
                                PrefabList.Add(sss);
                            }
                        }
                    }
                }
                d1 = Directory.GetDirectories(path);
                {
                    var __array2       = d1;
                    var __arrayLength2 = __array2.Length;
                    for (int __i2 = 0; __i2 < __arrayLength2; ++__i2)
                    {
                        var d11 = (string)__array2[__i2];
                        {
                            getPath(d11);
                        }
                    }
                }
            }
            int k = 0;

            {
                var __list5      = PrefabList;
                var __listCount5 = __list5.Count;
                for (int __i5 = 0; __i5 < __listCount5; ++__i5)
                {
                    var data = __list5[__i5];
                    {
                        try
                        {
                            UnityEngine.Object objects = AssetDatabase.LoadAssetAtPath(data, typeof(UnityEngine.Object));
                            if (objects != null)
                            {
                                if (objects.GetType().ToString() == "UnityEngine.GameObject")
                                {
                                    if (objects != null && objects != null)
                                    {
                                        EditorUtility.DisplayProgressBar("OptimizingRes", objects.name,
                                                                         k * 1.0f / PrefabList.Count);
                                    }
                                    //   Debug.Log("正在优化" + data + "属性");
                                    GameObject mpGameObject = objects as GameObject;

                                    foreach (var aa in EnumAssets.EnumGameObjectRecursive(mpGameObject))
                                    {
                                        try
                                        {
                                            //修改animator
                                            if (aa.GetComponent <Animation>() != null)
                                            {
                                                Animation myAnimation = aa.GetComponent <Animation>();
                                                if (myAnimation.clip != null)
                                                {
                                                    Debug.Log(data + "去掉多余动画成功");
                                                    myAnimation.clip = null;
                                                }
                                                foreach (AnimationState state in myAnimation)
                                                {
                                                    Debug.Log(state.clip.name);
                                                    myAnimation.RemoveClip(state.name);
                                                }
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            throw;
                                        }
                                    }

                                    //  Debug.Log(data + "属性优化完毕!!");
                                }
                            }
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                        k++;
                    }
                }
            }
            EditorUtility.ClearProgressBar();
            AssetDatabase.Refresh();
        }