Beispiel #1
0
    void Update()
    {
        if (grabbedState == States.Released && currentState == States.Grabbed)
        {
            grabbedState = States.Grabbed;

            StartCoroutine(coroutine);

            if (gameObject.GetComponent <SpriteRenderer>().sprite != null)
            {
                // Do some sound effect?
                Debug.Log("Do some sound effect?");
            }
            else
            {
                ClimbARHandhold.setHoldColor(gameObject, UnityEngine.Color.cyan);
            }
        }
        else if (grabbedState == States.Grabbed && currentState == States.Released)
        {
            grabbedState = States.Released;

            StopCoroutine(coroutine);

            if (gameObject.GetComponent <SpriteRenderer>().sprite != null)
            {
                // Do some sound effect?
                Debug.Log("Do some sound effect?");
            }
            else
            {
                ClimbARHandhold.setHoldColor(gameObject, UnityEngine.Color.cyan);
            }
        }
    }
Beispiel #2
0
    private void OnDisable()
    {
        MenuHold script = backHold.GetComponent <MenuHold>();

        Destroy(script);

        ClimbARHandhold.HoldLineRendererActive(backHold, false);
    }
Beispiel #3
0
 void Update()
 {
     if (currentState == States.Grabbed)
     {
         ClimbARHandhold.setHoldColor(gameObject, ClimbARHandhold.ENTERED_COLOR);
     }
     else if (currentState == States.Released)
     {
         ClimbARHandhold.setHoldColor(gameObject, ClimbARHandhold.RESET_COLOR);
     }
 }
Beispiel #4
0
 private void OnDisable()
 {
     foreach (GameObject hold in holds)
     {
         if (hold != null)
         {
             ClimbingHold script = hold.GetComponent <ClimbingHold>();
             Destroy(script);
             ClimbARHandhold.HoldLineRendererActive(hold, false);
         }
     }
 }
Beispiel #5
0
    private void OnDisable()
    {
        foreach (GameObject hold in holds)
        {
            if (hold != null)
            {
                ClimbARHandhold.HoldLineRendererActive(hold, false);

                HoldText hTextScript = hold.GetComponent <HoldText>();

                SoundHold script = hold.GetComponent <SoundHold>();
                Destroy(hTextScript);
                Destroy(script);

                ClimbARHandhold.DestroyChildren(hold);
            }
        }
    }
Beispiel #6
0
    // Use this for initialization
    void Start()
    {
        holds = GameObject.FindGameObjectsWithTag("Hold");
        ClimbARHandhold.HoldLineRendererActive(backHold, true);

        //if (holds.Length == 0)
        //{
        //    holds = ClimbARHandhold.InstantiateHandholds(prefabHold, GetComponent<Camera>(), new float[] { 1f, 1f, 0.1f, 0.1f });
        //    holds[0].transform.localPosition = new Vector2(-1, -1);
        //    DontDestroyOnLoad(holds[0]);
        //    ClimbingHold script = holds[0].GetComponent<ClimbingHold>();
        //    Destroy(script);
        //}

        //backHold = holds[0];
        //MenuHold menuHoldScript = backHold.AddComponent<MenuHold>();
        //menuHoldScript.setup(SceneUtils.SceneNames.menu);
        //backHold.GetComponent<LineRenderer>()
        //    .startColor = UnityEngine.Color.cyan;
        //backHold.GetComponent<LineRenderer>()
        //    .endColor = UnityEngine.Color.cyan;
    }
