This commit is contained in:
lq 2024-11-29 16:19:12 +08:00
parent 9450947206
commit 23a440edf5
362 changed files with 57172 additions and 6518 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 74f1aa4695d10664a965c00f6614a39b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6c518e84f27ffeb439ab28aa3e8747cb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dd9c40c69d2ff0d468bd5811d09bd0d1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4664c16ec00c057459379ec8124e229f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class EditorMenu
{
private static void InstanciateCanvas(string path)
{
Canvas[] canvases = GameObject.FindObjectsOfType<Canvas>();
if (canvases == null || canvases.Length == 0)
{
EditorUtility.DisplayDialog("No canvas in scene", "Please add a canvas to the scene and try again", "Ok");
return;
}
Canvas canvas = null;
foreach (Canvas c in canvases)
{
if (c.transform.parent == null)
{
canvas = c;
break;
}
}
if (canvas == null)
{
EditorUtility.DisplayDialog("No canvas in scene", "Please add a canvas to the scene and try again", "Ok");
return;
}
GameObject obj = Resources.Load<GameObject>(path);
GameObject newObj = (GameObject)GameObject.Instantiate(obj);
newObj.transform.SetParent(canvas.transform, false);
newObj.name = newObj.name.Replace("(Clone)", "");
Undo.RegisterCreatedObjectUndo(newObj, "Create Object");
}
[MenuItem("Tools/Date Picker/Light Theme")]
public static void AddLightTheme()
{
InstanciateCanvas("MenuPrefabs/MenuLight");
}
[MenuItem("Tools/Date Picker/Dark Theme")]
public static void AddDarkTheme()
{
InstanciateCanvas("MenuPrefabs/MenuDark");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 81f0f1ae76414204b9fbccc3116b2ccb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c7c7633203ecd45469316a291a0b5385
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
class Calendar
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5522f7b0412313140b60210c2cdd74f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,78 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
namespace Bitsplash.DatePicker
{
public class CellAddon : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler,IBeginDragHandler,IEndDragHandler,IDragHandler,IPointerDownHandler
{
DatePickerContent mParent;
int mChildIndex;
public void OnBeginDrag(PointerEventData eventData)
{
if (mParent != null)
((IDatePickerPrivate)mParent).RaiseStartSelection(mChildIndex);
}
public void OnDrag(PointerEventData eventData)
{
}
public void OnEndDrag(PointerEventData eventData)
{
if (mParent != null)
((IDatePickerPrivate)mParent).EndSelection();
}
public void OnPointerClick(PointerEventData eventData)
{
}
public void OnPointerDown(PointerEventData eventData)
{
if (mParent != null)
((IDatePickerPrivate)mParent).RaiseClick(mChildIndex);
}
public void OnPointerEnter(PointerEventData eventData)
{
if (eventData.pointerDrag != null)
{
var cellAddon = eventData.pointerDrag.GetComponent<CellAddon>();
if (cellAddon != null && mParent != null)
((IDatePickerPrivate)mParent).RaiseSelectionEnter(mChildIndex, cellAddon.mChildIndex);
}
}
public void OnPointerExit(PointerEventData eventData)
{
if (eventData.pointerDrag != null)
{
var cellAddon = eventData.pointerDrag.GetComponent<CellAddon>();
if (cellAddon != null && mParent != null)
((IDatePickerPrivate)mParent).RaiseSelectionExit(mChildIndex, cellAddon.mChildIndex);
}
}
public void SetParent(DatePickerContent parent,int childIndex)
{
mParent = parent;
mChildIndex = childIndex;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3355eceaf15fbb41b9a55f5f8839175
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Bitsplash
{
class CommonMethods
{
public static readonly Rect UVAbsolute = new Rect(0f, 0f, 1f, 1f);
internal static T EnsureComponent<T>(GameObject obj,bool hide = false) where T : Component
{
T comp = obj.GetComponent<T>();
if (comp == null)
comp = obj.AddComponent<T>();
if (Application.isPlaying == false && Application.isEditor == true)
{
// comp.tag = "EditorOnly";
comp.hideFlags = HideFlags.DontSaveInEditor;
}
return comp;
}
public static void HideObject(GameObject obj)
{
if (Application.isPlaying == false && Application.isEditor == true)
{
obj.tag = "EditorOnly";
obj.hideFlags = HideFlags.DontSaveInEditor;
}
obj.hideFlags = obj.hideFlags | HideFlags.HideInHierarchy | HideFlags.HideInInspector;
}
public static void SafeDestroy( UnityEngine.Object obj)
{
if (obj == null)
return;
if (Application.isEditor && Application.isPlaying == false)
UnityEngine.Object.DestroyImmediate(obj);
else
UnityEngine.Object.Destroy(obj);
obj = null;
}
public static Rect HorizontalTextureTile(float amount)
{
return new Rect(0f, 0f, amount, 1f);
}
public static Rect VerticalTextureTile(float amount)
{
return new Rect(0f, 0f,1f, amount);
}
public static float InterpolateInRectX(float v,Rect r)
{
return r.x + v * r.width;
}
public static float InterpolateInRectY(float v, Rect r)
{
return r.y + v * r.height;
}
public static Vector2 InterpolateInRect(Vector2 v,Rect r)
{
return new Vector2(r.x + v.x * r.width, r.y + v.y * r.height);
}
public static void DrawVertical(float x, Rect bounds, float thickness, Rect uv, Color color, VertexHelper vh)
{
Rect r = new Rect(x-thickness*0.5f, bounds.y, thickness,bounds.height);
DrawRect(r, uv, color, vh);
}
public static void DrawHorizontal(float y,Rect bounds,float thickness,Rect uv, Color color,VertexHelper vh)
{
Rect r = new Rect(bounds.x, y - thickness * 0.5f, bounds.width, thickness);
DrawRect(r, uv, color, vh);
}
public static void DrawRect(Rect rect,Rect uv,Color color,VertexHelper vh)
{
int index = vh.currentVertCount;
vh.AddVert(new Vector3(rect.xMin, rect.yMin, 0f), color, new Vector2(uv.xMin, uv.yMin));
vh.AddVert(new Vector3(rect.xMin, rect.yMax, 0f), color, new Vector2(uv.xMin, uv.yMax));
vh.AddVert(new Vector3(rect.xMax, rect.yMax, 0f), color, new Vector2(uv.xMax, uv.yMax));
vh.AddVert(new Vector3(rect.xMax, rect.yMin, 0f), color, new Vector2(uv.xMax, uv.yMin));
vh.AddTriangle(index, index+ 1, index+2);
vh.AddTriangle(index+2, index+3, index);
}
public static bool IsRangeSelected(DateTime from, DateTime to, HashSet<DateTime> selection)
{
from = from.Date;
to = to.Date;
if (from == to)
{
return selection.Count == 1 && selection.Contains(from);
}
if (from > to)
{
DateTime tmp = from;
from = to;
to = tmp;
}
DateTime iterator = from;
int count = 0;
while (iterator <= to)
{
if (selection.Contains(iterator.Date) == false)
return false;
count++;
iterator += TimeSpan.FromDays(1);
}
if (selection.Count != count)
return false;
return true;
}
public static void SelectRange(DateTime from, DateTime to, HashSet<DateTime> selection)
{
selection.Clear();
from = from.Date;
to = to.Date;
if (from == to)
{
selection.Add(from);
return;
}
if (from > to)
{
DateTime tmp = from;
from = to;
to = tmp;
}
DateTime iterator = from;
while (iterator <= to)
{
selection.Add(iterator.Date);
iterator += TimeSpan.FromDays(1);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9ed3373f404cfdb41971280286fab7b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 09a8fdbf9b2de994c813d6dd6f8c84a0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,244 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Bitsplash.DatePicker
{
/// <summary>
///
/// </summary>
public partial class DatePickerContent : IDatePickerPrivate
{
DateTime? mSelectionFirst;
DateTime? mDragFirst;
DateTime? mDragTo;
HashSet<DateTime> mDragSelectionRange = new HashSet<DateTime>();
bool mDragSelectionChanged = false;
Dictionary<DateTime, Color> mMarkerColors = new Dictionary<DateTime, Color>();
public void SetAllMarkerColors(Dictionary<DateTime, Color> markers)
{
mMarkerColors.Clear();
foreach (var pair in markers)
mMarkerColors.Add(pair.Key.Date, pair.Value);
RefreshSelection();
}
public void SetMarkerColor(DateTime date, Color color)
{
mMarkerColors[date.Date] = color;
RefreshSelection();
}
public void ClearMarker(DateTime date)
{
mMarkerColors.Remove(date.Date);
RefreshSelection();
}
public void ClearMarkerColor()
{
mMarkerColors.Clear();
RefreshSelection();
}
void SelectOne(DateTime date)
{
mSelection.SelectOne(date);
mSelectionFirst = date;
}
void ToogleOne(DateTime date)
{
if (mSelection.IsSingleDateSelected(date) && AllowEmptySelection)
{
mSelection.Clear();
mSelectionFirst = null;
}
else
SelectOne(date);
}
void UpdateSelection()
{
if(mDragSelectionChanged || ((IDatePickerCollectionPrivate) mSelection).Changed)
{
((IDatePickerCollectionPrivate)mSelection).Changed = false;
mDragSelectionChanged = false;
RefreshSelection();
}
}
void RefreshSelection()
{
for (int i = 0; i < mCells.Length; i++)
{
var date = mCells[i].DayValue.Date;
bool withinMonth = date.Month == DisplayDate.Month && date.Year == DisplayDate.Year;
Color markerColor;
if (mMarkerColors.TryGetValue(date, out markerColor) == false)
markerColor = new Color(0f, 0f, 0f, 0f);
if (mCells[i].MarkerColor != markerColor)
mCells[i].MarkerColor = markerColor;
if ((mSelection.Contains(date) || mDragSelectionRange.Contains(date)) && withinMonth)
{
if (mCells[i].CellSelected == false)
mCells[i].CellSelected = true;
}
else
{
if(mCells[i].CellSelected == true)
mCells[i].CellSelected = false;
}
}
}
void LimitRangeToMonth(HashSet<DateTime> selection,DateTime month)
{
selection.RemoveWhere((x) => x.Month != month.Month || x.Year != month.Year);
}
void SelectRange(DateTime from,DateTime to)
{
mSelection.SelectRange(from, to);
}
void ToogleMultiple(DateTime date)
{
if (mSelection.Contains(date))
{
if (mSelection.Count > 1 || AllowEmptySelection)
mSelection.Remove(date);
}
else
{
mSelection.Add(date);
}
}
void ConnectSelection(DateTime date)
{
date = date.Date;
if (mSelection.Contains(date)) // already within the selection
return;
if(mSelection.Count == 0 || mSelectionFirst.HasValue == false)
{
SelectOne(date);
return;
}
SelectRange(mSelectionFirst.Value, date);
}
void ProcessRangeClick(DatePickerCell cell, int cellChildIndex)
{
if (mDatePickerInput.MultipleSelectionValue == MultipleSelectionInputValue.Append)
ConnectSelection(cell.DayValue);
else if (mDatePickerInput.MultipleSelectionValue == MultipleSelectionInputValue.Singular)
ToogleOne(cell.DayValue);
}
void ProcessMultipleClick(DatePickerCell cell, int cellChildIndex)
{
if (mDatePickerInput.MultipleSelectionValue == MultipleSelectionInputValue.Append)
ToogleMultiple(cell.DayValue);
else if (mDatePickerInput.MultipleSelectionValue == MultipleSelectionInputValue.Singular)
ToogleOne(cell.DayValue);
}
void ProcessSelectionClick(DatePickerCell cell,int cellChildIndex)
{
switch (SelectionMode)
{
case SelectionType.Single:
ToogleOne(cell.DayValue);
break;
case SelectionType.Range:
ProcessRangeClick(cell, cellChildIndex);
break;
case SelectionType.Multiple:
ProcessMultipleClick(cell, cellChildIndex);
break;
}
}
protected virtual void OnCellClick(DatePickerCell cell, int cellChildIndex)
{
if (cell.CellEnabled == false)
return;
if (mDragFirst.HasValue || mDragTo.HasValue)
return;
ProcessSelectionClick(cell, cellChildIndex);
}
void RaiseSelectionChanged()
{
if (OnSelectionChanged != null)
OnSelectionChanged.Invoke();
}
void IDatePickerPrivate.RaiseClick(int childIndex)
{
OnCellClick(mCells[childIndex], childIndex);
}
void IDatePickerPrivate.RaiseStartSelection(int childIndex)
{
if (SelectionMode == SelectionType.Single)
return;
DateTime dayValue = mCells[childIndex].DayValue;
if (SelectionMode == SelectionType.Range || (SelectionMode == SelectionType.Multiple && mDatePickerInput.MultipleSelectionValue == MultipleSelectionInputValue.Singular))
mSelection.SelectOne(dayValue);
mDragFirst = dayValue;
if (mDragTo.HasValue && mDragFirst.HasValue)
{
CommonMethods.SelectRange(mDragTo.Value, mDragFirst.Value, mDragSelectionRange);
}
else
{
mDragSelectionRange.Clear();
mDragSelectionRange.Add(dayValue);
}
mSelectionFirst = null;
LimitRangeToMonth(mDragSelectionRange, mMonthFirst);
mDragSelectionChanged = true;
}
void IDatePickerPrivate.EndSelection()
{
if (SelectionMode == SelectionType.Single)
return;
if (mDragTo.HasValue && mDragFirst.HasValue)
{
CommonMethods.SelectRange(mDragTo.Value, mDragFirst.Value, mDragSelectionRange);
LimitRangeToMonth(mDragSelectionRange, mMonthFirst);
mSelection.AddItems(mDragSelectionRange);
}
mDragSelectionRange.Clear();
mDragSelectionChanged = true;
mDragTo = null;
mDragFirst = null;
}
void IDatePickerPrivate.RaiseSelectionEnter(int childIndex, int fromChildIndex)
{
if (SelectionMode == SelectionType.Single)
return;
mSelectionFirst = null;
mDragTo = mCells[childIndex].DayValue;
if (mDragTo.HasValue && mDragFirst.HasValue)
{
CommonMethods.SelectRange(mDragTo.Value, mDragFirst.Value, mDragSelectionRange);
LimitRangeToMonth(mDragSelectionRange, mMonthFirst);
}
mDragSelectionChanged = true;
}
void IDatePickerPrivate.RaiseSelectionExit(int childIndex, int fromChildIndex)
{
if (SelectionMode == SelectionType.Single)
return;
// if (mDragTo.HasValue && mDragTo.Value == mCells[childIndex].DayValue)
// mDragTo = null;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7503219deb4b33f4e9303c6234e05568
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,190 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
/// <summary>
/// holds dates selected by the date picker
/// </summary>
public class DatePickerCollection : IDatePickerCollectionPrivate
{
bool mInvalid = false;
HashSet<DateTime> mData = new HashSet<DateTime>();
bool mChanged = false;
bool mAllowEmpty = false;
DateTime[] mItems;
bool IDatePickerCollectionPrivate.Changed { get { return mChanged; } set { mChanged = value; } }
bool IDatePickerCollectionPrivate.AllowEmpty { get { return mAllowEmpty; } set
{
mAllowEmpty = value;
if(mAllowEmpty == false && mData.Count ==0)
{
ValidateNonEmpty();
Invalidate();
}
}
}
event Action InnerSelectionModified;
event Action IDatePickerCollectionPrivate.SelectionModified
{
add
{
InnerSelectionModified += value;
}
remove
{
InnerSelectionModified -= value;
}
}
public int Count
{
get { return mData.Count; }
}
/// <summary>
/// selects a range of dates , clearing all other dates
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
public void SelectRange(DateTime from,DateTime to)
{
if (CommonMethods.IsRangeSelected(from, to, mData))
return;
CommonMethods.SelectRange(from, to, mData);
Invalidate();
}
void Invalidate()
{
mChanged = true;
mInvalid = true;
if (InnerSelectionModified != null)
InnerSelectionModified();
}
/// <summary>
/// returns true if a date is the only date selected
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public bool IsSingleDateSelected(DateTime date)
{
date = date.Date;
if (mData.Contains(date) && mData.Count == 1)
return true;
return false;
}
/// <summary>
/// selects one date clearing all other dates
/// </summary>
/// <param name="date"></param>
public void SelectOne(DateTime date)
{
date = date.Date;
if (mData.Contains(date) && mData.Count == 1)
return;
mData.Clear();
Add(date);
}
void ValidateNonEmpty()
{
if (mAllowEmpty == false && mData.Count == 0)
mData.Add(DateTime.Today.Date);
}
/// <summary>
/// clears all selected dates. If the selection cannot be empty , DateTime.Today is set as the selection
/// </summary>
public void Clear()
{
if (mData.Count == 0)
return;
if (mAllowEmpty == false && IsSingleDateSelected(DateTime.Today))
return;
mData.Clear();
ValidateNonEmpty();
Invalidate();
}
/// <summary>
/// appends all the items to the date collection
/// </summary>
/// <param name="range"></param>
public void AddItems(HashSet<DateTime> range)
{
bool changed = false;
foreach(DateTime d in range)
{
if (mData.Add(d))
changed = true;
}
if (changed)
Invalidate();
}
/// <summary>
/// adds a date into the date selection.
/// </summary>
/// <param name="date"></param>
public void Add(DateTime date)
{
if(mData.Add(date.Date))
Invalidate();
}
/// <summary>
/// returns true if the date collection contains the specified date
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public bool Contains(DateTime date)
{
return mData.Contains(date.Date);
}
/// <summary>
/// gets the date item at index
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public DateTime GetItem(int index)
{
if(mInvalid || mItems == null)
{
mInvalid = false;
mItems = mData.OrderBy(x => x).ToArray();
}
return mItems[index];
}
/// <summary>
/// removes a date from the collection if it present. returns true if the date was present and was removed
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public bool Remove(DateTime date)
{
if (mData.Remove(date.Date))
{
ValidateNonEmpty();
Invalidate();
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ffa37277c4fcc84898295747af4801a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,464 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace Bitsplash.DatePicker
{
[ExecuteInEditMode]
public partial class DatePickerContent : MonoBehaviour , IDatePickerSettingsItem
{
[SerializeField]
[HideInInspector]
private bool isOpen;
const int RowCount = 6;
const int ColumnCount = 7;
[FormerlySerializedAs("FirstDayOfWeek")]
[SerializeField]
[Tooltip("the first day of the week for the content")]
private DayOfWeek firstDayOfWeek = DayOfWeek.Sunday;
[FormerlySerializedAs("RightToLeft")]
[SerializeField]
private bool rightToLeft = false;
[FormerlySerializedAs("BottomToTop")]
[SerializeField]
private bool bottomToTop = false;
[FormerlySerializedAs("CellPrefab")]
[SerializeField]
[Tooltip("drag a cell template here to use it with the datepicker")]
private DatePickerCell cellPrefab = null;
[FormerlySerializedAs("SelectionMode")]
[SerializeField]
[Tooltip("single,range and multiple selection types. ")]
private SelectionType selectionMode;
[FormerlySerializedAs("AllowEmptySelection")]
[SerializeField]
private bool allowEmptySelection = false;
[SerializeField]
private DateTime startDate = new DateTime(1960,1,1);
[SerializeField]
private DateTime endDate = new DateTime(2030, 12, 31);
void ValidateYear()
{
if (endDate < startDate)
endDate = startDate;
mMonthFirst = new DateTime(mMonthFirst.Year, mMonthFirst.Month, 1);
if(mMonthFirst > endDate)
{
mMonthFirst = new DateTime(endDate.Year, endDate.Month, 1);
}
if(mMonthFirst < startDate)
{
mMonthFirst = new DateTime(startDate.Year, startDate.Month, 1);
}
}
public DateTime StartDate
{
get { return startDate; }
set
{
startDate = value.Date;
ValidateYear();
Invalidate();
OnSettingsChanged();
}
}
public DateTime EndDate
{
get { return endDate; }
set
{
endDate = value.Date;
ValidateYear();
Invalidate();
OnSettingsChanged();
}
}
/// <summary>
/// the first day of the week for the date picker
/// </summary>
public DayOfWeek FirstDayOfWeek
{
get { return firstDayOfWeek; }
set
{
firstDayOfWeek = value;
OnSettingsChanged();
}
}
/// <summary>
/// set the date picker to right to left mode
/// </summary>
public bool RightToLeft
{
get { return rightToLeft; }
set
{
rightToLeft = value;
OnSettingsChanged();
}
}
/// <summary>
/// show days from bottom to top instead of top to bottom
/// </summary>
public bool BottomToTop
{
get { return bottomToTop; }
set
{
bottomToTop = value;
OnSettingsChanged();
}
}
//public DatePickerCell CellPrefab
//{
// get { return cellPrefab; }
// set
// {
// cellPrefab = value;
// }
//}
/// <summary>
/// set the selection mode for the date picker. Single ,Range or Multiple
/// </summary>
public SelectionType SelectionMode
{
get { return selectionMode; }
set
{
selectionMode = value;
OnSettingsChanged();
}
}
/// <summary>
/// allows selection of the date picker to be empty
/// </summary>
public bool AllowEmptySelection
{
get { return allowEmptySelection; }
set
{
allowEmptySelection = value;
OnSettingsChanged();
}
}
/// <summary>
/// used for internal purpose
/// </summary>
public event Action SettingsChanged;
/// <summary>
/// currently the displayed month and year
/// </summary>
DateTime mMonthFirst = DateTime.Today;
/// <summary>
/// genearted cells
/// </summary>
DatePickerCell[] mCells;
/// <summary>
/// the selection collection object for the content
/// </summary>
DatePickerCollection mSelection = new DatePickerCollection();
/// <summary>
/// a date to cell map for quick lookup
/// </summary>
Dictionary<DateTime, DatePickerCell> mDateToCell = new Dictionary<DateTime, DatePickerCell>();
/// <summary>
/// an input delegation for the date picker
/// </summary>
DatePickerInput mDatePickerInput;
/// <summary>
/// true if the datepicker should be recreated
/// </summary>
bool mInvalidated = true;
/// <summary>
/// This event triggers when the use navigates the datepicker
/// </summary>
public UnityEvent OnDisplayChanged;
/// <summary>
/// this event triggers when the date selection has changed
/// </summary>
public UnityEvent OnSelectionChanged;
/// <summary>
/// the date picker selection collection. Use this object to change and query the current date selection
/// </summary>
public DatePickerCollection Selection { get { return mSelection; } }
void EnsureInput()
{
mDatePickerInput = GetComponent<DatePickerInput>();
if (mDatePickerInput == null)
mDatePickerInput = gameObject.AddComponent<DatePickerStandardInput>();
}
/// <summary>
/// the currently displayed date in the datepicker
/// </summary>
public DateTime DisplayDate { get { return mMonthFirst; } }
/// <summary>
/// sets the month and year being displayed in the date picker.
/// </summary>
/// <param name="year"></param>
/// <param name="month"></param>
public void SetMonthAndYear(int year,int month)
{
FillCells(new DateTime(year, month, 1));
}
/// <summary>
/// sets the year being displayed in the date picker
/// </summary>
/// <param name="year"></param>
public void SetYear(int year)
{
FillCells(new DateTime(year, mMonthFirst.Month, 1));
}
/// <summary>
/// sets the month being displayed in the date picker
/// </summary>
/// <param name="month"></param>
public void SetMonth(int month)
{
FillCells(new DateTime(mMonthFirst.Year,month, 1));
}
/// <summary>
/// used internally
/// </summary>
public string EditorTitle { get {return "Board"; } }
/// <summary>
/// used internally
/// </summary>
public int Order { get { return 0; } }
/// <summary>
/// advances the display by 1 year
/// </summary>
public void NextYear()
{
FillCells(mMonthFirst.AddYears(1));
}
void OnSettingsChanged()
{
if (SettingsChanged != null)
SettingsChanged();
}
/// <summary>
/// retracts the display by 1 year
/// </summary>
public void PrevYear()
{
FillCells(mMonthFirst.AddYears(-1));
}
/// <summary>
/// advances the display by 1 month
/// </summary>
public void NextMonth()
{
FillCells(mMonthFirst.AddMonths(1));
}
/// <summary>
/// retracts the display by 1 month
/// </summary>
public void PrevMonth()
{
FillCells(mMonthFirst.AddMonths(-1));
}
public virtual string DateToString(DateTime date)
{
return date.Day.ToString();
}
void GenerateCells()
{
Clear();
if (cellPrefab == null)
return;
mCells = new DatePickerCell[((int)RowCount) * ((int)ColumnCount)];
float ColumnSize = 1f / ColumnCount;
float RowSize = 1f / RowCount;
for(float i=0; i<RowCount; i++)
{
float startY = i / RowCount;
if (BottomToTop == false)
startY = 1f - startY - RowSize;
float endY = startY + RowSize;
for (float j=0; j<ColumnCount; j++)
{
float startX = j / ColumnCount;
if (RightToLeft)
startX = 1f - startX - ColumnSize;
float endX = startX + ColumnSize;
GameObject newObj = GameObject.Instantiate(cellPrefab.gameObject, transform);
CommonMethods.SafeDestroy(newObj.GetComponent<DatePickerCellTemplate>());
CommonMethods.HideObject(newObj);
newObj.name = String.Format("day_{0}_{1}", j, i);
newObj.SetActive(true);
CommonMethods.EnsureComponent<IDateTimeItem>(newObj);
var rect = newObj.GetComponent<RectTransform>();
rect.anchorMin = new Vector2(startX, startY);
rect.anchorMax = new Vector2(endX, endY);
rect.anchoredPosition = new Vector2(0f, 0f);
rect.sizeDelta = new Vector2(0f, 0f);
int childIndex = (int)(i * ColumnCount + j);
childIndex = (int)(i * ColumnCount + j);
mCells[childIndex] = newObj.GetComponent<DatePickerCell>();
var addon = CommonMethods.EnsureComponent<CellAddon>(newObj);
addon.SetParent(this, childIndex);
}
}
FillCells(mMonthFirst);
}
DateTime MonthFromDate(DateTime date)
{
return new DateTime(date.Year, date.Month, 1);
}
DatePickerCell getCell(int day,int week)
{
return mCells[week * ColumnCount + day];
}
void FillCells(DateTime monthFirst)
{
monthFirst = monthFirst.Date;
mMonthFirst = monthFirst;
ValidateYear();
if (mCells == null)
return;
monthFirst = mMonthFirst;
int monthDayOfWeek = (int)monthFirst.DayOfWeek;
int span = monthDayOfWeek - (int)FirstDayOfWeek;
if (span < 0)
span += 7;
DateTime startFrom = (monthFirst - TimeSpan.FromDays(span)).Date;
DateTime endIn = startFrom + TimeSpan.FromDays(RowCount * ColumnCount);
DateTime monthLast = monthFirst + TimeSpan.FromDays(DateTime.DaysInMonth(monthFirst.Year, monthFirst.Month) - 1);
DateTime current = startFrom;
mDateToCell.Clear();
for (int i=0; i<mCells.Length; i++)
{
mCells[i].DayValue = current;
mCells[i].SetText(DateToString(current));
bool cellenabled = true;
if (current < monthFirst || current > monthLast || current < startDate || current > endDate)
cellenabled = false;
mCells[i].SetInitialSettings(cellenabled, false);
mDateToCell[current.Date] = mCells[i];
current += TimeSpan.FromDays(1);
}
RefreshSelection();
if (OnDisplayChanged != null)
OnDisplayChanged.Invoke();
}
protected void Clear()
{
IDateTimeItem[] children = GetComponentsInChildren<IDateTimeItem>();
for (int i = 0; i < children.Length; ++i)
{
if (children[i] != null)
{
if (children[i].gameObject.GetComponentInParent<DatePickerContent>() != this)
continue;
if (children[i].gameObject != gameObject)
CommonMethods.SafeDestroy(children[i].gameObject);
}
}
}
public void Invalidate()
{
mInvalidated = true;
}
void HookEvents()
{
((IDatePickerCollectionPrivate)mSelection).SelectionModified -= DatePicker_SelectionModified;
((IDatePickerCollectionPrivate)mSelection).SelectionModified += DatePicker_SelectionModified;
}
private void DatePicker_SelectionModified()
{
RaiseSelectionChanged();
}
public void Start()
{
HookEvents();
EnsureInput();
GenerateCells();
// if (AllowEmptySelection == false)
// SelectOne(DateTime.Today);
}
public void Update()
{
if(AllowEmptySelection != ((IDatePickerCollectionPrivate)mSelection).AllowEmpty)
((IDatePickerCollectionPrivate)mSelection).AllowEmpty = AllowEmptySelection;
UpdateSelection();
if(mInvalidated)
{
GenerateCells();
mInvalidated = false;
}
}
public void OnValidate()
{
ValidateYear();
OnSettingsChanged();
Invalidate();
}
/// <summary>
/// retrives the underlaying gameobject specified by dateTime. If the dateTime is not currently displayed , null is returned
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public DatePickerCell GetCellObjectByDate(DateTime dateTime)
{
DatePickerCell res = null;
if (mDateToCell.TryGetValue(dateTime.Date, out res))
return res;
return null;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bce6f4381e832d24583a1b0c14c9e752
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
interface IDatePickerCollectionPrivate
{
bool Changed { get; set; }
bool AllowEmpty { get; set; }
event Action SelectionModified;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 229d73d069ddf9b4d9736254e8837601
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class DatePickerBackgroundSetting : MonoBehaviour, IDatePickerSettingsItem
{
[SerializeField]
[HideInInspector]
private bool isOpen;
public string EditorTitle { get { return gameObject.name; } }
public int Order { get { return 1; } }
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 898e866135fe96b45a03ddabbde1a61f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Bitsplash.DatePicker
{
[RequireComponent(typeof(RectTransform))]
public abstract class DatePickerCell : MonoBehaviour
{
public abstract Color MarkerColor { get; set; }
public abstract bool CellSelected { get; set; }
public abstract bool CellEnabled { get; set; }
public abstract DateTime DayValue { get; set; }
public abstract void SetText(string text);
public abstract void SetInitialSettings(bool enabled, bool selected);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5131c682cad278d46b142466fb127d5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class DatePickerCellTemplate : MonoBehaviour, IDatePickerSettingsItem
{
[SerializeField]
[HideInInspector]
private bool isOpen;
public string EditorTitle { get { return gameObject.name; } }
public int Order { get { return 2; } }
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 746317b581967e24a9b69effdf5b1106
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,66 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bitsplash.DatePicker
{
/// <summary>
/// base class for date picker elements. They included buttons and texts
/// </summary>
public abstract class DatePickerElement : MonoBehaviour
{
[SerializeField]
[HideInInspector]
private bool isOpen;
protected virtual void Start()
{
SetLinkedElements();
}
/// <summary>
/// notifys the date picker element of the DatePickerSettings and DatePickerContent objects that govern it.
/// these objects are used to query and modify the date picker
/// </summary>
void SetLinkedElements()
{
var main = GetComponentInParent<DatePickerSettings>();
if (main == null)
Debug.LogError("Date Picker elements must have a parent GameObject with the behviour DatePickerSettings");
else
{
var content = main.Content;
if (content != null)
{
SetMain(main);
SetContent(content);
content.SettingsChanged -= OnSettingsChanged;
content.SettingsChanged += OnSettingsChanged;
}
}
}
protected virtual void OnSettingsChanged()
{
}
public virtual void OnValidate()
{
if(isActiveAndEnabled)
SetLinkedElements();
}
/// <summary>
/// sets the main DatePickerSettings object assicuated with this script
/// </summary>
/// <param name="main"></param>
protected abstract void SetMain(DatePickerSettings main);
/// <summary>
/// sets the main DatePickerContent object assicuated with this script
/// </summary>
/// <param name="content"></param>
protected abstract void SetContent(DatePickerContent content);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 913e98d0ced5ea44e8d1f7b4af557965
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public abstract class DatePickerInput : MonoBehaviour
{
public abstract MultipleSelectionInputValue MultipleSelectionValue { get; }
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 142eee2af40bc2543abe91bc216a3278
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public abstract class DatePickerLabel : MonoBehaviour
{
public abstract void SetText(string text);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f4f4126f9c9f47645840eab33f9a5e50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public partial class DatePickerSettings : MonoBehaviour
{
[SerializeField]
private Font textFont;
/// <summary>
/// the text font used for UI.Text
/// </summary>
public Font TextFont
{
get { return textFont; }
set
{
textFont = value;
if (TextTypeChanged != null)
TextTypeChanged();
}
}
public event Action TextTypeChanged;
DatePickerContent mContent = null;
/// <summary>
/// the datepicker content object for this date picker.
/// </summary>
public DatePickerContent Content
{
get
{
if (mContent == null)
{
var contents = GetComponentsInChildren<DatePickerContent>();
if (contents.Length == 0)
Debug.LogError("A DatePickerSettings behaviour must parent a DatePickerContent behaviour in a child GameObject");
else
if (contents.Length > 1)
Debug.LogError("A DatePickerSettings behaviout may only have one child DatePickerContent behaviour ");
else
mContent = contents[0];
}
return mContent;
}
}
private void Start()
{
}
private void OnValidate()
{
foreach (var elem in GetComponentsInChildren<DatePickerElement>())
{
elem.OnValidate();
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0fe3789ee2a1824eab74683544502a9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class DatePickerStandardInput : DatePickerInput
{
public override MultipleSelectionInputValue MultipleSelectionValue
{
get
{
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.RightCommand) || Input.GetKey(KeyCode.LeftCommand))
return MultipleSelectionInputValue.Append;
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
return MultipleSelectionInputValue.Append;
return MultipleSelectionInputValue.Singular;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5b41254ad534f5f4dbe3c4807a84449f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,124 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
namespace Bitsplash.DatePicker
{
/// <summary>
/// shows the week day names on top the date picker
/// </summary>
[ExecuteInEditMode]
public class DayTitle : DatePickerElement , IDatePickerSettingsItem
{
public string EditorTitle { get { return "Day Title"; } }
public DatePickerCell CellPrefab;
public string Format = "ddd";
DatePickerContent mContent;
bool mInvalid = true;
public int Order { get { return 8; } }
void GenerateCells()
{
Clear();
if (CellPrefab == null || mContent == null)
return;
float ColumnSize = 1f / 7f;
DateTime baseDate = DateTime.Today.Date;
int monthDayOfWeek = (int)baseDate.DayOfWeek;
int span = monthDayOfWeek - (int)mContent.FirstDayOfWeek;
if (span < 0)
span += 7;
DateTime startFrom = (baseDate - TimeSpan.FromDays(span)).Date;
for (int i = 0; i < 7; i++)
{
DateTime current = startFrom.Add(TimeSpan.FromDays(i)).Date;
float startX = ((float)i) / 7f;
if (mContent.RightToLeft)
startX = 1f - startX - ColumnSize;
float endX = startX + ColumnSize;
GameObject newObj = GameObject.Instantiate(CellPrefab.gameObject, transform);
CommonMethods.SafeDestroy(newObj.GetComponent<DatePickerCellTemplate>());
CommonMethods.HideObject(newObj);
newObj.name = String.Format("day_{0}", i);
newObj.SetActive(true);
CommonMethods.EnsureComponent<IDateTimeItem>(newObj);
var rect = newObj.GetComponent<RectTransform>();
rect.anchorMin = new Vector2(startX, 0f);
rect.anchorMax = new Vector2(endX, 1f);
rect.anchoredPosition = new Vector2(0f, 0f);
rect.sizeDelta = new Vector2(0f, 0f);
var cell = newObj.GetComponent<DatePickerCell>();
cell.SetInitialSettings(true, false);
cell.DayValue = current;
try
{
cell.SetText(current.ToString(Format));
}
catch(Exception)
{
Debug.LogWarning("invalid format in day title");
}
}
}
public void Clear()
{
IDateTimeItem[] children = GetComponentsInChildren<IDateTimeItem>();
for (int i = 0; i < children.Length; ++i)
{
if (children[i] != null)
{
if (children[i].gameObject.GetComponentInParent<DayTitle>() != this)
continue;
if (children[i].gameObject != gameObject)
CommonMethods.SafeDestroy(children[i].gameObject);
}
}
}
public void Invalidate()
{
mInvalid = true;
}
public override void OnValidate()
{
base.OnValidate();
Invalidate();
}
// Start is called before the first frame update
protected override void Start()
{
base.Start();
Invalidate();
}
protected override void OnSettingsChanged()
{
base.OnSettingsChanged();
Invalidate();
}
// Update is called once per frame
void Update()
{
if(mInvalid == true)
{
mInvalid = false;
GenerateCells();
}
}
protected override void SetContent(DatePickerContent content)
{
mContent = content;
Invalidate();
}
protected override void SetMain(DatePickerSettings main)
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5cde14b682a49eb4fa7cdce34de69813
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: eb00ea298ab962c40a0f91bb43ec1297
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.UI;
namespace Bitsplash.DatePicker
{
/// <summary>
/// this is a UI.Text implementation of the drop down
/// </summary>
public class DatePickerDropDown : DatePickerDropDownBase
{
public Text Label;
protected override void SetText(string text)
{
if (Label != null)
Label.text = text;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 137f420b74ffe624ba4e39c0746e5cd4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,159 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace Bitsplash.DatePicker
{
public abstract class DatePickerDropDownBase : MonoBehaviour
{
/// <summary>
///
/// </summary>
public string NoSelectionPrompt = "Select a date...";
/// <summary>
/// the date format of the label
/// </summary>
public string labelDateFormat = "d";
/// <summary>
/// the date picker settings object for the drop down
/// </summary>
public DatePickerSettings DropDownContent;
/// <summary>
/// the drop down button
/// </summary>
public Button DropDownButton;
GameObject mBlocker;
// Start is called before the first frame update
void Start()
{
InitDropDown();
}
/// <summary>
/// initializes the drop down events
/// </summary>
void InitDropDown()
{
if(DropDownButton == null)
Debug.LogWarning("Drop Down Button Not Assigned"); // show warninig
else
DropDownButton.onClick.AddListener(ButtonClicked); // listen to drop down button clicks
if (DropDownContent == null)
Debug.LogWarning("Drop Down Content Not Assigned");// show warninig
else
{
// set the selection mode to single.
DropDownContent.Content.SelectionMode = SelectionType.Single;
// listen to selection changed events on the date picker
DropDownContent.Content.OnSelectionChanged.AddListener(SelectionChanged);
// disable the drop down object
DropDownContent.gameObject.SetActive(false);
Canvas canvas = CommonMethods.EnsureComponent<Canvas>(DropDownContent.gameObject);
CommonMethods.EnsureComponent<GraphicRaycaster>(DropDownContent.gameObject);
}
}
protected abstract void SetText(string text);
/// <summary>
/// shows the drop down
/// </summary>
void Show()
{
var canvas = DropDownContent.GetComponent<Canvas>();
if (canvas == null)
return;
DropDownContent.gameObject.SetActive(true);
canvas.overrideSorting = true;
canvas.sortingOrder = 30000;
mBlocker = CreateBlocker();
}
/// <summary>
/// returnes the selected date from the drop down , or null if non is selected
/// </summary>
/// <returns></returns>
public System.DateTime? GetSelectedDate()
{
if (DropDownContent == null)
return null;
if (DropDownContent.Content.Selection.Count != 1)
return null;
return DropDownContent.Content.Selection.GetItem(0);
}
//hides the drop down
void Hide()
{
DropDownContent.gameObject.SetActive(false);
CommonMethods.SafeDestroy(mBlocker);
}
/// <summary>
/// called when the date picker selection has changed
/// </summary>
void SelectionChanged()
{
var d = GetSelectedDate(); // get the selected date
string t = NoSelectionPrompt;
try
{
if (d.HasValue)
t = d.Value.ToString(labelDateFormat); // find the correct string to show for the selected date
}
catch(Exception)
{
Debug.LogWarning("the format specified for the drop down is not valid");
}
SetText(t); // show the selected date
Hide();
}
protected virtual GameObject CreateBlocker()
{
var canvasItems = GetComponentsInParent<Canvas>();
if (canvasItems.Length == 0)
return null;
Canvas rootCanvas = canvasItems[0];
GameObject gameObject = new GameObject("Blocker");
RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
rectTransform.SetParent(rootCanvas.transform, false);
rectTransform.anchorMin = (Vector2)Vector3.zero;
rectTransform.anchorMax = (Vector2)Vector3.one;
rectTransform.sizeDelta = Vector2.zero;
Canvas canvas = gameObject.AddComponent<Canvas>();
canvas.overrideSorting = true;
Canvas component = DropDownContent.GetComponent<Canvas>();
canvas.sortingLayerID = component.sortingLayerID;
canvas.sortingOrder = component.sortingOrder - 1;
gameObject.AddComponent<GraphicRaycaster>();
gameObject.AddComponent<Image>().color = Color.clear;
gameObject.AddComponent<Button>().onClick.AddListener(new UnityAction(this.Hide));
return gameObject;
}
/// <summary>
/// handle the drop down button click
/// </summary>
void ButtonClicked()
{
if (DropDownContent != null)
{
if (DropDownContent.gameObject.activeSelf)
Hide();
else
Show();
}
}
// Update is called once per frame
void Update()
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b9db1035c44143c4fba0c43a46855e6d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5716532daf1a51c4f81a222c14307b60
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,151 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.Linq;
using UnityEngine.UI;
namespace Bitsplash.DatePicker.Editors
{
[CustomEditor(typeof(DatePickerSettings))]
public class DatePickerSettingsEditor : Editor
{
void DoButton(SerializedObject serialized)
{
var im = serialized.FindProperty("TargetImage");
if (im.objectReferenceValue != null)
{
var serilizedIm = new SerializedObject(im.objectReferenceValue);
EditorGUILayout.LabelField("Button Image", EditorStyles.boldLabel);
var imSprite = serilizedIm.FindProperty("m_Sprite");
EditorGUILayout.PropertyField(imSprite);
var imColor = serilizedIm.FindProperty("m_Color");
EditorGUILayout.PropertyField(imColor);
serilizedIm.ApplyModifiedProperties();
}
var tx = serialized.FindProperty("TargetText");
if (tx.objectReferenceValue != null)
{
EditorGUILayout.LabelField("Button Text", EditorStyles.boldLabel);
var serilizedTx = new SerializedObject(tx.objectReferenceValue);
var itTx = serilizedTx.GetIterator();
bool flagTx = true;
while (itTx.NextVisible(flagTx))
{
flagTx = false;
if (itTx.name.ToLower() == "m_script")
continue;
EditorGUILayout.PropertyField(itTx, includeChildren: true);
}
serilizedTx.ApplyModifiedProperties();
}
}
void DoBackgroundSetting(UnityEngine.Object obj)
{
var mono = (obj as MonoBehaviour);
if (mono == null)
return;
var image = mono.GetComponent<Image>();
if (image == null)
return;
var serilizedIm = new SerializedObject(image);
var imSprite = serilizedIm.FindProperty("m_Sprite");
EditorGUILayout.PropertyField(imSprite);
var imColor = serilizedIm.FindProperty("m_Color");
EditorGUILayout.PropertyField(imColor);
serilizedIm.ApplyModifiedProperties();
}
void DoCellTemplate(UnityEngine.Object obj)
{
var mono = (obj as MonoBehaviour);
if (mono == null)
return;
var cell = mono.GetComponent<StandardDatePickerCell>();
if (cell == null)
return;
var serialized = new SerializedObject(cell);
var it = serialized.GetIterator();
bool flag = true;
while (it.NextVisible(flag))
{
flag = false;
if (it.name.ToLower() == "m_script")
continue;
if (it.name.ToLower() == "textitem")
continue;
if (it.name.ToLower() == "mark")
continue;
if (it.name.ToLower() == "background")
continue;
EditorGUILayout.PropertyField(it, includeChildren: true);
}
serialized.ApplyModifiedProperties();
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
var picker = target as DatePickerSettings;
foreach(var item in picker.GetComponentsInChildren<IDatePickerSettingsItem>(true).OrderBy(x=> x.Order))
{
var obj = (UnityEngine.Object)item;
var serialized = new SerializedObject(obj);
var openProp = serialized.FindProperty("isOpen");
if (openProp == null)
continue;
openProp.boolValue = EditorGUILayout.Foldout(openProp.boolValue, item.EditorTitle);
if (openProp.boolValue)
{
EditorGUI.indentLevel++;
if(item is DatePickerBackgroundSetting)
{
DoBackgroundSetting(obj);
}
if (item is DatePickerCellTemplate)
{
DoCellTemplate(obj);
}
else if (item is DatePickerButton)
{
DoButton(serialized);
}
else
{
var it = serialized.GetIterator();
bool flag = true;
while (it.NextVisible(flag))
{
flag = false;
if (it.name.ToLower() == "m_script")
continue;
if (it.name.ToLower() == "m_material")
continue;
if (it.name.ToLower() == "m_raycasttarget")
continue;
if (it.name.ToLower() == "cellprefab")
continue;
if (it.name.ToLower() == "totalrows")
continue;
if (it.name.ToLower() == "totalcolumns")
continue;
if (it.name.ToLower() == "texturetile")
continue;
if (it.name.ToLower() == "m_oncullstatechanged")
continue;
if (it.name.ToLower() == "targettext")
continue;
if (it.name.ToLower() == "targetimage")
continue;
EditorGUILayout.PropertyField(it, includeChildren: true);
}
}
EditorGUI.indentLevel--;
}
serialized.ApplyModifiedProperties();
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 89764379a6026914da49676446dd3eeb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7720fc210d505eb4fa356a1d576e169c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Bitsplash.DatePicker
{
[ExecuteInEditMode]
public abstract class DatePickerButton : DatePickerElement
{
Button mButton;
public Image TargetImage;
public DatePickerText TargetText;
protected DatePickerContent Content { get; private set; }
public abstract void RaiseClicked();
protected override void SetContent(DatePickerContent content)
{
Content = content;
}
protected override void SetMain(DatePickerSettings main)
{
}
// Start is called before the first frame update
protected override void Start()
{
base.Start();
mButton = GetComponent<Button>();
if (mButton != null)
mButton.onClick.AddListener(RaiseClicked);
}
void OnDestroy()
{
if(mButton != null)
mButton.onClick.RemoveListener(RaiseClicked);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1dfa7e8dca76b844292af7378b9c5b1b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,220 @@
using Bitsplash.DatePicker;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Bitsplash.DatePicker
{
[ExecuteInEditMode]
public partial class DatePickerText : DatePickerElement
{
//[SerializeField]
private RectTransform contentGameObject = null;
// [HideInInspector]
[SerializeField]
private string text;
[SerializeField]
private Color color = Color.white;
[SerializeField]
private int textSize = 14;
[SerializeField]
private FontStyle fontStyle = FontStyle.Normal;
[SerializeField]
private TextAnchor alignment = TextAnchor.MiddleLeft;
protected DatePickerContent Content { get; set; }
bool mValidate = false;
public RectTransform ContentGameObject
{
get { return contentGameObject; }
set
{
contentGameObject = value;
RecreateTextObject();
}
}
public string Text
{
get { return text; }
set { SetText(value); }
}
public FontStyle FontStyle
{
get { return fontStyle; }
set
{
SetStyle(value);
}
}
public Color Color
{
get { return color; }
set { SetColor(value); }
}
public TextAnchor Alignment
{
get { return alignment; }
set
{
SetAlignment(value);
}
}
public int TextSize
{
get { return textSize; }
set
{
SetTextSize(value);
}
}
DatePickerSettings mMain;
[HideInInspector]
[SerializeField]
UnityEngine.Object mTextObject;
protected override void SetContent(DatePickerContent content)
{
Content = content;
}
protected override void SetMain(DatePickerSettings main)
{
mMain = main;
InnerSetMain();
if(mTextObject == null)
RecreateTextObject();
}
void OnEnable()
{
if(mTextObject == null)
RecreateTextObject(true);
}
void RecreateTextObject(bool overrideCheck = false)
{
if(overrideCheck || isActiveAndEnabled)
StartCoroutine(RecreateTextObjectCorout());
}
partial void DestroyTextMesh();
IEnumerator RecreateTextObjectCorout()
{
bool res = false;
CheckTextMesh(ref res);
if(mValidate)
yield return 0;
if (mTextObject != null || GetComponent<Text>() != null || res == true)
{
CommonMethods.SafeDestroy(mTextObject);
CommonMethods.SafeDestroy(GetComponent<Text>());
DestroyTextMesh();
mTextObject = null;
yield return 0;
}
VerifyTextObject();
}
void VerifyTextObject()
{
if (mMain == null)
return;
InnerVerifyTextObject();
if(mTextObject == null)
{
var obj = gameObject;
if (contentGameObject != null)
obj = contentGameObject.gameObject;
var text = CommonMethods.EnsureComponent<Text>(obj,true);
text.font = mMain.TextFont;
mTextObject = text;
}
ApplyText();
}
void ApplyText()
{
SetText(text);
SetTextSize(textSize);
SetColor(color);
SetAlignment(alignment);
SetStyle(fontStyle);
}
partial void InnerSetMain();
partial void InnerVerifyTextObject();
partial void MediateTextMeshProText(string text);
partial void MediateTextMeshProColor(Color color);
partial void MediateTextMeshAlignment(TextAnchor alignment);
partial void MediateTextMeshSize(int size);
partial void MediateTextMeshStyle(FontStyle style);
partial void CheckTextMesh(ref bool res);
private void SetAlignment(TextAnchor alignment)
{
this.alignment = alignment;
MediateTextMeshAlignment(alignment);
var comp = mTextObject as Text;
if (comp != null)
comp.alignment = alignment;
}
private void SetStyle(FontStyle style)
{
this.fontStyle = style;
MediateTextMeshStyle(style);
var comp = mTextObject as Text;
if (comp != null)
comp.fontStyle = style;
}
private void SetTextSize(int size)
{
this.textSize = size;
MediateTextMeshSize(size);
var comp = mTextObject as Text;
if (comp != null)
comp.fontSize = size;
}
public override void OnValidate()
{
mValidate = true;
bool create = mTextObject != null;
base.OnValidate();
if(create)
RecreateTextObject(false);
ApplyText();
mValidate = false;
}
private void SetText(string text)
{
this.text = text;
MediateTextMeshProText(text);
var comp = mTextObject as Text;
if (comp != null)
comp.text = text;
}
private void SetColor(Color color)
{
this.color = color;
MediateTextMeshProColor(color);
var comp = mTextObject as Text;
if (comp != null)
comp.color = color;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8bb441f29338d34a9797c452b59e9c1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,70 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Bitsplash.DatePicker
{
public class MonthTextBox : DatePickerText , IDatePickerSettingsItem
{
[SerializeField]
private string dateFormat = "MMMM, yyyy";
public string DateFormat
{
get { return dateFormat; }
set
{
dateFormat = value;
RefreshText();
}
}
public int Order { get { return 8; } }
public string EditorTitle
{
get { return "Month Text Box - " + gameObject.name; }
}
protected override void SetContent(DatePickerContent content)
{
if (Content != null)
Content.OnDisplayChanged.RemoveListener(DisplayChanged);
base.SetContent(content);
if (Content != null)
{
Content.OnDisplayChanged.AddListener(DisplayChanged);
DisplayChanged();
}
}
void RefreshText()
{
if (Content == null)
return;
try
{
Text = (Content.DisplayDate.ToString(dateFormat));
}
catch (Exception)
{
Debug.LogWarning("Invalid date format for text box - " + DateFormat);
}
}
void DisplayChanged()
{
RefreshText();
}
void OnDestroy()
{
if (Content != null)
Content.OnDisplayChanged.RemoveListener(DisplayChanged);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 400d813d42c781647b2dc21a32c8ba6a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class NextMonthButton : DatePickerButton , IDatePickerSettingsItem
{
public int Order { get { return 8; } }
public override void RaiseClicked()
{
if(Content != null)
Content.NextMonth();
}
public string EditorTitle
{
get { return "Next Month Button"; }
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7ffc543322d72b84aa2bf75522e23960
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class NextYearButton : DatePickerButton , IDatePickerSettingsItem
{
public int Order { get { return 8; } }
public override void RaiseClicked()
{
if (Content != null)
Content.NextYear();
}
public string EditorTitle
{
get { return "Next Year Button"; }
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e73eb1b556ab0be46880c15138df96d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class PrevMonthButton : DatePickerButton , IDatePickerSettingsItem
{
public int Order { get { return 8; } }
public override void RaiseClicked()
{
if (Content != null)
Content.PrevMonth();
}
public string EditorTitle
{
get { return "Prev Month Button"; }
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 195f418039695ea4095364cf24d4c3b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class PrevYearButton : DatePickerButton , IDatePickerSettingsItem
{
public int Order { get { return 8; } }
public override void RaiseClicked()
{
if (Content != null)
Content.PrevYear();
}
public string EditorTitle
{
get { return "Prev Year Button"; }
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3681ff00dc435a443b306c4f1595e340
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,64 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class SelectionTextBox : DatePickerText , IDatePickerSettingsItem
{
public string DateFormat = "ddd, MMM d";
public string Seperator = " ... ";
public string NothingSelectedString = "";
public int Order { get { return 8; } }
protected override void SetContent(DatePickerContent content)
{
if (Content != null)
Content.OnSelectionChanged.RemoveListener(SelectionChanged);
base.SetContent(content);
if (Content != null)
{
Content.OnSelectionChanged.AddListener(SelectionChanged);
SelectionChanged();
}
}
void RefreshText()
{
if (Content == null)
return;
try
{
string text = NothingSelectedString;
if (Content.Selection.Count > 0)
{
text = Content.Selection.GetItem(0).ToString(DateFormat);
if (Content.Selection.Count > 1)
{
text += Seperator + Content.Selection.GetItem(Content.Selection.Count - 1).ToString(DateFormat);
}
}
Text = text;
}
catch (Exception)
{
Debug.LogWarning("Invalid date format for text box - " + DateFormat);
}
}
void SelectionChanged()
{
RefreshText();
}
void OnDestroy()
{
if (Content != null)
Content.OnSelectionChanged.RemoveListener(SelectionChanged);
}
public string EditorTitle
{
get { return "Selection Text Box - " + gameObject.name; }
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e9c89daa2cd8eb4881510775ec65c5a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,22 @@
using Bitsplash.DatePicker;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class TodayButton : DatePickerButton , IDatePickerSettingsItem
{
public int Order { get { return 8; } }
public override void RaiseClicked()
{
if (Content != null)
Content.Selection.SelectOne(DateTime.Today);
}
public string EditorTitle
{
get { return "Today Button"; }
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 88e9aaf8039021e4cadc9e31971b0dba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class YearCombo : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dd88d254a331aba41bda202e8c92f4c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6c935428eb94cf646acf92ce8b730b98
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public enum DatePickerCulture
{
StandardEnglish,
Current,
Custom
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4811c86bb6bb11f4695785ab8bdce2da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public enum FrameLayout
{
Top,
Bottom,
TopAndBottom,
Right,
Left,
RightAndLeft,
Full
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bf4183d35228bb9448e07eabfa4072ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public enum TextTypeEnum
{
StandardText,
TextMeshPro
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 821dcfed7c0fc3040844ab37271d346f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public enum TitleButtons
{
Month,
MonthAndYear,
YearOnly
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6591e6862c6316244973c7fbb9cac356
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public enum TitleDate
{
Label,
Combo
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7eb270964dd07394eb8ad59f351208e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public enum TitleLayout
{
None,
Side,
Center,
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 59403a7c645a0ee4caa53dcb17509c58
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public enum WeekDaysLayout
{
/// <summary>
/// do not show week day names
/// </summary>
None,
/// <summary>
/// show short week day names
/// </summary>
Short,
/// <summary>
/// show full week day names
/// </summary>
Full
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7f42e0187e34f241be0beb7358826a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
interface IDatePickerPrivate
{
void RaiseClick(int childIndex);
void RaiseStartSelection(int childIndex);
void RaiseSelectionEnter(int childIndex, int fromChildIndex);
void RaiseSelectionExit(int childIndex, int fromChildIndex);
void EndSelection();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ea67901e275547845aa9b6b92fbc9ee9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public interface IDatePickerSettingsItem
{
String EditorTitle { get; }
int Order { get; }
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6f964946c10134c4da0f7bd6a0bbdc13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Bitsplash.DatePicker
{
public class IDateTimeItem : MonoBehaviour
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1623b4afd126e4b45b113279fe6bb809
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,6 @@
namespace Assets.Calendar
{
internal class MonoBehvaiour
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 82d87da444320464aae7b597605ab9bb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public enum MultipleSelectionInputValue
{
Singular,
Append
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 60c0ba85e00abac409ef820e1e0f1275
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitsplash.DatePicker
{
public enum SelectionType
{
Single,
Range,
Multiple
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1387337db5001c4498d9c6b366a90d51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,247 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Bitsplash.DatePicker
{
[ExecuteInEditMode]
public class StandardDatePickerCell : DatePickerCell
{
public DatePickerText TextItem;
public Image Mark;
public Image Background;
public int TextSize = 14;
public FontStyle FontStyle;
public Color EnabledTextColor;
public Color SelectedTextColor;
public Color DisabledTextColor;
public Sprite MarkSprite;
[NonSerialized]
public Color MarkSelectedColor = new Color(0f,0f,0f,0f);
public Color SelectedBackgroundColor;
// public Color HoverBackgroundColor;
public Color EnabledBackgroundColor;
public Color DisabledBackgroundColor;
public float SlideSpeed = 0.9f;
bool mSelected = false;
bool mEnabled = true;
DateTime mDayValue = new DateTime();
private IEnumerator mCoroutine;
Color TargetColor;
public override Color MarkerColor
{
get
{
return MarkSelectedColor;
}
set
{
MarkSelectedColor = value;
AssignTextAndBackground();
}
}
public override bool CellSelected
{
get
{
return mSelected;
}
set
{
mSelected = value;
AssignTextAndBackground();
}
}
public override bool CellEnabled
{
get
{
return mEnabled;
}
set
{
mEnabled = value;
AssignTextAndBackground();
}
}
public override DateTime DayValue
{
get
{
return mDayValue;
}
set
{
mDayValue = value;
}
}
Vector4 ColorToVector4(Color c)
{
return new Vector4(c.r, c.g, c.b, c.a);
}
bool CompareColor(Color a, Color b, float margin)
{
Vector4 va = new Vector4(a.r, a.g, a.b, a.a);
Vector4 vb = new Vector4(b.r, b.g, b.b, b.a);
return (va - vb).sqrMagnitude < margin * margin;
}
void SlideColor(Color color)
{
if (Background == null)
return;
if (mCoroutine != null)
{
StopCoroutine(mCoroutine);
mCoroutine = null;
}
if (CompareColor(Background.color, color, 0.01f))
return;
if (isActiveAndEnabled == false || SlideSpeed <0f)
{
Background.color = color;
return;
}
mCoroutine = SlideToColor(color, SlideSpeed);
StartCoroutine(mCoroutine);
}
private void OnDisable()
{
if (mCoroutine != null)
{
StopCoroutine(mCoroutine);
if (Background != null)
Background.color = TargetColor;
mCoroutine = null;
}
}
IEnumerator SlideToColor(Color color, float factor)
{
TargetColor = color;
Vector4 from = ColorToVector4(Background.color);
Vector4 to = ColorToVector4(color);
Vector4 move = (to - from);
float time = 0f;
float magnitude = move.magnitude;
Color start = Background.color;
while (CompareColor(Background.color, color, 0.01f) == false)
{
Background.color = Color.Lerp(start, color, (time * factor) / magnitude);
time += Time.deltaTime;
yield return 0;
}
}
public override void SetInitialSettings(bool enabled, bool selected)
{
mEnabled = enabled;
mSelected = selected;
AssignTextAndBackground(true);
}
void AssignTextAndBackground(bool dontSlide = false)
{
var color = SelectedTextColor;
var backColor = SelectedBackgroundColor;
if(mSelected == false)
{
if(mEnabled)
{
color = EnabledTextColor;
backColor = EnabledBackgroundColor;
}
else
{
color = DisabledTextColor;
backColor = DisabledBackgroundColor;
}
}
if (Mark != null)
Mark.color = MarkSelectedColor;
if (Mark != null)
Mark.sprite = MarkSprite;
if (TextItem != null)
{
TextItem.Color = color;
TextItem.TextSize = TextSize;
TextItem.FontStyle = FontStyle;
}
if(dontSlide)
{
if (Background != null)
Background.color = backColor;
}
else
SlideColor(backColor);
// if (Background != null)
// Background.color = backColor;
}
void CopyFrom(StandardDatePickerCell cell)
{
TextSize = cell.TextSize;
FontStyle = cell.FontStyle;
EnabledTextColor = cell.EnabledTextColor;
SelectedTextColor = cell.SelectedTextColor;
DisabledTextColor = cell.DisabledTextColor;
MarkSprite = cell.MarkSprite;
MarkSelectedColor = cell.MarkSelectedColor;
SelectedBackgroundColor = cell.SelectedBackgroundColor;
// public Color HoverBackgroundColor;
EnabledBackgroundColor = cell.EnabledBackgroundColor;
DisabledBackgroundColor = cell.DisabledBackgroundColor;
SlideSpeed = cell.SlideSpeed;
}
public void OnValidate()
{
if (GetComponent<DatePickerCellTemplate>() == null)
{
AssignTextAndBackground(true);
return;
}
var settings = GetComponentInParent<DatePickerSettings>();
if(settings != null)
{
foreach(var cell in settings.GetComponentsInChildren<StandardDatePickerCell>())
{
if (cell != this)
{
cell.CopyFrom(this);
cell.OnValidate();
}
}
}
}
public override void SetText(string text)
{
if (TextItem != null)
TextItem.Text = text;// DateToString(mDayValue));
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 199d4b967dcaed346a9b3c46fbbc8ace
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Bitsplash.DatePicker
{
partial class TextMediator : MonoBehaviour
{
partial void MediateTextMeshProText(string text);
partial void MediateTextMeshProColor(Color color);
public void SetText(string text)
{
MediateTextMeshProText(text);
var comp = GetComponent<Text>();
if (comp != null)
comp.text = text;
}
public void SetColor(Color color)
{
MediateTextMeshProColor(color);
var comp = GetComponent<Text>();
if (comp != null)
comp.color = color;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7aa9943f91ba280449a22527776243aa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More