コード例 #1
0
        public CustomTmplGo GetTmplGo(AvatarData avdata)
        {
            if (avdata == null)
            {
                return(null);
            }

            CustomTmplGo ctGo;

            if (!_tmplGos.TryGetValue(avdata, out ctGo))
            {
                // Not found then create new
                ctGo     = new CustomTmplGo();
                ctGo._go = CustomModelTmpls.CreateTmplGo(avdata);
                if (_tmplGos.Count > _nTmpls)                   // Remove the oldest template
                {
                    float      oldTime   = ctGo._tStamp;
                    AvatarData oldAvdata = avdata;
                    foreach (KeyValuePair <AvatarData, CustomTmplGo> pair in _tmplGos)
                    {
                        if (pair.Value._tStamp <= oldTime)
                        {
                            oldTime   = pair.Value._tStamp;
                            oldAvdata = pair.Key;
                        }
                    }
                    _tmplGos.Remove(oldAvdata);
                }
                _tmplGos.Add(avdata, ctGo);
            }
            ctGo._refCnt++;
            ctGo._tStamp = Time.time;
            return(ctGo);
        }
コード例 #2
0
 public AvatarData(AvatarData avData = null)
 {
     if (avData != null)
     {
         _baseModel = avData._baseModel;
         avData._avatarParts.CopyTo(_avatarParts, 0);
     }
 }
コード例 #3
0
    void Awake()
    {
        mMaleAvataData = new CustomCharactor.AvatarData();
//		mMaleAvataData.SetPart(CustomCharactor.AvatarData.ESlot.Torso,"Model/PlayerModel/male03-torso");
//		mMaleAvataData.SetPart(CustomCharactor.AvatarData.ESlot.Legs,"Model/PlayerModel/male03-legs");
//		mMaleAvataData.SetPart(CustomCharactor.AvatarData.ESlot.Feet,"Model/PlayerModel/male03-feet");

        mFemaleAvataData = new CustomCharactor.AvatarData();
//		mFemaleAvataData.SetPart(CustomCharactor.AvatarData.ESlot.Torso,"Model/PlayerModel/female03-torso");
//		mFemaleAvataData.SetPart(CustomCharactor.AvatarData.ESlot.Legs,"Model/PlayerModel/female03-legs");
//		mFemaleAvataData.SetPart(CustomCharactor.AvatarData.ESlot.Feet,"Model/PlayerModel/female03-feet");
    }
コード例 #4
0
        public static IEnumerable <string> GetParts(AvatarData cur, AvatarData origin)
        {
            List <string> parts = new List <string>(10);

            for (int i = 0; i < c_nSlots; i++)
            {
                string temp = GetPart((ESlot)i, cur, origin);
                if (!string.IsNullOrEmpty(temp) && !parts.Contains(temp))
                {
                    parts.Add(temp);
                }
            }
            return(parts);
        }
コード例 #5
0
        public static AvatarData Merge(AvatarData hPrior, AvatarData lPrior)
        {
            AvatarData ret = new AvatarData(lPrior);

            if (hPrior != null)
            {
                for (int i = 0; i < c_nSlots; i++)
                {
                    if (!string.IsNullOrEmpty(hPrior._avatarParts[i]))
                    {
                        ret._avatarParts[i] = hPrior._avatarParts[i];
                    }
                }
            }
            return(ret);
        }
