Skip to content

Commit

Permalink
Merge commit '88a60e21e0199aecd9b24bfc1daba1d5957ce6d9' into Nagata
Browse files Browse the repository at this point in the history
# Conflicts:
#	Assets/cleanPlaceData.json
  • Loading branch information
Nagata Yuto committed Nov 14, 2019
2 parents 6cb6da7 + 88a60e2 commit d7f365b
Show file tree
Hide file tree
Showing 10 changed files with 1,067 additions and 244 deletions.
999 changes: 837 additions & 162 deletions Assets/Scenes/MainScene.unity

Large diffs are not rendered by default.

222 changes: 163 additions & 59 deletions Assets/Script/CleanDataList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,127 @@ public class CleanPlaceData
[SerializeField] string place;
public string Place { get { return place; }private set { place = value; } }

[SerializeField] SEDataTime lastUpdateTime;
[SerializeField] SEDataTime cleanInterval;
public SEDataTime CleanInterval { get { return cleanInterval; } }
[SerializeField] string dateData;
public string DateDataText { get { return dateData; } }
[SerializeField] string cleanIntervalText;
public string CleanIntervalText { get { return cleanIntervalText; } }
[SerializeField] SEDataTime lastUpdateTime_forSave;//セーブ用の「最終更新時刻」
[SerializeField] SEDataTime cleanInterval_forSave;//セーブ用の「掃除間隔データ」

//時間などの文字列データ=============================================
public string LastUpdateTimeText { get {return TimeCovertToString.GetDateTime(LastUpdateTime); } }
public string CleanIntervalText { get { return TimeCovertToString.GetTimeSpan(CleanInterval); } }
public string NextCleanLeftTimeText { get { return TimeCovertToString.GetTimeSpan(NextCleanLeftTime); } }
//==============================================

//追加============================
public DateTime LastUpdateTime { get; private set; }//最終更新時刻
public TimeSpan CleanInterval { get; protected set; }//掃除間隔
public DateTime NextCleanDate { get { return LastUpdateTime + CleanInterval; } }//次に掃除する日時
public TimeSpan LastCleanPassTime { get { return DateTime.Now - LastUpdateTime; } }//最後に掃除してからの経過時間
public TimeSpan NextCleanLeftTime { get { return NextCleanDate - DateTime.Now; } }//次に掃除するまでの時間
//=============================

public CleanPlaceData(string place)
{
this.place = place;
lastUpdateTime = new SEDataTime(DateTime.Now);
dateData = lastUpdateTime.EntryDate();
cleanInterval = new SEDataTime();
cleanIntervalText = cleanInterval.DayInterval();
LastUpdateTime = DateTime.Now;
CleanInterval = new TimeSpan();
SetSETime();
}
#region SEDataTimeへの操作
public bool CheckHaveTarget()
{
return cleanInterval_forSave.CheackHaveTarget();
}

public bool SetTarget(string key)
{
return cleanInterval_forSave.ChangeTarget(key);
}

public void SetCleanIntervalDate(int i)
{
cleanInterval.ChangeDate(i);
cleanIntervalText = cleanInterval.DayInterval();
cleanInterval_forSave.ChangeDate(i);//SEのほうを変更
SetDateTime();//TimeSpanをSEに同期

}
#endregion

public void ResetLastUpdateTime()//lastUpdateTimeを現在の時間にする.
{
lastUpdateTime = new SEDataTime(DateTime.Now);
dateData = lastUpdateTime.EntryDate();
LastUpdateTime = DateTime.Now;
SetSETime();
}
/// <summary>
/// DateTime->SEへの変換
/// </summary>
void SetSETime()
{
lastUpdateTime_forSave =new SEDataTime(LastUpdateTime);
cleanInterval_forSave = new SEDataTime(CleanInterval);
}

/// <summary>
/// SE->DateTImeへの変換
/// </summary>
void SetDateTime()
{
LastUpdateTime = TimeCalucurator.REDataTime(lastUpdateTime_forSave);
CleanInterval = TimeCalucurator.ReTimeSpan(cleanInterval_forSave);
}


public void ChangeCleanTimeSpan(int num)
{
cleanInterval_forSave.ChangeDate(num);
SetDateTime();
}

public void InitAction()
{
SetDateTime();
}
}

/// <summary>
/// 時間データをstringで返す関数群
/// </summary>
public class TimeCovertToString
{
public static string GetTimeSpan( TimeSpan time)
{
string result = "";
result += time.Days+"";
return result;
}

public static string GetDateTime(DateTime time)
{
return time.Year +""+time.Month + "" + time.Day + "" + time.Hour + "" + time.Minute + "" + time.Second + "";
}
}

/// <summary>
/// 時間の計算をする関数群
/// </summary>
public class TimeCalucurator
{
public static TimeSpan GetTimeSpan(DateTime frontTime,DateTime backTime)
{
return frontTime - backTime;
}
public static DateTime REDataTime(SEDataTime time)
{
var datas = time.OutDayDatas();
DateTime reDataTime = new DateTime(datas[0],datas[1],datas[2],datas[3],datas[4],datas[5]);
return reDataTime;
}

public static TimeSpan ReTimeSpan(SEDataTime time)
{
var datas = time.OutDayDatas();
TimeSpan reDataTime = new TimeSpan(datas[0]*365+datas[1]*30+ datas[2], datas[3], datas[4], datas[5]);
return reDataTime;
}
}

