Exemplo n.º 1
0
    override public void updateIndex(Vector3 handPos)
    {
        if (layers.Count == 0)
        {
            return;
        }
        Vector3 handlePos     = getMetaphorObject().transform.position;
        Vector3 firstLayerPos = postionForLayerInIndex(0);
        Vector3 lastLayerPos  = postionForLayerInIndex(layers.Count - 1);
        float   distance      = Vector2.Distance(new Vector2(handPos.x, handPos.z), new Vector2(handlePos.x, handlePos.z));
        bool    inRange       = (distance <= detectRange) && ((handPos.y - lastLayerPos.y) <= (detectRange + fixGap)) && ((firstLayerPos.y - handPos.y) <= (detectRange + fixGap));

        if (!inRange)
        {
            fixGap = 0;
            layers[centerIndex].cancelHighLightText();
            centerIndex = 0;
            return;
        }
        else
        {
            fixGap = 0.5f * (detectRange - distance);
        }
        //centerAroundIndexs.Clear();
        centerIndex = Mathf.RoundToInt((handPos.y - firstLayerPos.y) / (lastLayerPos.y - firstLayerPos.y) * (layers.Count - 1));
        if (centerIndex < 0)
        {
            centerIndex = 0;
        }
        else if (centerIndex > layers.Count - 1)
        {
            centerIndex = layers.Count - 1;
        }
        LayerMetaphor toEnableLm = layers[centerIndex];
        Color         c          = Color.black;

        foreach (LayerMetaphor lm in layers)
        {
            if (!lm.isGrasped)
            {
                lm.disableGraspMovement();
                lm.disableGraspActions();
                lm.cancelHighLightText();
            }
            else
            {
                toEnableLm = lm;
                c          = Color.red;
            }
        }
        toEnableLm.enableGraspMovement();
        toEnableLm.enableRemovedGraspActions();
        toEnableLm.highLightText(c);
    }
    public virtual void updateIndex(Vector3 handPos)
    {
        if (layers.Count == 0)
        {
            return;
        }
        Vector3 handlePos     = getMetaphorObject().transform.position;
        Vector3 firstLayerPos = postionForLayerInIndex(0);
        Vector3 lastLayerPos  = postionForLayerInIndex(layers.Count - 1);
        float   distance      = Vector2.Distance(new Vector2(handPos.x, handPos.z), new Vector2(handlePos.x, handlePos.z));
        bool    inRange       = (distance <= detectRange) && ((handPos.y - lastLayerPos.y) <= (detectRange + fixGap)) && ((firstLayerPos.y - handPos.y) <= (detectRange + fixGap));

        if (!inRange)
        {
            fixGap = 0;
            layers[centerIndex].cancelHighLightText();
            centerIndex = 0;
            return;
        }
        else
        {
            fixGap = Mathf.Sqrt((detectRange - distance) / detectRange) * detectRange * 0.6f;
        }
        //centerAroundIndexs.Clear();
        centerIndex = 0;
        float gap = Mathf.Abs(postionForLayerInIndex(0).y - handPos.y);

        if (_oldVersion)
        {
            for (int i = 0; i < layers.Count; i++)
            {
                float gap_i = Mathf.Abs(postionForLayerInIndex(i).y - handPos.y);
                if (layers[i].isGrasped)
                {
                    gap_i = 0;
                }
                if (gap > gap_i)
                {
                    centerIndex = i;
                    gap         = gap_i;
                }
            }
        }
        else
        {
            centerIndex = Mathf.RoundToInt((handPos.y - firstLayerPos.y) / (lastLayerPos.y - firstLayerPos.y) * (layers.Count - 1));
        }
        if (centerIndex < 0)
        {
            centerIndex = 0;
        }
        else if (centerIndex > layers.Count - 1)
        {
            centerIndex = layers.Count - 1;
        }
        LayerMetaphor toEnableLm = layers[centerIndex];
        Color         c          = Color.black;

        foreach (LayerMetaphor lm in layers)
        {
            if (!lm.isGrasped)
            {
                lm.disableGraspMovement();
                lm.disableGraspActions();
                lm.cancelHighLightText();
            }
            else
            {
                toEnableLm = lm;
                c          = Color.red;
            }
        }
        toEnableLm.enableGraspMovement();
        toEnableLm.enableActivedGraspActions();
        toEnableLm.highLightText(c);

        //Debug.Log("bot:" + centerBotIndex + "center" + centerIndex + "top" + centerTopIndex);
    }