-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
v1.0.0
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
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.
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
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); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.