public void OnDrag(PointerEventData eventData) { Vector2 localPointerPosition; RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, eventData.position, eventData.pressEventCamera, out localPointerPosition); float offsetX = localPointerPosition.x; float diff = localPointerPosition.x - rect.sizeDelta.x; switch (drag_mode) { case DRAG_MODE.LEFT: rect.anchoredPosition = new Vector2(rect.anchoredPosition.x + offsetX, rect.anchoredPosition.y); rect.sizeDelta = new Vector2(rect.sizeDelta.x - offsetX, rect.sizeDelta.y); break; case DRAG_MODE.RIGHT: rect.sizeDelta = new Vector2(offsetX, rect.sizeDelta.y); break; case DRAG_MODE.NONE: break; default: break; } startTime = SlicerLibrary.ConvertPointToTime(rect.anchoredPosition.x, slicer.waveViz); endTime = SlicerLibrary.ConvertPointToTime(rect.anchoredPosition.x + rect.sizeDelta.x, slicer.waveViz); }
public void Slice() { AudioClipUtils audioClip = waveViz.GetAudioClip(); AudioClip clip = audioClip.GetAudioClip(); // データ取得を書く sliceTimes = GetSliceTimes(audioClip); //List<float> sliceTimes = new List<float> { 0, 3, 5 }; List <float> slicePoints = SlicerLibrary.ConvertTimeToPoint(sliceTimes, waveViz); for (int i = 0; i < slicePoints.Count - 1; i++) { if (slicePoints[i + 1] > waveViz.GetWidth()) { break; } GameObject slicedBlockObject = Instantiate(slicedBlockPrefab, Vector2.zero, Quaternion.identity, waveViz.contentRect.transform); SlicedBlock slicedBlock = slicedBlockObject.GetComponent <SlicedBlock>(); slicedBlock.slicer = this; slicedBlock.SetPosition(slicePoints[i], slicePoints[i + 1]); slicedBlock.OnPlayClick.AddListener(waveViz.Play); slicedBlocks.Add(slicedBlock); } }
public void SetPosition(float startX, float endX) { rect.pivot = Vector2.zero; rect.anchoredPosition = new Vector2(startX, 0); rect.sizeDelta = new Vector2(endX - startX, 0); startTime = SlicerLibrary.ConvertPointToTime(rect.anchoredPosition.x, slicer.waveViz); endTime = SlicerLibrary.ConvertPointToTime(rect.anchoredPosition.x + rect.sizeDelta.x, slicer.waveViz); }
public void OnWaveVisualizerWidthChanged(int width) { //すべて元どおりにしてしまう。 本来は残っているものだけを拡大縮小すべきだが... List <float> slicePoints = SlicerLibrary.ConvertTimeToPoint(sliceTimes, waveViz); for (int i = 0; i < slicePoints.Count - 1; i++) { if (slicePoints[i + 1] > waveViz.GetWidth()) { break; } slicedBlocks[i].SetPosition(slicePoints[i], slicePoints[i + 1]); } }