示例#1
0
 private void _setStubHero(int stubPos, bool isCreate = false, int heroId = 0)
 {
     //不管是创建还是删除,都得先删除了
     if (_stubHeroDic.ContainsKey(stubPos))
     {
         DestroyImmediate(_stubHeroDic[stubPos]);
         _stubHeroDic.Remove(stubPos);
         _stubPosDic[stubPos].SetStubState(StubState.Open);
     }
     if (isCreate)
     {
         UIBillboard _bb = null;
         if (0 == stubPos)
         {
             _bb = StubDrag_bb;
         }
         else
         {
             _bb = StubShow_bb;
         }
         if (_bb == null)
         {
             EDebug.LogErrorFormat("StubView._setStubHero error, stubPos:{0}", stubPos);
             return;
         }
         Hero       heroData = JsonMgr.GetSingleton().GetHeroByID(heroId);
         GameObject heroGo   = null;
         if (stubPos != 0)
         {
             int stubX = stubPos / 10;
             int stubY = stubPos % 10;
             heroGo = GameObject.Instantiate(ResourceMgr.Instance.LoadResource(heroData.ID) as GameObject,
                                             _bb.GetCamPos() + new Vector3((stubX - 1) * StubXSpace3D + (6 - stubY) * LeanOffset3D - 15f,
                                                                           (6 - stubY) * StubYSpace3D - 11f, 5), Quaternion.Euler(0, 125.75f, 0));
             heroGo.transform.localScale = Vector3.one * 1.8f;
         }
         else
         {
             heroGo = GameObject.Instantiate(ResourceMgr.Instance.LoadResource(heroData.ID) as GameObject,
                                             _bb.GetCamPos() + new Vector3(0, 0, 5),
                                             Quaternion.Euler(0, 125.75f, 0));
         }
         if (heroGo != null)
         {
             _stubHeroDic.Add(stubPos, heroGo);
             if (heroData.horseid != 0)
             {
                 GameObject horseGo = GameObject.Instantiate(ResourceMgr.Instance.LoadResource(heroData.horseid) as GameObject, heroGo.transform);
                 horseGo.transform.localPosition = Vector3.zero;
                 horseGo.transform.localScale    = Vector3.one;
             }
             heroGo.SetLayer(_bb.Layer);
         }
         else
         {
             EDebug.LogErrorFormat("StubView._setStubHero error, load heroGo failed, heroId:{0}", heroData.ID);
         }
         _stubPosDic[stubPos].SetStubState(StubState.Stubed);
     }
 }
    public void BuildHeroEvent(int heroId)
    {
        if (showID == heroId)
        {
            return;
        }
        if (Herotf != null)
        {
            Destroy(Herotf.gameObject);
        }
        Vector3 v3 = billboard.GetCamPos();

        v3.y           += -1.45f;
        v3.z           += 10f;
        billboard.Layer = LayerMask.NameToLayer("Hero");
        HeroData data = HeroMgr.GetSingleton().GetHeroData(heroId);

        GameObject heroGo = ResourceMgr.Instance.LoadResource(data.JsonData.resid) as GameObject;

        if (heroGo == null)
        {
            return;
        }
        heroGo = Instantiate(heroGo);
        Herotf = heroGo.transform;
        Herotf.localPosition = v3;
        int horseid = data.JsonData.horseid;

        if (horseid != 0)
        {
            GameObject horseGo = ResourceMgr.Instance.LoadResource(horseid) as GameObject;
            if (horseGo == null)
            {
                EDebug.LogError("加载马匹资源失败 -- " + horseid);
                return;
            }
            horseGo = Instantiate(horseGo, heroGo.transform, false);
            horseGo.transform.localPosition = Vector3.zero;
            horseGo.transform.localScale    = Vector3.one;
        }
        HeroShow hs = JsonMgr.GetSingleton().GetHeroShowByID(heroId);
        Vector3  vc = billboard.Cam.transform.eulerAngles;

        vc.x = hs.RotX;
        Quaternion qc = new Quaternion
        {
            eulerAngles = vc
        };

        billboard.Cam.transform.rotation = qc;
        Vector3 vh = heroGo.transform.localEulerAngles;

        vh.y = hs.RotY + +180f;
        Quaternion qh = new Quaternion
        {
            eulerAngles = vh
        };

        heroGo.transform.rotation = qh;
        billboard.Fov             = hs.Fov;
        showID = heroId;
        heroGo.SetLayer("Hero");
        player = heroGo.AddComponent <AnimatorPlayer>();
        player.RandomPlay(true);
    }