Skip to content

Commit

Permalink
掃除間隔の設定ができる
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagata Yuto committed Oct 28, 2019
1 parent d882004 commit 590410f
Show file tree
Hide file tree
Showing 8 changed files with 1,448 additions and 74 deletions.
1,268 changes: 1,229 additions & 39 deletions Assets/Scenes/MainScene.unity

Large diffs are not rendered by default.

85 changes: 76 additions & 9 deletions Assets/Script/CleanDataList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ public class CleanPlaceData
{
[SerializeField] string place;
public string Place { get { return place; }private set { place = value; } }
DateTime time;
[SerializeField] SEDataTime seDate;

[SerializeField] SEDataTime lastUpdateTime;
[SerializeField] SEDataTime cleanInterval;
[SerializeField] string dateData;
public string DateData { get { return dateData; } }
public DateTime Time { get { return time; } }
public string DateDataText { get { return dateData; } }
[SerializeField] string cleanIntervalText;
public string CleanIntervalText { get { return cleanIntervalText; } }

public CleanPlaceData(string place)
{
this.place = place;
this.time = DateTime.Now;
seDate = new SEDataTime(time);
dateData = seDate.EntryDate();
lastUpdateTime = new SEDataTime(DateTime.Now);
dateData = lastUpdateTime.EntryDate();
cleanInterval = new SEDataTime();
cleanIntervalText = cleanInterval.DayInterval();
}

public void SetCleanInterval_day(int i)
{
cleanInterval.ChengeData_day(i);
cleanIntervalText = cleanInterval.DayInterval();
}
}
[System.Serializable]
Expand All @@ -44,9 +53,57 @@ public SEDataTime(DateTime time)
this.second = time.Second;
}

public SEDataTime()
{
this.year = 0;
this.month = 0;
this.day = 0;
this.hour = 0;
this.minute = 0;
this.second = 0;
}

public string EntryDate()
{
return this.year + "" + this.month + "" + this.day + "" + this.hour + "" + this.minute + "" + this.second + "";
return this.month + "" + this.day + "" + this.hour + "" + this.minute + "" + this.second + "";
}
public string DayInterval()
{
string Result="";
if(this.year != 0)
{
Result += year + "";
}
if (this.month != 0)
{
Result += month + "";
}
if (this.day != 0)
{
Result += day + "";
}
if (this.hour != 0)
{
Result += hour + "";
}
if (this.minute != 0)
{
Result += minute + "";
}
if (this.second != 0)
{
Result += second + "";
}
if(Result == "")
{
return "0秒";
}
return Result;
}

public void ChengeData_day(int i)
{
day = i;
}
}

Expand Down Expand Up @@ -91,7 +148,17 @@ public string GetPlaceData(int index)

public string GetDateData(int index)
{
return placeDataList[index].DateData;
return placeDataList[index].DateDataText;
}

