Example #1
0
 public void OnAttack(System.Func <int, int, int, int> act, System.Action <int, int> idle)
 {
     OnAttackCallBack = act;
     OnIdle           = idle;
     GameBattleEx.Instance.RemoveCollision(this);
     RefreshCollision();
     GameBattleEx.Instance.RegisterCollision(this);
     Index = int.Parse(name.Substring(name.Length - 2));
     WsGlobal.SetObjectLayer(gameObject, LayerMask.NameToLayer("Trigger"));
 }
    //计算重力作用下的运动方向以及位移

    //public CharacterController charController;
    //Rigidbody rig;
    public void Init(int modelIdx)
    {
        tag        = "meteorUnit";
        UnitId     = modelIdx;
        charLoader = GetComponent <CharacterLoaderDebug>();
        if (charLoader == null)
        {
            charLoader = gameObject.AddComponent <CharacterLoaderDebug>();
        }
        posMng = GetComponent <PoseStatusDebug>();
        if (posMng == null)
        {
            posMng = gameObject.AddComponent <PoseStatusDebug>();
        }

        charLoader.LoadCharactor(UnitId);
        posMng.Init();
        WeaponR      = Global.ldaControlX("d_wpnR", charLoader.rootBone.gameObject).transform;
        WeaponL      = Global.ldaControlX("d_wpnL", charLoader.rootBone.gameObject).transform;
        ROOTNull     = Global.ldaControlX("b", gameObject).transform;
        RootdBase    = charLoader.rootBone;
        CameraTarget = RootdBase;
        weaponLoader = gameObject.GetComponent <WeaponLoaderEx>();
        if (weaponLoader == null)
        {
            weaponLoader = gameObject.AddComponent <WeaponLoaderEx>();
        }
        weaponLoader.Init();
        posMng.ChangeAction();
        WsGlobal.SetObjectLayer(gameObject, gameObject.layer);
        //charController = gameObject.AddComponent<CharacterController>();
        //charController.center = new Vector3(0, 18.0f, 0);
        //charController.height = 36.0f;
        //charController.radius = 8.0f;
        //charController.stepOffset = 8.0f;
        //mPosition = transform.position;
        //for (int i = 0; i < 32; i++)
        //{
        //    if (LayerMask.LayerToName(i) == "LocalPlayer")
        //        continue;
        //    if (LayerMask.LayerToName(i) == "Monster")
        //        continue;
        //    if (LayerMask.LayerToName(i) == "Trigger")
        //        continue;
        //    if (!Physics.GetIgnoreLayerCollision(gameObject.layer, i))
        //        mCacheLayerMask |= (1 << i);
        //}
    }
    public void LoadCharactor(int id)
    {
        owner        = GetComponent <MeteorUnit>();
        posMng       = owner.posMng;
        CharacterIdx = id;
        Skin         = new GameObject();
        Skin.transform.SetParent(transform);
        Skin.transform.localRotation = Quaternion.identity;
        Skin.transform.localScale    = Vector3.one;
        Skin.transform.localPosition = Vector3.zero;
        SkcFile skc = SkcLoader.Instance.Load(id);
        BncFile bnc = BncLoader.Instance.Load(id);

        Skin.name        = skc.Skin;
        rend             = Skin.AddComponent <SkinnedMeshRenderer>();
        rend.localBounds = skc.mesh.bounds;
        rend.materials   = skc.Material(id, owner.Camp);
        rend.sharedMesh  = skc.mesh;
        rend.sharedMesh.RecalculateBounds();
        bo    = new List <Transform>();
        dummy = new List <Transform>();
        List <Matrix4x4> bindPos = new List <Matrix4x4>();

        if (owner.Attr.IsPlayer)
        {
            Skin.layer = LayerMask.NameToLayer("LocalPlayer");
        }
        else
        {
            Skin.layer = LayerMask.NameToLayer("Monster");
        }

        bnc.GenerateBone(transform, ref bo, ref dummy, ref bindPos, ref rootBone);
        WsGlobal.SetObjectLayer(gameObject, Skin.layer);
        rend.bones = bo.ToArray();
        rend.sharedMesh.bindposes = bindPos.ToArray();
        rend.rootBone             = rootBone;
        RootPos  = rootBone.localPosition;
        RootQuat = rootBone.localRotation;
        AmbLoader.Ins.LoadCharacterAmb(id);
        //GenerateBounds(skc.mesh, bo);
        LoadBoxDef(id);
    }
    public void EquipWeapon(int unitid, bool ui = true)
    {
        InventoryItem i = ui ? weaponModel : Weapon;

        if (i == null)
        {
            i = ui ? weaponModel = Main.Ins.GameStateMgr.MakeEquip(unitid):Main.Ins.GameStateMgr.MakeEquip(unitid);
            //WeaponBase weaponProperty = U3D.GetWeaponProperty(i.Info().UnitId);
            EquipWeapon(i, true);
        }
        else
        {
            UnEquipWeapon();
            i = ui ? weaponModel = Main.Ins.GameStateMgr.MakeEquip(unitid):Main.Ins.GameStateMgr.MakeEquip(unitid);
            //WeaponBase weaponProperty = U3D.GetWeaponProperty(i.Info().UnitId);
            EquipWeapon(i, true);
        }

        if (ui)
        {
            if (i.Info().SubType == (int)(EquipWeaponType.Lance))
            {
                transform.localPosition = new Vector3(0, 9, 130);
            }
            else
            {
                transform.localPosition = new Vector3(0, 9, 110);
            }
        }
        if (RParent != null)
        {
            WsGlobal.SetObjectLayer(RParent.gameObject, LayerMask.NameToLayer("RenderModel"));
        }
        if (LParent != null)
        {
            WsGlobal.SetObjectLayer(LParent.gameObject, LayerMask.NameToLayer("RenderModel"));
        }
    }
