public void ToggleSelectedArea() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Debug.DrawRay(ray.origin, ray.direction * 100, Color.blue, 3.5f); if (Physics.Raycast(ray, out hit, 100)) { if (hit.collider.gameObject.tag == "Haptic Region") { HardlightCollider haptic = hit.collider.gameObject.GetComponent <HardlightCollider>(); if (haptic != null) { Debug.LogFormat("Starting Haptic: Region ID {0}\n", haptic.regionID); five_second_hum.CreateHandle(haptic.regionID).Play(); hit.collider.gameObject.GetComponent <MeshRenderer>().material.color = Color.blue; StartCoroutine(ChangeColorDelayed( hit.collider.gameObject, new Color(227 / 255f, 227 / 255f, 227 / 255f, 1f), 5.0f)); } } } } }
IEnumerator ColorSuitForTraversal() { //Save the beginning and end in local scope in case they get changed by additional input (Which could cause some null refs/index out of bounds) HardlightCollider start = ImpulseOrigin; HardlightCollider destination = ImpulseDestination; List <GraphEngine.SuitNode> nodes = ImpulseGenerator._grapher.Dijkstras(start.regionID, destination.regionID); if (nodes != null && nodes.Count > 0) { //For each step in the traversal for (int outter = 0; outter < nodes.Count; outter++) { if (nodes[outter] != null) { //Get the corresponding Suit based on the GraphEngine's edge map. HardlightCollider next = GetSuitForNode(nodes[outter]); if (next != null) { //Color that pad for it's effect duration. StartCoroutine(ColorPadForXDuration(next)); } } //Wait for next stage of the impulse yield return(new WaitForSeconds(ImpulseDuration / nodes.Count)); } } }
public void PlayDrawnHaptic(HardlightCollider clicked, RaycastHit hit) { //This could be done more efficiently. It is kept simple to make the code more readible. int index = suitObjects.IndexOf(clicked); //If the current duration is over. if (playingDurations[index] <= 0) { //We enforce a minimum duration mostly to ensure there is a good visual. playingDurations[index] = Mathf.Clamp(Duration, minDuration, float.MaxValue); //Color the suit (drawn haptic expiration handles decoloring. ColorSuitCollider(clicked, selectedColor); //Find where we drew on AreaFlag flag = clicked.regionID; //Play the last played sequence there. LibraryManager.Inst.LastSequence.CreateHandle(flag).Play(); //When the effects expire, the decoloring is handled there. //StartCoroutine(ChangeColorDelayed( // hit.collider.gameObject, // unselectedColor, // Duration)); } else { //Don't do anything } }
IEnumerator ColorSuitForEmanation() { //Save the beginning in local scope in case it gets changed by additional input HardlightCollider start = ImpulseOrigin; //List of Lists //Stage 1: The pad clicked //Stage 2: One adjacent pad //Stage 3: Four pads adjacent to the previous pad //Stage 4: A few pads adjacent to last stage List <List <GraphEngine.SuitNode> > nodes = ImpulseGenerator._grapher.BFS(start.regionID, (int)Depth); if (nodes != null && nodes.Count > 0) { //For each possible stage for (int outter = 0; outter < nodes.Count; outter++) { if (nodes[outter] != null && nodes[outter].Count > 0) { //For each node in this stage for (int inner = 0; inner < nodes[outter].Count; inner++) { HardlightCollider next = GetSuitForNode(nodes[outter][inner]); if (next != null) { //Color that pad for the duration of the Effect StartCoroutine(ColorPadForXDuration(next)); } } } //Wait for next stage of the impulse yield return(new WaitForSeconds(ImpulseDuration / nodes.Count)); } } }
void OnTriggerEnter(Collider collider) { HardlightCollider hit = collider.GetComponent <HardlightCollider>(); if (hit != null) { LibraryManager.Inst.LastSequence.CreateHandle(hit.regionID).Play(); } }
/// <summary> /// Colors a particular suit visual to the labeled color. /// Performs a null check on suit first. /// </summary> /// <param name="suit"></param> /// <param name="col"></param> protected void ColorSuit(HardlightCollider suit, Color col) { //This is just sanitization and to make the code more robust. if (suit != null) { //We could easily be more efficient than getting the MeshRenderer each time (like having SuitBodyCollider hold onto a ref to it's MeshRenderer) //However this isn't a VR application, so ease of programming/readability is the priority here. suit.GetComponent <MeshRenderer>().material.color = col; } }
private void ClickedSuitInTraversalMode(HardlightCollider clicked, RaycastHit hit) { //None are currently selected if (ImpulseOrigin == null) { //Select first ImpulseOrigin = clicked; //Mark it as selected ColorSuit(clicked, OriginColor); } //First one is already selected else { //If we click back on the first node. if (ImpulseOrigin == clicked) { //Unselect First ColorSuit(clicked, unselectedColor); ImpulseOrigin = null; //If we had a destination if (ImpulseDestination != null) { //Clear it. ColorSuit(ImpulseDestination, unselectedColor); ImpulseDestination = null; } } else { //If we had a destination (from last play) if (ImpulseDestination != null) { //Clear it to avoid leaving unnecessary colored nodes ColorSuit(ImpulseDestination, unselectedColor); ImpulseDestination = null; } //Set our destination ImpulseDestination = clicked; ColorSuit(clicked, OriginColor); //Leftover log to see that we're playing from the start to end. //Debug.Log((int)TraversalOrigin.regionID + "\t " + (int)suit.regionID); //Play Impulse from the origin to our brand new destination. ImpulseGenerator.Impulse imp = ImpulseGenerator.BeginTraversingImpulse(ImpulseOrigin.regionID, clicked.regionID); //Then play it ConfigureAndPlayImpulse(imp); } } }
HardlightCollider GetSuitForNode(GraphEngine.SuitNode target) { HardlightCollider suit = null; //Get the SuitBodyCollider node where the region IDs match. If multiple match, take the first suit = SuitNodes.Where(x => x.regionID == target.Location).First(); //Yay functional programming //This is potentially problematic if you are using a suit model with MULTIPLE flags set for individual locations. //It would likely give some inaccurate visuals or have odd error cases. //Debug.Log("Asking for " + target.Location.ToString() + " " + suit.regionID.ToString() + "\n"); return(suit); }
public IEnumerator ColorPadForXDuration(HardlightCollider suit, Color targetColor, Color revertColor, float MinDuration = 0.0f) { //I don't think we need to save this local reference. Just in case. HardlightCollider current = suit; //You could do a fancy color lerp functionality here... ColorSuit(current, targetColor); //var duration = Mathf.Clamp(MinDuration, .1f, 100.0f); //I clamp this to a min of .1 for user visibility. yield return(new WaitForSeconds(MinDuration)); ColorSuit(current, revertColor); }
public void Collide(Collider col, Vector3 where) { #region Hit Player //Layer 31 is the default haptics layer. //This lets us check if what we hit is a 'haptic object' since thats all the Example Projectile wants to hit. if (col.gameObject.layer == NSManager.HAPTIC_LAYER) { //Debug.DrawLine(transform.position, transform.position + Vector3.up * 100, Color.cyan, 15); bool hapticCollisionOccurred = false; //Is what we hit a Hardlight Suit? HardlightSuit body = col.gameObject.GetComponent <HardlightSuit>(); //We make some assumptions about the impact point. //Our projectiles are moving fast, so we keep track of our position last frame (lastPosition) and use that instead of our current one. //I won't pretend to know what is best for your game (Desert of Danger uses a highly sophisticated predictive system because the projectiles are nearly hitscan) //This demo uses last frame to avoid tunneling and accidentally hitting the back pads. //If we hit a suit if (body != null) { CollideWithBody(body, col, where); hapticCollisionOccurred = true; } else { HardlightCollider individualCollider = col.gameObject.GetComponent <HardlightCollider>(); if (individualCollider != null) { CollideWithBody(HardlightSuit.Find(), col, where); //CollideWithHardlightCollider(individualCollider, where); hapticCollisionOccurred = true; } } if (hapticCollisionOccurred && DestroyAfterCollision) { DestroyProjectile(DestroyDelay); } } #endregion }
public override void OnSuitClicked(HardlightCollider clicked, RaycastHit hit) { Adding = true; if (suitObjects.Contains(clicked)) { Adding = false; suitObjects.Remove(clicked); StartCoroutine(ChangeColorDelayed( hit.collider.gameObject, unselectedColor, 0.0f)); } else { hit.collider.gameObject.GetComponent <MeshRenderer>().material.color = selectedColor; suitObjects.Add(clicked); } }
/// <summary> /// Colors a pad as playing for the Effect Duratin /// </summary> /// <param name="suit">The node to color</param> /// <returns></returns> IEnumerator ColorPadForXDuration(HardlightCollider suit) { //This function simulates the color of the pad. //It doesn't actually track the under-the-hood information of what is/isn't playing //That means if you call halt, it will still color despite no haptics. //Tools for that functionality are currently in the pipeline. //I don't think we need to save this local reference. Just in case. HardlightCollider current = suit; //You could do a fancy color lerp functionality here... ColorSuit(current, selectedColor); var duration = Mathf.Clamp(EffectDuration, .1f, 100.0f); //I clamp this to a min of .1 for user visibility. yield return(new WaitForSeconds(duration)); //Revert our color Color targetColor = (current == ImpulseOrigin || current == ImpulseDestination) ? OriginColor : unselectedColor; ColorSuit(current, targetColor); }
public override void OnSuitClicked(HardlightCollider clicked, RaycastHit hit) { //Start with which mode this SuitDemo is in // Emanation - Start at a point and affect in waves the neighbor pads. if (CurrentMode == ImpulseType.Emanating) { //Debug.Log((int)suit.regionID + "\n"); ImpulseGenerator.Impulse imp = ImpulseGenerator.BeginEmanatingEffect(clicked.regionID, (int)Depth); if (imp != null) { ColorSuit(ImpulseOrigin, unselectedColor); //Select first ImpulseOrigin = clicked; ConfigureAndPlayImpulse(imp); } } // Traversing - Start at a point and move in stages to the destination through neighbor pads else if (CurrentMode == ImpulseType.Traversing) { ClickedSuitInTraversalMode(clicked, hit); } }
public override void OnSuitClicking(HardlightCollider clicked, RaycastHit hit) { Debug.Log("Clicked on " + clicked.name + " with a regionID value of: " + (int)clicked.regionID + "\n"); }
public override void OnSuitClicking(HardlightCollider suit, RaycastHit hit) { }
public override void OnSuitClicked(HardlightCollider clicked, RaycastHit hit) { //Click to recalibrate Suit //Click to play that pad? }
public void GetInput() { #region [1-9] SuitDemos for (int i = 0; i < AllDemos.Length; i++) { if (AllDemos[i] != null) { if (Input.GetKeyDown(AllDemos[i].ActivateHotkey)) { SelectSuitDemo(AllDemos[i]); } } } #endregion #region [7] Massage Toggle if (Input.GetKeyDown(KeyCode.Alpha7)) { ToggleMassage(); } #endregion #region [Space] Clear all effects if (Input.GetKeyDown(KeyCode.Space)) { ClearAllEffects(); } #endregion #region [Arrows] Direction Controls bool moving = false; float velVal = 350; if ((Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) && myRB.transform.position.x > -Extent) { myRB.AddForce(Vector3.left * velVal); } if ((Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) && myRB.transform.position.x < Extent) { myRB.AddForce(Vector3.right * velVal); } if ((Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) && myRB.transform.position.y < Extent) { myRB.AddForce(Vector3.up * velVal); } if ((Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) && myRB.transform.position.y > -Extent) { myRB.AddForce(Vector3.down * velVal); } if (!moving) { myRB.velocity = Vector3.zero; } #endregion #region Clicking on SuitBodyCollider if (Input.GetMouseButtonDown(0)) { //Where the mouse is Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //Debug.DrawRay(ray.origin, ray.direction * 100, Color.blue, 3.5f); //Raycast to see if we hit if (Physics.Raycast(ray, out hit, 100)) { //Get the clicked SuitBodyCollider HardlightCollider clicked = hit.collider.gameObject.GetComponent <HardlightCollider>(); //Assuming there is one if (clicked != null) { //Do whatever our current demo wants to do with that click info. CurrentDemo.OnSuitClicked(clicked, hit); } } } #endregion #region Clicking on SuitBodyCollider if (Input.GetMouseButton(0)) { //Where the mouse is Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //Debug.DrawRay(ray.origin, ray.direction * 100, Color.blue, 3.5f); //Raycast to see if we hit if (Physics.Raycast(ray, out hit, 100)) { //Get the clicked SuitBodyCollider HardlightCollider clicked = hit.collider.gameObject.GetComponent <HardlightCollider>(); //Assuming there is one if (clicked != null) { //Do whatever our current demo wants to do with that click info. CurrentDemo.OnSuitClicking(clicked, hit); } } } else { if (CurrentDemo != null) { CurrentDemo.OnSuitNoInput(); } } #endregion #region [Esc] Application Quit Code if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } #endregion }
public override void OnSuitClicking(HardlightCollider clicked, RaycastHit hit) { PlayDrawnHaptic(clicked, hit); }
public void ColorSuitCollider(HardlightCollider suitCollider, Color setColor) { ColorSuitCollider(suitCollider.gameObject, setColor); }
abstract public void OnSuitClicking(HardlightCollider suit, RaycastHit hit);