/// <summary>
/// CleanPlaceDataを丸ごと取得
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public CleanPlaceData GetCleanPlaceData(int index)
{
return placeDataList[index];
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions Assets/Script/DataSaveClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ bool CheckFile(string path){
/// <returns></returns>
string CreateDataPath(string path)
{
#if UNITY_EDITOR
return Application.dataPath + "/" + path + ".json";
#else

return Application.persistentDataPath + "/" + path + ".json";
#endif
}
}
32 changes: 32 additions & 0 deletions Assets/Script/DisplayCleanPlaceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DisplayCleanPlaceData : MonoBehaviour
{
CleanPlaceData myData;
[SerializeField] Text lastUpdateTime;
[SerializeField] Text intervalTime;

/// <summary>
/// 表示するデータの登録
/// </summary>
/// <param name="data"></param>
public void SetCleanPlaceData(CleanPlaceData data)
{
myData = data;
}

/// <summary>
/// データをテキストに表示する関数
/// </summary>
public void DisplayData()
{
if (myData != null)
{
lastUpdateTime.text = myData.DateDataText;
intervalTime.text = myData.CleanIntervalText;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Script/DisplayCleanPlaceData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 63 additions & 15 deletions Assets/Script/MainBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ public enum CurrentMode
ADDPLACEMODE,//場所のデータを追加する状態
DATAUPDATE,//データを更新する状態
REMOVE,//データを削除する状態
PLACEDATAMODE//場所のデータの詳細を表示している状態
PLACEDATAMODE,//場所のデータの詳細を表示している状態
SETINTERVALMODE//掃除する間隔の登録をする状態
}
[SerializeField]CurrentMode currentMode = CurrentMode.DISPLAY;
[SerializeField]protected CleanDataList cleanDataList = new CleanDataList();//掃除場所のデータリストを扱うクラス
[SerializeField] string inputData;//受け取った入力を入れる変数
[SerializeField] bool canInput;//入力受け取り状態を表す変数


[SerializeField] protected int nowTargetIndex = -1;//MainBaseに実装を映したい

DataSaveClass dataSave = new DataSaveClass();//セーブとロードを行うクラス
#region データをセーブするpath群
string cleanDataListPath = "cleanPlaceData";
Expand Down Expand Up @@ -84,21 +87,23 @@ void Update()
SaveData();
break;
case CurrentMode.REMOVE:
int num = 0;
bool result = int.TryParse(inputData, out num);
if (result)//入力が数字だった時
{
cleanDataList.RemoveData(num);
ChangeMode(CurrentMode.DATAUPDATE);
ResetInputData();
}
else//入力が数字以外だった場合
{
ResetInputData();
WaitInput();
int num = 0;
bool result = int.TryParse(inputData, out num);
if (result)//入力が数字だった時
{
cleanDataList.RemoveData(num);
ChangeMode(CurrentMode.DATAUPDATE);
ResetInputData();
}
else//入力が数字以外だった場合
{
ResetInputData();
WaitInput();
}

break;
}

break;
case CurrentMode.PLACEDATAMODE:
if (inputData == "display")
{
Expand All @@ -110,8 +115,31 @@ void Update()
ChangeMode(CurrentMode.REMOVE);
ResetInputData();
WaitInput();
}else if (inputData == "interval")
{
ChangeMode(CurrentMode.SETINTERVALMODE);
ResetInputData();
WaitInput();
}
break;
case CurrentMode.SETINTERVALMODE:
{
int num = 0;
bool result = int.TryParse(inputData, out num);
if (result)//入力が数字だった時
{
var nowData = cleanDataList.GetCleanPlaceData(nowTargetIndex);
nowData.SetCleanInterval_day(num);
ChangeMode(CurrentMode.DATAUPDATE);
ResetInputData();
}
else//入力が数字以外だった場合
{
ResetInputData();
WaitInput();
}
break;
}
}
}

Expand Down Expand Up @@ -142,6 +170,11 @@ void InputUpdate()
if (Input.GetKeyDown(KeyCode.P))
{
SetInputData("placeData");
SetTargetIndex(0);
}
if (Input.GetKeyDown(KeyCode.N))
{
SetInputData("interval");
}
}

Expand Down Expand Up @@ -187,6 +220,7 @@ protected virtual void AwakeModeAction(CurrentMode mode)
{
case CurrentMode.DISPLAY:
Debug.Log(currentMode);
ResetInputData();
break;
case CurrentMode.ADDPLACEMODE:
Debug.Log(currentMode);
Expand Down Expand Up @@ -226,6 +260,20 @@ protected virtual void ResetInputData()
{
inputData = "";
}

/// <summary>
/// 現在のplaceDataの番号
/// </summary>
/// <param name="i"></param>
protected void SetTargetIndex(int i)
{
nowTargetIndex = i;
}

protected void ResetTargetIndex()
{
nowTargetIndex = -1;
}
/// <summary>
/// データをjsonファイルに書き込む
/// </summary>
Expand Down
41 changes: 31 additions & 10 deletions Assets/Script/Main_UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ public class Main_UI : MainBase
[SerializeField] InputField addPlaceInputField;//データを追加するときに使うinputField
[SerializeField] Text displayPlaceText;//プレイスリストのデータを一覧表示するText
[SerializeField] LayOutTextList layoutTextList;//プレイリストのデータ
[SerializeField] GameObject PlaceDataPanel;
[SerializeField] DisplayCleanPlaceData PlaceDataPanel;//現在選択しているplaceDataの情報を表示するパネル

[SerializeField]int nowTargetIndex=-1;//MainBaseに実装を映したい
[SerializeField] GameObject setIntervalPanel;//インターバルの入力をする時のパネル
[SerializeField] InputField setIntervalDataInputField;//インターバルの入力をするためのinputField


//[SerializeField]int nowTargetIndex=-1;//MainBaseに実装を映したい

//モードの立ち上がりの処理
protected override void AwakeModeAction(CurrentMode mode)
Expand All @@ -33,7 +37,12 @@ protected override void AwakeModeAction(CurrentMode mode)
case CurrentMode.DATAUPDATE:
break;
case CurrentMode.PLACEDATAMODE:
PlaceDataPanel.SetActive(true);
PlaceDataPanel.gameObject.SetActive(true);
PlaceDataPanel.SetCleanPlaceData(cleanDataList.GetCleanPlaceData(nowTargetIndex));
PlaceDataPanel.DisplayData();
break;
case CurrentMode.SETINTERVALMODE:
setIntervalPanel.SetActive(true);
break;
}
}
Expand All @@ -49,14 +58,14 @@ protected override void EndModeAction(CurrentMode mode)
InitInputFieldText();
break;
case CurrentMode.DATAUPDATE:
//DisplayData();
break;
case CurrentMode.REMOVE:
nowTargetIndex = -1;
//ClosePlaceData();
break;
case CurrentMode.PLACEDATAMODE:
PlaceDataPanel.SetActive(false);
PlaceDataPanel.gameObject.SetActive(false);
break;
case CurrentMode.SETINTERVALMODE:
setIntervalPanel.SetActive(false);
break;
}
}
Expand Down Expand Up @@ -93,7 +102,7 @@ public void ChangeDisplayMode()
}
public void OpenPlaceDataMode(int n)
{
nowTargetIndex =n;
SetTargetIndex(n);
SetInputData("placeData");
Enter();
}
Expand All @@ -114,6 +123,19 @@ public void RemovePlaceData()
StartCoroutine(WaitFrame(1,()=> SetInputData(nowTargetIndex.ToString())));
StartCoroutine(WaitFrame(1, () => Enter()));
}


