feat: level editor saves

This commit is contained in:
LordDemonix 2025-09-17 10:12:15 +02:00
parent 0481d65630
commit 891ac3b712
12 changed files with 8206 additions and 10 deletions

View file

@ -36,7 +36,7 @@ Material:
m_Scale: {x: 1, y: 1} m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: 0}
- _CloudsTex: - _CloudsTex:
m_Texture: {fileID: 2800000, guid: 961fa74443856d247867fce623b3d325, type: 3} m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1} m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: 0}
- _Cube: - _Cube:
@ -115,7 +115,7 @@ Material:
m_Floats: m_Floats:
- _AtmosFalloff: 14 - _AtmosFalloff: 14
- _BumpScale: 1 - _BumpScale: 1
- _CloudIntensityMin: 0.01 - _CloudIntensityMin: 0.1
- _Cutoff: 0.5 - _Cutoff: 0.5
- _DetailIntensity: 0 - _DetailIntensity: 0
- _DetailIntensityMin: 0.01 - _DetailIntensityMin: 0.01

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

View file

@ -0,0 +1,130 @@
fileFormatVersion: 2
guid: d727abdb2d39a8a45bd94b50e306f2cb
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 4096
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 1
swizzle: 50462976
cookieLightType: 1
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 4096
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 4096
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Android
maxTextureSize: 4096
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e5d403b83a5063b48bae611fdec50686
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Dynamic; using System.Dynamic;
using System.Linq; using System.Linq;
@ -7,6 +7,7 @@ using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering; using UnityEngine.Rendering;
using UnityEngine.UIElements; using UnityEngine.UIElements;
using static UnityEditor.PlayerSettings;
using static UnityEngine.GraphicsBuffer; using static UnityEngine.GraphicsBuffer;
[ExecuteAlways] [ExecuteAlways]
@ -24,10 +25,11 @@ public class GameManager : MonoBehaviour
[HideInInspector] public int nodeCount = 100; [HideInInspector] public int nodeCount = 100;
[HideInInspector] public int hoverRadiusCon = 50; [HideInInspector] public int hoverRadiusCon = 50;
[HideInInspector] public int hoverRadiusNode = 50; [HideInInspector] public int hoverRadiusNode = 50;
[HideInInspector] public int selectedLevel = -1;
[SerializeField] [SerializeField] [HideInInspector] public List<Connection> connections = new List<Connection>();
[HideInInspector] public List<Connection> connections = new List<Connection>(); [SerializeField] [HideInInspector] public List<Node> nodes = new List<Node>();
[HideInInspector] public List<Node> nodes = new List<Node>(); [SerializeField] [HideInInspector] public List<LevelData> levels = new List<LevelData>();
[Serializable] [Serializable]
public class Connection public class Connection
@ -151,6 +153,123 @@ public class GameManager : MonoBehaviour
con.lineRenderer.enabled = true; con.lineRenderer.enabled = true;
} }
} }
public void LoadLevelData(int index)
{
if(index >= levels.Count)
{
Debug.LogWarning("LevelIndex out of range");
return;
}
connections.Clear();
nodes.Clear();
for (int i = NodeParent.childCount - 1; i >= 0; i--)
DestroyImmediate(NodeParent.GetChild(i).gameObject);
foreach (LineRenderer line in ConnectionParent.GetComponentsInChildren<LineRenderer>())
DestroyImmediate(line.gameObject);
foreach(LevelData.NodeData nodeData in levels[index].nodes)
{
var auto = PrefabUtility.InstantiatePrefab(NodePrefab, NodeParent) as GameObject;
auto.transform.localPosition = nodeData.position;
nodes.Add(auto.GetComponent<Node>());
auto.GetComponent<Node>().Owner = nodeData.owner;
}
foreach (LevelData.ConnectionData conData in levels[index].connections)
{
var dummy = new GameObject("dummy");
dummy.transform.SetParent(ConnectionParent);
var newCon = new Connection
{
nodeA = nodes[conData.nodeAIndex],
nodeB = nodes[conData.nodeBIndex],
allowed = conData.allowed,
lineRenderer = dummy.AddComponent<LineRenderer>()
};
newCon.lineRenderer.enabled = false;
newCon.lineRenderer.material = new Material(Shader.Find("Sprites/Default"));
newCon.lineRenderer.positionCount = 3;
connections.Add(newCon);
}
selectedLevel = index;
maxConnectionLength = levels[index].maxConnectionLength;
nodeCount = nodes.Count;
Debug.Log("Loaded Level " + index);
}
public void SaveLevelData(int index = -1)
{
LevelData data = new LevelData();
data.maxConnectionLength = maxConnectionLength;
// Nodes speichern
foreach (var node in nodes)
{
data.nodes.Add(new LevelData.NodeData
{
position = node.transform.localPosition,
owner = node.Owner
});
}
// Connections speichern
foreach (var con in connections)
{
int idxA = nodes.IndexOf(con.nodeA);
int idxB = nodes.IndexOf(con.nodeB);
if (idxA >= 0 && idxB >= 0)
{
data.connections.Add(new LevelData.ConnectionData
{
nodeAIndex = idxA,
nodeBIndex = idxB,
allowed = con.allowed
});
}
}
if (index == -1 || index >= levels.Count)
levels.Add(data);
else
levels[index] = data;
int newIndex = index < 0 ? levels.Count - 1 : index;
selectedLevel = newIndex;
Debug.Log("Saved Level " + newIndex);
}
}
[Serializable]
public class LevelData
{
[Serializable]
public class NodeData
{
public Vector3 position;
public int owner;
}
[Serializable]
public class ConnectionData
{
public int nodeAIndex;
public int nodeBIndex;
public bool allowed = true;
}
public float maxConnectionLength = 0;
public List<NodeData> nodes = new List<NodeData>();
public List<ConnectionData> connections = new List<ConnectionData>();
} }
#if UNITY_EDITOR #if UNITY_EDITOR
@ -189,7 +308,7 @@ public class GameManagerEditor : Editor
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
if (GUILayout.Button("Generate Nodes")) if (GUILayout.Button("Distribute Nodes"))
{ {
gm.GenerateAlongSphere(); gm.GenerateAlongSphere();
SceneView.RepaintAll(); SceneView.RepaintAll();
@ -225,6 +344,53 @@ public class GameManagerEditor : Editor
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
for(int i = 0; i < gm.levels.Count; i++)
{
if (gm.selectedLevel == i)
GUILayout.Label("▷ Level " + i, EditorStyles.boldLabel);
else
GUILayout.Label(" Level " + i);
}
GUILayout.EndVertical();
GUILayout.BeginVertical();
for (int i = 0; i < gm.levels.Count; i++)
{
if (GUILayout.Button("Load"))
gm.LoadLevelData(i);
}
GUILayout.EndVertical();
GUILayout.BeginVertical();
for (int i = 0; i < gm.levels.Count; i++)
{
GUILayout.BeginHorizontal();
if (gm.selectedLevel == i)
if (GUILayout.Button("Save"))
gm.SaveLevelData(i);
if (GUILayout.Button("Delete"))
{
gm.levels.Remove(gm.levels[i]);
if (gm.selectedLevel == i)
gm.selectedLevel = -1;
if (gm.selectedLevel > i)
gm.selectedLevel--;
if(gm.levels.Count <= 0)
gm.selectedLevel = -1;
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
if (GUILayout.Button("Save as new"))
gm.SaveLevelData();
} }
private void OnSceneGUI() private void OnSceneGUI()

View file

@ -5,7 +5,7 @@ public class Node : MonoBehaviour
{ {
[Range(-1, 1)] [Range(-1, 1)]
[SerializeField] [SerializeField]
private int Owner = -1; public int Owner = -1;
public Material materialOwnerSelf, materialOwnerOther, materialOwnerNone; public Material materialOwnerSelf, materialOwnerOther, materialOwnerNone;

18
Assets/Scripts/Player.cs Normal file
View file

@ -0,0 +1,18 @@
using UnityEngine;
public class Player : MonoBehaviour
{
public float units;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9a4d2cac3973df146885e58ef88aad00

146
Assets/SimpleEarth.mat Normal file
View file

@ -0,0 +1,146 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-9211397388168847639
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 9
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: SimpleEarth
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _ALPHAPREMULTIPLY_ON
- _ALPHATEST_ON
- _DETAIL_MULX2
- _EMISSION
- _SPECULAR_SETUP
- _SURFACE_TYPE_TRANSPARENT
m_InvalidKeywords: []
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses:
- MOTIONVECTORS
- DepthOnly
- SHADOWCASTER
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 2800000, guid: d727abdb2d39a8a45bd94b50e306f2cb, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 2800000, guid: c2fa05cb71836f246b5eabf3f3c6151c, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: d727abdb2d39a8a45bd94b50e306f2cb, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 1
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BlendOp: 0
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.379
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 2
- _DstBlend: 10
- _DstBlendAlpha: 10
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _SampleGI: 0
- _Smoothness: 0
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 1
- _WorkflowMode: 0
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 0.023584902, g: 1, b: 0.9220745, a: 1}
- _Color: {r: 0.023584902, g: 1, b: 0.9220745, a: 1}
- _EmissionColor: {r: 0, g: 3.482202, b: 3.2757185, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 98a844c570be8ba478279dc6d3f13609
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -117,8 +117,8 @@ Material:
- _WorkflowMode: 1 - _WorkflowMode: 1
- _ZWrite: 1 - _ZWrite: 1
m_Colors: m_Colors:
- _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} - _BaseColor: {r: 0.0066749714, g: 0.093463406, b: 0.09433961, a: 1}
- _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1} - _Color: {r: 0.006674971, g: 0.09346338, b: 0.09433959, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: [] m_BuildTextureStacks: []