示例#1
0
    public void EquipPart(EquipPart part)
    {
        fashionList = new List <FashionPositionInfo>();
        FashionPositionInfo fpi = new FashionPositionInfo();

        fpi.fasionID    = 0;
        fpi.presentName = "0";
        fpi.replace     = false;
        fpi.equipName   = "";
        for (int i = 0; i < part.partPath.Length; ++i) //length = 8
        {
            string path = part.partPath[i];
            if (string.IsNullOrEmpty(path))
            {
                path = XEquipUtil.GetDefaultPath((EPartType)i, (entity as NativeRole).defEquip);
            }
            fpi.equipName = path;
            fashionList.Add(fpi);
        }
        EquipAll(fashionList.ToArray());
    }
示例#2
0
        private void Preview(EquipPart part)
        {
            //1.mesh collection
            List <CombineInstance> ciList = new List <CombineInstance>();

            Texture[]            m_tex = new Texture[8];
            DefaultEquip.RowData data  = XTableMgr.GetTable <DefaultEquip>().GetByUID(m_profession + 1);
            string name = "";

            for (int i = 0; i < part.partPath.Length; ++i)
            {
                string          path = part.partPath[i];
                CombineInstance ci   = new CombineInstance();
                if (string.IsNullOrEmpty(path))
                {
                    path = XEquipUtil.GetDefaultPath((EPartType)i, data);
                }
                else if (name == "")
                {
                    int index = path.LastIndexOf("_");
                    if (index >= 0)
                    {
                        name = path.Substring(0, index);
                    }
                }
                if (!string.IsNullOrEmpty(path))
                {
                    path = "Assets/Resources/Equipments/" + path;
                    Mesh    mesh = AssetDatabase.LoadAssetAtPath <Mesh>(path + AssetType.Asset);
                    Texture tex  = AssetDatabase.LoadAssetAtPath <Texture>(path + AssetType.TGA);
                    if (mesh != null)
                    {
                        ci.mesh  = mesh;
                        m_tex[i] = tex;
                    }
                    if (ci.mesh != null)
                    {
                        ciList.Add(ci);
                    }
                }
            }

            if (ciList.Count > 0)
            {
                if (newGo != null)
                {
                    GameObject.DestroyImmediate(newGo);
                }
                string skinPrfab = "Assets/Resources/Prefabs/" + combineConfig.PrefabName[m_profession] + AssetType.Prefab;
                newGo = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath <Object>(skinPrfab)) as GameObject;
                if (name != "")
                {
                    newGo.name = name;
                }
                newGo.transform.localRotation = Quaternion.Euler(new Vector3(0, 180, 0));

                //2.combine
                Transform           t      = newGo.transform;
                SkinnedMeshRenderer newSmr = t.GetComponent <SkinnedMeshRenderer>();
                newSmr.sharedMesh = new Mesh();
                newSmr.sharedMesh.CombineMeshes(ciList.ToArray(), true, false);

                //3.set material
                Material mat = new Material(Shader.Find("Custom/Skin/RimlightBlend8"));
                for (int i = 0; i < m_tex.Length; ++i)
                {
                    mat.SetTexture("_Tex" + i.ToString(), m_tex[i]);
                }
                newSmr.sharedMaterial = mat;

                if (data.WeaponPoint != null && data.WeaponPoint.Length > 0)
                {
                    string    weapon = data.WeaponPoint[0].ToString();
                    Transform trans  = newGo.transform.Find(weapon);
                    if (trans != null)
                    {
                        string path = part.mainWeapon;
                        if (string.IsNullOrEmpty(path))
                        {
                            path = data.Weapon;
                        }

                        GameObject mainWeapon = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Resources/Equipments/" + path + AssetType.Prefab);
                        if (mainWeapon != null)
                        {
                            GameObject instance = GameObject.Instantiate(mainWeapon) as GameObject;
                            instance.transform.parent        = trans;
                            instance.transform.localPosition = Vector3.zero;
                            instance.transform.localRotation = Quaternion.identity;
                            instance.transform.localScale    = Vector3.one;
                        }
                    }
                }
            }
        }