Example #1
0
        // path - RootAssetPath
        public static PrefabMatchInfo GetPrefabMatchInfo2(MonoBehaviour component, GameObject asset, string path, string[] properties)
        {
            var matchingComponent = new PrefabMatchInfo {
                PrefabAssetPath = path, ComponentName = component.gameObject.name
            };

            matchingComponent.URL    = (component as OpenUrl).Url;
            matchingComponent.URL_ID = (component as OpenUrl).Url_ID;

            return(matchingComponent);
        }
Example #2
0
        void RenameUrlInPrefab(OpenUrl component, string newFormattedUrl, PrefabMatchInfo match)
        {
            // https://forum.unity.com/threads/how-do-i-edit-prefabs-from-scripts.685711/#post-4591885
            using (var editingScope = new PrefabUtility.EditPrefabContentsScope(match.PrefabAssetPath))
            {
                var prefabRoot = editingScope.prefabContentsRoot;

                var prefabbedComponent = prefabRoot.GetComponentsInChildren <OpenUrl>(true)[match.ComponentID];
                prefabbedComponent.Url = newFormattedUrl;

                // https://forum.unity.com/threads/remove-all-missing-components-in-prefabs.897761/
                GameObjectUtility.RemoveMonoBehavioursWithMissingScript(prefabRoot);
            }
        }