コード例 #1
0
//	public PlayerEnum TestPlayerIndex;
//	public Transform DaoJuTest;
    // Update is called once per frame
//	void Update()
//	{
//		if (pcvr.bIsHardWare && Camera.main == null) {
//			return;
//		}
//
//		if (Input.GetKeyUp(KeyCode.M)) {
//			MoveDaoJuObjToPlayer(TestPlayerIndex, DaoJuTest);
//		}
//	}

    public void MoveDaoJuObjToPlayer(PlayerEnum indexVal, Transform daoJuTr)
    {
        int indexDJ = (int)indexVal - 1;

        Vector3[] path = new Vector3[2];
        path[0]   = Camera.main.WorldToScreenPoint(daoJuTr.position);
        path[0].x = (XkGameCtrl.ScreenWidth * path[0].x) / Screen.width;
        path[0].y = (XkGameCtrl.ScreenHeight * path[0].y) / Screen.height;
        BuJiBaoCtrl buJiScript = daoJuTr.GetComponent <BuJiBaoCtrl>();
        BuJiBaoType buJiBaoVal = buJiScript.BuJiBao;

        switch (buJiBaoVal)
        {
        case BuJiBaoType.ShuangBeiFenShuDJ:
            path[1] = DaoJuEndTr[8 + indexDJ].position;
            break;

        case BuJiBaoType.JiSuDJ:
            path[1] = DaoJuEndTr[12 + indexDJ].position;
            break;

        case BuJiBaoType.NLHuDun:
        case BuJiBaoType.HuoLiAllOpenDJ:
            path[1] = DaoJuEndTr[4 + indexDJ].position;
            break;

        default:
            path[1] = DaoJuEndTr[indexDJ].position;
            break;
        }

        int        daoJuMax = DaoJuObjList.Count;
        GameObject daoJu    = null;

        for (int i = 0; i < daoJuMax; i++)
        {
            if (DaoJuObjList[i] != null && !DaoJuObjList[i].activeSelf)
            {
                daoJu = DaoJuObjList[i];
                break;
            }
        }

        if (daoJu == null)
        {
            daoJu = DaoJuMoveCtrl.SpawnDaoJuMoveObj(transform);
            DaoJuObjList.Add(daoJu);
        }
        DaoJuMoveCtrl daoJuMove = daoJu.GetComponent <DaoJuMoveCtrl>();
        int           indexBJ   = (int)buJiScript.BuJiBao - 2;

        //Debug.Log("indexBJ *** "+indexBJ);
        daoJuMove.MoveDaoJuToPlayer(DaoJuTexture[indexBJ], indexVal, buJiScript.BuJiBao, path);
    }
    public static GameObject SpawnDaoJuMoveObj(Transform parTr)
    {
        GameObject obj = new GameObject("daoJu");

        obj.transform.parent        = parTr;
        obj.transform.localPosition = Vector3.zero;
        obj.layer = LayerMask.NameToLayer("NGUI");
        UITexture uITextureCom = obj.AddComponent <UITexture>();

        uITextureCom.depth = 7;

        TweenRotation tweenCom = obj.AddComponent <TweenRotation>();

        tweenCom.style    = UITweener.Style.Loop;
        tweenCom.duration = 1f;
        tweenCom.from     = Vector3.zero;
        tweenCom.to       = new Vector3(0f, 0f, 360f);

        DaoJuMoveCtrl daoJuScript = obj.AddComponent <DaoJuMoveCtrl>();

        daoJuScript.SetDaoJuInfo(uITextureCom, tweenCom);
        return(obj);
    }