コード例 #6
0
        public override bool Equals(object obj)
        {
            AvatarData av = (AvatarData)obj;

            if (av._baseModel != _baseModel)
            {
                return(false);
            }
            for (int i = 0; i < c_nSlots; i++)
            {
                if (av._avatarParts[i] != _avatarParts[i])
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #7
0
        public void DismissTmplGo(AvatarData avdata)
        {
            if (avdata == null)
            {
                return;
            }

            CustomTmplGo ctGo;

            if (_tmplGos.TryGetValue(avdata, out ctGo))
            {
                ctGo._refCnt--;
                if (ctGo._refCnt <= 0)
                {
                    _tmplGos.Remove(avdata);
                }
            }
        }
コード例 #8
0
        public bool Deserialize(byte[] data)
        {
            try
            {
                System.IO.MemoryStream ms = new System.IO.MemoryStream(data, false);

                using (System.IO.BinaryReader br = new System.IO.BinaryReader(ms))
                {
                    int version = br.ReadInt32();

                    if (version > CURRENT_VERSION)
                    {
                        Debug.LogWarning("version:" + version + " greater than current version:" + CURRENT_VERSION);
                        return(false);
                    }

                    charactorName = br.ReadString();
                    byte[] texBuff = PETools.Serialize.ReadBytes(br);
                    if (null != texBuff && texBuff.Length > 0)
                    {
                        headIcon = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                        headIcon.LoadImage(texBuff);
                        headIcon.Apply();
                    }

                    sex = (ESex)br.ReadInt32();

                    nudeAvatarData = new AvatarData();
                    nudeAvatarData.Deserialize(PETools.Serialize.ReadBytes(br));

                    appearData = new AppearBlendShape.AppearData();
                    appearData.Deserialize(PETools.Serialize.ReadBytes(br));

                    return(true);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogWarning(e);
                return(false);
            }
        }
コード例 #9
0
        static GameObject CreateTmplGo(AvatarData avdata)
        {
            string            baseModel = avdata._baseModel;
            GameObject        go        = GameObject.Instantiate(Resources.Load(baseModel)) as GameObject;
            PEModelController mCtrl     = go.GetComponentInChildren <PEModelController>();

            if (mCtrl == null)
            {
                Debug.LogError("[CreateTmplGo]Cannot find PEModelController in baseModel:" + baseModel);
                return(null);
            }
            PERagdollController rCtrl = go.GetComponentInChildren <PERagdollController>();

            if (rCtrl == null)
            {
                Debug.LogError("[CreateTmplGo]Cannot find PERagdollController in baseModel:" + baseModel);
                return(null);
            }
            Debug.LogError("[CreateTmplGo]create baseModel:" + baseModel);
            // Model
            SkinnedMeshRenderer mSmr = mCtrl.GetComponent <SkinnedMeshRenderer> ();

            if (null == mSmr)
            {
                mSmr = mCtrl.gameObject.AddComponent <SkinnedMeshRenderer> ();
            }
            if (mSmr.sharedMesh == null)
            {
                mSmr.sharedMesh      = new Mesh();
                mSmr.sharedMesh.name = "PlayerAppearance1";
            }
            else
            {
                mSmr.sharedMesh.Clear();
            }
            List <Material>  materials    = new List <Material> ();
            List <Transform> bones        = new List <Transform> ();
            List <Transform> mAllBoneList = new List <Transform> (mCtrl.GetComponentsInChildren <Transform> (true));

            foreach (string partPathName in avdata)
            {
                if (string.IsNullOrEmpty(partPathName))
                {
                    continue;
                }

                SkinnedMeshRenderer tmpSmr = new CustomPartInfo(partPathName).Smr;
                if (null == tmpSmr)
                {
                    continue;
                }

                List <Transform> tmpBones = CustomUtils.FindSmrBonesByName(mAllBoneList, tmpSmr);
                int nSub = tmpSmr.sharedMesh.subMeshCount;
                for (int iSub = 0; iSub < nSub; iSub++)
                {
                    //all sub mesh must find bones
                    bones.AddRange(tmpBones);
                }
                materials.AddRange(tmpSmr.sharedMaterials);                  // smr.materials
            }
            mSmr.bones     = bones.ToArray();
            mSmr.materials = materials.ToArray();

            //Ragdoll
            SkinnedMeshRenderer rSmr = rCtrl.GetComponent <SkinnedMeshRenderer> ();

            if (null == rSmr)
            {
                rSmr = rCtrl.gameObject.AddComponent <SkinnedMeshRenderer> ();
            }
            rSmr.sharedMesh = mSmr.sharedMesh;
            List <Transform> rAllBoneList = new List <Transform> (rCtrl.GetComponentsInChildren <Transform> (true));

            bones                = CustomUtils.FindSmrBonesByName(rAllBoneList, mSmr);
            rSmr.bones           = bones.ToArray();
            rSmr.sharedMaterials = mSmr.sharedMaterials;

            go.SetActive(false);
            return(go);
        }
コード例 #10
0
        static string GetPart(ESlot slot, AvatarData cur, AvatarData ori)
        {
            int i = (int)slot;

            return(!string.IsNullOrEmpty(cur._avatarParts[i]) ? cur._avatarParts[i] : ori._avatarParts[i]);
        }