Files
2025-11-30 08:35:03 +02:00

49 lines
1.0 KiB
C#

using System;
using System.IO;
using Newtonsoft.Json;
using UnityEngine;
namespace Needle.Engine
{
public class NeedlePackageConfig
{
public const string NAME = "package.needle.json";
public UnityConfig unity;
[Serializable]
public struct UnityConfig
{
}
public static bool Exists(string dir)
{
if (dir.EndsWith(NAME)) return File.Exists(dir);
return File.Exists(dir + "/" + NAME);
}
public static void Create(string dir)
{
var path = dir + "/" + NAME;
var content = JsonConvert.SerializeObject(new NeedlePackageConfig(), Formatting.Indented);
File.WriteAllText(path, content);
}
public static bool TryRead(string dir, out NeedlePackageConfig config)
{
config = null;
var filepath = dir.EndsWith(NAME) ? dir : dir + "/" + NAME;
if (!File.Exists(filepath)) return false;
try
{
config = JsonConvert.DeserializeObject<NeedlePackageConfig>(File.ReadAllText(filepath));
return true;
}
catch (Exception err)
{
Debug.LogException(err);
return false;
}
}
}
}