public GameObject LoadPrefabResource() { string resourcePath = AssetUtils.GetResourcePath(_filePath); return(Resources.Load <GameObject>(resourcePath) as GameObject); }
static string Address(AssetUnitInfo key) { return(key.reference + "_" + AssetUtils.StdAssetIDName(key)); }
public string GetAssetFilePath() { return(AssetUtils.GetAssetPath(_filePath)); }
public static async Task <HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, FunctionContext executionContext) { var log = executionContext.GetLogger("CreateEmptyAsset"); log.LogInformation("C# HTTP trigger function processed a request."); // Get request body data. string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var data = (RequestBodyModel)JsonConvert.DeserializeObject(requestBody, typeof(RequestBodyModel)); // Return bad request if input asset name is not passed in if (data.AssetNamePrefix == null) { return(HttpRequest.ResponseBadRequest(req, "Please pass asset name prefix in the request body")); } ConfigWrapper config = ConfigUtils.GetConfig(); IAzureMediaServicesClient client; try { client = await Authentication.CreateMediaServicesClientAsync(config, log); log.LogInformation("AMS Client created."); } catch (Exception e) { if (e.Source.Contains("ActiveDirectory")) { log.LogError("TIP: Make sure that you have filled out the appsettings.json file before running this sample."); } log.LogError($"{e.Message}"); return(HttpRequest.ResponseBadRequest(req, e.Message)); } // Set the polling interval for long running operations to 2 seconds. // The default value is 30 seconds for the .NET client SDK client.LongRunningOperationRetryTimeout = 2; // Creating a unique suffix so that we don't have name collisions if you run the sample // multiple times without cleaning up. string uniqueness = Guid.NewGuid().ToString().Substring(0, 13); string assetName = $"{data.AssetNamePrefix}-{uniqueness}"; Asset asset; try { // let's create the asset asset = await AssetUtils.CreateAssetAsync(client, log, config.ResourceGroup, config.AccountName, assetName, data.AssetStorageAccount); log.LogInformation($"Asset '{assetName}' created."); // let's get the asset to have full metadata like container asset = await client.Assets.GetAsync(config.ResourceGroup, config.AccountName, assetName); } catch (Exception e) { log.LogError("Error when creating the asset."); log.LogError($"{e.Message}"); return(HttpRequest.ResponseBadRequest(req, e.Message)); } AnswerBodyModel dataOk = new() { AssetName = asset.Name, AssetId = asset.AssetId, Container = asset.Container }; return(HttpRequest.ResponseOk(req, dataOk)); } }
private void RenderTitleBar() { EditorGUILayout.BeginVertical(); { //Load save EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); { if (GUILayout.Button("Save", EditorStyles.toolbarButton)) { Localisation.SaveStrings(); } if (GUILayout.Button("Reload", EditorStyles.toolbarButton)) { Localisation.ReloadStrings(); UpdateKeys(); } EditorGUILayout.Separator(); GUILayout.Button("Scale", EditorStyles.toolbarButton); int fontSize = EditorGUILayout.IntSlider(_editorPrefs._tableFontSize, kMinFontSize, kMaxFontSize); if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton)) { fontSize = kDefaultFontSize; } if (_editorPrefs._tableFontSize != fontSize) { _editorPrefs._tableFontSize = fontSize; _textStyle.fontSize = _editorPrefs._tableFontSize; _editTextStyle.fontSize = _editorPrefs._tableFontSize; SaveEditorPrefs(); } EditorGUILayout.Separator(); GUILayout.Button("Font", EditorStyles.toolbarButton); Font currentFont = _editorPrefs._font.GetAsset(); Font font = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false); if (currentFont != font) { _editorPrefs._font = new EditorAssetRef <Font>(font); if (font == null) { _textStyle.font = _keyStyle.font; } else { _textStyle.font = font; } SaveEditorPrefs(); } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); //Filters EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); { GUILayout.Button("Filter", EditorStyles.toolbarButton); EditorGUI.BeginChangeCheck(); _filter = EditorGUILayout.TextField(_filter, EditorStyles.toolbarSearchField); if (EditorGUI.EndChangeCheck()) { _needsRepaint = true; UpdateKeys(); } if (GUILayout.Button("Clear", EditorStyles.toolbarButton)) { _filter = ""; UpdateKeys(); SelectKey(_editorPrefs._selectedKeys); } if (GUILayout.Button("Choose Localisation Folder", EditorStyles.toolbarButton)) { string folder = LocalisationProjectSettings.Get()._localisationFolder; folder = EditorUtility.OpenFolderPanel("Choose Localisation Folder", folder, ""); LocalisationProjectSettings.Get()._localisationFolder = AssetUtils.GetAssetPath(folder); AssetDatabase.SaveAssets(); Localisation.ReloadStrings(true); _needsRepaint = true; } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); //Headers EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); { float keyWidth = _editorPrefs._keyWidth - (kResizerWidth * 0.5f); float firstLanguageWidth = _editorPrefs._firstLanguageWidth - kResizerWidth; float secondLangWidth = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth; keyWidth -= _scrollPosition.x; //Key if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.Width(Mathf.Max(keyWidth, 0f)))) { _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc; } //Keys Resizer RenderResizer(ref _keysResizerRect); //First Language GUILayout.Button(Localisation.GetCurrentLanguage().ToString(), EditorStyles.toolbarButton, GUILayout.Width(firstLanguageWidth)); //Language Resizer RenderResizer(ref _languageResizerRect); //Second Language EditorGUI.BeginChangeCheck(); SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(_editorPrefs._secondLanguage, EditorStyles.toolbarPopup, GUILayout.Width(secondLangWidth)); if (EditorGUI.EndChangeCheck()) { if (_editorPrefs._secondLanguage != Localisation.GetCurrentLanguage()) { Localisation.UnloadStrings(_editorPrefs._secondLanguage); } _editorPrefs._secondLanguage = language; } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); }
public string GetResouceFilePath() { return(AssetUtils.GetResourcePath(_filePath)); }
private void RenderTitleBar() { EditorGUILayout.BeginVertical(GUILayout.Height(kToolBarHeight)); { //Title EditorGUILayout.BeginHorizontal(_toolbarStyle); { string titleText = kWindowTitle + " - <b>Localisation.xml</b>"; if (Localisation.HasUnsavedChanges()) { titleText += "<b>*</b>"; } EditorGUILayout.LabelField(titleText, _titleStyle); } EditorGUILayout.EndHorizontal(); //Load save EditorGUILayout.BeginHorizontal(_toolbarStyle); { if (GUILayout.Button("Save", EditorStyles.toolbarButton)) { Localisation.SaveStrings(); } if (GUILayout.Button("Reload", EditorStyles.toolbarButton)) { Localisation.ReloadStrings(); } EditorGUILayout.Separator(); GUILayout.Button("Scale", EditorStyles.toolbarButton); int fontSize = EditorGUILayout.IntSlider(_editorPrefs._fontSize, 8, 16); if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton)) { fontSize = kDefaultFontSize; EditorGUI.FocusTextInControl(string.Empty); } if (_editorPrefs._fontSize != fontSize) { _editorPrefs._fontSize = fontSize; _keyStyle.fontSize = _editorPrefs._fontSize; _textStyle.fontSize = _editorPrefs._fontSize; SaveEditorPrefs(); } EditorGUILayout.Separator(); GUILayout.Button("Font", EditorStyles.toolbarButton); Font currentFont = _editorPrefs._font.GetAsset(); Font font = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false); if (currentFont != font) { _editorPrefs._font = new EditorAssetRef <Font>(font); if (font == null) { _textStyle.font = _keyStyle.font; } else { _textStyle.font = font; } SaveEditorPrefs(); } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); //Filters EditorGUILayout.BeginHorizontal(_toolbarStyle); { GUILayout.Button("Filter", EditorStyles.toolbarButton); EditorGUI.BeginChangeCheck(); _filter = EditorGUILayout.TextField(_filter); if (EditorGUI.EndChangeCheck()) { _needsRepaint = true; } if (GUILayout.Button("Clear", EditorStyles.toolbarButton)) { _filter = ""; SelectKey(_editorPrefs._selectedKey); } if (GUILayout.Button("Choose Localisation Folder", EditorStyles.toolbarButton)) { string folder = LocalisationProjectSettings.Get()._localisationFolder; folder = EditorUtility.OpenFolderPanel("Choose Localisation Folder", folder, ""); LocalisationProjectSettings.Get()._localisationFolder = AssetUtils.GetAssetPath(folder); AssetDatabase.SaveAssets(); Localisation.ReloadStrings(true); _needsRepaint = true; } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); //Headers EditorGUILayout.BeginHorizontal(); { //Key EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(_editorPrefs._keyWidth - 3)); { if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.ExpandWidth(true))) { _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc; } } EditorGUILayout.EndHorizontal(); //Keys Resizer RenderResizer(ref _keysResizerRect); //Text EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(_editorPrefs._firstLanguageWidth - 3)); { //First Language GUILayout.Button(Localisation.GetCurrentLanguage().ToString(), EditorStyles.toolbarButton, GUILayout.ExpandWidth(true)); } EditorGUILayout.EndHorizontal(); //Language Resizer RenderResizer(ref _languageResizerRect); //Second Language float secondLangWidth = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth; EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(secondLangWidth)); { EditorGUI.BeginChangeCheck(); SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(_editorPrefs._secondLanguage, EditorStyles.toolbarButton); if (EditorGUI.EndChangeCheck()) { if (_editorPrefs._secondLanguage != Localisation.GetCurrentLanguage()) { Localisation.UnloadStrings(_editorPrefs._secondLanguage); } _editorPrefs._secondLanguage = language; } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); }
private void SetupOverlays() { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); Logger.LogDebug("Setting up MapOverlays"); // Create intermediate textures to draw on OverlayTex = new Texture2D(TextureSize, TextureSize, TextureFormat.RGBA32, mipChain: false); FogFilter ??= new Texture2D(TextureSize, TextureSize, TextureFormat.RGBA32, mipChain: false); var bundle = AssetUtils.LoadAssetBundleFromResources("minimapmanager", typeof(MinimapManager).Assembly); // Load mask image for the map overlay CircleMask = bundle.LoadAsset <Sprite>("CircleMask"); // Create overlay material and shader var composeOverlayShader = bundle.LoadAsset <Shader>("MinimapComposeOverlay"); ComposeOverlayMaterial = new Material(composeOverlayShader); ComposeOverlayMaterial.SetTexture("_VanillaTex", OverlayTex); ComposeOverlayMaterial.SetTexture("_FogTex", FogFilter); bundle.Unload(false); // Copy vanilla textures Graphics.CopyTexture(TransparentTex, OverlayTex); Graphics.CopyTexture(Minimap.instance.m_fogTexture, FogFilter); // Create custom overlay GOs OverlayLarge = new GameObject("CustomLayerLarge"); var rectLarge = OverlayLarge.AddComponent <RectTransform>(); rectLarge.SetParent(Minimap.instance.m_mapImageLarge.transform, false); rectLarge.SetAsFirstSibling(); rectLarge.anchorMin = Vector2.zero; rectLarge.anchorMax = Vector2.one; rectLarge.offsetMin = Vector2.zero; rectLarge.offsetMax = Vector2.zero; var maskImage = OverlayLarge.AddComponent <Image>(); maskImage.sprite = CircleMask; maskImage.preserveAspect = true; maskImage.raycastTarget = false; var mask = OverlayLarge.AddComponent <Mask>(); mask.showMaskGraphic = false; var rawLarge = new GameObject("RawImageLarge"); var rawRectLarge = rawLarge.AddComponent <RectTransform>(); rawRectLarge.SetParent(rectLarge, false); rawRectLarge.anchorMin = Vector2.zero; rawRectLarge.anchorMax = Vector2.one; rawRectLarge.offsetMin = Vector2.zero; rawRectLarge.offsetMax = Vector2.zero; var imageLarge = rawLarge.AddComponent <RawImage>(); imageLarge.texture = OverlayTex; imageLarge.material = null; imageLarge.raycastTarget = false; imageLarge.maskable = true; Rect imageLargeRect = imageLarge.uvRect; imageLargeRect.width = rectLarge.rect.width / rectLarge.rect.height; imageLargeRect.height = 1; imageLargeRect.center = new Vector2(0.5f, 0.5f); imageLarge.uvRect = imageLargeRect; OverlaySmall = new GameObject("CustomLayerSmall"); var rectSmall = OverlaySmall.AddComponent <RectTransform>(); rectSmall.SetParent(Minimap.instance.m_mapImageSmall.transform, false); rectSmall.SetAsFirstSibling(); rectSmall.anchorMin = Vector2.zero; rectSmall.anchorMax = Vector2.one; var imageSmall = OverlaySmall.AddComponent <RawImage>(); imageSmall.texture = OverlayTex; imageSmall.material = null; imageSmall.raycastTarget = false; watch.Stop(); Logger.LogDebug($"Setup took {watch.ElapsedMilliseconds}ms time"); }
public static AssetMethodUsages ReadFrom(UnsafeReader reader) { return(new AssetMethodUsages(reader.ReadString(), reader.ReadString(), new TextRange(reader.ReadInt32(), reader.ReadInt32()), AssetUtils.ReadOWORD(reader), (EventHandlerArgumentMode)reader.ReadInt32(), reader.ReadString(), HierarchyReferenceUtil.ReadReferenceFrom(reader))); }
public void AnalyzePrefabs() { MissingList.Clear(); FixList.Clear(); NofixList.Clear(); var parser = new PrefabParser(); foreach (var go in _prefabs) { if (go != null) { var path = AssetDatabase.GetAssetPath(go); parser.Load(path); var monos = parser.GetMonoBehaviourNodes(); foreach (var item in monos) { var asset = AssetUtils.GetAssetFromId(item.ScriptFileID, item.ScriptGUID); if (asset == null) // missing { if (MissingList.Find(n => { return(n.FileID == item.ScriptFileID && n.GUID == item.ScriptGUID); }) == null) { MissingList.Add(new ScriptID() { FileID = item.ScriptFileID, GUID = item.ScriptGUID }); } } } } } // 从参考数据库查询missing id的名字 foreach (var item in MissingList) { var r = _refDb.Search(item.FileID, item.GUID); if (r != null) { item.Name = r.Name; } } // 通过名字在项目中寻找其正确id foreach (var item in MissingList) { string fileID = null; string guid = null; Object _ = null; if (AssetUtils.TrySearchClass(item.Name, ref fileID, ref guid, ref _)) { FixList.Add(new ScriptID() { Name = item.Name, FileID = fileID, GUID = guid }); } else { NofixList.Add(item); } } // log var sb = new StringBuilder(100); sb.AppendLine("分析结果如下:"); sb.AppendLine("--------"); sb.AppendLine($"丢失{MissingList.Count}:"); foreach (var item in MissingList) { sb.AppendLine($"类名:{item.Name},fileID:{item.FileID},guid:{item.GUID}"); } sb.AppendLine("--------"); sb.AppendLine($"可修复{FixList.Count}:"); foreach (var item in FixList) { sb.AppendLine($"类名:{item.Name},fileID:{item.FileID},guid:{item.GUID}"); } sb.AppendLine("--------"); sb.AppendLine($"不可修复{NofixList.Count}:"); foreach (var item in NofixList) { sb.AppendLine($"类名:{item.Name},fileID:{item.FileID},guid:{item.GUID}"); } sb.AppendLine("--------"); Debug.Log(sb.ToString()); }
void UpdateBaseLayer(Section section, string selection) { if (section.Type != SectionType.Language) { currentOSM = section.OSM.Value; currentSelection = selection; } if (section.Type == SectionType.Vector) { if (currentOSM == "nutiteq.osm") { // Nutiteq styles are bundled with the SDK, we can initialize them via constuctor if (currentSelection == "default") { currentLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault); } else if (currentSelection == "gray") { currentLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleGray); } else { currentLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDark); } } else if (currentOSM == "mapzen.osm") { // Mapzen styles are all bundled in one .zip file. // Selection contains both the style name and file name (cf. Sections.cs in Shared) string fileName = currentSelection.Split(':')[0]; string styleName = currentSelection.Split(':')[1]; // Create a style set from the file and style BinaryData styleAsset = AssetUtils.LoadAsset("styles/" + fileName + ".zip"); var package = new ZippedAssetPackage(styleAsset); CompiledStyleSet styleSet = new CompiledStyleSet(package, styleName); // Create datasource and style decoder var source = new CartoOnlineTileDataSource(currentOSM); var decoder = new MBVectorTileDecoder(styleSet); currentLayer = new VectorTileLayer(source, decoder); } Menu.LanguageChoiceEnabled = true; ResetLanguage(); } else if (section.Type == SectionType.Raster) { // We know that the value of raster will be Positron or Darkmatter, // as Nutiteq and Mapzen use vector tiles // Additionally, raster tiles do not support language choice string url = (currentSelection == "positron") ? Urls.Positron : Urls.DarkMatter; TileDataSource source = new HTTPTileDataSource(1, 19, url); currentLayer = new RasterTileLayer(source); // Language choice not enabled in raster tiles Menu.LanguageChoiceEnabled = false; } else if (section.Type == SectionType.Language) { if (currentLayer is RasterTileLayer) { // Raster tile language chance is not supported return; } UpdateLanguage(selection); } MapView.Layers.Clear(); MapView.Layers.Add(currentLayer); Menu.Hide(); currentListener = null; currentListener = MapView.InitializeVectorTileListener(VectorLayer); }
public IUnityAssetDataElement Build(SeldomInterruptChecker checker, IPsiSourceFile currentSourceFile, AssetDocument assetDocument) { var anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer); if (!anchorRaw.HasValue) { return(null); } var anchor = anchorRaw.Value; var isStripped = AssetUtils.IsStripped(assetDocument.Buffer); var gameObject = AssetUtils.GetGameObject(assetDocument.Buffer)?.ToReference(currentSourceFile) as LocalReference; var prefabInstance = AssetUtils.GetPrefabInstance(assetDocument.Buffer)?.ToReference(currentSourceFile) as LocalReference; var correspondingSourceObject = AssetUtils.GetCorrespondingSourceObject(assetDocument.Buffer)?.ToReference(currentSourceFile) as ExternalReference; var location = new LocalReference(currentSourceFile.PsiStorage.PersistentIndex, anchor); if (AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer)) { var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries; if (entries == null) { return(null); } AssetDocumentReference documentReference = null; foreach (var entry in entries) { if (entry.Key.MatchesPlainScalarText(UnityYamlConstants.ScriptProperty)) { documentReference = entry.Content.Value.AsFileID(); break; } } if (isStripped || documentReference != null) { var scriptAnchorRaw = documentReference?.AnchorLong; return(new AssetDocumentHierarchyElement( new ScriptComponentHierarchy(location, !scriptAnchorRaw.HasValue ? null : new ExternalReference(documentReference.ExternalAssetGuid, scriptAnchorRaw.Value), gameObject, prefabInstance, correspondingSourceObject, isStripped ))); } } else if (AssetUtils.IsTransform(assetDocument.Buffer)) { var father = AssetUtils.GetTransformFather(assetDocument.Buffer)?.ToReference(currentSourceFile) as LocalReference; var rootIndex = AssetUtils.GetRootIndex(assetDocument.Buffer); return(new AssetDocumentHierarchyElement( new TransformHierarchy(location, gameObject, father, rootIndex, prefabInstance, correspondingSourceObject, isStripped))); } else if (AssetUtils.IsGameObject(assetDocument.Buffer)) { var name = AssetUtils.GetGameObjectName(assetDocument.Buffer); if (isStripped || name != null) { return(new AssetDocumentHierarchyElement(new GameObjectHierarchy(location, name, prefabInstance, correspondingSourceObject, isStripped))); } } else if (AssetUtils.IsPrefabModification(assetDocument.Buffer)) { var modification = AssetUtils.GetPrefabModification(assetDocument.Document); var parentTransform = modification?.GetValue("m_TransformParent")?.AsFileID()?.ToReference(currentSourceFile) as LocalReference; var modifications = modification?.GetValue("m_Modifications") as IBlockSequenceNode; var result = new List <PrefabModification>(); if (modifications != null) { foreach (var entry in modifications.Entries) { var map = entry.Value as IBlockMappingNode; if (map == null) { continue; } var target = map.GetValue("target").AsFileID()?.ToReference(currentSourceFile); if (target == null) { continue; } var name = map.GetValue("propertyPath").GetPlainScalarText(); if (name == null) { continue; } var valueNode = map.FindMapEntryBySimpleKey("value")?.Content; if (valueNode == null) { continue; } IAssetValue value = null; foreach (var assetInspectorValueDeserializer in myAssetInspectorValueDeserializers) { if (assetInspectorValueDeserializer.TryGetInspectorValue(currentSourceFile, valueNode, out value)) { break; } } if (value == null) { continue; } result.Add(new PrefabModification(target, name, value)); } } var sourcePrefabGuid = AssetUtils.GetSourcePrefab(assetDocument.Buffer)?.ToReference(currentSourceFile) as ExternalReference; if (sourcePrefabGuid == null) { return(null); } return(new AssetDocumentHierarchyElement(new PrefabInstanceHierarchy(location, sourcePrefabGuid.ExternalAssetGuid, parentTransform, result))); } else // regular component { var name = AssetUtils.GetRawComponentName(assetDocument.Buffer); if (name == null) { return(null); } return(new AssetDocumentHierarchyElement( new ComponentHierarchy(name, location, gameObject, prefabInstance, correspondingSourceObject, isStripped))); } return(null); }
public object Build(SeldomInterruptChecker checker, IPsiSourceFile currentAssetSourceFile, AssetDocument assetDocument) { var anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer); if (!anchorRaw.HasValue) { return(null); } var anchor = anchorRaw.Value; var isStripped = AssetUtils.IsStripped(assetDocument.Buffer); var location = new LocalReference(currentAssetSourceFile.PsiStorage.PersistentIndex.NotNull("owningPsiPersistentIndex != null"), anchor); if (isStripped) { var prefabInstance = AssetUtils.GetPrefabInstance(currentAssetSourceFile, assetDocument.Buffer) as LocalReference?; var correspondingSourceObject = AssetUtils.GetCorrespondingSourceObject(currentAssetSourceFile, assetDocument.Buffer) as ExternalReference?; if (prefabInstance != null && correspondingSourceObject != null) { return(new StrippedHierarchyElement(location, prefabInstance.Value, correspondingSourceObject.Value)); } return(null); } var gameObject = AssetUtils.GetGameObjectReference(currentAssetSourceFile, assetDocument.Buffer) as LocalReference?; if (gameObject != null && AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer)) { var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries; if (entries == null) { return(null); } IHierarchyReference documentReference = null; foreach (var entry in entries) { if (entry.Key.MatchesPlainScalarText(UnityYamlConstants.ScriptProperty)) { documentReference = entry.Content.Value.ToHierarchyReference(currentAssetSourceFile); break; } } if (documentReference is ExternalReference scriptReference) { return(new ScriptComponentHierarchy(location, gameObject.Value, scriptReference)); } } else if (gameObject != null && AssetUtils.IsTransform(assetDocument.Buffer)) { var father = AssetUtils.GetTransformFather(currentAssetSourceFile, assetDocument.Buffer) as LocalReference?; if (father == null) { return(null); } var rootIndex = AssetUtils.GetRootIndex(assetDocument.Buffer); return(new TransformHierarchy(location, gameObject.Value, father.Value, rootIndex)); } else if (AssetUtils.IsGameObject(assetDocument.Buffer)) { var name = AssetUtils.GetGameObjectName(assetDocument.Buffer); if (name != null) { return(new GameObjectHierarchy(location, name)); } } else if (AssetUtils.IsPrefabModification(assetDocument.Buffer)) { var modification = AssetUtils.GetPrefabModification(assetDocument.Document); var parentTransform = modification?.GetValue("m_TransformParent")?.ToHierarchyReference(currentAssetSourceFile) as LocalReference? ?? LocalReference.Null; var modifications = modification?.GetValue("m_Modifications") as IBlockSequenceNode; var result = new List <PrefabModification>(); if (modifications != null) { foreach (var entry in modifications.Entries) { var map = entry.Value as IBlockMappingNode; var target = map?.GetValue("target").ToHierarchyReference(currentAssetSourceFile); if (target == null) { continue; } var name = map.GetValue("propertyPath").GetPlainScalarText(); if (name == null) { continue; } var valueNode = map.FindMapEntryBySimpleKey("value")?.Content; if (valueNode == null) { continue; } IAssetValue value = null; foreach (var assetInspectorValueDeserializer in myAssetInspectorValueDeserializers) { if (assetInspectorValueDeserializer.TryGetInspectorValue(currentAssetSourceFile, valueNode, out value)) { break; } } var objectReference = map.FindMapEntryBySimpleKey("objectReference")?.Content.Value.ToHierarchyReference(currentAssetSourceFile); var valueRange = valueNode.GetTreeTextRange(); result.Add(new PrefabModification(target, name, value, new TextRange(assetDocument.StartOffset + valueRange.StartOffset.Offset, assetDocument.StartOffset + valueRange.EndOffset.Offset), objectReference)); } } var sourcePrefabGuid = AssetUtils.GetSourcePrefab(currentAssetSourceFile, assetDocument.Buffer) as ExternalReference?; if (sourcePrefabGuid == null) { return(null); } return(new PrefabInstanceHierarchy(location, parentTransform, result, sourcePrefabGuid.Value.ExternalAssetGuid)); } else if (gameObject != null)// regular component { var name = AssetUtils.GetRawComponentName(assetDocument.Buffer); if (name == null) { return(null); } return(new ComponentHierarchy(location, gameObject.Value, name)); } return(null); }
public void OnQuit() { if (HasChanges() || _timelineEditor.HasChanges()) { if (EditorUtility.DisplayDialog("State Machine Has Been Modified", "Do you want to save the changes you made to the state machine:\n\n" + AssetUtils.GetAssetPath(_currentFileName) + "\n\nYour changes will be lost if you don't save them.", "Save", "Don't Save")) { Save(); } } }
/// <summary> Adds the default categories to the database by taking into account the database type. Returns TRUE if the operation was successful </summary> /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param> public void AddDefaultCategories(bool saveAssets) { if (!Contains(GENERAL)) { // CreateCategory(GENERAL, new List<string>(), false, false); #if UNITY_EDITOR var listOfNames = AssetUtils.CreateAsset <ListOfNames>(GetPath(DatabaseType), GetDatabaseFileName(DatabaseType, GENERAL)); #else ListOfNames listOfNames = ScriptableObject.CreateInstance <ListOfNames>(); #endif listOfNames.CategoryName = GENERAL; listOfNames.DatabaseType = DatabaseType; Categories.Add(listOfNames); UpdateListOfCategoryNames(); SetDirty(saveAssets); } ListOfNames general = GetCategory(GENERAL); switch (DatabaseType) { case NamesDatabaseType.UIButton: if (!general.Contains(UNNAMED)) { general.AddName(UNNAMED, false); } if (!general.Contains(BACK)) { general.AddName(BACK, false); } break; case NamesDatabaseType.UICanvas: if (!general.Contains(MASTER_CANVAS)) { general.AddName(MASTER_CANVAS, false); } break; case NamesDatabaseType.UIView: if (!general.Contains(UNNAMED)) { general.AddName(UNNAMED, false); } break; case NamesDatabaseType.UIDrawer: if (!general.Contains(UNNAMED)) { general.AddName(UNNAMED, false); } if (!general.Contains(LEFT)) { general.AddName(LEFT, false); } if (!general.Contains(RIGHT)) { general.AddName(RIGHT, false); } if (!general.Contains(UP)) { general.AddName(UP, false); } if (!general.Contains(DOWN)) { general.AddName(DOWN, false); } break; } }
private bool ShowOnLoadSaveChangesDialog() { if (HasChanges() || _timelineEditor.HasChanges()) { int option = EditorUtility.DisplayDialogComplex("State Machine Has Been Modified", "Do you want to save the changes you made to the state machine:\n\n" + AssetUtils.GetAssetPath(_currentFileName) + "\n\nYour changes will be lost if you don't save them.", "Save", "Don't Save", "Cancel"); switch (option) { //Save case 0: Save(); return(true); //Dont save case 1: return(true); //Cancel load default: case 2: return(false); } } return(true); }
/// <summary> Returns a NamesDatabase with the given fileName from the target resourcesPath. If the database is not found, a new one will get created instead. </summary> /// <param name="fileName"> Database filename </param> /// <param name="resourcesPath"> Database relative file path to the Resources folder </param> public static NamesDatabase GetDatabase(string fileName, string resourcesPath) { // return(AssetUtils.GetScriptableObject <NamesDatabase>("_" + fileName, resourcesPath, false, false)); }
private Guid?FindGuidOf([NotNull] IClrDeclaredElement declaredElement) { return(AssetUtils.GetGuidFor(myMetaFileGuidCache, declaredElement.GetContainingType())); }
static void RunTest() { AssetUtils.CreateFolder("Assets/Models/shambler"); }