Exemplo n.º 1
0
        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)
            SuitBodyCollider            start       = ImpulseOrigin;
            SuitBodyCollider            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.
                        SuitBodyCollider 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));
                }
            }
        }
Exemplo n.º 2
0
    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")
                {
                    SuitBodyCollider haptic = hit.collider.gameObject.GetComponent <SuitBodyCollider>();

                    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));
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
        IEnumerator ColorSuitForEmanation()
        {
            //Save the beginning in local scope in case it gets changed by additional input
            SuitBodyCollider 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++)
                        {
                            SuitBodyCollider 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));
                }
            }
        }
 bool AssignQuickButton(SuitBodyCollider suit, int index)
 {
     if (suit != null && SceneReferences[index] == null)
     {
         SceneReferences[index] = suit;
         return(true);
     }
     return(false);
 }
Exemplo n.º 5
0
            Collider AddColliderForSuit(SuitBodyCollider suit)
            {
                GameObject go = suit.gameObject;

                Collider col = go.AddComponent <BoxCollider>();

                col.gameObject.layer = HapticsLayer;
                col.isTrigger        = true;
                return(col);
            }
Exemplo n.º 6
0
 /// <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>
 private void ColorSuit(SuitBodyCollider 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;
     }
 }
Exemplo n.º 7
0
        void OnTriggerEnter(Collider collider)
        {
            SuitBodyCollider hit = collider.GetComponent <SuitBodyCollider>();

            if (hit != null)
            {
                AreaFlag flag = hit.regionID;
                //Debug.Log(flag.ToString() + "  " + (int)flag + "\n");
                onTriggerEnterSequence.CreateHandle(collider.GetComponent <SuitBodyCollider>().regionID).Play();
            }
        }
Exemplo n.º 8
0
        private void ClickedSuitInTraversalMode(SuitBodyCollider 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);
                }
            }
        }
Exemplo n.º 9
0
        SuitBodyCollider GetSuitForNode(GraphEngine.SuitNode target)
        {
            SuitBodyCollider 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);
        }
Exemplo n.º 10
0
            string AddComponentForSuit()
            {
                string output = string.Empty;

                for (int i = 0; i < SuitHolders.Count; i++)
                {
                    if (SuitHolders[i] != null)
                    {
                        output += "Processing " + SuitHolders[i].name + "";
                        GameObject targetGO = AddChildObjects ? SuitHolders[i].transform.FindChild(SuitHolders[i].name + childAppendName).gameObject : SuitHolders[i];

                        Collider col = null;
                        //Check if it has one already
                        SuitBodyCollider suit = targetGO.GetComponent <SuitBodyCollider>();
                        if (suit == null)
                        {
                            //Add one if it doesn't
                            //suit = targetGO.AddComponent<SuitBodyCollider>(); - Not undo-able

                            if (AddExclusiveTriggerCollider)
                            {
                                col = AddColliderForSuit(suit);
                            }

                            output += "\t  Adding Suit Body Collider to " + SuitHolders[i].name + "";
                        }

                        output += "\t  Adding " + DefaultOptions[i].ToString() + " " + SuitHolders[i].name + "\n";

                        //Add this region to it.
                        suit.regionID = suit.regionID | DefaultOptions[i];

                        //Save the collider if we made one
                        if (col != null)
                        {
                            suit.myCollider = col;
                        }

                        SceneReferences[i] = suit;


                        //Don't let the user change anything until they've deleted these?
                        //These functions aren't robust enough yet.
                        CanChangeValues = false;
                    }
                }

                output = "Creating SuitBodyCollider - Operation Finished\n\n" + output + "\n";
                return(output);
            }
 public override void OnSuitClicked(SuitBodyCollider clicked, RaycastHit hit)
 {
     if (selected.Contains(clicked))
     {
         selected.Remove(clicked);
         StartCoroutine(ChangeColorDelayed(
                            hit.collider.gameObject,
                            unselectedColor,
                            0.0f));
     }
     else
     {
         hit.collider.gameObject.GetComponent <MeshRenderer>().material.color = selectedColor;
         selected.Add(clicked);
     }
 }
            //When we change the field. Lookup that object and assign the quickbutton if it can
            SuitBodyCollider LookupSceneReference(int index)
            {
                SuitBodyCollider suit    = null;
                GameObject       targObj = SuitHolders[index];

                if (SuitHolders[index] != null)
                {
                    string    lookupName = SuitHolders[index].name + childAppendName;
                    Transform objToCheck = AddChildObjects ? targObj.transform.FindChild(lookupName) : targObj.transform;

                    if (objToCheck != null)
                    {
                        return(objToCheck.gameObject.GetComponent <SuitBodyCollider>());
                    }
                }
                return(null);
            }
