Skip to content

Commit

Permalink
Merge pull request #7 from MidraLab/develop
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
ayutaz authored Dec 29, 2023
2 parents c50ace9 + d4b73f7 commit ee26569
Show file tree
Hide file tree
Showing 18 changed files with 483 additions and 91 deletions.
3 changes: 3 additions & 0 deletions Assets/UniMasterLinker/Scripts/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions Assets/UniMasterLinker/Scripts/Editor/UpdateAPIClassMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#if UNITY_EDITOR

using System.Threading;
using Cysharp.Threading.Tasks;
using UniMasterLinker.Util;
using UnityEditor;

namespace UniMasterLinker.Editor
{
/// <summary>
/// ゲームマスターのAPIクラスを更新するエディタ拡張
/// </summary>
public class UpdateAPIClassMenu : EditorWindow
{
/// <summary>
/// APIクラスの更新
/// </summary>
[MenuItem("UniMasterLinker/APIクラスの更新")]
private static async void UpdateAPIClassFile()
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
// 実装例
// var baseWeapon = GoogleSheetUtil.GetGameInfo(Constant.Constant.GameMasterSheetURL,
// Constant.Constant.BaseWeapon, tokenSource.Token);
// var materialWeapon = GoogleSheetUtil.GetGameInfo(
// Constant.Constant.GameMasterSheetURL, Constant.Constant.MaterialWeapon, tokenSource.Token);
//
//
// var (baseWeaponPramJson, materialWeaponParamJson) =
// await UniTask.WhenAll(baseWeapon, materialWeapon;
//
// // プレイヤーの初期パラメータAPIクラスを生成
// UpdateGameMasterAPIClass.CreateParamAPIClassFile(baseWeaponPramJson, Constant.Constant.BaseWeapon);
// UpdateGameMasterAPIClass.CreateParamAPIClassFile(materialWeaponParamJson, Constant.Constant.MaterialWeapon);
//
// //データオブジェクトクラスも存在していない場合は、作成する
// CreateDataObjectClass.CreateDataObjectClasses(Constant.Constant.BaseWeapon, Constant.Constant.MaterialWeapon,Constant.Constant.Enemy,Constant.Constant.AlchemyTable,Constant.Constant.Element);
//
// // データオブジェクト(ScriptableObject)が存在しない場合は作成する
// CreateDataObject.CreateDataObjectFiles(Constant.Constant.BaseWeapon, Constant.Constant.MaterialWeapon,Constant.Constant.Enemy,Constant.Constant.AlchemyTable,Constant.Constant.Element);
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Assets/UniMasterLinker/Scripts/Editor/UpdateGameDataObjectMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if UNITY_EDITOR

using System.Threading;
using Cysharp.Threading.Tasks;
using UniMasterLinker.Util;
using UnityEditor;

namespace UniMasterLinker.Editor
{
/// <summary>
/// ゲームデータオブジェクトの更新
/// </summary>
public class UpdateGameDataObjectMenu : EditorWindow
{
private static CancellationTokenSource _cancellationTokenSource;

/// <summary>
/// ゲームデータオブジェクトの更新
/// </summary>
[MenuItem("UniMasterLinker/ゲームデータオブジェクトの更新")]
private static void UpdateDataObject()
{
_cancellationTokenSource = new CancellationTokenSource();
UpdateGameDataObject.UpdateDataObject(_cancellationTokenSource.Token).Forget();
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions Assets/UniMasterLinker/Scripts/Util/CreateDataObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#if UNITY_EDITOR

using UnityEditor;
using UnityEngine;

namespace UniMasterLinker.Util
{
/// <summary>
/// データオブジェクトを作成するクラス
/// </summary>
public static class CreateDataObject
{
/// <summary>
/// データオブジェクトのクラスの作成パス
/// </summary>
private const string DataRootPath = "/UniMasterLinker/DataObject/";

/// <summary>
/// データオブジェクトのクラスを作成する
/// </summary>
public static void CreateDataObjectFiles(params string[] dataObjectNameList)
{
foreach (var dataObjectName in dataObjectNameList)
{
var objectName = dataObjectName + "DataObject";
if (IsExistDataObject(objectName)) continue;
CrateDataObject(objectName);
}
}

/// <summary>
/// データオブジェクトを作成
/// </summary>
/// <param name="dataObjectName"></param>
private static void CrateDataObject(string dataObjectName)
{
var obj = ScriptableObject.CreateInstance(dataObjectName);
var path = "Assets" + DataRootPath + dataObjectName + ".asset";
AssetDatabase.CreateAsset(obj, path);
}

/// <summary>
/// データオブジェクトが存在するか
/// </summary>
/// <param name="dataObjectName"></param>
private static bool IsExistDataObject(string dataObjectName)
{
var path = Application.dataPath + DataRootPath + dataObjectName + ".asset";
return System.IO.File.Exists(path);
}
}
}
#endif
3 changes: 3 additions & 0 deletions Assets/UniMasterLinker/Scripts/Util/CreateDataObject.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions Assets/UniMasterLinker/Scripts/Util/CreateDataObjectClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#if UNITY_EDITOR

namespace UniMasterLinker.Util
{
/// <summary>
/// データオブジェクトのクラスを作成するクラス
/// </summary>
public class CreateDataObjectClass
{
/// <summary>
/// データオブジェクトのクラスの作成パス
/// </summary>
private const string DataRootPath = "/UniMasterLinker/Scripts/DataObject/";

/// <summary>
/// データオブジェクトのクラスを作成する
/// </summary>
public static void CreateDataObjectClasses(params string[] classNameList)
{
foreach (var className in classNameList)
{
if (IsExistDataObjectClass(className)) continue;
CrateDataObjectClass(className);
}
}

/// <summary>
/// データオブジェクトのクラスが存在するか
/// </summary>
/// <param name="className"></param>
/// <returns></returns>
private static bool IsExistDataObjectClass(string className)
{
return GenerateClassUtil.IsExistClass(className, DataRootPath);
}

/// <summary>
/// データオブジェクトのクラスを作成
/// </summary>
/// <param name="className"></param>
private static void CrateDataObjectClass(string className)
{
var scriptContent = CreateDataObjectScriptContent(className);
var createFileName = GetCreateFileName(className);
GenerateClassUtil.CreateScript(createFileName, scriptContent, DataRootPath);
}

/// <summary>
/// データオブジェクトのクラス名を取得
/// </summary>
/// <param name="className"></param>
/// <returns></returns>
private static string GetCreateFileName(string className)
{
return className + "DataObject";
}

/// <summary>
/// データオブジェクトのクラス内容を作成
/// </summary>
/// <param name="className"></param>
/// <returns></returns>
private static string CreateDataObjectScriptContent(string className)
{
return $@"using UniMasterLinker.API;
using UnityEngine;
namespace UniMasterLinker.DataObject
{{
[CreateAssetMenu(fileName = ""{className}DataObject"", menuName = ""UniMasterLinker/{className}DataObject"", order = 0)]
public class {className}DataObject : DataObjectBase<{className}Data>
{{
}}
}}";
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions Assets/UniMasterLinker/Scripts/Util/GenerateClassUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;

namespace UniMasterLinker.Util
{
/// <summary>
/// クラスの生成を行うUtilityクラス
/// </summary>
public class GenerateClassUtil
{
#if UNITY_EDITOR

/// <summary>
/// スクリプトファイルを生成
/// </summary>
/// <param name="fileName"></param>
/// <param name="content"></param>
/// <param name="dataRootPath"></param>
public static void CreateScript(string fileName, string content, string dataRootPath)
{
var createPath = Application.dataPath + "/" + dataRootPath + "/" + fileName + ".cs";

using (var writer = new StreamWriter(createPath, false))
{
writer.WriteLine(content);
}

AssetDatabase.Refresh();
}
#endif

/// <summary>
/// 自動生成クラスファイルが存在するか
/// </summary>
/// <param name="className"></param>
/// <param name="dataRootPath"></param>
/// <returns></returns>
/// <exception></exception>
public static bool IsExistClass(string className, string dataRootPath)
{
var path = Application.dataPath + dataRootPath + className + "DataObject" + ".cs";
return File.Exists(path);
}
}
}
3 changes: 3 additions & 0 deletions Assets/UniMasterLinker/Scripts/Util/GenerateClassUtil.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 22 additions & 13 deletions Assets/UniMasterLinker/Scripts/Util/GoogleSheetUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace UniMasterLinker.Util
{
/// <summary>
/// GoogleSheet(GAS)のユーティリティ
/// </summary>
public static class GoogleSheetUtil
{
/// <summary>
Expand Down Expand Up @@ -47,11 +50,12 @@ public static async UniTask<T> GetGameInfo<T>(string url, string sheetName, Canc
/// </summary>
/// <param name="url"></param>
/// <param name="sheetName"></param>
/// <param name="token"></param>
/// <returns></returns>
public static async UniTask<string> GetGameInfo(string url, string sheetName)
public static async UniTask<string> GetGameInfo(string url, string sheetName,CancellationToken token)
{
var request = UnityWebRequest.Get($"{url}?sheetName={sheetName}");
await request.SendWebRequest();
await request.SendWebRequest().WithCancellation(token);
if (request.result is UnityWebRequest.Result.ConnectionError or UnityWebRequest.Result.ProtocolError
or UnityWebRequest.Result.DataProcessingError)
{
Expand All @@ -72,9 +76,9 @@ public static async UniTask<string> GetGameInfo(string url, string sheetName)
/// マスターデータのキーの文字列を取得
/// </summary>
/// <returns></returns>
public static List<string> GetParameterKeyList(string json)
public static List<string> GetParameterKeyList(string paramJsonStr)
{
var parseJson = JObject.Parse(json);
var parseJson = JObject.Parse(paramJsonStr);
var gameInfoArray = (JArray)parseJson["gameInfo"];
var gameInfo = (JObject)gameInfoArray?[0];

Expand All @@ -84,11 +88,11 @@ public static List<string> GetParameterKeyList(string json)
/// <summary>
/// マスターデータのパラメータのタイプの取得
/// </summary>
/// <param name="json"></param>
/// <param name="paramJsonStr"></param>
/// <returns></returns>
public static List<string> GetParameterTypeList(string json)
public static List<string> GetParameterTypeList(string paramJsonStr)
{
var parseJson = JObject.Parse(json);
var parseJson = JObject.Parse(paramJsonStr);
var gameInfoArray = (JArray)parseJson["gameInfo"];
var gameInfo = (JObject)gameInfoArray?[0];

Expand All @@ -98,11 +102,11 @@ public static List<string> GetParameterTypeList(string json)
/// <summary>
/// マスターデータのパラメータの説明の取得
/// </summary>
/// <param name="json"></param>
/// <param name="paramJsonStr"></param>
/// <returns></returns>
public static List<string> GetParameterDescriptionList(string json)
public static List<string> GetParameterDescriptionList(string paramJsonStr)
{
var parseJson = JObject.Parse(json);
var parseJson = JObject.Parse(paramJsonStr);
var gameInfoArray = (JArray)parseJson["gameInfo"];
var gameInfo = (JObject)gameInfoArray?[0];

Expand All @@ -112,14 +116,19 @@ public static List<string> GetParameterDescriptionList(string json)
/// <summary>
/// マスタデータのjsonをAPIをScriptableObjectに変換できる形に変換する
/// </summary>
/// <param name="json"></param>
/// <param name="paramJsonStr"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
private static T ConvertGameInfo<T>(string json)
private static T ConvertGameInfo<T>(string paramJsonStr)
{
var parsedJson = JObject.Parse(json);
var parsedJson = JObject.Parse(paramJsonStr);
var gameInfoArray = (JArray)parsedJson["gameInfo"];

if (gameInfoArray == null)
{
throw new NullReferenceException("gameInfoArray is null");
}

// Create a new JSON array to hold the converted objects
var finalArray = new JArray();

Expand Down
Loading

0 comments on commit ee26569

Please sign in to comment.