/// <summary> /// 增減時間 /// </summary> /// <param name="duration"></param> /// <param name="arrowChange"></param> /// <param name="dateTime"></param> /// <returns></returns> public static DateTime DateFrom(Duration duration, ArrowChange arrowChange, DateTime dateTime) { var positiveNegative = 1; switch (arrowChange) { case ArrowChange.Increase: positiveNegative *= 1; break; case ArrowChange.Reduce: positiveNegative *= -1; break; } switch (duration) { case Duration.Day: dateTime = dateTime.AddDays(1 * positiveNegative); break; case Duration.Week: dateTime = dateTime.AddDays(7 * positiveNegative); break; case Duration.Month: dateTime = dateTime.AddMonths(1 * positiveNegative); break; } return(dateTime); }
public void RemoveArrow(ArrowChange arrow) { arrowsUsed--; removedArrow = true; Toolbox.Instance.pool.Release(arrowInstance, arrow.gameObject); if (arrows.Count > 0) { arrows.Remove(arrow.gameObject); } }
void Update() { if (removedArrow || (Input.touchCount <= 0 && !Input.GetMouseButtonDown(0))) { removedArrow = false; touched = false; return; } var touchPosition = snap.Snap(Camera.main.ScreenToWorldPoint(Input.GetMouseButtonDown(0) ? (Vector2)Input.mousePosition : Input.GetTouch(0).position)); Vector2 gridPosition = grid.ConvertWorldToGrid(touchPosition); if (!touched && grid.IsInBounds(gridPosition)) { touched = true; if (grid.GetObjectsInCell((int)gridPosition.x, (int)gridPosition.y).Any(obj => obj.objectType == CarGridObject.GridObjectType.Arrow)) { return; } GameObject arrowObj = Toolbox.Instance.pool.Retrieve(arrowInstance); ArrowChange component = arrowObj.GetComponent <ArrowChange>(); component.manager = this; component.grid = grid; component.swipe.AllowSwipe(); grid.AddObject(component); arrowObj.transform.position = new Vector3(touchPosition.x, touchPosition.y, arrowObj.transform.position.z); snap.Snap(arrowObj.transform); if (arrowsUsed == numberOfArrows && arrows.Count > 0) { var arrow = arrows.Last(); arrows.RemoveAt(arrows.Count - 1); Toolbox.Instance.pool.Release(arrowInstance, arrow); arrowsUsed--; } arrows.Insert(0, arrowObj); arrowsUsed++; } }