Commit 3e34c4b8 authored by 18신대성's avatar 18신대성

stage Selector UI 구현

parent 7861051d
This diff is collapsed.
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3762876622413059634
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5348814945624111502}
- component: {fileID: 4558618491563163276}
- component: {fileID: 6278400532885659243}
- component: {fileID: 5750987770888961294}
m_Layer: 5
m_Name: StageButton
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &5348814945624111502
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3762876622413059634}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2167206040876976037}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -470, y: -138}
m_SizeDelta: {x: 140, y: 140}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4558618491563163276
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3762876622413059634}
m_CullTransparentMesh: 0
--- !u!114 &6278400532885659243
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3762876622413059634}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 21300000, guid: 66fc7ec5dc20bab47b168dfae5fbb19e, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!114 &5750987770888961294
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3762876622413059634}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
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: 6278400532885659243}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!1 &5888492629013806799
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2167206040876976037}
- component: {fileID: 2771110586884929903}
- component: {fileID: 5362406042658780520}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2167206040876976037
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5888492629013806799}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 5348814945624111502}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2771110586884929903
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5888492629013806799}
m_CullTransparentMesh: 0
--- !u!114 &5362406042658780520
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5888492629013806799}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.9733331, g: 1, b: 0, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 65
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 6
m_MaxSize: 65
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 12
fileFormatVersion: 2
guid: 8939d9dd74b1afb498ab8705da6054b8
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 2db931095b0be3b43bc0dbfcb9454416
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
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
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
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: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Newtonsoft.Json;
public class GameManager : SingletonBehaviour<GameManager>
{
[Header("Saved Data")]
public ClearData playerData;
/// <summary>
/// The index of the current stage.
/// </summary>
......@@ -94,7 +91,7 @@ public class GameManager : SingletonBehaviour<GameManager>
Debug.Log("Stage Clear!");
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
SaveClearData(stageIdx, true);
StageSelector.inst.SaveClearData(stageIdx, true);
yield return new WaitForSeconds(3);
BackToStageSelect();
......@@ -103,7 +100,7 @@ public class GameManager : SingletonBehaviour<GameManager>
public void GameOver()
{
Debug.Log("Game Over!");
SaveClearData(stageIdx, false);
StageSelector.inst.SaveClearData(stageIdx, false);
isGameOver = true;
StopAllCoroutines();
StartCoroutine(RestartStage());
......@@ -124,46 +121,9 @@ public class GameManager : SingletonBehaviour<GameManager>
SceneManager.LoadScene("SelectStage");
}
public void SaveClearData(int stage = -1, bool isClear = false)
{
if (stage != -1)
{
if (playerData.isCleared.ContainsKey(stage))
{
playerData.isCleared[stage] = isClear;
}
else playerData.isCleared.Add(stage, isClear);
}
string jsonData = JsonConvert.SerializeObject(playerData);
File.WriteAllText("./saveData.json", jsonData);
}
public void LoadClearData()
{
if (File.Exists("./saveData.json"))
{
Debug.Log("data Load");
string strData = File.ReadAllText("./saveData.json");
playerData = JsonConvert.DeserializeObject<ClearData>(strData);
}
else
{
Debug.Log("generate New Data");
playerData = new ClearData();
SaveClearData();
}
}
public class ClearData
{
public Dictionary<int, bool> isCleared = new Dictionary<int, bool>();
}
// Start is called before the first frame update
void Start()
{
GameManager.inst.LoadClearData();
if (!MapManager.inst.isMapEditingOn)
{
isGameOver = false;
......
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using Newtonsoft.Json;
public class StageSelector : MonoBehaviour
public class StageSelector : SingletonBehaviour<StageSelector>
{
public Text stageIndex;
public static int selectedStage;
public TextAsset[] stage;
int totalStageCount;
public void ChangeStage(int i)
public ClearData playerData;
[Header("UI Settings")]
public GameObject buttonUI;
public Sprite tutorialFalse;
public Color tutorialFalseColor = new Color(1f, 0.9921569f, 0.8666667f);
public Sprite tutorialTrue;
public Color tutorialTrueColor = new Color(0.9686275f, 0.9137256f, 0.04313726f);
public Sprite mainFalse;
public Color mainFalseColor = Color.white;
public Sprite mainTrue;
public Color mainTrueColor = new Color(0.1921569f, 1f, 0.3843138f);
int tutorialCount = 12;
int maxRow = 8; // y-=155
Vector3 tutorialPoint = new Vector3(-470, 265); // x+=160
Vector3 mainPoint = new Vector3(-470, -138);
List<Button> buttons = new List<Button>();
public void GenerateStageUI()
{
if(i < 0 && selectedStage == 0) selectedStage = totalStageCount - 1;
else selectedStage = (selectedStage + i) % totalStageCount;
stageIndex.text = "Stage : " + (selectedStage + 1);
int rowCount = 0;
for (int i = 0; i < tutorialCount; i++)
{
var uiInst = Instantiate(buttonUI, transform);
var uiText = uiInst.GetComponentInChildren<Text>();
buttons.Add(uiInst.GetComponent<Button>());
uiInst.transform.localPosition = tutorialPoint;
uiText.text = (i + 1).ToString();
if (playerData.isCleared.ContainsKey(i + 1) && playerData.isCleared[i + 1])
{
uiInst.GetComponent<Image>().sprite = tutorialTrue;
uiText.color = tutorialTrueColor;
}
else
{
uiInst.GetComponent<Image>().sprite = tutorialFalse;
uiText.color = tutorialFalseColor;
}
if ((rowCount + 1) / maxRow > 0)
{
tutorialPoint += new Vector3(-160 * (maxRow - 1), -155);
rowCount = 0;
}
else tutorialPoint += new Vector3(160, 0);
rowCount++;
}
rowCount = 0;
for (int i = tutorialCount; i < stage.Length; i++)
{
var uiInst = Instantiate(buttonUI, transform);
var uiText = uiInst.GetComponentInChildren<Text>();
buttons.Add(uiInst.GetComponent<Button>());
uiInst.transform.localPosition = mainPoint;
uiText.text = (i - tutorialCount + 1).ToString();
if (playerData.isCleared.ContainsKey(i + 1) && playerData.isCleared[i + 1])
{
uiInst.GetComponent<Image>().sprite = mainTrue;
uiText.color = mainTrueColor;
}
else
{
uiInst.GetComponent<Image>().sprite = mainFalse;
uiText.color = mainFalseColor;
}
if ((rowCount + 1) / maxRow > 0)
{
mainPoint += new Vector3(-160 * (maxRow - 1), -155);
rowCount = 0;
}
else mainPoint += new Vector3(160, 0);
rowCount++;
}
for (int i = 0; i < stage.Length; i++)
{
int _i = i;
buttons[i].onClick.AddListener(() => StartSelectedStage(_i));
}
}
public void StartSelectedStage()
public void StartSelectedStage(int stageNum)
{
selectedStage = stageNum;
gameObject.GetComponent<Canvas>().enabled = false;
SceneManager.LoadScene("PlayStage");
}
public void SaveClearData(int stage = -1, bool isClear = false)
{
if (stage != -1)
{
if (playerData.isCleared.ContainsKey(stage))
{
playerData.isCleared[stage] = isClear;
}
else playerData.isCleared.Add(stage, isClear);
}
string jsonData = JsonConvert.SerializeObject(playerData);
File.WriteAllText("./saveData.json", jsonData);
}
public void LoadClearData()
{
if (File.Exists("./saveData.json"))
{
Debug.Log("data Load");
string strData = File.ReadAllText("./saveData.json");
playerData = JsonConvert.DeserializeObject<ClearData>(strData);
}
else
{
Debug.Log("generate New Data");
playerData = new ClearData();
SaveClearData();
}
}
public class ClearData
{
public Dictionary<int, bool> isCleared = new Dictionary<int, bool>();
}
void Awake()
{
DontDestroyOnLoad(this);
stage = Resources.LoadAll<TextAsset>("Stages");
LoadClearData();
}
// Start is called before the first frame update
void Start()
{
GameManager.inst.LoadClearData();
GenerateStageUI();
selectedStage = 0;
totalStageCount = stage.Length;
}
// Update is called once per frame
void Update()
{
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment