public void initializeTimelineTrackMarkers(float trackMarkersOriginY) { // few factors // What % of timelineMaxTime is clamped // what is the difference between the left and right uv coordinates? trackMarkersHeightY = trackMarkersOriginY; timelineTrackUVwidth = timeline.TrackFaceUVs[0].x - timeline.TrackFaceUVs[1].x; // Debug.Log("timelineDiff " + timelineTrackUVwidth); // that difference is X units of time clamped inside the timeline (at current scale) --- this is our INITIAL clamp currentFromTimeClamp = 0; currentToTimeClamp = timeline.timelineMaximumTime / 2; // Debug.Log("toclamptime " + currentToTimeClamp); amountOfTimelineMarkers = Mathf.FloorToInt(currentToTimeClamp - currentFromTimeClamp) + 1; // timelineDelta = (timelineTrackUVwidth / timeline.transform.localScale.x) / (timeline.timelineMaximumTime / 2); // adjust for timeline scale // make sure all the material textures are scaled at 1,1; foreach (AnimationTrack track in animationTracks) { Material mat = track.GetComponent <Renderer>().material; mat.SetTextureScale("_MainTex", new Vector2(1, 1)); } // Debug.Log("TimelineDiff " + timelineTrackUVwidth); // set up timeline track markers timelineTrackMarkers = new TimelineTrackMarker[Mathf.FloorToInt(amountOfTimelineMarkers)]; timeDelta = (timeline.timelineMaximumTime / 2) / amountOfTimelineMarkers; // set up positions for these timeline track markers for (int i = 0; i < timelineTrackMarkers.Length; i++) { TimelineTrackMarker t = Instantiate(timeline.timelineTrackMarkerPrefab, timeline.transform).GetComponent <TimelineTrackMarker>(); timelineTrackMarkers[i] = t; int time = Mathf.RoundToInt(i * timeDelta + currentFromTimeClamp); string timeText = time.ToString(); t.ChangeText(timeText); // center coord of timeline track + amount of y needed to get to top of timeline renderer + amount o t.transform.localPosition = new Vector3(trackSectionOriginX - i * timelineDelta, trackMarkersHeightY, 0.2f / timeline.transform.localScale.z); // t.transform.localScale = new Vector3(1 / t.transform.parent.localScale.x, 1 / t.transform.parent.localScale.y, 1 / t.transform.parent.localScale.z); } }
// do some planning #region timelineTrackMarker, keyFrame, and ticker calculations private void recalculateTimelineTrackMarkers() { // calculate amount of integers between currentToTimeClamp and c amountOfTimelineMarkers = 0; float currentNumber = currentFromTimeClamp; Debug.Log("currentFromTimeClamp " + currentFromTimeClamp); Debug.Log("currentToTimeClamp " + currentToTimeClamp); float timelineStartCoordinate; if (currentNumber != Mathf.FloorToInt(currentNumber)) { // convert currentNumber to timelineCoordinate int nextNumber = Mathf.FloorToInt(currentNumber) + 1; float nextIntegerTimelineMarkerCoordinate = timeline.ConvertFromTimeToTimelineZPosition(nextNumber); timelineStartCoordinate = nextIntegerTimelineMarkerCoordinate; } else { timelineStartCoordinate = trackSectionOriginX; amountOfTimelineMarkers += 1; currentNumber += 1; } while (currentNumber <= currentToTimeClamp) { if (currentNumber == Mathf.RoundToInt(currentNumber)) { amountOfTimelineMarkers += 1; currentNumber += 1; } else { currentNumber = (Mathf.RoundToInt(currentNumber) + 1); } } foreach (TimelineTrackMarker t in timelineTrackMarkers) { Destroy(t.gameObject); } timelineTrackMarkers = new TimelineTrackMarker[Mathf.FloorToInt(amountOfTimelineMarkers)]; for (int i = 0; i < timelineTrackMarkers.Length; i++) { TimelineTrackMarker t = Instantiate(timeline.timelineTrackMarkerPrefab, timeline.transform).GetComponent <TimelineTrackMarker>(); timelineTrackMarkers[i] = t; int time = Mathf.RoundToInt(i * timeDelta + currentFromTimeClamp); string timeText = time.ToString(); t.ChangeText(timeText); // center coord of timeline track + amount of y needed to get to top of timeline renderer + amount o t.transform.localPosition = new Vector3(timelineStartCoordinate - i * timelineDelta, trackMarkersHeightY, 0.2f / timeline.transform.localScale.z); // t.transform.localScale = new Vector3(1 / t.transform.parent.localScale.x, 1 / t.transform.parent.localScale.y, 1 / t.transform.parent.localScale.z); } }