ReplaceReferences() public static method

Replaces all the references in the supplied array (does not work with internal properties).
public static ReplaceReferences ( Component components, Sprite find, Sprite replaceWith, bool spriteRenderersOnly ) : int
components UnityEngine.Component
find UnityEngine.Sprite Find.
replaceWith UnityEngine.Sprite Replace with.
spriteRenderersOnly bool If set to true sprite renderers only.
return int
Beispiel #1
0
        /// <summary>
        /// Replaces all the references in all scenes.
        /// </summary>
        /// <param name="spriteInfoList">Sprite info list.</param>
        /// <param name="spriteRenderersOnly">If set to <c>true</c> sprite renderers only.</param>
        /// <param name="skipCurrent">If set to <c>true</c> skip current scene.</param>
        /// <returns>The replaced references count.</returns>
        public static int ReplaceReferencesInAllScenes(List <SPSpriteInfo> spriteInfoList, SPReferenceReplacerWindow.ReplaceMode replaceMode, bool spriteRenderersOnly, bool skipCurrent)
        {
            int  count        = 0;
            bool replaceAtlas = (replaceMode == SPReferenceReplacerWindow.ReplaceMode.AtlasWithSource);

            // Grab the current scene name
            //string startingScene = EditorApplication.currentScene;

            Scene  scene         = EditorSceneManager.GetActiveScene();
            string startingScene = scene.ToString();

            // Get all scene names
            string[] sceneNames = SPTools.GetAllScenesNames();

            if (sceneNames.Length == 0)
            {
                return(count);
            }

            foreach (string sceneName in sceneNames)
            {
                // Check if we should skip the scene
                if (skipCurrent && sceneName.Equals(startingScene))
                {
                    continue;
                }

                // Try opening the scene
                //if (EditorApplication.OpenScene(sceneName))
                Scene _scene = EditorSceneManager.OpenScene(sceneName);
                if (EditorSceneManager.SetActiveScene(_scene))
                {
                    Component[] comps = Object.FindObjectsOfType <Component>();

                    foreach (SPSpriteInfo spriteInfo in spriteInfoList)
                    {
                        if (spriteInfo.source == null || !(spriteInfo.source is Sprite) || spriteInfo.targetSprite == null)
                        {
                            continue;
                        }

                        count += SPTools.ReplaceReferences(comps, (replaceAtlas ? spriteInfo.targetSprite : (spriteInfo.source as Sprite)), (replaceAtlas ? (spriteInfo.source as Sprite) : spriteInfo.targetSprite), spriteRenderersOnly);
                    }

                    //EditorApplication.SaveScene();
                    Scene __scene = EditorSceneManager.GetActiveScene();
                    EditorSceneManager.SaveScene(__scene);
                }
            }

            // Load back the original scene
            //EditorApplication.OpenScene(sceneName)
            EditorSceneManager.OpenScene(startingScene);

            // Return the replaced references count
            return(count);
        }
Beispiel #2
0
        /// <summary>
        /// Replaces all the references in the project (does not work with internal properties).
        /// </summary>
        /// <param name="spriteInfoList">Sprite info list.</param>
        /// <param name="spriteRenderersOnly">If set to <c>true</c> sprite renderers only.</param>
        /// <returns>The replaced references count.</returns>
        public static int ReplaceReferencesInProject(List <SPSpriteInfo> spriteInfoList, bool spriteRenderersOnly)
        {
            Component[] comps = SPTools.GetProjectPrefabComponents();

            int count = 0;

            foreach (SPSpriteInfo spriteInfo in spriteInfoList)
            {
                if (spriteInfo.source != null && spriteInfo.source is Sprite && spriteInfo.targetSprite != null)
                {
                    count += SPTools.ReplaceReferences(comps, (spriteInfo.source as Sprite), spriteInfo.targetSprite, spriteRenderersOnly);
                }
            }

            return(count);
        }