Example #5
0
    //适用于非武器类型的任意模型的显示,包括地图都可以用此方法读,且支持IFL材质,创建虚拟体,只匹配序号,不匹配名称
    public static void ShowMeteorObject(string file, Transform parent, bool gen = false)
    {
        if (file.EndsWith(".des"))
        {
            file = file.Substring(0, file.Length - 4);
        }
        DesFile fIns   = Main.Ins.DesLoader.Load(file);
        GMBFile gmb    = Main.Ins.GMBLoader.Load(file);
        GMCFile fModel = Main.Ins.GMCLoader.Load(file);

        //保存材质球
        if (Application.isEditor)
        {
            if (!System.IO.Directory.Exists("Assets/Materials/Weapons/resources/"))
            {
                System.IO.Directory.CreateDirectory("Assets/Materials/Weapons/resources/");
            }
        }

        //看des文件是否为空
        //优先GMB
        if (gmb != null)
        {
            //还未处理IFL序列图动态加载。
            Material[] mat = new Material[gmb.TexturesCount];
            for (int i = 0; i < mat.Length; i++)
            {
                mat[i] = null;
            }
            Dictionary <int, string> iflMat = new Dictionary <int, string>();//IFL材质特殊处理,IFL材质均为mobile/particle/additive
            for (int x = 0; x < gmb.TexturesCount; x++)
            {
                string tex = gmb.TexturesNames[x];
                if (tex.ToLower().EndsWith(".ifl"))
                {
                    if (!iflMat.ContainsKey(x))
                    {
                        iflMat.Add(x, tex);
                    }
                    continue;
                }

                string iden = string.Format("{0}_{1:D2}", file, x);
                mat[x] = Resources.Load <Material>(iden);
                if (mat[x] == null)
                {
                    mat[x] = new Material(ShaderMng.Find("AlphaTexture"));
                    int del = tex.LastIndexOf('.');
                    if (del != -1)
                    {
                        tex = tex.Substring(0, del);
                    }
                    Texture texture = Resources.Load <Texture>(tex);
                    if (texture == null)
                    {
                        Debug.LogError("texture miss on load gmb:" + file + " texture name:" + tex);
                    }
                    mat[x].SetTexture("_MainTex", texture);
                    mat[x].name = iden;
                    if (gen)
                    {
                        //UnityEditor.AssetDatabase.CreateAsset(mat[x], "Assets/Materials/Weapons/resources/" + mat[x].name + ".mat");
                        //UnityEditor.AssetDatabase.Refresh();
                    }
                }
            }

            for (int i = 0; i < fIns.SceneItems.Count; i++)
            {
                GameObject objMesh         = new GameObject();
                bool       addIflComponent = false;
                int        iflParam        = -1;
                int        iflMatIndex     = 0;
                objMesh.name = fIns.SceneItems[i].name;
                objMesh.transform.localRotation = Quaternion.identity;
                objMesh.transform.localPosition = Vector3.zero;
                objMesh.transform.localScale    = Vector3.one;
                objMesh.layer = parent.gameObject.layer;
                //bool realObject = false;//是不是正常物体,虚拟体无需设置材质球之类
                if (i < gmb.SceneObjectsCount)
                {
                    //for (int j = 0; j < gmb.SceneObjectsCount; j++)
                    //{
                    //    if (gmb.mesh[j].name == objMesh.name)
                    //    {
                    //realObject = true;
                    Mesh w = new Mesh();
                    //前者子网格编号,后者 索引缓冲区
                    Dictionary <int, List <int> > tr = new Dictionary <int, List <int> >();
                    List <Vector3> ve  = new List <Vector3>();
                    List <Vector2> uv  = new List <Vector2>();
                    List <Vector3> nor = new List <Vector3>();
                    List <Color>   col = new List <Color>();
                    for (int k = 0; k < gmb.mesh[i].faces.Count; k++)
                    {
                        int key = gmb.mesh[i].faces[k].material;
                        if (tr.ContainsKey(key))
                        {
                            tr[key].Add(gmb.mesh[i].faces[k].triangle[0]);
                            tr[key].Add(gmb.mesh[i].faces[k].triangle[1]);
                            tr[key].Add(gmb.mesh[i].faces[k].triangle[2]);
                        }
                        else
                        {
                            tr.Add(key, new List <int>());
                            tr[key].Add(gmb.mesh[i].faces[k].triangle[0]);
                            tr[key].Add(gmb.mesh[i].faces[k].triangle[1]);
                            tr[key].Add(gmb.mesh[i].faces[k].triangle[2]);
                        }
                    }
                    for (int k = 0; k < gmb.mesh[i].vertices.Count; k++)
                    {
                        //ve.Add(gmb.mesh[i].vertices[k].pos);
                        Vector3 vec = gmb.mesh[i].vertices[k].pos - (Vector3)fIns.SceneItems[i].pos;
                        vec = Quaternion.Inverse(fIns.SceneItems[i].quat) * vec;
                        //ve.Add(fModel.mesh[i].vertices[k].pos);
                        ve.Add(vec);
                        uv.Add(gmb.mesh[i].vertices[k].uv);
                        col.Add(gmb.mesh[i].vertices[k].color);
                        nor.Add(gmb.mesh[i].vertices[k].normal);
                    }
                    w.SetVertices(ve);
                    w.uv           = uv.ToArray();
                    w.subMeshCount = tr.Count;
                    int             ss        = 0;
                    List <Material> targetMat = new List <Material>();
                    foreach (var each in tr)
                    {
                        w.SetIndices(each.Value.ToArray(), MeshTopology.Triangles, ss++);
                        if (each.Key >= 0 && each.Key < gmb.shader.Length)
                        {
                            int materialIndex = gmb.shader[each.Key].TextureArg0;
                            if (materialIndex >= 0 && materialIndex < mat.Length)
                            {
                                if (mat[materialIndex] == null)
                                {
                                    targetMat.Add(new Material(Shader.Find("Unlit/Transparent")));
                                    addIflComponent = true;
                                    iflParam        = materialIndex;
                                    iflMatIndex     = targetMat.Count - 1;
                                }
                                else
                                {
                                    targetMat.Add(mat[materialIndex]);
                                }
                            }
                            else
                            {
                                Material defaults = Resources.Load <Material>(string.Format("{0}_{1:D2}", file, materialIndex));
                                if (defaults == null)
                                {
                                    defaults = new Material(Shader.Find("Unlit/Texture"));
                                }
                                defaults.name = string.Format("{0}_{1:D2}", file, materialIndex);
                                if (gen)
                                {
                                    //UnityEditor.AssetDatabase.CreateAsset(defaults, "Assets/Materials/Weapons/resources/" + defaults.name + ".mat");
                                    //UnityEditor.AssetDatabase.Refresh();
                                }
                                targetMat.Add(defaults);
                            }
                        }
                    }
                    MeshRenderer mr = objMesh.AddComponent <MeshRenderer>();
                    MeshFilter   mf = objMesh.AddComponent <MeshFilter>();
                    mf.mesh         = w;
                    mf.mesh.colors  = col.ToArray();
                    mf.mesh.normals = nor.ToArray();
                    mf.mesh.RecalculateBounds();
                    mf.mesh.RecalculateNormals();

                    mr.materials = targetMat.ToArray();
                    string vis = "";
                    if (fIns.SceneItems[i].ContainsKey("visible", out vis))
                    {
                        if (vis == "0")
                        {
                            mr.enabled = false;
                            //BoxCollider co = mr.gameObject.AddComponent<BoxCollider>();
                        }
                    }
                    string block = "";
                    if (fIns.SceneItems[i].ContainsKey("blockplayer", out block))
                    {
                        if (block == "no")
                        {
                            MeshCollider co = mr.gameObject.GetComponent <MeshCollider>();
                            if (co == null)
                            {
                                co = mr.gameObject.AddComponent <MeshCollider>();
                            }
                            if (co != null)
                            {
                                co.enabled   = false;
                                co.convex    = false;
                                co.isTrigger = false;
                            }
                        }
                    }
                    else
                    {
                        Collider coexist = mr.gameObject.GetComponent <Collider>();
                        if (coexist == null)
                        {
                            MeshCollider co = mr.gameObject.AddComponent <MeshCollider>();
                            co.isTrigger = false;
                        }
                    }
                }
                //}

                objMesh.transform.SetParent(parent);

                if (addIflComponent && iflMat.ContainsKey(iflParam))
                {
                    IFLLoader iflL = objMesh.AddComponent <IFLLoader>();
                    iflL.fileNameReadOnly  = iflMat[iflParam];
                    iflL.IFLFile           = Resources.Load <TextAsset>(iflMat[iflParam]);
                    iflL.matIndex          = iflMatIndex;
                    iflL.useSharedMaterial = false;
                    iflL.LoadIFL();
                }

                //如果是板凳桌子,加上双面网格,避免一些BUG
                if (parent.name.ToLower().Contains("chair") || parent.name.ToLower().Contains("desk"))
                {
                    objMesh.AddComponent <DoubleSideMeshCollider>();
                }
                objMesh.transform.localRotation = fIns.SceneItems[i].quat;
                objMesh.transform.localScale    = Vector3.one;
                objMesh.transform.localPosition = fIns.SceneItems[i].pos;
            }
        }
        else if (fModel != null)
        {
            //Debug.LogError("error !!!!!!!!!!!!!!!!!!!!!!!!! not support gmc file any more");

            Material[] mat = new Material[fModel.TexturesCount];
            for (int i = 0; i < mat.Length; i++)
            {
                mat[i] = null;
            }
            Dictionary <int, string> iflMat = new Dictionary <int, string>();//IFL材质特殊处理,IFL材质均为mobile/particle/additive

            for (int x = 0; x < fModel.TexturesCount; x++)
            {
                string tex = fModel.TexturesNames[x];
                if (tex.ToLower().EndsWith(".ifl"))
                {
                    if (!iflMat.ContainsKey(x))
                    {
                        iflMat.Add(x, tex);
                    }
                    continue;
                }

                mat[x] = Resources.Load <Material>(string.Format("{0}_{1:D2}", file, x));
                if (mat[x] == null)
                {
                    mat[x] = new Material(ShaderMng.Find("AlphaTexture"));
                    int del = tex.LastIndexOf('.');
                    if (del != -1)
                    {
                        tex = tex.Substring(0, del);
                    }
                    Texture texture = Resources.Load <Texture>(tex);
                    if (texture == null)
                    {
                        Debug.LogError("texture miss on load gmc:" + file + " texture name:" + tex);
                    }
                    mat[x].SetTexture("_MainTex", texture);
                    mat[x].name = string.Format("{0}_{1:D2}", file, x);
                    if (gen)
                    {
                        //UnityEditor.AssetDatabase.CreateAsset(mat[x], "Assets/Materials/Weapons/resources/" + mat[x].name + ".mat");
                        //UnityEditor.AssetDatabase.Refresh();
                    }
                }
                //mat[x] = Resources.Load<Material>(string.Format("{0}_{1:D2}", file, x));
                //if (mat[x] == null)
                //{
                //    mat[x] = new Material(ShaderUtil.Find("UnlitAlphaTexture"));
                //    string tex = fModel.TexturesNames[x];
                //    int del = tex.LastIndexOf('.');
                //    if (del != -1)
                //        tex = tex.Substring(0, del);
                //    Texture texture = Resources.Load<Texture>(tex);
                //    if (texture == null)
                //        Debug.LogError("texture miss on load gmc:" + file + " texture name:" + tex);
                //    mat[x].SetTexture("_MainTex", texture);
                //    mat[x].name = string.Format("{0}_{1:D2}", file, x);
                //    //AssetDatabase.CreateAsset(mat[x], "Assets/Materials/" + file + "/resources/" + mat[x].name + ".mat");
                //    //AssetDatabase.Refresh();
                //}
            }
            for (int i = 0; i < fIns.SceneItems.Count; i++)
            {
                GameObject objMesh         = new GameObject();
                bool       addIflComponent = false;
                int        iflParam        = -1;
                int        iflMatIndex     = 0;
                objMesh.name = fIns.SceneItems[i].name;
                objMesh.transform.localRotation = Quaternion.identity;
                objMesh.transform.localPosition = Vector3.zero;
                objMesh.transform.localScale    = Vector3.one;
                objMesh.layer = parent.gameObject.layer;
                //bool realObject = false;//是不是正常物体,虚拟体无需设置材质球之类
                if (i < fModel.SceneObjectsCount)
                {
                    //for (int j = 0; j < fModel.SceneObjectsCount; j++)
                    //{
                    //if (fModel.mesh[j].name == objMesh.name)
                    {
                        //realObject = true;
                        Mesh w = new Mesh();
                        //前者子网格编号,后者 索引缓冲区
                        Dictionary <int, List <int> > tr = new Dictionary <int, List <int> >();
                        List <Vector3> ve  = new List <Vector3>();
                        List <Vector2> uv  = new List <Vector2>();
                        List <Vector3> nor = new List <Vector3>();
                        List <Color>   col = new List <Color>();
                        for (int k = 0; k < fModel.mesh[i].faces.Count; k++)
                        {
                            int key = fModel.mesh[i].faces[k].material;
                            if (tr.ContainsKey(key))
                            {
                                tr[key].Add(fModel.mesh[i].faces[k].triangle[0]);
                                tr[key].Add(fModel.mesh[i].faces[k].triangle[1]);
                                tr[key].Add(fModel.mesh[i].faces[k].triangle[2]);
                            }
                            else
                            {
                                tr.Add(key, new List <int>());
                                tr[key].Add(fModel.mesh[i].faces[k].triangle[0]);
                                tr[key].Add(fModel.mesh[i].faces[k].triangle[1]);
                                tr[key].Add(fModel.mesh[i].faces[k].triangle[2]);
                            }
                        }
                        for (int k = 0; k < fModel.mesh[i].vertices.Count; k++)
                        {
                            Vector3 vec = fModel.mesh[i].vertices[k].pos - (Vector3)fIns.SceneItems[i].pos;
                            vec = Quaternion.Inverse(fIns.SceneItems[i].quat) * vec;
                            //ve.Add(fModel.mesh[i].vertices[k].pos);
                            ve.Add(vec);
                            uv.Add(fModel.mesh[i].vertices[k].uv);
                            col.Add(fModel.mesh[i].vertices[k].color);
                            nor.Add(fModel.mesh[i].vertices[k].normal);
                        }
                        w.SetVertices(ve);
                        w.uv           = uv.ToArray();
                        w.subMeshCount = tr.Count;
                        int             ss        = 0;
                        List <Material> targetMat = new List <Material>();
                        foreach (var each in tr)
                        {
                            w.SetIndices(each.Value.ToArray(), MeshTopology.Triangles, ss++);
                            if (each.Key >= 0 && each.Key < fModel.shader.Length)
                            {
                                int materialIndex = fModel.shader[each.Key].TextureArg0;
                                if (materialIndex >= 0 && materialIndex < mat.Length)
                                {
                                    if (mat[materialIndex] == null)
                                    {
                                        targetMat.Add(new Material(Shader.Find("Unlit/Transparent")));
                                        addIflComponent = true;
                                        iflParam        = materialIndex;
                                        iflMatIndex     = targetMat.Count - 1;
                                    }
                                    else
                                    {
                                        targetMat.Add(mat[materialIndex]);
                                    }
                                }
                                else
                                {
                                    //即使没有贴图,也存在材质
                                    Material defaults = Resources.Load <Material>(string.Format("{0}_{1:D2}", file, materialIndex));
                                    if (defaults == null)
                                    {
                                        defaults = new Material(Shader.Find("Unlit/Texture"));
                                    }
                                    defaults.name = string.Format("{0}_{1:D2}", file, materialIndex);
                                    if (gen)
                                    {
                                        //UnityEditor.AssetDatabase.CreateAsset(defaults, "Assets/Materials/Weapons/resources/" + defaults.name + ".mat");
                                        //UnityEditor.AssetDatabase.Refresh();
                                    }
                                    targetMat.Add(defaults);
                                }
                            }
                        }
                        MeshRenderer mr = objMesh.AddComponent <MeshRenderer>();
                        MeshFilter   mf = objMesh.AddComponent <MeshFilter>();
                        mf.mesh         = w;
                        mf.mesh.colors  = col.ToArray();
                        mf.mesh.normals = nor.ToArray();
                        mf.mesh.RecalculateBounds();
                        mf.mesh.RecalculateNormals();

                        mr.materials = targetMat.ToArray();
                        string vis = "";
                        if (fIns.SceneItems[i].ContainsKey("visible", out vis))
                        {
                            if (vis == "0")
                            {
                                mr.enabled = false;
                                //BoxCollider co = mr.gameObject.AddComponent<BoxCollider>();
                            }
                        }
                        string block = "";
                        if (fIns.SceneItems[i].ContainsKey("blockplayer", out block))
                        {
                            if (block == "no")
                            {
                                Collider co = mr.gameObject.GetComponent <MeshCollider>();
                                if (co == null)
                                {
                                    co = mr.gameObject.AddComponent <MeshCollider>();
                                }
                                if (co != null)
                                {
                                    MeshCollider mec = co as MeshCollider;
                                    if (mec != null)
                                    {
                                        mec.enabled   = false;
                                        mec.convex    = false;//unity bug
                                        mec.isTrigger = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            Collider coexist = mr.gameObject.GetComponent <Collider>();
                            if (coexist == null)
                            {
                                MeshCollider co = mr.gameObject.AddComponent <MeshCollider>();
                                co.isTrigger = false;
                            }
                        }
                    }
                }

                objMesh.transform.SetParent(parent);
                if (addIflComponent && iflMat.ContainsKey(iflParam))
                {
                    IFLLoader iflL = objMesh.AddComponent <IFLLoader>();
                    iflL.fileNameReadOnly  = iflMat[iflParam];
                    iflL.IFLFile           = Resources.Load <TextAsset>(iflMat[iflParam]);
                    iflL.matIndex          = iflMatIndex;
                    iflL.useSharedMaterial = false;
                    iflL.LoadIFL();
                }
                //如果是板凳桌子,加上双面网格,避免一些BUG
                if (parent.name.ToLower().Contains("chair") || parent.name.ToLower().Contains("desk"))
                {
                    objMesh.AddComponent <DoubleSideMeshCollider>();
                }
                objMesh.transform.localRotation = fIns.SceneItems[i].quat;
                objMesh.transform.localScale    = Vector3.one;
                objMesh.transform.localPosition = fIns.SceneItems[i].pos;
            }
        }
        else
        {
            //一个预设
            GameObject prefab = Resources.Load(file) as GameObject;
            if (prefab != null)
            {
                GameObject obj = GameObject.Instantiate(prefab, parent);
                obj.transform.localScale    = Vector3.one;
                obj.transform.localPosition = Vector3.zero;
                obj.transform.rotation      = Quaternion.identity;
                BoxCollider co = obj.GetComponentInChildren <BoxCollider>();
                co.isTrigger = true;
                int k = obj.transform.childCount;
                while (obj.transform.childCount != 0)
                {
                    Transform tri = obj.transform.GetChild(0);
                    tri.SetParent(parent);
                }
                GameObject.Destroy(obj);
                WsGlobal.SetObjectLayer(parent.gameObject, parent.gameObject.layer);
            }
        }
    }
Example #6
0
 //把背包里的物品,装备到身上.
 public void EquipWeapon()
 {
     UnEquipWeapon();
     Init();
     DesLoader.Instance.Refresh();
     GMCLoader.Instance.Refresh();
     GMBLoader.Instance.Refresh();
     if (!string.IsNullOrEmpty(StrWeaponL))
     {
         GameObject weaponPrefab = Resources.Load <GameObject>(StrWeaponL);
         //如果新武器系统包含了这件武器。
         if (weaponPrefab == null)
         {
             if (L != null)
             {
                 DestroyImmediate(L);
             }
             L = new GameObject().transform;
             L.SetParent(LP);
             L.gameObject.layer = LP.gameObject.layer;
             L.localRotation    = Quaternion.identity;
             L.localPosition    = Vector3.zero;
             L.localScale       = Vector3.one;
             L.name             = StrWeaponR;
             WsGlobal.ShowMeteorObject(StrWeaponL, L.transform, GenerateMaterial);
             WsGlobal.SetObjectLayer(L.gameObject, L.gameObject.layer);
         }
         else
         {
             if (L != null)
             {
                 DestroyImmediate(L);
             }
             GameObject objWeapon = GameObject.Instantiate(weaponPrefab);
             L = objWeapon.transform;
             L.SetParent(LP);
             L.gameObject.layer = LP.gameObject.layer;
             L.localPosition    = Vector3.zero;
             //这种导入来的模型,需要Y轴旋转180,与原系统的物件坐标系存在一些问题
             L.localRotation = new Quaternion(0, 1, 0, 0);
             L.name          = StrWeaponL;
             L.localScale    = Vector3.one;
             WsGlobal.SetObjectLayer(L.gameObject, L.gameObject.layer);
         }
     }
     if (!string.IsNullOrEmpty(StrWeaponR))
     {
         GameObject weaponPrefab = Resources.Load <GameObject>(StrWeaponR);
         if (weaponPrefab == null)
         {
             if (R != null)
             {
                 DestroyImmediate(R);
             }
             R = new GameObject().transform;
             R.SetParent(RP);
             R.gameObject.layer = RP.gameObject.layer;
             R.localRotation    = Quaternion.identity;
             R.localPosition    = Vector3.zero;
             R.localScale       = Vector3.one;
             R.name             = StrWeaponR;
             WsGlobal.ShowMeteorObject(StrWeaponR, R.transform, GenerateMaterial);
             WsGlobal.SetObjectLayer(R.gameObject, R.gameObject.layer);
         }
         else
         {
             //预设要绕Y旋转180
             if (R != null)
             {
                 DestroyImmediate(R);
             }
             GameObject objWeapon = GameObject.Instantiate(weaponPrefab);
             R = objWeapon.transform;
             R.SetParent(RP);
             R.gameObject.layer = RP.gameObject.layer;
             R.localPosition    = Vector3.zero;
             R.localRotation    = new Quaternion(0, 1, 0, 0);
             R.name             = StrWeaponR;
             R.localScale       = Vector3.one;
             WsGlobal.SetObjectLayer(R.gameObject, R.gameObject.layer);
         }
     }
 }
Example #7
0
    public void Init(int modelIdx, int layer, bool updateModel = false)
    {
        tag           = "meteorUnit";
        UnitId        = modelIdx;
        IgnoreGravity = true;

        if (updateModel)
        {
            //把伤害盒子去掉,把受击盒子去掉
            hitList.Clear();

            if (charLoader != null)
            {
                GameObject.Destroy(charLoader.rootBone.parent.gameObject);
                GameObject.Destroy(charLoader.Skin.gameObject);
                charLoader = null;
            }
        }

        if (Attr == null && Main.Ins.MeteorManager != null && Main.Ins.LocalPlayer != null)
        {
            Attr = Main.Ins.LocalPlayer.Attr;
        }
        if (charLoader == null)
        {
            charLoader = new CharacterLoader();
        }
        if (posMng == null)
        {
            posMng = new PoseStatus();
        }
        if (updateModel)
        {
            transform.position = Vector3.zero;
            transform.rotation = Quaternion.identity;
        }
        charLoader.LoadCharactor(UnitId, transform);
        posMng.Init(this);
        WeaponR      = NodeHelper.Find("d_wpnR", charLoader.rootBone.gameObject).transform;
        WeaponL      = NodeHelper.Find("d_wpnL", charLoader.rootBone.gameObject).transform;
        ROOTNull     = NodeHelper.Find("b", gameObject).transform;
        RootdBase    = charLoader.rootBone;
        CameraTarget = RootdBase;
        weaponLoader = gameObject.GetComponent <WeaponLoader>();
        if (updateModel)
        {
            Destroy(weaponLoader);
            weaponLoader = null;
        }
        if (weaponLoader == null)
        {
            weaponLoader = gameObject.AddComponent <WeaponLoader>();
        }
        weaponLoader.Init(this);
        charController = gameObject.GetComponent <CharacterController>();
        if (charController == null)
        {
            charController = gameObject.AddComponent <CharacterController>();
        }
        charController.center     = new Vector3(0, 16, 0);
        charController.height     = 32;
        charController.radius     = 9.0f;//不这么大碰不到寻路点.
        charController.stepOffset = 7.6f;
        posMng.ChangeAction();
        WsGlobal.SetObjectLayer(gameObject, layer);
        InventoryItem itWeapon = Main.Ins.GameStateMgr.MakeEquip(1);

        weaponLoader.EquipWeapon(itWeapon);
        this.name = Main.Ins.CombatData.GetCharacterName(UnitId);
    }
Example #8
0
 void EquipChanged(InventoryItem it)
 {
     weaponLoader.EquipWeapon(it);
     WsGlobal.SetObjectLayer(gameObject, gameObject.layer);
 }