Пример #1
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (windowDrop != null)
        {
            if (windowDrop.activeSelf)
            {
                GameObject    gameController = GameObject.FindGameObjectWithTag("gc");
                WindowManager windowManager  = gameController.GetComponent <WindowManager>();

                windowManager.SetWindowState(false);
                                #if UNITY_EDITOR
                // Debug.Log("Window Drop is disengaged onEndDrag");
                                #endif
            }
        }

        transform.SetParent(parentToReturnTo);                                                  // Snaps object back to orginal parent if dropped outside of a dropzone
        transform.SetSiblingIndex(placeholder.transform.GetSiblingIndex());                     // Returns card back to placeholder location

        GetComponent <CanvasGroup>().blocksRaycasts = true;                                     // turn Raycast back on
        Destroy(placeholder);

        if (transform.parent.gameObject == partsPanel)
        {
            transform.localScale = partsPanelScale;
            transform.SetParent(panelOrigin);
            transform.SetSiblingIndex(orderIndex);
        }

        if (transform.parent.gameObject == trashCan)
        {
            transform.SetParent(panelOrigin);
            transform.SetSiblingIndex(orderIndex);
        }

        if (transform.parent.gameObject == windowDrop)
        {
            transform.SetParent(panelOrigin);
            transform.SetSiblingIndex(orderIndex);
        }

        if (transform.parent.gameObject == buildBoard)
        {
            if (!onBuildBoard)
            {
                onBuildBoard = true;
                // Pass the animal part tag to Score Manager
                GameObject   gameController = GameObject.FindGameObjectWithTag("gc");
                ScoreManager scoreManager   = gameController.GetComponent <ScoreManager>();
                scoreManager.AddAnimalPartByTag(transform.gameObject.tag);
            }
            transform.SetAsLastSibling();
        }

        if (transform.parent.gameObject != buildBoard)
        {
            if (onBuildBoard)
            {
                onBuildBoard = false;
                // Pass the animal part tag to Score Manager
                GameObject   gameController = GameObject.FindGameObjectWithTag("gc");
                ScoreManager scoreManager   = gameController.GetComponent <ScoreManager>();
                scoreManager.RemoveAnimalPartByTag(transform.gameObject.tag);
            }
        }

        // Debug.Log("ParentToReturnTo is: " + panelOrigin.name);
    }