Beispiel #7
0
    void attachMenuHoldToHold(Dictionary <string, GameObject> menuItems)
    {
        foreach (string menuItem in menuItems.Keys)
        {
            GameObject menuHold = menuItems[menuItem];
            if (menuHold == null)
            {
                Debug.Log("No hold for menu item " + menuItem);
            }
            else
            {
                // Draw custom hold sprite for menu hold if present in Resources folder
                if (menuSprites[menuItem] != null)
                {
                    GameObject customSpriteObject = GameObject.Instantiate(customHoldSprite);
                    customSpriteObject.transform.SetParent(menuHold.transform);
                    customSpriteObject.transform.localPosition = new Vector3(0, 0, 0);

                    float radius = menuHold.GetComponent <CircleCollider2D>().radius;
                    ClimbARHandhold.DrawHoldSprite(customSpriteObject.GetComponent <SpriteRenderer>(), menuSprites[menuItem],
                                                   radius / camWidth, radius / camWidth);
                }
                // Draw line renderer otherwise
                else
                {
                    ClimbARHandhold.HoldLineRendererActive(menuHold, true);
                    ClimbARHandhold.setHoldColor(menuHold, UnityEngine.Color.cyan);
                }

                GameObject holdText       = new GameObject();
                HoldText   holdTextScript = holdText.AddComponent <HoldText>();
                holdTextScript.setup(menuItem, holdText, menuHold);

                MenuHold menuHoldScript = menuHold.AddComponent <MenuHold>();
                menuHoldScript.setup(menuItem);
            }
        }
    }
Beispiel #8
0
    private void OnDisable()
    {
        foreach (GameObject hold in holds)
        {
            if (hold != null)
            {
                MenuHold mHoldScript = hold.GetComponent <MenuHold>();
                HoldText hTextScript = hold.GetComponent <HoldText>();

                // Hide the rendered sprite
                hold.GetComponent <SpriteRenderer>().enabled = false;
                ClimbARHandhold.DestroyChildren(hold);
                ClimbARHandhold.HoldLineRendererActive(hold, false);
                hold.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);

                // Reset line renderer to uniform color
                hold.GetComponent <LineRenderer>().startColor = UnityEngine.Color.cyan;
                hold.GetComponent <LineRenderer>().endColor   = UnityEngine.Color.cyan;

                Destroy(mHoldScript);
                Destroy(hTextScript);
            }
        }
    }
