private void spawnTP() { // player1 stop moving GameObject p1 = GameObject.FindGameObjectsWithTag(tagPlayer1)[0]; fc1 = p1.GetComponent <FiducialController>(); fc1.doNotMove(); // player2 stop moving GameObject p2 = GameObject.FindGameObjectsWithTag(tagPlayer2)[0]; fc2 = p2.GetComponent <FiducialController>(); fc2.doNotMove(); Vector3 position1 = new Vector3(player1.position.x, player1.position.y, player1.position.z); Vector3 position2 = new Vector3(player2.position.x, player2.position.y, player2.position.z); GameObject tp1 = new GameObject(); tp1 = Instantiate(Tp_Prefab, position1, player1.rotation); tp_list.Add(tp1); GameObject tp2 = new GameObject(); tp2 = Instantiate(Tp_Prefab, position2, player2.rotation); tp_list.Add(tp2); SoundManager.Instance.PlayTransformClip(); }
// Use this for initialization void Start() { // Determine the duration fiducialController = this.GetComponent <FiducialController>(); m_settings = Settings.Instance; duration = (int)(m_settings.GetMarkerWidthMultiplier(fiducialController.MarkerID) * 2);// 1 = 1/4, 2 = 2/4, 3 = 3/4, 4 = 4/4 }
public float CalculateYPosition(Vector3 pos, FiducialController fiducialController, int currentBeat) { //only does something, if the marker lays still if (fiducialController.MovementDirection == Vector2.zero) { //if marker is not in the recognised jokerMarker dictionary - set y Position if (oldPosition.x != pos.x) { Debug.Log("Joker Marker " + fiducialController.MarkerID + " has been set."); realOldYPosition = pos.y; //checks which pentatonic tunes are not occupied List <GameObject[]> allActiveMarkers = m_lastComeLastServe.GetAllActiveMarkers(); List <int> freePentatonicTuneHeights = new List <int>(); int i = 0; bool isInRangeOfString = false; //Gets current tune of marker and thereby knows on which string it must calc free tune if (m_lastComeLastServe.enableChords) { i = m_tokenPosition.GetNote(Camera.main.ScreenToWorldPoint(pos)); i = i < m_settings.tunesPerString ? 0 : (i < (m_settings.tunesPerString * 2) ? 1 : 2); } for (int j = 0; j < pentatonicTunes.Length; j++) { //if chords are not enabled, jump between strings if (!m_lastComeLastServe.enableChords && (i + 1) * m_settings.tunesPerString < pentatonicTunes[j]) { i++; } //else if chords are enabled, check if current pentatonic tune is in range of current string else if (m_lastComeLastServe.enableChords && i * m_settings.tunesPerString < pentatonicTunes[j] && pentatonicTunes[j] < (i + 1) * m_settings.tunesPerString) { isInRangeOfString = true; } else { isInRangeOfString = false; } if ((m_lastComeLastServe.enableChords ? isInRangeOfString : 1 == 1) && (allActiveMarkers[i][currentBeat] == null || m_tokenPosition.GetNote(allActiveMarkers[i][currentBeat].transform.position) + 1 != pentatonicTunes[j])) { freePentatonicTuneHeights.Add(pentatonicTunes[j]); } } //Gets random pentatonic tune and calculates y position based on said tune pos.y = heightOffSet_bottom + freePentatonicTuneHeights[(int)Random.Range(0, freePentatonicTuneHeights.Count)] * cellHeightInPx - cellHeightInPx / 2; oldPosition = pos; return(pos.y); } else { return(oldPosition.y); } } //marker is moving return(pos.y); }
void Start() { m_fiducial = belongingMarker.GetComponent <FiducialController>(); m_settings = Settings.Instance; m_tokenPosition = TokenPosition.Instance; m_lastComeLastServe = GameObject.FindObjectOfType <LastComeLastServe>(); m_sRend = belongingMarker.GetComponent <SpriteRenderer>(); childrenSpriteRenderer = GetComponentsInChildren <SpriteRenderer>(); spriteWidthMultiplier = m_settings.GetMarkerWidthMultiplier(m_fiducial.MarkerID); scaleFactorTopBottomX = belongingMarker.transform.localScale.x * m_settings.thickenFactorTopBottomX;; scaleFactorLefRightX = m_settings.scaleFactorLefRightX; scaleFactorY = m_settings.scaleFactorY; if (lineTop == null) { lineTop = transform.Find("Line_Top"); } if (lineBottom == null) { lineBottom = transform.Find("Line_Bottom"); } if (lineLeft == null) { lineLeft = transform.Find("Line_Left"); } if (lineRight == null) { lineRight = transform.Find("Line_Right"); } startLoopBar = GameObject.Find(m_settings.startBarLoop).transform; endLoopBar = GameObject.Find(m_settings.endtBarLoop).transform; bm_spriteRenderer = belongingMarker.GetComponent <SpriteRenderer>(); left_spriteRenderer = lineLeft.GetComponent <SpriteRenderer>(); right_spriteRenderer = lineRight.GetComponent <SpriteRenderer>(); top_spriteRenderer = lineTop.GetComponent <SpriteRenderer>(); bottom_spriteRenderer = lineBottom.GetComponent <SpriteRenderer>(); bottomOffset = Camera.main.ScreenToWorldPoint(new Vector3(0, Camera.main.pixelHeight / 2 + m_settings.heightOffSetInPx_bottom, 0)).y; maxSpeedToShowOtherLinesForOrientation = m_settings.maxSpeedToShowOtherLinesForOrientation; inActiveColor = m_settings.linesForOrientationInactiveColor; this.SetColorOfLines(inActiveColor, 1, true); otherMarkersOnSameBeat = new List <LinesForOrientation>(); oldBeat = 0; }
void Start() { fiducial = GetComponent <FiducialController>(); rend = GetComponent <SpriteRenderer>(); Settings m_settings = Settings.Instance; red = m_settings.red; redMaterial.color = red; blue = m_settings.blue; blueMaterial.color = blue; green = m_settings.green; greenMaterial.color = green; m_lastComeLastServe = Object.FindObjectOfType <LastComeLastServe>(); }
//private EnemiesSpawner enemySpawner; // Start is called before the first frame update void Start() { t = GetComponent <Transform>(); planet = GetComponent <Transform>(); planet_pos = planet.position; GameObject p1 = GameObject.FindGameObjectsWithTag(tagPlayer1)[0]; player1 = p1.transform; fc1 = p1.GetComponent <FiducialController>(); GameObject p2 = GameObject.FindGameObjectsWithTag(tagPlayer2)[0]; player2 = p2.transform; fc2 = p2.GetComponent <FiducialController>(); StartCoroutine(fightRoutine()); }
private void Start() { nebula = GetComponent <Transform>(); nebula_pos = nebula.position; GameObject p1 = GameObject.FindGameObjectsWithTag(tagPlayer1)[0]; player1 = p1.transform; fc1 = p1.GetComponent <FiducialController>(); GameObject p2 = GameObject.FindGameObjectsWithTag(tagPlayer2)[0]; player2 = p2.transform; fc2 = p2.GetComponent <FiducialController>(); enemySpawner = EnemiesSpawner.instance; StartCoroutine(fightRoutine()); }
void Start() { m_settings = Settings.Instance; GameObject[] loopMarkers = GameObject.FindGameObjectsWithTag(m_settings.loopMarkerTag); int counter = 0; foreach (GameObject loopMarker in loopMarkers) { if (loopMarker.GetComponent <LoopController>().startMarker) { counter++; } //save other LoopMarker if (loopMarker.GetComponent <LoopController>().startMarker != this.startMarker) { otherLoopMarker = loopMarker; } if (counter > 1) { Debug.LogError("More than one Loop Start Gameobject defined. Must be exactely one."); break; } } if (counter == 0) { Debug.LogError("No Loop Start GameObject defined. Must be exactely one."); } if (ghostPrefab == null) { Debug.LogError("No ghost prefab defined."); } m_tuioManager = TuioManager.Instance; m_tokenPosition = TokenPosition.Instance; m_locationBar = FindObjectsOfType <LocationBar>()[0]; m_fiducialController = this.GetComponent <FiducialController>(); transform.position = new Vector3(startMarker ? m_tokenPosition.GetXPosForBeat(0) : m_tokenPosition.GetXPosForBeat(16), transform.position.y, transform.position.z); newPos = transform.position; }
public override void OnInspectorGUI() { controller = base.target as FiducialController; Camera mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>(); EditorGUILayout.BeginHorizontal(); controller.MarkerID = EditorGUILayout.IntField("Marker ID", controller.MarkerID); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); controller.AutoHideGO = EditorGUILayout.Toggle("Auto-hide GameObject", controller.AutoHideGO); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); controller.IsPositionMapped = EditorGUILayout.Toggle("Control Position", controller.IsPositionMapped); EditorGUILayout.EndHorizontal(); if (controller.IsPositionMapped) { EditorGUILayout.BeginHorizontal(); controller.InvertX = EditorGUILayout.Toggle("Invert X-Axis", controller.InvertX); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); controller.InvertY = EditorGUILayout.Toggle("Invert Y-Axis", controller.InvertY); EditorGUILayout.EndHorizontal(); if (!mainCamera.orthographic && !controller.isAttachedToGUIComponent()) { EditorGUILayout.BeginHorizontal(); controller.CameraOffset = EditorGUILayout.Slider("Camera offset", controller.CameraOffset, mainCamera.nearClipPlane, mainCamera.farClipPlane); EditorGUILayout.EndHorizontal(); } } EditorGUILayout.Separator(); if (!controller.isAttachedToGUIComponent()) { EditorGUILayout.BeginHorizontal(); controller.IsRotationMapped = EditorGUILayout.Toggle("Control Rotation", controller.IsRotationMapped); EditorGUILayout.EndHorizontal(); if (controller.IsRotationMapped) { EditorGUILayout.BeginHorizontal(); controller.RotateAround = (FiducialController.RotationAxis)EditorGUILayout.EnumPopup("Rotation Axis", controller.RotateAround); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); controller.RotationMultiplier = EditorGUILayout.Slider("Rotation Factor", controller.RotationMultiplier, 0.01f, 5f); EditorGUILayout.EndHorizontal(); } } if (GUI.changed) EditorUtility.SetDirty(controller); }
public Vector3 CalculateGridPosition(int markerID, float cameraOffset, bool isLoopBarMarker, bool isJoker, FiducialController fiducialController, Vector3 oldPositionInScreen) { //does not change position if the marker is currently being played if (!isLoopBarMarker && m_lastComeLastServe.IsBeingPlayed(markerID)) { return(fiducialController.gameObject.transform.position); } TuioObject m_obj = m_tuioManager.GetMarker(markerID); Vector3 position = new Vector3(m_obj.getX() * (Screen.width), isLoopBarMarker ? 0.5f * Screen.height : (1 - m_obj.getY()) * Screen.height, cameraOffset); //when the marker is snapped... if (fiducialController.IsSnapped()) { position.x = this.CalculateXPosition(position, isLoopBarMarker, m_settings.GetMarkerWidthMultiplier(markerID), false); // calculate x position while not moving //reads correctOldPos if marker is a JokerMarkers if (isJoker) { realOldPos = new Vector3(oldPositionInScreen.x, fiducialController.gameObject.GetComponent <JokerMarker>().GetRealOldYPosition(), oldPositionInScreen.z); } //...and the new position is NOT far away enough from the old position (different for Joker Markers), then set position to oldPosition if (isJoker ? !this.MovedFurtherThanThreshold(position, realOldPos, isJoker) : !this.MovedFurtherThanThreshold(position, oldPositionInScreen, isJoker)) { position = oldPositionInScreen; } //...and the new position is far away enoug from the old position, set snapped to false else if (this.MovedFurtherThanThreshold(position, oldPositionInScreen, isJoker)) { fiducialController.SetIsSnapped(false); } } //otherwise, if marker is NOT snapped... else if (!fiducialController.IsSnapped()) { //...and motion speed is zero, snap him to nearest grid position, set snapped to true and save the time of snapping (for lastcomelastserve algorithm) if (m_obj.getMotionSpeed() == 0) { #region X-Axis position.x = this.CalculateXPosition(position, isLoopBarMarker, m_settings.GetMarkerWidthMultiplier(markerID), false); // calculate x position while not moving #endregion #region Y-Axis //suggests the y Position because it's a joker marker if (isJoker) { position.y = fiducialController.gameObject.GetComponent <JokerMarker>().CalculateYPosition(position, fiducialController, this.GetTactPosition(Camera.main.ScreenToWorldPoint(position))); } else if (!isLoopBarMarker) { float snappingDistance = -cellHeightInPx / 2; //if marker is below grid area if (position.y < heightOffsetInPx_top + snappingDistance) { position.y = 0; } //if marker is above grid area else if (position.y > gridHeightInPx + heightOffsetInPx_bottom - snappingDistance) { position.y = gridHeightInPx + heightOffsetInPx_bottom - cellHeightInPx; } //if marker is on grid area else { float yPos = position.y - heightOffsetInPx_bottom - snappingDistance; float markerYOffset = yPos % cellHeightInPx; if (markerYOffset < cellHeightInPx / 2) { position.y = yPos - markerYOffset; } else { position.y = yPos - markerYOffset + cellHeightInPx; } } position.y += (heightOffsetInPx_bottom + snappingDistance); } #endregion //check if another tune is currently being played, if so: snap marker if (!m_lastComeLastServe.IsOtherMarkerBeingPlayedAtThisBeat(this.GetTactPosition(m_lastComeLastServe.markers[beats].transform.position))) { fiducialController.SetIsSnapped(true); fiducialController.SetLastTimeSnapped(Time.time); } } else { position.x = this.CalculateXPosition(position, isLoopBarMarker, m_settings.GetMarkerWidthMultiplier(markerID), true); // calculate x position while moving } } return(this.m_MainCamera.ScreenToWorldPoint(position)); }
//Gets beat from each marker of the passed list and checks if this marker is the latest marker on said beat private void RunThroughMarkerListAndUpdateActiveMarkers(List <GameObject> markerList, GameObject[] activeMarkersArray, Color color) { foreach (GameObject marker in markerList) { FiducialController m_fiducial = marker.GetComponent <FiducialController>(); if (m_fiducial.IsSnapped()) { //gets beat on which the the marker lies on int beat = m_tokenPosition.GetTactPosition(marker.transform.position); //gets tune on which the marker lies on and checks if the tune has changed. If so --> log message int tune = m_tokenPosition.GetNote(marker.transform.position); if ((tune + 1) != currentTunes[m_fiducial.MarkerID]) { //only sends Log message if it's not the first tune change if (currentTunes[m_fiducial.MarkerID] != 0) { Debug.Log("Marker " + m_fiducial.MarkerID + " changed tune from " + (currentTunes[m_fiducial.MarkerID] + 1) + " to " + (tune + 1) + "."); } currentTunes[m_fiducial.MarkerID] = tune + 1; } //checks if this marker isn't already the one in the activeMarker list if (activeMarkersArray[beat] != marker) { int width = (int)(m_settings.GetMarkerWidthMultiplier(m_fiducial.MarkerID) * 2); //if beat position is empty or if position is not empty, current marker hast snapped before marker on beat if (activeMarkersArray[beat] == null || (activeMarkersArray[beat].GetComponent <FiducialController>().GetLastTimeSnapped() < m_fiducial.GetLastTimeSnapped())) { //if the marker is wider/longer than one beat if (width > 1) //mind 1/2 { beat = beat == 0 ? 1 : beat; // TODO: beat can't be at 0 for width > 1 //checks if second beat of the marker is not ok, if so: break if (beat - 1 > m_settings.beats || (activeMarkersArray[beat - 1] != null && (activeMarkersArray[beat - 1].GetComponent <FiducialController>().GetLastTimeSnapped() > m_fiducial.GetLastTimeSnapped()))) //1/2 { break; } else { if (width > 2) // mind 3/4 { beat = beat == 0 ? 2 : beat; // TODO: beat can't be at 0 for width > 1 //checks if third beat of the marker is not ok, if so: break if (beat + 1 < 0 || (activeMarkersArray[beat + 1] != null && (activeMarkersArray[beat + 1].GetComponent <FiducialController>().GetLastTimeSnapped() > m_fiducial.GetLastTimeSnapped()))) //3/4 { break; } else { if (width > 3) // 4/4 { beat = beat == 0 ? 3 : beat; // TODO: beat can't be at 0 for width > 3 //checks if fourth beat of the marker is not ok, if so: break if (beat - 2 > m_settings.beats || (activeMarkersArray[beat - 2] != null && (activeMarkersArray[beat - 2].GetComponent <FiducialController>().GetLastTimeSnapped() > m_fiducial.GetLastTimeSnapped()))) //4/4 { break; } this.ActivateMarkerOnBeatWithColor(marker, activeMarkersArray, beat - 2, color); //4/4 } this.ActivateMarkerOnBeatWithColor(marker, activeMarkersArray, beat + 1, color); //3/4 } } this.ActivateMarkerOnBeatWithColor(marker, activeMarkersArray, beat - 1, color); //1/2 } } this.ActivateMarkerOnBeatWithColor(marker, activeMarkersArray, beat, color); //1/4 Debug.Log("Marker " + m_fiducial.MarkerID + " got activated on position " + (width > 3 ? beat - 1 : (width > 1 ? beat : beat + 1)) + " on tune " + (m_tokenPosition.GetNote(marker.transform.position) + 1) + " for " + width + " beat/s."); } } } } }
private IEnumerator Sample() { while (true) { FiducialController _buffer = _fc[0]; Debug.Log("Check-------------"); for (int i = 0; i < 3; i++) { Debug.Log(i + "bool : " + _fc[i].isConectted); if (_fc[i].isConectted == true) { id = _fc[i].MarkerID; _buffer = _fc[i]; Debug.Log("isConnected" + _fc[i].MarkerID); break; } } _audioSource = this.GetComponent <AudioSource>(); switch (this.gameObject.name) { case "Bass": //var id = (int)Part.Bass * 3 + Random.Range(0, 3); id = (id) + 0 * 3; //map to -> 0~2 //_audioSource.clip = _soundManager.GetComponent<MusicManager>().audioClips[id]; break; case "Chord": //id = (int)Part.Chord * 3 + Random.Range(0, 3); id = (id % 12) + 1 * 3; //map to -> 0~2 //_audioSource.clip = _soundManager.GetComponent<MusicManager>().audioClips[id]; break; case "Drum": //id = (int)Part.Drum * 3 + Random.Range(0, 3); id = (id % 24) + 2 * 3; //map to -> 0~2 //_audioSource.clip = _soundManager.GetComponent<MusicManager>().audioClips[id]; break; case "Melody": //id = (int)Part.Melody * 3 + Random.Range(0, 2); id = (id % 36) + 3 * 3; //map to -> 0~2 //_audioSource.clip = _soundManager.GetComponent<MusicManager>().audioClips[id]; break; } if (_buffer.isConectted) { Debug.Log("currentID" + id); _audioSource.clip = _soundManager.GetComponent <MusicManager>().audioClips[id]; _audioSource.Play(); } yield return(new WaitForSeconds(_audioSource.clip.length)); } }
void Awake() { Instance = this; _fiducialSavePath = Application.persistentDataPath + "Fiducials.json"; }
public override void OnInspectorGUI() { controller = base.target as FiducialController; Camera mainCamera = GameObject.FindGameObjectWithTag("MainCamera").camera; EditorGUILayout.BeginHorizontal(); controller.MarkerID = EditorGUILayout.IntField("Marker ID", controller.MarkerID); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); controller.AutoHideGO = EditorGUILayout.Toggle("Auto-hide GameObject", controller.AutoHideGO); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); controller.IsPositionMapped = EditorGUILayout.Toggle("Control Position", controller.IsPositionMapped); EditorGUILayout.EndHorizontal(); if (controller.IsPositionMapped) { EditorGUILayout.BeginHorizontal(); controller.InvertX = EditorGUILayout.Toggle("Invert X-Axis", controller.InvertX); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); controller.InvertY = EditorGUILayout.Toggle("Invert Y-Axis", controller.InvertY); EditorGUILayout.EndHorizontal(); if (!mainCamera.isOrthoGraphic && !controller.isAttachedToGUIComponent()) { EditorGUILayout.BeginHorizontal(); controller.CameraOffset = EditorGUILayout.Slider("Camera offset", controller.CameraOffset, mainCamera.nearClipPlane, mainCamera.farClipPlane); EditorGUILayout.EndHorizontal(); } } EditorGUILayout.Separator(); if (!controller.isAttachedToGUIComponent()) { EditorGUILayout.BeginHorizontal(); controller.IsRotationMapped = EditorGUILayout.Toggle("Control Rotation", controller.IsRotationMapped); EditorGUILayout.EndHorizontal(); if (controller.IsRotationMapped) { EditorGUILayout.BeginHorizontal(); controller.RotateAround = (FiducialController.RotationAxis)EditorGUILayout.EnumPopup("Rotation Axis", controller.RotateAround); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); controller.RotationMultiplier = EditorGUILayout.Slider("Rotation Factor", controller.RotationMultiplier, 0.01f, 5f); EditorGUILayout.EndHorizontal(); } } if (GUI.changed) { EditorUtility.SetDirty(controller); } }