mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-05-08 17:54:12 +02:00
feat: export level (#57)
This commit is contained in:
parent
02ef8cdf74
commit
edc6504e10
14
.vscode/extensions.json
vendored
14
.vscode/extensions.json
vendored
@ -1,9 +1,9 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"editorconfig.editorconfig",
|
||||
"jebbs.plantuml",
|
||||
"visualstudiotoolsforunity.vstuc",
|
||||
"ms-dotnettools.csharp",
|
||||
"ms-dotnettools.csdevkit"
|
||||
]
|
||||
"recommendations": [
|
||||
"editorconfig.editorconfig",
|
||||
"jebbs.plantuml",
|
||||
"visualstudiotoolsforunity.vstuc",
|
||||
"ms-dotnettools.csharp",
|
||||
"ms-dotnettools.csdevkit"
|
||||
]
|
||||
}
|
||||
|
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
@ -1,10 +1,10 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Attach to Unity",
|
||||
"type": "vstuc",
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Attach to Unity",
|
||||
"type": "vstuc",
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
16
.vscode/settings.json
vendored
16
.vscode/settings.json
vendored
@ -1,10 +1,10 @@
|
||||
{
|
||||
"editor.bracketPairColorization.enabled": true,
|
||||
"editor.wordWrap": "on",
|
||||
"[csharp]": {
|
||||
"editor.tabSize": 4,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnType": true
|
||||
},
|
||||
"omnisharp.useModernNet": false
|
||||
"editor.bracketPairColorization.enabled": true,
|
||||
"editor.wordWrap": "on",
|
||||
"[csharp]": {
|
||||
"editor.tabSize": 4,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnType": true
|
||||
},
|
||||
"omnisharp.useModernNet": false
|
||||
}
|
||||
|
@ -96,6 +96,19 @@ TextureImporter:
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites:
|
||||
@ -134,7 +147,8 @@ TextureImporter:
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
nameFileIdTable:
|
||||
RegularBlock01_0: 229215520534054086
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
|
@ -96,6 +96,19 @@ TextureImporter:
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites:
|
||||
@ -134,7 +147,8 @@ TextureImporter:
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
nameFileIdTable:
|
||||
NewLevelButton 1_0: 4829622404114481491
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
|
@ -96,6 +96,19 @@ TextureImporter:
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites:
|
||||
@ -134,7 +147,8 @@ TextureImporter:
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
nameFileIdTable:
|
||||
CubePortalLabelled_0: -799402021850825835
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
|
@ -96,6 +96,19 @@ TextureImporter:
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites:
|
||||
@ -134,7 +147,8 @@ TextureImporter:
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
nameFileIdTable:
|
||||
ShipPortalLabelled_0: -1834338360412052916
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
|
@ -96,6 +96,19 @@ TextureImporter:
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites:
|
||||
@ -134,7 +147,8 @@ TextureImporter:
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
nameFileIdTable:
|
||||
Remove_0: -6564193165698205349
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
|
@ -306,6 +306,9 @@ GameObject:
|
||||
- component: {fileID: 678214373}
|
||||
- component: {fileID: 678214375}
|
||||
- component: {fileID: 678214374}
|
||||
- component: {fileID: 678214377}
|
||||
- component: {fileID: 678214376}
|
||||
- component: {fileID: 678214378}
|
||||
m_Layer: 5
|
||||
m_Name: Save
|
||||
m_TagString: Untagged
|
||||
@ -370,6 +373,90 @@ CanvasRenderer:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 678214372}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!114 &678214376
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 678214372}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Navigation:
|
||||
m_Mode: 3
|
||||
m_WrapAround: 0
|
||||
m_SelectOnUp: {fileID: 0}
|
||||
m_SelectOnDown: {fileID: 0}
|
||||
m_SelectOnLeft: {fileID: 0}
|
||||
m_SelectOnRight: {fileID: 0}
|
||||
m_Transition: 1
|
||||
m_Colors:
|
||||
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
|
||||
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
|
||||
m_ColorMultiplier: 1
|
||||
m_FadeDuration: 0.1
|
||||
m_SpriteState:
|
||||
m_HighlightedSprite: {fileID: 0}
|
||||
m_PressedSprite: {fileID: 0}
|
||||
m_SelectedSprite: {fileID: 0}
|
||||
m_DisabledSprite: {fileID: 0}
|
||||
m_AnimationTriggers:
|
||||
m_NormalTrigger: Normal
|
||||
m_HighlightedTrigger: Highlighted
|
||||
m_PressedTrigger: Pressed
|
||||
m_SelectedTrigger: Selected
|
||||
m_DisabledTrigger: Disabled
|
||||
m_Interactable: 1
|
||||
m_TargetGraphic: {fileID: 678214374}
|
||||
m_OnClick:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 678214377}
|
||||
m_TargetAssemblyTypeName: JSONExporter, Assembly-CSharp
|
||||
m_MethodName: ExportJSON
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
|
||||
m_IntArgument: 0
|
||||
m_FloatArgument: 0
|
||||
m_StringArgument:
|
||||
m_BoolArgument: 0
|
||||
m_CallState: 2
|
||||
--- !u!114 &678214377
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 678214372}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d3227fe18f4441647bdd19d3131efa02, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
editor: {fileID: 0}
|
||||
--- !u!114 &678214378
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 678214372}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f5bf592d3d8430744a08058675701934, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
mapParent: {fileID: 0}
|
||||
blockGroupContainer: {fileID: 394350961}
|
||||
buttonPrefabTemplate: {fileID: 1993500743}
|
||||
--- !u!1 &739948034
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
147
Assets/Scripts/JSONExporter.cs
Normal file
147
Assets/Scripts/JSONExporter.cs
Normal file
@ -0,0 +1,147 @@
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using SimpleFileBrowser;
|
||||
using TMPro;
|
||||
|
||||
[RequireComponent(typeof(LevelEditor))]
|
||||
public class JSONExporter : MonoBehaviour
|
||||
{
|
||||
public TMP_Text statusText;
|
||||
private LevelEditor editor;
|
||||
private string levelsFolder;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
editor = GetComponent<LevelEditor>();
|
||||
levelsFolder = Path.Combine(Application.dataPath, "Resources/Levels");
|
||||
if (!Directory.Exists(levelsFolder))
|
||||
Directory.CreateDirectory(levelsFolder);
|
||||
|
||||
if (statusText == null)
|
||||
{
|
||||
var statusObj = GameObject.Find("StatusText");
|
||||
if (statusObj != null)
|
||||
statusText = statusObj.GetComponent<TMP_Text>();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetStatus("Ready to export...", Color.white);
|
||||
}
|
||||
|
||||
public void ExportJSON()
|
||||
{
|
||||
SetStatus("Exporting...", Color.yellow);
|
||||
StartCoroutine(ShowSaveDialog());
|
||||
}
|
||||
|
||||
private IEnumerator ShowSaveDialog()
|
||||
{
|
||||
yield return FileBrowser.WaitForSaveDialog(
|
||||
FileBrowser.PickMode.Files,
|
||||
false,
|
||||
levelsFolder,
|
||||
"NewLevel.json",
|
||||
"Save Level JSON",
|
||||
"Save"
|
||||
);
|
||||
|
||||
if (!FileBrowser.Success)
|
||||
{
|
||||
SetStatus("Save canceled.", Color.red);
|
||||
yield break;
|
||||
}
|
||||
|
||||
string chosenPath = FileBrowser.Result[0];
|
||||
string fileName = Path.GetFileNameWithoutExtension(chosenPath);
|
||||
string destPath = Path.Combine(levelsFolder, fileName + ".json");
|
||||
|
||||
var elements = new List<SerializableElement>();
|
||||
var allCols = Object.FindObjectsByType<Collider2D>(FindObjectsSortMode.None);
|
||||
foreach (var col in allCols)
|
||||
{
|
||||
var go = col.gameObject;
|
||||
if (!go.name.Contains("(Clone)") || go.name.ToLower().Contains("ground"))
|
||||
continue;
|
||||
|
||||
Vector3 scale = go.transform.localScale;
|
||||
Vector3 pos = go.transform.position;
|
||||
|
||||
elements.Add(new SerializableElement
|
||||
{
|
||||
type = go.name.Replace("(Clone)", ""),
|
||||
x = Mathf.Round(pos.x * 100f) / 100f,
|
||||
y = Mathf.Round(pos.y * 100f) / 100f,
|
||||
scaleX = Mathf.Round(scale.x * 100f) / 100f,
|
||||
scaleY = Mathf.Round(scale.y * 100f) / 100f
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.Count == 0)
|
||||
{
|
||||
SetStatus("No elements to export.", Color.red);
|
||||
yield break;
|
||||
}
|
||||
|
||||
LevelData data = new LevelData
|
||||
{
|
||||
name = fileName,
|
||||
musicName = "",
|
||||
order = 0,
|
||||
elements = elements.ToArray()
|
||||
};
|
||||
string json = JsonUtility.ToJson(data, prettyPrint: true);
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllText(destPath, json);
|
||||
SetStatus("Export successful: " + fileName + ".json", Color.green);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError("Export error: " + e);
|
||||
SetStatus("Export error. See console.", Color.red);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
var loader = Object.FindAnyObjectByType<LevelsLoader>();
|
||||
if (loader != null)
|
||||
loader.RefreshLevels();
|
||||
}
|
||||
|
||||
private void SetStatus(string message, Color color)
|
||||
{
|
||||
if (statusText != null)
|
||||
{
|
||||
statusText.text = message;
|
||||
statusText.color = color;
|
||||
statusText.gameObject.SetActive(false);
|
||||
statusText.gameObject.SetActive(true);
|
||||
Canvas.ForceUpdateCanvases();
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private class SerializableElement
|
||||
{
|
||||
public string type;
|
||||
public float x;
|
||||
public float y;
|
||||
public float scaleX;
|
||||
public float scaleY;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private class LevelData
|
||||
{
|
||||
public string name;
|
||||
public string musicName;
|
||||
public int order;
|
||||
public SerializableElement[] elements;
|
||||
}
|
||||
}
|
2
Assets/Scripts/JSONExporter.cs.meta
Normal file
2
Assets/Scripts/JSONExporter.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3227fe18f4441647bdd19d3131efa02
|
@ -41,6 +41,16 @@ public class LevelEditor : MonoBehaviour
|
||||
|
||||
void GenerateButtons()
|
||||
{
|
||||
if (buttonPrefabTemplate == null)
|
||||
{
|
||||
Debug.LogError("LevelEditor.GenerateButtons(): buttonPrefabTemplate n’est pas assigné !");
|
||||
return;
|
||||
}
|
||||
if (blockGroupContainer == null)
|
||||
{
|
||||
Debug.LogError("LevelEditor.GenerateButtons(): blockGroupContainer n’est pas assigné !");
|
||||
return;
|
||||
}
|
||||
ClearCurrentButtons();
|
||||
|
||||
Transform container = blockGroupContainer;
|
||||
@ -440,9 +450,4 @@ public class LevelEditor : MonoBehaviour
|
||||
currentBlock.transform.Rotate(0f, 0f, -90f); // ➔ Rotation de 90° dans le sens horaire
|
||||
Debug.Log("🔄 Bloc pivoté de 90° !");
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
// TODO : Implémenter la sauvegarde du niveau
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user