[System.Serializable]
public class SEDataTime{
[SerializeField] int year;
Expand All @@ -53,6 +145,7 @@ public class SEDataTime{
Dictionary<string,int> dataTimeDictionary;



public SEDataTime(DateTime time)
{
this.year = time.Year;
Expand All @@ -63,57 +156,37 @@ public SEDataTime(DateTime time)
this.second = time.Second;
}

public SEDataTime()
public SEDataTime(TimeSpan time)
{
//var day_temp = time.Days;
this.year = 0;
this.month = 0;
this.day = 0;
this.hour = 0;
this.minute = 0;
this.second = 0;
}

public string EntryDate()
{
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)
/*while (day_temp > 365)
{
Result += hour + "";
day_temp -= 365;
this.year += 1;
}
if (this.minute != 0)
{
Result += minute + "";
}
if (this.second != 0)
{
Result += second + "";
}
if(Result == "")
while (day_temp > 30)
{
return "0秒";
}
return Result;
day_temp -= 30;
this.month += 1;
}*/

this.day = time.Days;
this.hour = time.Hours;
this.minute = time.Minutes;
this.second = time.Seconds;
}

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

public bool ChangeTarget(string key)
Expand Down Expand Up @@ -144,6 +217,13 @@ public void ChangeDate(int value)
}
if (dataTimeDictionary.ContainsKey(targetkey))
{
year = 0;
month = 0;
day = 0;
hour = 0;
minute = 0;
second = 0;

//dataTimeDictionary[targetkey] = value;
switch (targetkey)
{
Expand Down Expand Up @@ -200,7 +280,31 @@ void InitDictionary()
dataTimeDictionary.Add("Second", second);
}


//時間に換算する関数
public void CalcuToHour()
{
DateTime date1 = new DateTime(2010, 1, 1, 8, 0, 15);
DateTime date2 = new DateTime(2010, 6, 1, 11, 2, 16);
TimeSpan interval = date2 - date1;
Debug.Log(interval);
DateTime date3 = new DateTime(1,1,1,0,0,0);
date3 += interval;
//Debug.Log(date3);
interval = new TimeSpan(1, 2, 3);
date2 += interval;
//Debug.Log(date2);
}
public List<int> OutDayDatas()
{
var result = new List<int>();
result.Add(year);
result.Add(month);
result.Add(day);
result.Add(hour);
result.Add(minute);
result.Add(second);
return result;
}
}

/// <summary>
Expand Down Expand Up @@ -244,7 +348,7 @@ public string GetPlaceData(int index)

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

/// <summary>
Expand Down
30 changes: 15 additions & 15 deletions Assets/Script/DisplayCleanPlaceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ public class DisplayCleanPlaceData : MonoBehaviour
[SerializeField] Text lastUpdateTime;
[SerializeField] Text intervalTime;

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

/// <summary>
/// データをテキストに表示する関数
/// <summary>
/// データをテキストに表示する関数
/// </summary>
public void DisplayData()
{
if (myData != null)
{
lastUpdateTime.text = myData.DateDataText;
intervalTime.text = myData.CleanIntervalText;
}
public void DisplayData()
{
if (myData != null)
{
lastUpdateTime.text = myData.LastUpdateTimeText;
intervalTime.text = myData.CleanIntervalText;
}
}
}
37 changes: 35 additions & 2 deletions Assets/Script/MainBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ public enum CurrentMode
void Start()
{
LoadData();
foreach(var d in cleanDataList.placeDataList)
{
d.InitAction();
}

ChangeMode(CurrentMode.DISPLAY);


SEDataTime data = new SEDataTime();

//data.CalcuToHour();
//data.TimeSpanCalculater();
//data.REDataTime();
}

void Update()
Expand Down Expand Up @@ -106,6 +118,19 @@ void Update()
break;
}
case CurrentMode.PLACEDATAMODE:
if (inputData == "test")
{
var nowData = cleanDataList.GetCleanPlaceData(nowTargetIndex);
/*Debug.Log("Next limit : "+nowData.NextCleanDate);
Debug.Log("Next span : " + nowData.NextCleanLeftTime.Days);
Debug.Log("Next span : " + nowData.NextCleanLeftTime.Hours);
Debug.Log("Next span : " + nowData.NextCleanLeftTime.Minutes);*/
Debug.Log( nowData.NextCleanLeftTimeText);


WaitInput();
}

if (inputData == "display")
{
ChangeMode(CurrentMode.DISPLAY);
Expand Down Expand Up @@ -141,7 +166,7 @@ void Update()
if (result)//入力が数字だった時
{
var nowData = cleanDataList.GetCleanPlaceData(nowTargetIndex);
if (nowData.CleanInterval.CheackHaveTarget())
if (nowData.CheckHaveTarget())
{
nowData.SetCleanIntervalDate(num);
ChangeMode(CurrentMode.DATAUPDATE);
Expand All @@ -158,7 +183,7 @@ void Update()
else//入力が数字以外だった場合
{
var nowData = cleanDataList.GetCleanPlaceData(nowTargetIndex);
if (!nowData.CleanInterval.ChangeTarget(inputData))
if (!nowData.SetTarget(inputData))
{
Debug.Log("error Input : "+inputData);
}
Expand Down Expand Up @@ -325,4 +350,12 @@ void SaveData(){
void LoadData(){
cleanDataList=dataSave.LoadData<CleanDataList>(cleanDataListPath);
}

[ContextMenu("testTimeLimit")]
public void Debug_testLimit()
{
var nowData = cleanDataList.GetCleanPlaceData(nowTargetIndex);
//var data= nowData.CleanInterval.DayDataUntilNextClean(nowData.CleanInterval,nowData.LastUpdateTime);
//Debug.Log(data);
}
}
Loading

0 comments on commit d7f365b

Please sign in to comment.