예제 #1
0
    public void Sync()
    {
        Hold[]  curFocus = hScenes.GetCurHolds();
        Vector3 pivot    = Vector3.zero;
        int     index    = 0;
        float   ratio    = size.transform.localScale.x;
        Vector3 tmp      = Vector3.zero;
        int     n        = 0;

        //中心座標を探す
        for (int i = (int)AvatarControl.BODYS.RH; i <= (int)AvatarControl.BODYS.LF; i++)
        {
            if (curFocus[i] != null)
            {
                Vector3 pos = curFocus[i].gameObject.transform.localPosition;
                holdR[i] = curFocus[i].gameObject.transform.localScale.x / ratio / 2;
                pivot   += pos;
                n++;
                index += (int)Mathf.Pow(2, i);
            }
        }
        //Debug.Log("index:"+index);
        //Debug.Log("arr:"+centerArr[index]);
        if (n != 0)
        {
            pivot /= n;
        }
        //
        for (int i = (int)AvatarControl.BODYS.RH; i <= (int)AvatarControl.BODYS.LF; i++)
        {
            if (curFocus[i] != null)
            {
                pHolds[i].SetActive(true);
                holdPos[i]  = (curFocus[i].gameObject.transform.localPosition - pivot) / ratio + centerArr[index];
                holdPos[i] += Vector3.forward * ac.CalcZPos(holdPos[i]);
                pHolds[i].transform.localPosition = holdPos[i];
                pHolds[i].transform.localScale    = Vector3.one * holdR[i] * 2;
            }
            else
            {
                pHolds[i].SetActive(false);
                holdPos[i] = Vector3.zero;
                holdR[i]   = 0.0f;
            }
        }
    }
예제 #2
0
    public void OnDrag(PointerEventData data)
    {
        if (finger == data.pointerId)
        {
            Vector3 p = cam.ScreenToWorldPoint(
                new Vector3(
                    data.position.x,
                    data.position.y,
                    -cam.transform.position.z
                    )
                );

            if (gameObject.name.Equals(BODY_NAME))
            {
                transform.position = new Vector3(p.x, p.y, ac.CalcBodyZPos(p));
            }
            else
            {
                transform.position = new Vector3(p.x, p.y, ac.CalcZPos(p));
            }
        }
    }
예제 #3
0
    public void OnDrag(PointerEventData data)
    {
        if (finger == data.pointerId)
        {
            //float len = (cam.transform.position - target.position).magnitude;
            Vector3 p = cam.ScreenToWorldPoint(
                new Vector3(
                    data.position.x,
                    data.position.y,
                    target.position.z - cam.transform.position.z));

            target.position = p;

            if (isRHD || isRFD || isLHD || isLFD)
            {
                //バウンド処理
                float z      = target.localPosition.z;
                float boundZ = ac.CalcZPos(target.localPosition);
                if (z > boundZ)
                {
                    target.localPosition =
                        new Vector3(target.localPosition.x,
                                    target.localPosition.y,
                                    boundZ);
                }

                if (isFixed)
                {
                    float   r   = 0.0f;
                    Vector3 pos = Vector3.zero;
                    if (isRHD)
                    {
                        r   = hp.GetR((int)AvatarControl.BODYS.RH);
                        pos = hp.GetHoldPos((int)AvatarControl.BODYS.RH);
                    }
                    else if (isRFD)
                    {
                        r   = hp.GetR((int)AvatarControl.BODYS.RF);
                        pos = hp.GetHoldPos((int)AvatarControl.BODYS.RF);
                    }
                    else if (isLHD)
                    {
                        r   = hp.GetR((int)AvatarControl.BODYS.LH);
                        pos = hp.GetHoldPos((int)AvatarControl.BODYS.LH);
                    }
                    else if (isLFD)
                    {
                        r   = hp.GetR((int)AvatarControl.BODYS.LF);
                        pos = hp.GetHoldPos((int)AvatarControl.BODYS.LF);
                    }

                    Vector3 v = target.localPosition - pos;

                    if (v.magnitude > r)
                    {
                        target.localPosition = pos + v.normalized * r;
                    }
                }
            }
            else if (isBDY)
            {
                Vector2 o     = new Vector2(0.0f, 0.6f);
                float   bodyR = 0.5f;
                float   z     = target.localPosition.z;
                Vector2 v     = (Vector2)target.localPosition - o;
                Vector2 tmp   = target.localPosition;
                if (v.magnitude > bodyR)
                {
                    tmp = o + v.normalized * bodyR;
                }
                float zUB = ac.CalcZPos(tmp) - 0.15f;
                float zLB = -0.35f;

                z = Mathf.Min(z, zUB);
                z = Mathf.Max(z, zLB);

                target.localPosition = new Vector3(tmp.x, tmp.y, z);
            }

            /*
             * if (gameObject.name.Equals(BODY_NAME)){
             *      //target.position = new Vector3(p.x, p.y, ac.CalcBodyZPos(p));
             *      target.position = p;
             * }else{
             *      target.position = new Vector3(p.x, p.y, ac.CalcZPos(p));
             * }*/
            target.localRotation = transform.localRotation;
        }
    }