// // Initialize / Construct / Enable / Clear // public void Clear() { ClearUndo(); RestoreAssetsFromBackup(); ClearBackups(); m_OpenendVisualTreeAssetOldPath = string.Empty; m_ActiveStyleSheet = null; m_FileSettings = null; if (m_VisualTreeAsset != null) { if (!AssetDatabase.Contains(m_VisualTreeAsset)) { m_VisualTreeAsset.Destroy(); } m_VisualTreeAsset = null; } m_OpenUSSFiles.Clear(); m_Settings = null; }
void Clear() { ClearUndo(); ClearBackups(); m_OpenendVisualTreeAssetOldPath = string.Empty; m_OpenendMainStyleSheetOldPath = string.Empty; if (m_VisualTreeAsset != null) { if (!AssetDatabase.Contains(m_VisualTreeAsset)) { m_VisualTreeAsset.Destroy(); } m_VisualTreeAsset = null; } if (m_MainStyleSheet != null) { if (!AssetDatabase.Contains(m_MainStyleSheet)) { m_MainStyleSheet.Destroy(); } m_MainStyleSheet = null; } m_Settings = null; }
public void LoadDocument(VisualTreeAsset visualTreeAsset, VisualElement documentElement) { NewDocument(documentElement); if (visualTreeAsset == null) { return; } m_VisualTreeAssetBackup = visualTreeAsset.DeepCopy(); m_VisualTreeAsset = visualTreeAsset; m_VisualTreeAsset.ConvertAllAssetReferencesToPaths(); // Load styles. var styleSheetsUsed = m_VisualTreeAsset.GetAllReferencedStyleSheets(); for (int i = 0; i < styleSheetsUsed.Count; ++i) { AddStyleSheetToDocument(styleSheetsUsed[i], null); } m_OpenendVisualTreeAssetOldPath = AssetDatabase.GetAssetPath(m_VisualTreeAsset); hasUnsavedChanges = false; m_Settings = BuilderDocumentSettings.CreateOrLoadSettingsObject(m_Settings, uxmlPath); ReloadDocumentToCanvas(documentElement); }
void CreateOrLoadSettingsObject() { if (m_Settings != null) { return; } m_Settings = new BuilderDocumentSettings(); var diskDataFound = LoadSettingsFromDisk(m_Settings); if (diskDataFound) { return; } m_Settings.UxmlGuid = AssetDatabase.AssetPathToGUID(uxmlPath); m_Settings.UxmlPath = uxmlPath; }
public void LoadDocument(VisualTreeAsset visualTreeAsset, VisualElement documentElement) { NewDocument(documentElement); if (visualTreeAsset == null) { return; } m_VisualTreeAssetBackup = visualTreeAsset.DeepCopy(); m_VisualTreeAsset = visualTreeAsset; PostLoadDocumentStyleSheetCleanup(); hasUnsavedChanges = false; m_OpenendVisualTreeAssetOldPath = AssetDatabase.GetAssetPath(m_VisualTreeAsset); m_Settings = BuilderDocumentSettings.CreateOrLoadSettingsObject(m_Settings, uxmlPath); ReloadDocumentToCanvas(documentElement); }
public static BuilderDocumentSettings CreateOrLoadSettingsObject( BuilderDocumentSettings settings, string uxmlPath) { if (settings != null) { return(settings); } settings = new BuilderDocumentSettings(); var diskDataFound = settings.LoadSettingsFromDisk(uxmlPath); if (diskDataFound) { return(settings); } settings.UxmlGuid = AssetDatabase.AssetPathToGUID(uxmlPath); settings.UxmlPath = uxmlPath; return(settings); }
bool LoadSettingsFromDisk(BuilderDocumentSettings settings) { var guid = AssetDatabase.AssetPathToGUID(uxmlPath); if (string.IsNullOrEmpty(guid)) { return(false); } var folderPath = diskSettingsJsonFolderPath; var fileName = guid + ".json"; var path = folderPath + "/" + fileName; if (!File.Exists(path)) { return(false); } var json = File.ReadAllText(path); EditorJsonUtility.FromJsonOverwrite(json, settings); return(true); }