Exemplo n.º 13
0
        /// <summary>
        /// Colors a pad as playing for the Effect Duratin
        /// </summary>
        /// <param name="suit">The node to color</param>
        /// <returns></returns>
        IEnumerator ColorPadForXDuration(SuitBodyCollider 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.
            SuitBodyCollider current = suit;

            //You could do a fancy color lerp functionality here...
            ColorSuit(current, selectedColor);

            //I clamp this to a min of .1 for user visibility.
            yield return(new WaitForSeconds(Mathf.Clamp(EffectDuration, .1f, 100)));

            //Revert our color
            Color targetColor = (current == ImpulseOrigin || current == ImpulseDestination) ? OriginColor : unselectedColor;

            ColorSuit(current, targetColor);
        }
            void CreateSuitObjectField(int index, GUILayoutOption[] options)
            {
                //GUILayout.Label("Suit Object Field " + SuitHolders.Count);
                if (SuitHolders != null && SuitHolders.Count > index)
                {
                    GameObject o = SuitHolders[index];
                    //GUIContent label = new GUIContent("Intended Parent");
                    SuitHolders[index] = EditorGUILayout.ObjectField(o, typeof(GameObject), true, options) as GameObject;

                    //Disallow Prefabs
                    if (SuitHolders[index] != null && PrefabUtility.GetPrefabType(SuitHolders[index]) == PrefabType.Prefab)
                    {
                        SuitHolders[index] = null;
                    }

                    //If the value changes
                    if (SuitHolders[index] != null && o != SuitHolders[index])
                    {
                        SuitBodyCollider suit = LookupSceneReference(index);
                        AssignQuickButton(suit, index);
                    }
                }
            }
Exemplo n.º 15
0
        public override void OnSuitClicked(SuitBodyCollider 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);
            }
        }
            string DetectComponentsToRemove()
            {
                string output = string.Empty;

                //We want to clear out the list
                ObjectsToDestroy.Clear();

                ComponentsToDestroy  = 0;
                GameObjectsToDestroy = 0;

                if (SceneReferences != null)
                {
                    for (int i = 0; i < SceneReferences.Count; i++)
                    {
                        if (SceneReferences[i] != null)
                        {
                            //If add child objects
                            if (AddChildObjects)
                            {
                                int componentCount = SceneReferences[i].gameObject.GetComponents <Component>().Length;

                                //Debug.Log("Component Count is equal to " + componentCount + "\n");

                                if (componentCount < 4)
                                {
                                    ComponentsToDestroy++;
                                    if (AddExclusiveTriggerCollider)
                                    {
                                        ComponentsToDestroy++;
                                    }
                                    GameObjectsToDestroy++;
                                    //Mark for deletion - they'll have to confirm removal.
                                    ObjectsToDestroy.Add(SceneReferences[i].gameObject);
                                    output += "Marking : " + SceneReferences[i].gameObject + "'s SuitBodyCollider Component for removal - has " + componentCount + " components\n";
                                }
                            }
                            //Attached to the parrent
                            else
                            {
                                if (SuitHolders[i] != null)
                                {
                                    SuitBodyCollider suit = SuitHolders[i].GetComponent <SuitBodyCollider>();

                                    if (suit != null)
                                    {
                                        ComponentsToDestroy++;
                                        ObjectsToDestroy.Add(suit);
                                        output += "Marking : " + SuitHolders[i].name + "'s SuitBodyCollider Component for removal\n";
                                    }

                                    if (AddExclusiveTriggerCollider && suit.myCollider != null)
                                    {
                                        ComponentsToDestroy++;
                                        ObjectsToDestroy.Add(suit.myCollider);
                                        output += "Marking : " + SuitHolders[i] + "'s " + suit.myCollider.GetType().ToString() + " Component for removal\n";
                                    }
                                }
                            }
                        }
                    }
                }

                output += "Operation Finished - " + ObjectsToDestroy.Count + " objects marked to destory\n";

                return(output);
            }
Exemplo n.º 17
0
 abstract public void OnSuitClicked(SuitBodyCollider suit, RaycastHit hit);
Exemplo n.º 18
0
        public override void OnSuitClicked(SuitBodyCollider clicked, RaycastHit hit)
        {
            //Click to recalibrate Suit

            //Click to play that pad?
        }
Exemplo n.º 19
0
 public override void OnSuitClicked(SuitBodyCollider clicked, RaycastHit hit)
 {
     Debug.Log("Clicked on " + clicked.name + " with a regionID value of: " + (int)clicked.regionID + "\n");
 }
Exemplo n.º 20
0
        void Update()
        {
            bool  moving = false;
            float velVal = 350;

            #region Direction Controls
            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
                    SuitBodyCollider clicked = hit.collider.gameObject.GetComponent <SuitBodyCollider>();

                    //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 Application Quit Code
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }
            #endregion
        }