Open slimshader opened 5 years ago
Hi @slimshader! This asset is an adaptation of standalone game data editor for use in Unity. And there is thin connection between Unity and Charon. Only .NET types for use in formulas are taken from Unity's project. Other stuff is on developer's concern. Charon is designed to store settings for game entities (HP, Mana, Names, Damage etc). Their appearance (prefabs, textures, materials etc) is best stored in Unity native assets. However, you can import any data in game data file from Unity editor. For example you could import list of available resources:
using GameDevWare.Charon.Utils
const string pathToResources = "Assets/Resources/";
const string pathToGameData = "StreamingAssets/gamedata.gdjs"
const string importedEntityName = "GameAsset"
var assets = (
from assetPath in AssetDatabase.GetAllAssetPaths()
where assetPath.StartsWith(pathToResources)
select new { Path = assetPath, Name = Path.GetFileNameWithoutExtension(assetPath) }
).ToList();
var assetsJson = JsonConvert.WriteString(assets);
var importAsync = CharonCli.ImportAsync(Path.GetFullPath(pathToGameData), new[] { importedEntityName }, CommandInput.JsonString(assetsJson), ImportMode.Replace);
importAsync.ContinueWith(t => { /* do some stuff */ });
This gives you list of existing resources to refer from your game data entities (for example 'Prefab' reference from your 'Character' entity).
Hi @slimshader! This asset is an adaptation of standalone game data editor for use in Unity. And there is thin connection between Unity and Charon. Only .NET types for use in formulas are taken from Unity's project. Other stuff is on developer's concern. Charon is designed to store settings for game entities (HP, Mana, Names, Damage etc). Their appearance (prefabs, textures, materials etc) is best stored in Unity native assets. However, you can import any data in game data file from Unity editor. For example you could import list of available resources:
using GameDevWare.Charon.Utils const string pathToResources = "Assets/Resources/"; const string pathToGameData = "StreamingAssets/gamedata.gdjs" const string importedEntityName = "GameAsset" var assets = ( from assetPath in AssetDatabase.GetAllAssetPaths() where assetPath.StartsWith(pathToResources) select new { Path = assetPath, Name = Path.GetFileNameWithoutExtension(assetPath) } ).ToList(); var assetsJson = JsonConvert.WriteString(assets); var importAsync = CharonCli.ImportAsync(Path.GetFullPath(pathToGameData), new[] { importedEntityName }, CommandInput.JsonString(assetsJson), ImportMode.Replace); importAsync.ContinueWith(t => { /* do some stuff */ });
This gives you list of existing resources to refer from your game data entities (for example 'Prefab' reference from your 'Character' entity).
Thanks. I can't find docs for CharonCli tho, also trying with latest example this code can't find JsonConvert.WriteString()
Thanks. I can't find docs for CharonCli
There is none, actually. But it is just wrapper for Command Line Interface, so you could use CLI docs for reference.
code can't find JsonConvert.WriteString()
It is just Json.NET serializer. You could use any other.
Ah I thought maybe it was Newtonsoft JSON but it didn't have it either
Thanks. I can't find docs for CharonCli
There is none, actually. But it is just wrapper for Command Line Interface, so you could use CLI docs for reference.
code can't find JsonConvert.WriteString()
It is just Json.NET serializer. You could use any other.
Turns out it is just Newtonsoft.JSON only in uniy package, it does not have WriteString() method. Also: DO I understand from code directly that I should manually overwrite my json database with Prefabs lists?
Turns out it is just Newtonsoft.JSON only in uniy package, it does not have WriteString() method.
you are right, it is JsonConvert.SerializeObject();
in Newtonsoft.JSON
Also: DO I understand from code directly that I should manually overwrite my json database with Prefabs lists?
Yes, if you want to refer or catalog some Unity's entities (textures, models, other resources) you need to setup some import routine. You don't need to import manualy every time they change because Unity has 'change hooks' AssetPostprocessor, FileSystemWatcher, IPreprocessBuild, BuildPipeline. Use them to automaticaly import stuff in game data.
Turns out it is just Newtonsoft.JSON only in uniy package, it does not have WriteString() method.
you are right, it is
JsonConvert.SerializeObject();
in Newtonsoft.JSONAlso: DO I understand from code directly that I should manually overwrite my json database with Prefabs lists?
Yes, if you want to refer or catalog some Unity's entities (textures, models, other resources) you need to setup some import routine. You don't need to import manualy every time they change because Unity has 'change hooks' AssetPostprocessor, FileSystemWatcher, IPreprocessBuild, BuildPipeline. Use them to automaticaly import stuff in game data.
I've added to the project new file with:
using GameDevWare.Charon.Utils;
using UnityEditor;
using System.Linq;
using Newtonsoft.Json;
using System.IO;
using UnityEngine;
public class NewBehaviourScript : AssetPostprocessor
{
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets,
string[] movedAssets, string[] movedFromAssetPaths)
{
const string pathToResources = "Assets/Resources/";
const string pathToGameData = "Assets/StreamingAssets/RpgGameData.gdjs";
const string importedEntityName = "GameAsset";
var assets = (
from assetPath in AssetDatabase.GetAllAssetPaths()
where assetPath.StartsWith(pathToResources)
select new { Path = assetPath, Name = Path.GetFileNameWithoutExtension(assetPath) }
).ToList();
var assetsJson = JsonConvert.SerializeObject(assets);
var fullPath = Path.GetFullPath(pathToGameData);
var importAsync = CharonCli.ImportAsync(fullPath, new[] { importedEntityName },
CommandInput.JsonString(assetsJson), ImportMode.CreateAndUpdate);
importAsync.ContinueWith(t =>
{
Debug.Log(t.ToString());
/* do some stuff */
});
}
}
And while I see:
Fulfilled promise, result=GameDevWare.Charon.Utils.RunResult.
In the Console output after I add new Prefab to Resources folder, I see no changes in RpgGameData
I see no changes in RpgGameData
Do you have GameAsset
entity with two attributes Path
and Name
in RpgGameData.gdjs file? It can't import in non-existent entity. Also import could ends with errors.
BTW more detailed result could be taken from RunResult with following code:
importAsync.ContinueWith(t =>
{
if (t.HasErrors) {
Debug.Log(t.Error);
return;
}
using(var result = t.GetResult())
{
if (result.ExitCode == 0) {
return; // no errors
}
// print captured Standard Output and Standard Error
Debug.Log(result.GetOutputData() + "\r\n" + result.GetErrorData());
}
});
Hi,
first: great asset, evaluating it right now for out next project.
A question: currently we are using ScriptableObjects to store game data, this allows us to store for example types like Unity's Color or more importantly Prefab instances that can be Instantiate()d at run-time. Will more types be supported by Charon? If not, what do you recommend tu support this case when working with Charon?