Inheritance: MonoBehaviour
Example #1
0
    void Start()
    {
        canChangeItem = true;
        int count = listEnhanceItems.Count;

        dFactor      = (Mathf.RoundToInt((1f / count) * 10000f)) * 0.0001f;
        mCenterIndex = count / 2;
        if (count % 2 == 0)
        {
            mCenterIndex = count / 2 - 1;
        }
        int index = 0;

        for (int i = count - 1; i >= 0; i--)
        {
            listEnhanceItems[i].CurveOffSetIndex = i;
            listEnhanceItems[i].CenterOffSet     = dFactor * (mCenterIndex - index);
            listEnhanceItems[i].SetSelectState(false);
            GameObject obj = listEnhanceItems[i].gameObject;



            if (inputType == InputSystemType.NGUIAndWorldInput)
            {
                DragEnhanceView script = obj.GetComponent <DragEnhanceView>();
                if (script != null)
                {
                    script.SetScrollView(this);
                }
            }
            else
            {
                UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>();
                if (script != null)
                {
                    script.SetScrollView(this);
                }
            }
            index++;
        }

        // set the center item with startCenterIndex
        if (startCenterIndex < 0 || startCenterIndex >= count)
        {
            Debug.LogError("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count  out of index ##");
            startCenterIndex = mCenterIndex;
        }

        // sorted items
        listSortedItems      = new List <EnhanceItem>(listEnhanceItems.ToArray());
        totalHorizontalWidth = cellWidth * count;
        curCenterItem        = listEnhanceItems[startCenterIndex];
        curHorizontalValue   = 0.5f - curCenterItem.CenterOffSet;
        LerpTweenToTarget(0f, curHorizontalValue, false);

        //
        // enable the drag actions
        //
        EnableDrag(true);
    }
    public GameObject RayCast(Camera cam, Vector3 inPos)                                          // GameObject RayCast
    {
        Vector3 pos = cam.ScreenToViewportPoint(inPos);

        if (float.IsNaN(pos.x) || float.IsNaN(pos.y))
        {
            return(null);
        }
        if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f)
        {
            return(null);
        }

        Ray   ray = cam.ScreenPointToRay(inPos);
        float dis = 100f;

        RaycastHit[] hits = Physics.RaycastAll(ray, dis, rayCastMask);
        if (hits.Length > 0)
        {
            for (int i = 0; i < hits.Length; i++)
            {
                GameObject      go       = hits[i].collider.gameObject;
                DragEnhanceView dragView = go.GetComponent <DragEnhanceView>();
                if (dragView == null)
                {
                    continue;
                }
                else
                {
                    // just return current hover object our drag target
                    return(go);
                }
            }
        }
        return(null);
    }
Example #3
0
    public void initialize()
    {
        // Clear();
        listSortedItems.Clear();
        TextuerName = TextuerPropModel.GetInstance();
        InstantiateTextuer(TextuerName.TEYP);

        canChangeItem = true;
        int count = listEnhanceItems.Count;

        dFactor      = (Mathf.RoundToInt((1f / count) * 10000f)) * 0.0001f;
        mCenterIndex = count / 2;
        if (count % 2 == 0)
        {
            mCenterIndex = count / 2 - 1;
        }
        int index = 0;

        for (int i = count - 1; i >= 0; i--)
        {
            listEnhanceItems[i].CurveOffSetIndex = i;
            listEnhanceItems[i].CenterOffSet     = dFactor * (mCenterIndex - index);
            //listEnhanceItems[i].SetSelectState(false);
            GameObject obj = listEnhanceItems[i].gameObject;

            if (inputType == InputSystemType.NGUIAndWorldInput)
            {
                DragEnhanceView script = obj.GetComponent <DragEnhanceView>();
                if (script != null)
                {
                    script.SetScrollView(this);
                }
            }
            else
            {
                UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>();
                if (script != null)
                {
                    script.SetScrollView(this);
                }
            }
            index++;
        }

        // set the center item with startCenterIndex
        if (startCenterIndex < 0 || startCenterIndex >= count)
        {
            Debug.LogError("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count  out of index ##");
            startCenterIndex = mCenterIndex;
        }

        // sorted items
        listSortedItems      = new List <EnhanceItem>(listEnhanceItems.ToArray());
        totalHorizontalWidth = cellWidth * count * cellWidthDeviant;
        curCenterItem        = listEnhanceItems[startCenterIndex];
        curHorizontalValue   = 0.5f - curCenterItem.CenterOffSet;
        LerpTweenToTarget(0f, curHorizontalValue, false);

        //
        // enable the drag actions
        //
        EnableDrag(true);

        UITexture ME1 = Resources.Load <UITexture>("Prefabs/fuzi1");

        //curCenterItem.GetComponent<UITexture>().mainTexture = Resources.Load<Texture>("Texture/centre" + curCenterItem.CurveOffSetIndex);

        fish1                         = Instantiate(ME1, new Vector3(0, -1, 0), this.transform.rotation) as UITexture;
        fish1.mainTexture             = Resources.Load <Texture>("song/" + TextuerName.listTextuerProp[curCenterItem.Number].textureSong);
        fish1.depth                   = 99;
        fish1.transform.parent        = transform;
        fish1.transform.localScale    = new Vector3(1, 1, 1);
        fish1.transform.localPosition = new Vector3(0, -1, 0);
        setAct(RS.getCurrentTextuer);
        setAct2(SO.GetComponent <StopOperation>().StopCallbackFunction);
        depthFactor = listEnhanceItems.Count;

        if (act != null)
        {
            act(curCenterItem.Number);
        }
        if (act2 != null)
        {
            act2(curCenterItem.Number);
        }
        SO.GetComponent <glrc>().chushihua();
    }