Beispiel #1
0
        private string GetRealPath(JsonAsset asset)
        {
            if (!string.IsNullOrEmpty(asset.Storage) && asset.Storage != JsonAsset.StorageApp)
            {
                return(null);
            }
            var root = _appHelpers.AppPathRoot(false);

            return(Path.Combine(root, asset.Folder, asset.Name));
        }
        /// <summary>
        /// Updates the surface graph asset (save new one, discard cached data, reload asset).
        /// </summary>
        /// <returns>True if cannot save it, otherwise false.</returns>
        public static bool SaveSurface(JsonAsset asset, RenderingGraph assetInstance, byte[] surfaceData)
        {
            if (!asset)
            {
                throw new ArgumentNullException(nameof(asset));
            }

            assetInstance.VisjectSurface = surfaceData;
            return(FlaxEditor.Editor.SaveJsonAsset(asset.Path, assetInstance));
        }
Beispiel #3
0
 private static SettingsBase LoadAsset(JsonAsset asset, string typename)
 {
     if (asset && !asset.WaitForLoaded() && asset.DataTypeName == typename)
     {
         if (asset.CreateInstance() is SettingsBase result)
         {
             return(result);
         }
     }
     return(null);
 }
Beispiel #4
0
 private static T LoadAsset <T>(JsonAsset asset) where T : new()
 {
     if (asset && !asset.WaitForLoaded())
     {
         if (asset.CreateInstance() is T result)
         {
             return(result);
         }
     }
     return(new T());
 }
        /// <summary>
        /// Updates the surface graph asset (save new one, discard cached data, reload asset).
        /// </summary>
        /// <param name="data">Surface data.</param>
        /// <returns>True if cannot save it, otherwise false.</returns>
        public static bool SaveSurface(JsonAsset asset, ExpressionGraph assetInstance, byte[] surfaceData)
        {
            if (!asset)
            {
                throw new ArgumentNullException(nameof(asset));
            }

            assetInstance.VisjectSurface = surfaceData;

            bool success = FlaxEditor.Editor.SaveJsonAsset(asset.Path, assetInstance);

            asset.Reload();
            return(success);
        }
Beispiel #6
0
        private static bool SaveAsset <T>(GameSettings gameSettings, ref JsonAsset asset, T obj) where T : SettingsBase
        {
            if (asset)
            {
                // Override settings
                return(Editor.SaveJsonAsset(asset.Path, obj));
            }

            // Create new settings asset and link it to the game settings
            var path = StringUtils.CombinePaths(Globals.ProjectContentFolder, "Settings", CustomEditors.CustomEditorsUtil.GetPropertyNameUI(typeof(T).Name) + ".json");

            if (Editor.SaveJsonAsset(path, obj))
            {
                return(true);
            }
            asset = FlaxEngine.Content.LoadAsync <JsonAsset>(path);
            return(Editor.SaveJsonAsset(GameSettingsAssetPath, gameSettings));
        }
        /// <summary>
        /// Tries to load surface graph from the asset.
        /// </summary>
        /// <param name="createDefaultIfMissing">True if create default surface if missing, otherwise won't load anything.</param>
        /// <returns>Loaded surface bytes or null if cannot load it or it's missing.</returns>
        public static byte[] LoadSurface(JsonAsset asset, ExpressionGraph assetInstance, bool createDefaultIfMissing)
        {
            if (!asset)
            {
                throw new ArgumentNullException(nameof(asset));
            }
            if (assetInstance == null)
            {
                throw new ArgumentNullException(nameof(assetInstance));
            }

            // Return its data
            if (assetInstance.VisjectSurface?.Length > 0)
            {
                return(assetInstance.VisjectSurface);
            }

            // Create it if it's missing
            if (createDefaultIfMissing)
            {
                // A bit of a hack
                // Create a Visject Graph with a main node and serialize it!
                var surfaceContext = new VisjectSurfaceContext(null, null, new FakeSurfaceContext());

                // Add the main node
                var node = NodeFactory.CreateNode(ExpressionGraphGroups, 1, surfaceContext, MainNodeGroupId, MainNodeTypeId);
                if (node == null)
                {
                    Debug.LogWarning("Failed to create main node.");
                    return(null);
                }
                surfaceContext.Nodes.Add(node);
                // Initialize
                node.Location = Vector2.Zero;

                surfaceContext.Save();

                return(surfaceContext.Context.SurfaceData);
            }
            else
            {
                return(null);
            }
        }
        public static async System.Threading.Tasks.Task <JsonAsset> FetchBitCoinAsync()
        {
            using (var httpClient = new HttpClient())
            {
                var JSONResultSnipplet = await httpClient.GetStringAsync("https://api.coindesk.com/v1/bpi/currentprice.json");

                JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                dynamic JSONFinal = javaScriptSerializer.Deserialize <object>(JSONResultSnipplet);


                var fetchedAsset = new JsonAsset();

                fetchedAsset.ChartName = JSONFinal["chartName"];
                fetchedAsset.PriceEur  = (float)JSONFinal["bpi"]["EUR"]["rate_float"];
                fetchedAsset.Time      = JSONFinal["time"]["updated"];



                return(fetchedAsset);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Sets the custom settings (or unsets if provided asset is null).
        /// </summary>
        /// <param name="key">The custom key (must be unique per context).</param>
        /// <param name="customSettingsAsset">The custom settings asset.</param>
        /// <returns>True if failed otherwise false.</returns>
        public static bool SetCustomSettings(string key, JsonAsset customSettingsAsset)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            var gameSettings = Load();

            if (customSettingsAsset == null && gameSettings.CustomSettings != null)
            {
                gameSettings.CustomSettings.Remove(key);
            }
            else
            {
                if (gameSettings.CustomSettings == null)
                {
                    gameSettings.CustomSettings = new Dictionary <string, JsonAsset>();
                }
                gameSettings.CustomSettings[key] = customSettingsAsset;
            }

            return(Editor.SaveJsonAsset(GameSettingsAssetPath, gameSettings));
        }