Beispiel #3
0
        /// <summary>
        /// Replaces all the references in the scene (does not work with internal properties).
        /// </summary>
        /// <param name="spriteInfoList">Sprite info list.</param>
        /// <param name="spriteRenderersOnly">If set to <c>true</c> sprite renderers only.</param>
        /// <returns>The replaced references count.</returns>
        public static int ReplaceReferencesInScene(List <SPSpriteInfo> spriteInfoList, bool spriteRenderersOnly)
        {
            Component[] comps = Resources.FindObjectsOfTypeAll <Component>();

            int count = 0;

            foreach (SPSpriteInfo spriteInfo in spriteInfoList)
            {
                if (spriteInfo.source != null && spriteInfo.source is Sprite && spriteInfo.targetSprite != null)
                {
                    count += SPTools.ReplaceReferences(comps, (spriteInfo.source as Sprite), spriteInfo.targetSprite, spriteRenderersOnly);
                }
            }

            return(count);
        }
Beispiel #4
0
        /// <summary>
        /// Replaces all the references in all scenes.
        /// </summary>
        /// <param name="spriteInfoList">Sprite info list.</param>
        /// <param name="spriteRenderersOnly">If set to <c>true</c> sprite renderers only.</param>
        /// <param name="skipCurrent">If set to <c>true</c> skip current scene.</param>
        /// <returns>The replaced references count.</returns>
        public static int ReplaceReferencesInAllScenes(List <SPSpriteInfo> spriteInfoList, bool spriteRenderersOnly, bool skipCurrent)
        {
            int count = 0;

            // Grab the current scene name
            string startingScene = EditorSceneManager.GetActiveScene().name;

            // Get all scene names
            string[] sceneNames = SPTools.GetAllScenesNames();

            if (sceneNames.Length == 0)
            {
                return(count);
            }

            foreach (string sceneName in sceneNames)
            {
                // Check if we should skip the scene
                if (skipCurrent && sceneName.Equals(startingScene))
                {
                    continue;
                }

                // Try opening the scene
                Scene scene = EditorSceneManager.OpenScene(sceneName, OpenSceneMode.Single);
                if (scene.IsValid())
                {
                    Component[] comps = Object.FindObjectsOfType <Component>();

                    foreach (SPSpriteInfo spriteInfo in spriteInfoList)
                    {
                        if (spriteInfo.source != null && spriteInfo.source is Sprite && spriteInfo.targetSprite != null)
                        {
                            count += SPTools.ReplaceReferences(comps, (spriteInfo.source as Sprite), spriteInfo.targetSprite, spriteRenderersOnly);
                        }
                    }

                    EditorSceneManager.SaveOpenScenes();
                }
            }

            // Load back the original scene
            EditorSceneManager.OpenScene(startingScene, OpenSceneMode.Single);

            // Return the replaced references count
            return(count);
        }
Beispiel #5
0
        /// <summary>
        /// Replaces all the references in the project (does not work with internal properties).
        /// </summary>
        /// <param name="spriteInfoList">Sprite info list.</param>
        /// <param name="spriteRenderersOnly">If set to <c>true</c> sprite renderers only.</param>
        /// <returns>The replaced references count.</returns>
        public static int ReplaceReferencesInProject(List <SPSpriteInfo> spriteInfoList, SPReferenceReplacerWindow.ReplaceMode replaceMode, bool spriteRenderersOnly)
        {
            Component[] comps = SPTools.GetProjectPrefabComponents();

            bool replaceAtlas = (replaceMode == SPReferenceReplacerWindow.ReplaceMode.AtlasWithSource);

            int count = 0;

            foreach (SPSpriteInfo spriteInfo in spriteInfoList)
            {
                if (spriteInfo.source == null || !(spriteInfo.source is Sprite) || spriteInfo.targetSprite == null)
                {
                    continue;
                }

                count += SPTools.ReplaceReferences(comps, (replaceAtlas ? spriteInfo.targetSprite : (spriteInfo.source as Sprite)), (replaceAtlas ? (spriteInfo.source as Sprite) : spriteInfo.targetSprite), spriteRenderersOnly);
            }

            return(count);
        }