Example #1
0
 public string GetExportFullPath()
 {
     if (string.IsNullOrEmpty(labModelExportPath))
     {
         return(FileSystem.Get().GetFullPath(EFilePathType.EngineDefaultResources));
     }
     return(FileSystem.AssetPathToFullPath(labModelExportPath));
 }
Example #2
0
        private static void RewriteJson(bool format)
        {
            var objects = Selection.objects;

            if (objects == null || objects.Length == 0)
            {
                return;
            }

            foreach (var selected in objects)
            {
                try
                {
                    string assetPath = AssetDatabase.GetAssetPath(selected);
                    //TextAsset textAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(assetPath);
                    if (selected is TextAsset textAsset)
                    {
                        var text = textAsset.text;
                        if (!string.IsNullOrEmpty(text))
                        {
                            var json = JsonMapper.ToObject(text);
                            if (json != null)
                            {
                                JsonWriter jsonWriter = new JsonWriter();
                                if (format)
                                {
                                    jsonWriter.IndentValue = 4;
                                    jsonWriter.PrettyPrint = true;
                                }
                                json.ToJson(jsonWriter);
                                File.WriteAllText(FileSystem.AssetPathToFullPath(assetPath), jsonWriter.ToString());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    DebugUtility.LogException(ex);
                }
            }

            AssetDatabase.Refresh();
        }