-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
🚧 0.7.x update
- 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.
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 @@ | ||
/* | ||
* Copyright (c) 2024 Carter Games | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
using CarterGames.Cart.Core; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CarterGames.TheCart.Core.Editor | ||
{ | ||
[CustomPropertyDrawer(typeof(ReadonlyAttribute), true)] | ||
public class ReadonlyPropertyDrawer : PropertyDrawer | ||
{ | ||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
EditorGUI.BeginProperty(position, label, property); | ||
|
||
EditorGUI.BeginDisabledGroup(true); | ||
EditorGUI.PropertyField(position, property, label); | ||
EditorGUI.EndDisabledGroup(); | ||
|
||
EditorGUI.EndProperty(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,134 @@ | ||
/* | ||
* Copyright (c) 2024 Carter Games | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
using System.IO; | ||
using CarterGames.Cart.Core.Management.Editor; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CarterGames.Cart.Core.Data.Editor | ||
{ | ||
/// <summary> | ||
/// Creates data asset for the user. | ||
/// </summary> | ||
public sealed class DataAssetCreator : EditorWindow | ||
{ | ||
/* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | ||
| Fields | ||
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ | ||
|
||
private string dataAssetName; | ||
private bool makeDataAssetWhenGenerated; | ||
|
||
/* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | ||
| Menu Items | ||
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ | ||
|
||
/// <summary> | ||
/// Makes a menu item for the creator to open. | ||
/// </summary> | ||
[MenuItem("Tools/Carter Games/The Cart/Core/Data/Asset Creator", priority = 515)] | ||
private static void ShowWindow() | ||
{ | ||
var window = GetWindow<DataAssetCreator>(); | ||
window.titleContent = new GUIContent("Data Asset Creator"); | ||
window.Show(); | ||
} | ||
|
||
/* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | ||
| Methods | ||
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ | ||
|
||
/// <summary> | ||
/// Draws the GUI. | ||
/// </summary> | ||
private void OnGUI() | ||
{ | ||
GUILayout.Space(4f); | ||
|
||
EditorGUILayout.BeginVertical("HelpBox"); | ||
GUILayout.Space(1.5f); | ||
|
||
EditorGUILayout.LabelField("Data Asset Name", EditorStyles.boldLabel); | ||
GeneralUtilEditor.DrawHorizontalGUILine(); | ||
dataAssetName = EditorGUILayout.TextField(dataAssetName); | ||
|
||
GUILayout.Space(1.5f); | ||
EditorGUILayout.EndVertical(); | ||
|
||
GUILayout.Space(4f); | ||
|
||
EditorGUILayout.BeginVertical("HelpBox"); | ||
GUILayout.Space(1.5f); | ||
|
||
EditorGUILayout.LabelField("Will create:", EditorStyles.boldLabel); | ||
GeneralUtilEditor.DrawHorizontalGUILine(); | ||
EditorGUILayout.LabelField(new GUIContent("DataAsset: "), | ||
new GUIContent("DataAsset" + dataAssetName + ".cs")); | ||
|
||
GUILayout.Space(1.5f); | ||
EditorGUILayout.EndVertical(); | ||
|
||
GUILayout.Space(4f); | ||
|
||
if (GUILayout.Button("Create")) | ||
{ | ||
CreateAssetFile(out string path); | ||
|
||
AssetDatabase.SaveAssets(); | ||
AssetDatabase.Refresh(); | ||
|
||
EditorUtility.RequestScriptReload(); | ||
|
||
if (Dialogue.Display("Data Asset Creator", | ||
"Would you like to open the newly created files for editing?", "Yes", "No")) | ||
{ | ||
AssetDatabase.OpenAsset(AssetDatabase.LoadAssetAtPath<TextAsset>(path)); | ||
} | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Creates the asset file for the data class the user is making. | ||
/// </summary> | ||
/// <param name="filePath">The path to create at.</param> | ||
private void CreateAssetFile(out string filePath) | ||
{ | ||
filePath = EditorUtility.SaveFilePanelInProject("Save New Data Asset Class", | ||
$"DataAsset{dataAssetName}", "cs", ""); | ||
|
||
var script = AssetDatabase.FindAssets($"t:Script {nameof(DataAssetCreator)}")[0]; | ||
var pathToTextFile = AssetDatabase.GUIDToAssetPath(script); | ||
pathToTextFile = pathToTextFile.Replace("DataAssetCreator.cs", "DataAssetTemplate.txt"); | ||
|
||
TextAsset template = AssetDatabase.LoadAssetAtPath<TextAsset>(pathToTextFile); | ||
template = new TextAsset(template.text); | ||
var replace = template.text.Replace("%DataAssetName%", "DataAsset" + dataAssetName); | ||
replace = replace.Replace("%DataTypeName%", "Data" + dataAssetName); | ||
|
||
File.WriteAllText(filePath, replace); | ||
EditorUtility.SetDirty(AssetDatabase.LoadAssetAtPath<TextAsset>(pathToTextFile)); | ||
} | ||
} | ||
} |
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,12 @@ | ||
using CarterGames.Cart.Core.Data; | ||
using UnityEngine; | ||
|
||
|
||
namespace Data | ||
{ | ||
[CreateAssetMenu(fileName = "%DataAssetName%")] | ||
public class %DataAssetName% : DataAsset | ||
{ | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.