namespace UIWidgets.Examples
{
using System;
using System.ComponentModel;
using UnityEngine;
///
/// Track data.
///
[Serializable]
public class TrackData : ITrackData, IObservable, INotifyPropertyChanged
{
[SerializeField]
DateTime startPoint;
///
/// Start point.
///
public DateTime StartPoint
{
get
{
return startPoint;
}
set
{
if (startPoint != value)
{
startPoint = value;
NotifyPropertyChanged("StartPoint");
}
}
}
[SerializeField]
DateTime endPoint;
///
/// End point.
///
public DateTime EndPoint
{
get
{
return endPoint;
}
set
{
if (endPoint != value)
{
endPoint = value;
NotifyPropertyChanged("EndPoint");
}
}
}
[SerializeField]
[HideInInspector]
int order;
///
/// Order.
///
public int Order
{
get
{
return order;
}
set
{
if (order != value)
{
order = value;
fixedOrder = false;
}
}
}
[SerializeField]
[HideInInspector]
bool fixedOrder;
///
/// Is order fixed?
///
public bool FixedOrder
{
get
{
return fixedOrder;
}
set
{
if (fixedOrder != value)
{
fixedOrder = value;
}
}
}
[SerializeField]
string name;
///
/// Name.
///
public string Name
{
get
{
return name;
}
set
{
if (name != value)
{
name = value;
NotifyPropertyChanged("Name");
}
}
}
[SerializeField]
string description;
///
/// Description.
///
public string Description
{
get
{
return description;
}
set
{
if (description != value)
{
description = value;
NotifyPropertyChanged("Description");
}
}
}
///
/// Is item dragged?
///
public bool IsDragged
{
get;
set;
}
///
/// Occurs when a property value changes.
///
public event OnChange OnChange;
///
/// Occurs when a property value changes.
///
public event PropertyChangedEventHandler PropertyChanged;
///
/// Raise PropertyChanged event.
///
/// Property name.
protected void NotifyPropertyChanged(string propertyName)
{
var c_handlers = OnChange;
if (c_handlers != null)
{
c_handlers();
}
var handlers = PropertyChanged;
if (handlers != null)
{
handlers(this, new PropertyChangedEventArgs(propertyName));
}
}
///
/// Get new EndPoint by specified StartPoint to maintain same length.
///
/// New start point.
/// New EndPoint value.
public DateTime EndPointByStartPoint(DateTime newStart)
{
return newStart + (EndPoint - StartPoint);
}
///
/// Set StartPoint and EndPoint to maintain same length.
///
/// New start point.
/// New end point.
public void SetPoints(DateTime newStart, DateTime newEnd)
{
StartPoint = newStart;
EndPoint = endPoint;
}
///
/// Change StartPoint and EndPoint.
///
/// New StartPoint.
/// New EndPoint.
public void ChangePoints(DateTime newStart, DateTime newEnd)
{
var changed = (startPoint != newStart) || (endPoint != newEnd);
if (changed)
{
startPoint = newStart;
endPoint = newEnd;
NotifyPropertyChanged("StartPoint");
}
}
///
/// Copy data to target.
///
/// Target.
public void CopyTo(TrackData target)
{
target.StartPoint = StartPoint;
target.EndPoint = EndPoint;
target.Name = Name;
target.Description = Description;
}
///
/// Convert this instance to string.
///
/// String representation.
public override string ToString()
{
return Name;
}
}
}