using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using Newtonsoft.Json;
public class SettingMain : MonoBehaviour
{
public UISettingDirector uiSettingDirector;
void Start()
{
Debug.Log(Application.persistentDataPath);
var path = string.Format("{0}/login_info.json", Application.persistentDataPath);
if (this.IsNewbie())
{
var dic = InfoManager.instance.diclogInInfos = new Dictionary<string, LogInInfo>();
var json = JsonConvert.SerializeObject(dic);
File.WriteAllText(path, json);
}
else
{
var json = File.ReadAllText(path);
InfoManager.instance.diclogInInfos = JsonConvert.DeserializeObject<Dictionary<string, LogInInfo>>(json);
}
this.uiSettingDirector.Init();
}
private bool IsNewbie()
{
var path = string.Format("{0}/login_info.json", Application.persistentDataPath);
if (!File.Exists(path))
{
return true;
}
else return false;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UISettingDirector : MonoBehaviour
{
public UISettingLists uiSettingLists;
public UILogInMenu uiLogInMenu;
public GameObject uiPopuploginMessage;
private GameObject openedPopupMessage;
public void Init()
{
EventManager.instance.openLoginPopupMessage = (text) =>
{
if (openedPopupMessage != null) Destroy(openedPopupMessage.gameObject);
var go = Instantiate(this.uiPopuploginMessage);
this.openedPopupMessage = go;
go.transform.Find("message").transform.Find("txtMessage").GetComponent<TMP_Text>().text = text;
};
this.uiSettingLists.Init();
this.uiLogInMenu.Init();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UISettingLists : MonoBehaviour
{
public Button[] btnswitchs;
public GameObject[] onSwitchs;
public GameObject[] offSwitchs;
public GameObject[] onIcons;
public GameObject[] offIcons;
public Slider[] sliders;
private bool[] isOnSwitch;
public void Init()
{
this.isOnSwitch = new bool[this.btnswitchs.Length];
for(int i = 0; i < this.btnswitchs.Length; i++)
{
int idx = i;
this.btnswitchs[idx].onClick.AddListener(() =>
{
if (!this.isOnSwitch[idx])
{
this.isOnSwitch[idx] = true;
this.offSwitchs[idx].SetActive(false);
this.onSwitchs[idx].SetActive(true);
}
else
{
this.isOnSwitch[idx] = false;
this.offSwitchs[idx].SetActive(true);
this.onSwitchs[idx].SetActive(false);
}
});
}
StartCoroutine(CheckSliderValue());
}
IEnumerator CheckSliderValue()
{
while (true)
{
if(this.sliders[0].value == 0)
{
this.onIcons[0].SetActive(false);
this.offIcons[0].SetActive(true);
}
else
{
this.onIcons[0].SetActive(true);
this.offIcons[0].SetActive(false);
}
if (this.sliders[1].value == 0)
{
this.onIcons[1].SetActive(false);
this.offIcons[1].SetActive(true);
}
else
{
this.onIcons[1].SetActive(true);
this.offIcons[1].SetActive(false);
}
yield return null;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UILogInMenu : MonoBehaviour
{
public Button btnCreateAcount;
public GameObject uiPopupCreateAccountGo;
public Button btnLogIn;
public TMP_Text intpuTxtID;
public TMP_Text intpuTxtPW;
public Button btnFindPW;
public GameObject uiPopupFindPW;
public Button btnDeleteAccount;
public GameObject uiPopupDeleteAccount;
public TMP_Text recentId;
public void Init()
{
this.btnCreateAcount.onClick.AddListener(() =>
{
Instantiate(this.uiPopupCreateAccountGo);
});
this.btnLogIn.onClick.AddListener(() =>
{
if(InfoManager.instance.GetLogInInfo(this.intpuTxtID.text, this.intpuTxtPW.text))
{
this.recentId.text = this.intpuTxtID.text;
EventManager.instance.openLoginPopupMessage("LogIn complete");
}
else
{
EventManager.instance.openLoginPopupMessage("Wrong ID or PW");
}
});
this.btnFindPW.onClick.AddListener(() =>
{
Instantiate(this.uiPopupFindPW);
});
this.btnDeleteAccount.onClick.AddListener(() =>
{
Instantiate(this.uiPopupDeleteAccount);
});
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UIPopupDeleteAccount : MonoBehaviour
{
public Button btnDeleteAcount;
public Button btnClose;
public TMP_Text inputID;
public TMP_Text inputPW;
void Start()
{
this.btnDeleteAcount.onClick.AddListener(() =>
{
var logInInfos = InfoManager.instance.diclogInInfos;
if (logInInfos.ContainsKey(this.inputID.text))
{
if (logInInfos[this.inputID.text].pw == this.inputPW.text)
{
logInInfos.Remove(this.inputID.text);
EventManager.instance.openLoginPopupMessage("Your account was deleted");
InfoManager.instance.SaveLogInInfo();
Destroy(this.gameObject);
}
else
{
EventManager.instance.openLoginPopupMessage("Wrong PW");
}
}
else
{
EventManager.instance.openLoginPopupMessage("Wrong ID");
}
});
this.btnClose.onClick.AddListener(() =>
{
Destroy(this.gameObject);
});
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UIPopupCreateAccount : MonoBehaviour
{
public Button btnCreateNewAcount;
public Button btnClose;
public TMP_Text inputID;
public TMP_Text inputPW;
void Start()
{
this.btnCreateNewAcount.onClick.AddListener(() =>
{
string id = this.inputID.text;
string pw = this.inputPW.text;
InfoManager.instance.AddLogInInfo(id, pw);
EventManager.instance.openLoginPopupMessage("New account created");
InfoManager.instance.SaveLogInInfo();
Destroy(this.gameObject);
});
this.btnClose.onClick.AddListener(() =>
{
Destroy(this.gameObject);
});
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Windows;
public class UIPopupFindPW : MonoBehaviour
{
public TMP_Text inputTxtID;
public Button btnFindPW;
public Button btnClose;
void Start()
{
this.btnFindPW.onClick.AddListener(() =>
{
if (InfoManager.instance.diclogInInfos.ContainsKey(this.inputTxtID.text))
{
TextEditor te = new TextEditor();
te.text = InfoManager.instance.diclogInInfos[this.inputTxtID.text].pw;
te.SelectAll();
te.Copy();
EventManager.instance.openLoginPopupMessage("Your PW has been copied to the clipboard");
Destroy(this.gameObject);
}
else
{
EventManager.instance.openLoginPopupMessage("Wrong PW");
}
});
this.btnClose.onClick.AddListener(() =>
{
Destroy(this.gameObject);
});
}
}
옵션 스위치의 on/off 기능과 슬라이더 기능(슬라이더가 0이되면 아이콘의 이미지가 바뀜) 구현
로그인 기능 구현
PW 찾기(PW가 클리보드에 복사 됨) / 제거 기능 구현
-> 클립보드에 텍스트 복사
TextEditor te = new TextEditor();
te.text = InfoManager.instance.diclogInInfos[this.inputTxtID.text].pw;
te.SelectAll();
te.Copy();
'C# > 수업 과제' 카테고리의 다른 글
Unity) [유니티 3D] 키보드, 마우스를 통한 이동과 레이캐스트를 통한 오브젝트 제어 (0) | 2023.02.22 |
---|---|
Unity) [유니티 UI] 버튼을 사용한 다수의 스크롤 뷰 구현 (0) | 2023.02.18 |
원형 큐에 대해 (0) | 2023.02.18 |
SpaceShooter2D (0) | 2023.02.12 |
UNITY) [유니티 UI] 타이틀 UI 구현 (0) | 2023.02.10 |