static void Apply(GameObject gameObject)
        {
            gameObject = PrefabUtility.FindPrefabRoot(gameObject);

            var pi = gameObject.GetComponent <PEPrefabScript>();

            if (pi == null)
            {
                DefaultApply(gameObject);
                PEUtils.DoAutoSave();
            }
            else
            {
                PEUtils.DoApply(pi);
            }
        }
Ejemplo n.º 2
0
        public void CheckPrefab(params string[] paths)
        {
            var i            = 0;
            var prefabsPaths = paths.Where(p => p.EndsWith(".prefab")).ToArray();

            foreach (var path in prefabsPaths)
            {
                if (prefabsPaths.Length > 5 && i++ % 50 == 0)
                {
                    EditorUtility.DisplayProgressBar("Checking prefab dependencies", path, i / (float)prefabsPaths.Length);
                }

                if (prefabsPaths.Length > 5 && !canPrefabContainsNestedInstances(path))
                {
                    continue;
                }

                CheckPrefab(AssetDatabase.AssetPathToGUID(path), PEUtils.GetAssetByPath <GameObject>(path));

                if (i % 100 != 0)
                {
                    continue;
                }

#if UNITY_5
                EditorUtility.UnloadUnusedAssetsImmediate();
#else
                EditorUtility.UnloadUnusedAssets();
#endif
            }

            foreach (var path in paths.Where(p => !p.EndsWith(".prefab")))
            {
                if (!modelPathToApply.Contains(path))
                {
                    continue;
                }

                var importer = AssetImporter.GetAtPath(path);

                if (!(importer is ModelImporter))
                {
                    continue;
                }

                var asset = PEUtils.GetAssetByPath <GameObject>(path);
                if (asset == null)
                {
                    continue;
                }

                var prefabScript = asset.GetComponent <PEPrefabScript>();
                if (prefabScript == null)
                {
                    continue;
                }

                modelPathToApply.Remove(path);

                if (PEPrefs.DebugLevel > 0)
                {
                    Debug.Log("Applying " + path);
                }
                prefabScript.Prefab = asset;
                prefabScript.BuildLinks();
                EditorApplication.delayCall += () => PEUtils.DoApply(prefabScript);
            }

            EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 3
0
        public void CheckPrefab(params string[] paths)
        {
            paths = paths.Where(p => !PathFilter(p)).ToArray();
            var i = 0;
            var t = paths.Length;

            foreach (var path in paths)
            {
                var importer = AssetImporter.GetAtPath(path);
                var p        = (float)i++ / (float)t;

                if (importer is ModelImporter)
                {
                    if (!modelPathToApply.Contains(path))
                    {
                        continue;
                    }

                    var asset = PEUtils.GetAssetByPath <GameObject>(path);
                    if (asset == null)
                    {
                        continue;
                    }

                    var prefabScript = asset.GetComponent <PEPrefabScript>();
                    if (prefabScript == null)
                    {
                        continue;
                    }

                    modelPathToApply.Remove(path);

                    if (PEPrefs.DebugLevel > 0)
                    {
                        Debug.Log("Applying " + path);
                    }
                    prefabScript.Prefab = asset;
                    prefabScript.BuildLinks();
                    EditorApplication.delayCall += () => PEUtils.DoApply(prefabScript);
                }
                else
                {
                    if (!path.EndsWith(".prefab"))
                    {
                        continue;
                    }

                    CheckPrefab(AssetDatabase.AssetPathToGUID(path), PEUtils.GetAssetByPath <GameObject>(path));

                    if (paths.Length > 10 && i % 50 == 0)
                    {
                        EditorUtility.DisplayProgressBar("Checking prefab dependencies", path, p);
                    }

                    if (i % 100 == 0)
                    {
                        EditorUtility.UnloadUnusedAssets();
                    }
                }
            }
            if (paths.Length > 10)
            {
                EditorUtility.ClearProgressBar();
            }
        }