Beispiel #9
0
    // Use this for initialization
    void Start()
    {
        holds = GameObject.FindGameObjectsWithTag("Hold");

        loopManager = gameObject.GetComponent <LoopManager>();

        loopManager.Setup(soundItems);

        // If starting directly into music scene, holds will be empty
        if (DEBUG)
        {
            holds = ClimbARHandhold.InstantiateHandholds(prefabHold, GetComponent <Camera>(), new float[] { 1f, 1f, 0.2f, 0.2f, 2f, 2f, 0.2f, 0.2f, 1f, 1f, 0.1f, 0.1f, 0.4f, 0.4f, 0.3f, 0.2f });
            holds[0].transform.localPosition = new Vector2(-1, -1);
            holds[1].transform.localPosition = new Vector2(1, 1);
            holds[2].transform.localPosition = new Vector2(-1, 1);
            holds[3].transform.localPosition = new Vector2(1, -1);
        }
        // If not debugging and no holds, just return
        else if (holds.Length <= 0)
        {
            return;
        }

        // Otherwise we actually have holds, assign it to hold
        HashSet <int> usedHoldIndexes  = new HashSet <int>();
        HashSet <int> usedSoundIndexes = new HashSet <int>();

        if (holds.Length < soundItems.Length)
        {
            Debug.Log("Not enough handholds for the number of sound items");
        }

        for (int i = 0; i < Mathf.Min(holds.Length, soundItems.Length); i++)
        {
            GameObject soundHold = holds[i];
            if (soundHold == null)
            {
                Debug.Log("no valid hold found");
            }
            else
            {
                ClimbARHandhold.HoldLineRendererActive(soundHold, true);
                ClimbingHold holdScript = soundHold.GetComponent <ClimbingHold>();
                Destroy(holdScript);

                SoundHold soundHoldScript = soundHold.AddComponent <SoundHold>();

                soundHoldScript.Setup(soundItems[i], i, loopManager);

                loopManager.RegisterHold(soundHoldScript.holdIndex, i);

                soundHoldScript.GetComponent <LineRenderer>()
                .startColor = UnityEngine.Color.cyan;
                soundHoldScript.GetComponent <LineRenderer>()
                .endColor = UnityEngine.Color.cyan;

                GameObject holdText       = new GameObject();
                HoldText   holdTextScript = holdText.AddComponent <HoldText>();
                holdTextScript.addText("   " + soundItems[i], holdText, soundHold);
            }
        }
    }
    // coroutine for overlaying bounding boxes on color image
    IEnumerator GrabFrameAndClassify(float delay)
    {
        classifyRunning = true;
        Debug.Log("starting classification coroutine");

        GameObject     bodyView = GameObject.Find("KinectBodyView");
        BodySourceView view     = bodyView.GetComponent <BodySourceView>();

        view.isClassifying = true;

        yield return(new WaitForSeconds(delay));

        if (_Reader == null)
        {
            Debug.Log("Using hardcoded bounding boxes or image");
            view.isClassifying = false;
            yield return(null);
        }
        ColorFrame frame = _Reader.AcquireLatestFrame();

        if (frame != null)
        {
            int     numHolds;
            float[] holdsBoundingBoxes;
            int     imageWidth;
            int     imageHeight;

            if (DEBUG)
            {
                Debug.Log("In debug mode; using hardcoded bounding boxes");
                //holdsBoundingBoxes = new int[] { 500, 500, 100, 100, 700, 700, 150, 150 };
                holdsBoundingBoxes = new float[] { 500, 500, 100, 100, 500, 100, 200, 200 };
                numHolds           = holdsBoundingBoxes.Length / 4;

                imageWidth  = 1000;
                imageHeight = 1000;
            }
            else
            {
                // don't apply texture, just load it for classification
                frame.CopyConvertedFrameDataToArray(
                    _Data,
                    ColorImageFormat.Bgra);
                _Texture.LoadRawTextureData(_Data);

                // classify image using OpenCV classifier

                FrameDescription frameDesc = _Sensor
                                             .ColorFrameSource
                                             .CreateFrameDescription(ColorImageFormat.Bgra);
                imageWidth         = frameDesc.Width;
                imageHeight        = frameDesc.Height;
                holdsBoundingBoxes = classifyWithOpenCV(imageWidth, imageHeight);
                if (holdsBoundingBoxes[0] < 0)
                {
                    if (!DEBUG)
                    {
                        frame.Dispose();
                        frame = null;
                    }
                    Debug.LogError("Error with classifying. Exiting coroutine");
                    classifyRunning = false;
                    yield break;
                }
                numHolds = holdsBoundingBoxes.Length / 4;
            }

            float[] projectorBounds = StateManager.instance.getProjectorBounds();
            float[] holdsProjectorTransformed;

            if (!StateManager.instance.debugView)
            {
                holdsProjectorTransformed =
                    ClimbARTransformation.transformOpenCvToUnitySpace(
                        projectorBounds,
                        holdsBoundingBoxes);
            }
            else
            {
                holdsProjectorTransformed = new float[holdsBoundingBoxes.Length];
                for (int i = 0; i < holdsBoundingBoxes.Length; i++)
                {
                    holdsProjectorTransformed[i] = (float)holdsBoundingBoxes[i];
                }
            }

            Debug.Log("instantiating " + numHolds + " holds");

            cleanHandHolds(ref this.handholds);
            this.handholds = ClimbARHandhold.InstantiateHandholds(
                this.Handhold,
                this.mainCam,
                holdsProjectorTransformed);

            // persist holds
            for (int i = 0; i < this.handholds.Length; i++)
            {
                DontDestroyOnLoad(this.handholds[i]);
            }

            if (!DEBUG)
            {
                frame.Dispose();
                frame = null;
            }
        }
        else
        {
            Debug.LogError("Frame was null");
        }

        // release locks for this file and the body source view text
        classifyRunning    = false;
        view.isClassifying = false;
    }