Exemple #1
0
        /// <summary>
        /// 由sourceChaCtrl拷貝MoreAccessories至targetChaCtrl
        /// </summary>
        /// <param name="sourceChaCtrl">來源</param>
        /// <param name="targetChaCtrl">目標</param>
        public static void CopyMoreAccessories(ChaControl sourceChaCtrl, ChaControl targetChaCtrl)
        {
            Queue <int> accQueue = new Queue <int>();

            TryGetValueFromWeakKeyDict(MoreAccObj.GetField("_accessoriesByChar"), sourceChaCtrl.chaFile, out object sourceCharAdditionalData);
            TryGetValueFromWeakKeyDict(MoreAccObj.GetField("_accessoriesByChar"), targetChaCtrl.chaFile, out object targetCharAdditionalData);

            sourceCharAdditionalData.GetField("rawAccessoriesInfos").ToDictionary <ChaFileDefine.CoordinateType, List <ChaFileAccessory.PartsInfo> >()
            .TryGetValue((ChaFileDefine.CoordinateType)sourceChaCtrl.fileStatus.coordinateType, out List <ChaFileAccessory.PartsInfo> sourceParts);
            Dictionary <ChaFileDefine.CoordinateType, List <ChaFileAccessory.PartsInfo> > rawAccInfos = targetCharAdditionalData.GetField("rawAccessoriesInfos").ToDictionary <ChaFileDefine.CoordinateType, List <ChaFileAccessory.PartsInfo> >();

            rawAccInfos.TryGetValue((ChaFileDefine.CoordinateType)targetChaCtrl.fileStatus.coordinateType, out List <ChaFileAccessory.PartsInfo> targetParts);

            while (targetParts.Count < sourceParts.Count)
            {
                targetParts.Add(new ChaFileAccessory.PartsInfo());
            }
            ChaFileAccessory.PartsInfo[] sourcePartsArray = sourceChaCtrl.nowCoordinate.accessory.parts.Concat(sourceParts).ToArray();
            ChaFileAccessory.PartsInfo[] targetPartsArray = targetChaCtrl.nowCoordinate.accessory.parts.Concat(targetParts).ToArray();

            Logger.LogDebug($"MoreAcc Source Count : {sourcePartsArray.Length}");
            Logger.LogDebug($"MoreAcc Target Count : {targetPartsArray.Length}");

            Patches.ChangeAccessories(sourceChaCtrl, sourcePartsArray, targetChaCtrl, targetPartsArray, accQueue);

            targetParts.Clear();
            targetParts.AddRange(targetPartsArray);

            //遍歷空欄dequeue accQueue
            while (accQueue.Count > 0)
            {
                targetParts.Add(MessagePackSerializer.Deserialize <ChaFileAccessory.PartsInfo>(
                                    MessagePackSerializer.Serialize <ChaFileAccessory.PartsInfo>(sourcePartsArray[accQueue.Dequeue()])
                                    ));
                Logger.LogDebug($"->DeQueue: MoreAcc{targetParts.Count - 1} / Part: {(ChaListDefine.CategoryNo)targetParts.Last().type} / ID: {targetParts.Last().id}");
            }

            //由後往前刪除空欄
            RemoveEmptyFromBackToFront(targetParts);
            Logger.LogDebug($"MoreAcc Finish Count : {targetParts.Count}");

            targetChaCtrl.nowCoordinate.accessory.parts = targetParts.Take(20).ToArray();
            targetParts.RemoveRange(0, 20);
            Logger.LogDebug($"targetParts Count : {targetParts.Count}");

            //資料寫入MoreAcc
            List <ListInfoBase>          infoAccessory = targetCharAdditionalData.GetField("infoAccessory").ToList <ListInfoBase>();
            List <GameObject>            objAccessory  = targetCharAdditionalData.GetField("objAccessory").ToList <GameObject>();
            List <GameObject[]>          objAcsMove    = targetCharAdditionalData.GetField("objAcsMove").ToList <GameObject[]>();
            List <ChaAccessoryComponent> cusAcsCmp     = targetCharAdditionalData.GetField("cusAcsCmp").ToList <ChaAccessoryComponent>();
            List <bool> showAccessories = targetCharAdditionalData.GetField("showAccessories").ToList <bool>();

            while (infoAccessory.Count < targetParts.Count)
            {
                infoAccessory.Add(null);
            }
            while (objAccessory.Count < targetParts.Count)
            {
                objAccessory.Add(null);
            }
            while (objAcsMove.Count < targetParts.Count)
            {
                objAcsMove.Add(new GameObject[2]);
            }
            while (cusAcsCmp.Count < targetParts.Count)
            {
                cusAcsCmp.Add(null);
            }
            while (showAccessories.Count < targetParts.Count)
            {
                showAccessories.Add(true);
            }

            //targetCharAdditionalData.SetField("nowAccessories", targetParts);
            targetCharAdditionalData.SetField("infoAccessory", infoAccessory);
            targetCharAdditionalData.SetField("objAccessory", objAccessory);
            targetCharAdditionalData.SetField("objAcsMove", objAcsMove);
            targetCharAdditionalData.SetField("cusAcsCmp", cusAcsCmp);
            targetCharAdditionalData.SetField("showAccessories", showAccessories);

            //_accessoriesByChar[targetChaCtrl.chaFile] = targetCharAdditionalData;
            //MoreAccObj.SetField("_accessoriesByChar", _accessoriesByChar);
            //Update();

            if (KK_StudioCoordinateLoadOption._isHairAccessoryCustomizerExist)
            {
                HairAccessoryCustomizer_Support.GetDataFromExtData(targetChaCtrl, out Dictionary <int, object> nowCoor);
                if (null != nowCoor)
                {
                    Logger.LogDebug($"->Hair Count: {nowCoor.Count} : {string.Join(",", nowCoor.Select(x => x.Key.ToString()).ToArray())}");
                }
            }
            Logger.LogDebug($"->MoreAcc Parts Count : {GetAccessoriesAmount(targetChaCtrl.chaFile)}");

            Logger.LogDebug("Load MoreAccessories Finish");
        }