public void ChengeSetIntervalMode()
{
SetInputData("interval");
Enter();
}

public void SetIntervalData()
{
SetInputData(setIntervalDataInputField.textComponent.text);
Enter();
}
#region InputDataを扱わないボタン

#endregion
Expand All @@ -134,8 +156,7 @@ void DisplayData()
layoutTextList.ResetText();
for (int i = 0; i < cleanDataList.placeDataList.Count; i++)
{
layoutTextList.AddText(cleanDataList.GetPlaceData(i) +
cleanDataList.GetDateData(i));
layoutTextList.AddText(cleanDataList.GetPlaceData(i));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/cleanPlaceData.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"placeDataList":[{"place":"daigo","seDate":{"year":2019,"month":10,"day":24,"hour":17,"minute":51,"second":6},"dateData":""},{"place":"daigogo","seDate":{"year":2019,"month":10,"day":24,"hour":17,"minute":52,"second":8},"dateData":""},{"place":"daigogogo","seDate":{"year":2019,"month":10,"day":24,"hour":18,"minute":2,"second":22},"dateData":"2019年10月24日18時2分22秒"},{"place":"12","seDate":{"year":2019,"month":10,"day":24,"hour":18,"minute":10,"second":52},"dateData":"2019年10月24日18時10分52秒"},{"place":"daigo","seDate":{"year":2019,"month":10,"day":24,"hour":18,"minute":12,"second":19},"dateData":"2019年10月24日18時12分19秒"}]}
{"placeDataList":[{"place":"daigo","lastUpdateTime":{"year":0,"month":0,"day":0,"hour":0,"minute":0,"second":0},"cleanInterval":{"year":0,"month":0,"day":0,"hour":0,"minute":0,"second":0},"dateData":"","cleanIntervalText":""},{"place":"daigogogo","lastUpdateTime":{"year":0,"month":0,"day":0,"hour":0,"minute":0,"second":0},"cleanInterval":{"year":0,"month":0,"day":0,"hour":0,"minute":0,"second":0},"dateData":"2019年10月24日18時2分22秒","cleanIntervalText":""},{"place":"daigo","lastUpdateTime":{"year":2019,"month":10,"day":28,"hour":20,"minute":18,"second":1},"cleanInterval":{"year":0,"month":0,"day":24,"hour":0,"minute":0,"second":0},"dateData":"2019年10月28日20時18分1秒","cleanIntervalText":""},{"place":"aaa","lastUpdateTime":{"year":2019,"month":10,"day":28,"hour":20,"minute":20,"second":21},"cleanInterval":{"year":0,"month":0,"day":0,"hour":0,"minute":0,"second":0},"dateData":"2019年10月28日20時20分21秒","cleanIntervalText":""},{"place":"aaa","lastUpdateTime":{"year":2019,"month":10,"day":28,"hour":20,"minute":21,"second":57},"cleanInterval":{"year":0,"month":0,"day":20,"hour":0,"minute":0,"second":0},"dateData":"10月28日20時21分57秒","cleanIntervalText":"20日"}]}

0 comments on commit 590410f

Please sign in to comment.