private static void PopulatePrefabSerializedProgramAssetReferences(string prefabPath) { using (EditPrefabAssetScope editScope = new EditPrefabAssetScope(prefabPath)) { if (!editScope.IsEditable) { return; } editScope.PrefabRoot.GetComponentsInChildren(prefabBehavioursTempList); if (prefabBehavioursTempList.Count < 1) { return; } bool dirty = false; foreach (UdonBehaviour udonBehaviour in prefabBehavioursTempList) { if (PopulateSerializedProgramAssetReference(udonBehaviour)) { dirty = true; } } if (dirty) { editScope.MarkDirty(); } } }
private static void PopulatePrefabSerializedProgramAssetReferences(string prefabPath) { using (EditPrefabAssetScope editScope = new EditPrefabAssetScope(prefabPath)) { if (!editScope.IsEditable) { return; } UdonBehaviour[] udonBehaviours = editScope.PrefabRoot.GetComponentsInChildren <UdonBehaviour>(); if (udonBehaviours.Length <= 0) { return; } bool dirty = false; foreach (UdonBehaviour udonBehaviour in udonBehaviours) { if (PopulateSerializedProgramAssetReference(udonBehaviour)) { dirty = true; } } if (dirty) { editScope.MarkDirty(); } } }
// // ─── TEXT COMPONENT REPLACEMENT ────────────────────────────────── // #region TEXT COMPONENT REPLACEMENT private void ReplaceTextComponent(ReplaceUnit updatedReference) { TextInformation textInfo = updatedReference.textInformation; // * Don't even think of performing below operations on previously saved prefabs loaded into the memory // * They are like lost souls that want to trap your innocent code // * Whatever you execute on them gets lost in a limbo and flushed down along the garbage collection // * If you want to edit a prefab, make sure you just loaded it and you work on a fresh, crunchy instance using (var editScope = new EditPrefabAssetScope(updatedReference.prefabPath)) { GameObject root = editScope.prefabRoot; TextMeshProUGUI tmProText = GetTMProText(updatedReference, textInfo, root); textInfo.StyleTMProText(tmProText, _fontAssetMap); if (updatedReference.isReferenced) { TMProAdapter tmProAdapter = GetTextAdapter(updatedReference, root, tmProText); if (tmProAdapter == null) { return; } AssignTMProReference(updatedReference, tmProAdapter, root); } } }
private static void RefreshPrefabUdonBehaviours(List <string> prefabAssetPaths) { if (prefabAssetPaths.Count == 0) { return; } foreach ((string prefabPath, int index) in prefabAssetPaths.Select((item, index) => (item, index))) { using (EditPrefabAssetScope editScope = new EditPrefabAssetScope(prefabPath)) { if (!editScope.IsEditable) { continue; } UdonBehaviour[] udonBehaviours = editScope.PrefabRoot.GetComponentsInChildren <UdonBehaviour>(); if (udonBehaviours.Length <= 0) { continue; } foreach (UdonBehaviour udonBehaviour in udonBehaviours) { udonBehaviour.RefreshProgram(); } editScope.MarkDirty(); } } }
private void LoadPrefabs() { string[] assetPaths = GetAllAssetPaths(new[] { PREFAB_SEARCH_LOCATION }); try { AssetDatabase.StartAssetEditing(); foreach (string path in assetPaths) { Type assetType = AssetDatabase.GetMainAssetTypeAtPath(path); bool isValidPrefab = assetType == typeof(GameObject); if (!isValidPrefab) { Debug.Log($"<color=yellow>Rejected {assetType} at {path}</color>"); continue; } Debug.Log($"{path}"); using (var editScope = new EditPrefabAssetScope(path)) { GameObject root = editScope.prefabRoot; if (root.TryGetComponentsInChildren <TextMeshProUGUI>(out List <TextMeshProUGUI> textComponents, skipNestedPrefabs: true)) { Debug.Log($"Found text components"); foreach (var textComponent in textComponents) { (_onComponentField.value as OnComponentFound <TextMeshProUGUI>).DoOnFoundComponent(textComponent); } editScope.SavePrefabOnDispose = true; } else { editScope.SavePrefabOnDispose = false; } } } } catch (Exception ex) { Debug.LogError(ex.Message + "\n" + ex.StackTrace); } finally { AssetDatabase.StopAssetEditing(); } }
private void SavePrefab() { string addressBookPath = "Packages/com.mariaheineboombyte.fabulous-text-replacer/Editor/Scriptable/UpdatedReferenceAddressBook.asset"; UnityEngine.Object addressBook = AssetDatabase.LoadAssetAtPath(addressBookPath, typeof(UpdatedReferenceAddressBook)); _updatedReferenceAddressBook = addressBook as UpdatedReferenceAddressBook; string assetPath = "Assets/RemoteAssets/DeeplyNested.prefab"; using (var editScope = new EditPrefabAssetScope(assetPath)) { GameObject root = editScope.prefabRoot; GameObject adaptersParent = new GameObject("AdaptersParent"); adaptersParent.transform.parent = root.transform; adaptersParent.transform.SetAsFirstSibling(); } }