Example #1
0
    // ----------END VARIABLES----------

    /// <summary>
    /// Start used for initialization
    /// </summary>
    void Start()
    {
        man = this.transform.parent.GetComponent <EventPanelManager> ();

        /*GameObject puzzleCamera = GameObject.Find ("Puzzle Camera");
         *
         * if (puzzleCamera == null) {
         *      Debug.LogError ("Puzzle camera not present in scene");
         * }
         *
         * puzzleCameraController = puzzleCamera.GetComponent<PuzzleCameraController> ();*/
    }
Example #2
0
    private void SwipeCalculation(Camera cameraToUse)
    {
        Vector2 prev        = swipeGesture.PreviousPos[swipeGesture.recognizedId];
        Vector2 swipeVector = swipeGesture.ScreenFlicks[swipeGesture.recognizedId];

        // The end of the flick gesture (really the beginning, I think these are backwards but it doesn't affect anything)
        Vector2 next = prev - swipeVector;

        //Debug.LogError("Swipe Detected - Direction: " + swipeVector);
        //Debug.Log ("Start: " + start);

        // If we should show the line, then calculate where the screen-coordinate end points lie in world coordinates
        // We do this because line renderers only work with positions in 3D, not screen coordinates
        screenStartEnd[0].Set(prev.x, prev.y, cameraToUse.nearClipPlane + 10f);
        screenStartEnd[1].Set(next.x, next.y, cameraToUse.nearClipPlane + 10f);
        startEnd[0] = cameraToUse.ScreenToWorldPoint(new Vector3(prev.x, prev.y, cameraToUse.nearClipPlane + 10));
        startEnd[1] = cameraToUse.ScreenToWorldPoint(new Vector3(next.x, next.y, cameraToUse.nearClipPlane + 10));
        //Debug.Log("Line Drawn: " + startEnd[0] + " to " + startEnd[1]);

        // Begin event detection
        // Here we iterate through every actively playing event, and see if our swipe path matches with the neutrino event path

        if (currentEvents != null)
        {
            if (currentEvents.IsEventPlaying())
            {
                // Iterate through actively playing events
                for (int ev = 0; ev < currentEvents.eventsPlaying.Length; ++ev)
                {
                    if (currentEvents.eventsPlaying[ev].isPlaying)
                    {
                        // Get the start and end positions of the neutrino path for this event, in world coordinates
                        Vector3 vStart = currentEvents.events[ev].startPos;
                        Vector3 vEnd   = currentEvents.events[ev].endPos;

                        // Convert them to screen coordinates
                        Vector3 screenStart = cameraToUse.WorldToScreenPoint(vStart);
                        Vector3 screenEnd   = cameraToUse.WorldToScreenPoint(vEnd);
                        //Vector

                        // First check - distance check
                        // See if the midpoints of both paths are relatively close

                        // path midpoint
                        Vector2 screenMid;
                        screenMid.x = screenStart.x + 0.5f * (screenEnd.x - screenStart.x);
                        screenMid.y = screenStart.y + 0.5f * (screenEnd.y - screenStart.y);

                        // swipe midpoint
                        Vector2 swipeMid = next + 0.5f * (prev - next);

                        // Distance between them
                        float positionDiff = Vector2.Distance(swipeMid, screenMid);

                        // If the difference is too large, draw the missed line and return immediately - ya missed it!
                        // Move on to next event
                        //this position check doesn't need to be done for the front,side,top cameras.
                        if (cameraToUse == Camera.main)
                        {
                            if (positionDiff > Mathf.Min((Screen.height / 4f), (Screen.width / 4f)))
                            {
                                Debug.Log("Missed due to position");
                                DrawSwipeLine(SwipeType.missed, swipeGesture.recognizedId % 10, cameraToUse);
                                continue;
                            }
                        }

                        Vector3 worldEventVector = (vEnd - vStart).normalized;
                        Vector3 worldSwipeVector = (startEnd[0] - startEnd[1]).normalized;

                        Vector3 change = screenEnd - screenStart;

                        Vector2 v     = new Vector2(change.x, change.y);
                        float   vTest = 0.0f;

                        if (cameraToUse == Camera.main)
                        {
                            //totalVector = swipeVector.normalized;
                            //for main camera to comparison in world space...
                            vTest = Mathf.Abs(Vector2.Dot(swipeVector.normalized, v.normalized));
                        }
                        else
                        {
                            if (totalVector.magnitude > 0)
                            {
                                if (Vector3.Dot(totalVector.normalized, worldSwipeVector.normalized) < 0.0f)
                                {
                                    worldSwipeVector = -worldSwipeVector;
                                }
                            }

                            totalVector += worldSwipeVector;
                            totalVector  = totalVector.normalized;
                            vTest        = Mathf.Abs(Vector3.Dot(worldEventVector, totalVector));
                            if (refinePanel != null)
                            {
                                string txt        = refinePanel.GetComponent <UnityEngine.UI.Text>().text;
                                int    percentIdx = txt.IndexOf('%');
                                string subTxt     = txt.Substring(percentIdx - 5, 5);
                                string accuracy   = (vTest * 100f).ToString("F2");
                                if (vTest * 100f < 10f)
                                {
                                    accuracy = "0" + accuracy;
                                }
                                string newTxt = txt.Replace(subTxt, accuracy);
                                refinePanel.GetComponent <UnityEngine.UI.Text>().text = newTxt;
                            }

                            //change this to just be a gradient from red to green based on vTest.
                            if (cameraToUse == frontCamera)
                            {
                                totalScore.z = vTest;
                                //Debug.Log(vTest);
                                //TODO: add event to summary panel
                                frontPanel.GetComponent <UnityEngine.UI.Image>().color = UnityEngine.Color.Lerp(UnityEngine.Color.red, UnityEngine.Color.green, vTest);

                                if (!swipeGameMode.isSoftTutorial())
                                {
                                    //always add points
                                    int score = (int)(vTest * 10) * 10;
                                    //EventInfo e = epm.addEvent(currentEvents.events[currentEvents.lastEventNumber].eventSource.name, currentEvents.totalEnergy, vStart, vEnd,
                                    //    screenStart, screenEnd, summaryColor, score, false);
                                    Debug.Log("Added: " + score + " points.");
                                    neutrinoScore += score;
                                    updateScore();
                                    spawnPoints(score, new Vector3(1915, 1400, 0));
                                }
                                else
                                {
                                    collectSound.Play();
                                }
                            }
                            else if (cameraToUse == sideCamera)
                            {
                                totalScore.y = vTest;
                                sidePanel.GetComponent <UnityEngine.UI.Image>().color = UnityEngine.Color.Lerp(UnityEngine.Color.red, UnityEngine.Color.green, vTest);

                                if (!swipeGameMode.isSoftTutorial())
                                {
                                    //always add points
                                    int score = (int)(vTest * 10) * 10;
                                    //EventInfo e = epm.addEvent(currentEvents.events[currentEvents.lastEventNumber].eventSource.name, currentEvents.totalEnergy, vStart, vEnd,
                                    //    screenStart, screenEnd, summaryColor, score, false);
                                    //Debug.Log("Added: " + score + " points.");
                                    neutrinoScore += score;
                                    updateScore();
                                    spawnPoints(score, new Vector3(3050, 1400, 0));
                                }
                                else
                                {
                                    collectSound.Play();
                                }
                            }
                            else if (cameraToUse == topCamera)
                            {
                                totalScore.x = vTest;
                                topPanel.GetComponent <UnityEngine.UI.Image>().color = UnityEngine.Color.Lerp(UnityEngine.Color.red, UnityEngine.Color.green, vTest);

                                if (!swipeGameMode.isSoftTutorial())
                                {
                                    //always add points
                                    int score = (int)(vTest * 10) * 10;
                                    //EventInfo e = epm.addEvent(currentEvents.events[currentEvents.lastEventNumber].eventSource.name, currentEvents.totalEnergy, vStart, vEnd,
                                    //    screenStart, screenEnd, summaryColor, score, false);
                                    //Debug.Log("Added: " + score + " points.");
                                    neutrinoScore += score;
                                    updateScore();
                                    spawnPoints(score, new Vector3(800, 1400, 0));
                                }
                                else
                                {
                                    collectSound.Play();
                                }
                            }
                        }

                        if (cameraToUse == Camera.main)
                        {
                            if (vTest < initialSwipeAccuracy)
                            {
                                //if vTest < than prior vTest, mark red, else green...
                                DrawSwipeLine(SwipeType.missed, swipeGesture.recognizedId % 10, cameraToUse);
                                continue;
                            }
                        }
                        else
                        {
                            if (vTest < 0.999f)
                            {
                                //if vTest < than prior vTest, mark red, else green...
                                DrawSwipeLine(SwipeType.missed, swipeGesture.recognizedId % 10, cameraToUse);
                                if (swipeGameMode.SwipedAllThree())
                                {
                                    if (vTest < goalAccuracy)
                                    {
                                        StartCoroutine(DelayedResolve(0.5f, false));
                                        continue;
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }

                        // ----- EVENT DETECTED SUCCESSFULLY - Let the user know by drawing a green line
                        DrawSwipeLine(SwipeType.found, swipeGesture.recognizedId % 10, cameraToUse);

                        // Now calculate a few more things and add the event to the panel

                        if (!currentEvents.eventsPlaying[ev].isDetected && !inResolveMode)
                        {
                            //first swipe complete, entering resolve mode with 3 cameras
                            //add event to summary panel, increment score based on accuracy

                            //TODO:
                            if (summaryPanel != null)
                            {
                                if (!swipeGameMode.isSoftTutorial())
                                {
                                    EventPanelManager epm = summaryPanel.GetComponent <EventPanelManager>();
                                    if (epm != null)
                                    {
                                        //TODO: add bonus
                                        //Debug.Log(currentEvents.lastEventNumber + currentEvents.events[currentEvents.lastEventNumber].eventSource.name);
                                        Color summaryColor = new Color(Random.Range(0.3f, 1f), Random.Range(0.3f, 1f), Random.Range(0.3f, 1f));
                                        //add in empty event to init score to 0
                                        //EventInfo e = epm.addEvent(currentEvents.events[currentEvents.lastEventNumber].eventSource.name, currentEvents.totalEnergy, vStart, vEnd,
                                        //    screenStart, screenEnd, summaryColor, 0, false);
                                        //add in event again with actual score
                                        int score = 100;// (int)(vTest * 10) * 10;
                                        //e = epm.addEvent(currentEvents.events[currentEvents.lastEventNumber].eventSource.name, currentEvents.totalEnergy, vStart, vEnd,
                                        //    screenStart, screenEnd, summaryColor, score, false);
                                        Debug.Log("Added: " + score + " points.");
                                        neutrinoScore += score;

                                        updateScore();

                                        //what value is this?
                                        /// spawnPoints(score, new Vector3(3520, 1800, 0));
                                        spawnPoints(score, new Vector3(1920, 1700, 0));
                                    }
                                }
                                else
                                {
                                    collectSound.Play();
                                }
                            }

                            currentEvents.eventsPlaying[ev].isDetected = true;

                            /*if(cameraToUse == Camera.main)
                             * {
                             *  if(detectionCone != null)
                             *  {
                             *      detectionCone.SetActive(true);
                             *      Quaternion q = detectionCone.transform.rotation;
                             *      q.SetLookRotation(worldSwipeVector.normalized);
                             *      detectionCone.transform.rotation = q;
                             *  }
                             * }*/
                            swipeGameMode.EventSwiped();
                        }

                        if (cameraToUse != Camera.main && inResolveMode)
                        {
                            //if we are here, we've successfully swiped the event..
                            //tell user good job or something, then accumulate event and return to game.
                            //Debug.Log("SUCCESS");
                            StartCoroutine(DelayedResolve(swipeGameMode.isSoftTutorial() ? 0.5f : 4f, true));

                            //add 1000 point bonus
                            if (summaryPanel != null)
                            {
                                if (!swipeGameMode.isSoftTutorial())
                                {
                                    EventPanelManager epm = summaryPanel.GetComponent <EventPanelManager>();
                                    if (epm != null)
                                    {
                                        //TODO: add bonus
                                        //Debug.Log(currentEvents.lastEventNumber + currentEvents.events[currentEvents.lastEventNumber].eventSource.name);
                                        Color summaryColor2 = new Color(Random.Range(0.3f, 1f), Random.Range(0.3f, 1f), Random.Range(0.3f, 1f));
                                        //add in empty event to init score to 0
                                        EventInfo e = epm.addEvent(currentEvents.events[currentEvents.lastEventNumber].eventSource.name, currentEvents.totalEnergy, vStart, vEnd,
                                                                   screenStart, screenEnd, summaryColor2, 0, false);
                                        //add in event again with actual score
                                        //e = epm.addEvent(currentEvents.events[currentEvents.lastEventNumber].eventSource.name, currentEvents.totalEnergy, vStart, vEnd,
                                        //    screenStart, screenEnd, summaryColor2, 1000, false);
                                        Debug.Log("Added bonus: " + 100 + " points.");
                                        neutrinoScore += 100;
                                        neutrinoCount++;
                                        updateScore();
                                        spawnPoints(100, new Vector3(1920, 1700, 0));
                                    }
                                }
                            }

                            if (congratsPanel != null)
                            {
                                swipeGameMode.DisableCameras();

                                if (!swipeGameMode.isSoftTutorial())
                                {
                                    congratsPanel.SetActive(true);
                                    congratsPanel.GetComponent <UnityEngine.UI.Text>().text = "Great Job!  You detected a neutrino from a: " + currentEvents.events[currentEvents.lastEventNumber].eventSource.name;
                                }
                            }

                            Color summaryColor = Color.white;
                            if (!swipeGameMode.isSoftTutorial())
                            {
                                if (eventPanel != null)
                                {
                                    EventPanelManager epm = eventPanel.GetComponent <EventPanelManager>();
                                    //Debug.Log(currentEvents.lastEventNumber + currentEvents.events[currentEvents.lastEventNumber].eventSource.name);
                                    EventInfo e = epm.addEvent(currentEvents.events[currentEvents.lastEventNumber].eventSource.name, currentEvents.totalEnergy, vStart, vEnd,
                                                               screenStart, screenEnd, Color.white, (int)vTest * 100);

                                    if (e != null)
                                    {
                                        summaryColor = e.gameObject.GetComponent <UnityEngine.UI.Image>().color;
                                        earthView.AddDetectedEvent(currentEvents.events[currentEvents.lastEventNumber].startPos,
                                                                   currentEvents.events[currentEvents.lastEventNumber].endPos + (currentEvents.events[currentEvents.lastEventNumber].endPos - currentEvents.events[currentEvents.lastEventNumber].startPos).normalized * 500000f, summaryColor, vTest, goalAccuracy);
                                    }
                                }
                            }

                            /*  if (summaryPanel != null)
                             * {
                             *  EventPanelManager epm = summaryPanel.GetComponent<EventPanelManager>();
                             *  if (epm != null)
                             *  {
                             *      //TODO: add 100 point bonus
                             *      //Debug.Log(currentEvents.lastEventNumber + currentEvents.events[currentEvents.lastEventNumber].eventSource.name);
                             *      EventInfo e = epm.addEvent(currentEvents.events[currentEvents.lastEventNumber].eventSource.name, currentEvents.totalEnergy, vStart, vEnd,
                             *          screenStart, screenEnd, summaryColor, (int)vTest * 100, false);
                             *  }
                             * } */

                            //assuming just one event here for now..
                            //add point to sphere map...
                            if (!swipeGameMode.isSoftTutorial())
                            {
                                if (sphereMap != null)
                                {
                                    Vector3 dir = currentEvents.events[currentEvents.lastEventNumber].startPos - currentEvents.events[currentEvents.lastEventNumber].endPos;
                                    dir = dir.normalized;
                                    float longitude = (2 * Mathf.Acos(Vector3.Dot(dir, Vector3.up)) / Mathf.PI) - 1;
                                    float lat       = (2 * Mathf.Acos(Vector3.Dot(dir, Vector3.forward)) / Mathf.PI) - 1;
                                    sphereMap.PlotPoint(lat, longitude, summaryColor);
                                }
                            }

                            /*if(scorePanel != null)
                             * {
                             *  //neutrinoScore++;
                             *  string countTxt = "Score: " + neutrinoScore.ToString() + " Points";
                             *  scorePanel.GetComponent<UnityEngine.UI.Text>().text = countTxt;
                             * } */
                        }
                    }
                }
            }
            else if (cameraToUse.Equals(Camera.main))
            {
                // Else then no events playing, so draw an idle swipe line
                DrawSwipeLine(SwipeType.idle, swipeGesture.recognizedId % 10, cameraToUse);
            }
        }
    }