Exemple #1
0
        /// <summary>
        /// 檢核LoadState,這是因為異步流程所需,檢查Extdata是否已從Coordinate載入完成
        /// </summary>
        /// <param name="chaCtrl">檢核的ChaControl</param>
        /// <returns>檢核通過</returns>
        public static bool CheckControllerPrepared(ChaControl chaCtrl, bool doReload = false)
        {
            if (!KK_StudioCoordinateLoadOption._isHairAccessoryCustomizerExist)
            {
                return(true);
            }
            ChaFileCoordinate coordinate = chaCtrl.nowCoordinate;
            bool?flag = true;

            Dictionary <int, object> dataFromCoorExt = GetDataFromCoordinate(coordinate);

            GetDataFromController(chaCtrl, out Dictionary <int, object> dataFromCon);

            //過濾假的HairAccInfo
            if (null != dataFromCoorExt)
            {
                foreach (KeyValuePair <int, object> rk in dataFromCoorExt.Where(x => null == Patches.GetChaAccessoryComponent(chaCtrl, x.Key)?.gameObject.GetComponent <ChaCustomHairComponent>()).ToList())
                {
                    dataFromCoorExt.Remove(rk.Key);
                }
                Logger.LogDebug($"Test with {dataFromCoorExt.Count} HairAcc after remove fake HairAccData {string.Join(",", dataFromCoorExt.Select(x => x.Key.ToString()).ToArray())}");
            }
            if (null != dataFromCon)
            {
                foreach (KeyValuePair <int, object> rk in dataFromCon.Where(x => null == Patches.GetChaAccessoryComponent(chaCtrl, x.Key)?.gameObject.GetComponent <ChaCustomHairComponent>()).ToList())
                {
                    dataFromCon.Remove(rk.Key);
                }
                Logger.LogDebug($"Test with {dataFromCon.Count} HairAcc after remove fake HairAccData {string.Join(",", dataFromCon.Select(x => x.Key.ToString()).ToArray())}");
            }

            if (null != dataFromCoorExt && dataFromCoorExt.Count > 0)
            {
                if (null != dataFromCon && dataFromCon.Count == dataFromCoorExt.Count)
                {
                    foreach (KeyValuePair <int, object> kv in dataFromCoorExt)
                    {
                        if (dataFromCon.ContainsKey(kv.Key))
                        {
                            continue;
                        }
                        else
                        {
                            flag = false; break;
                        }
                    }
                }
                else
                {
                    flag = false;
                }
            }
            else
            {
                //No data from coordinate extData
                if (null != dataFromCon && dataFromCon.Count != 0)
                {
                    flag = false;
                }
                else
                {
                    flag = null;
                }
            }

            if (null == flag)
            {
                return(true);
            }
            else if (true == flag)
            {
                MonoBehaviour HairAccCusController = chaCtrl.GetComponents <MonoBehaviour>().FirstOrDefault(x => Equals(x.GetType().Name, "HairAccessoryController"));
                HairAccCusController.Invoke("UpdateAccessories", new object[] { true });
                return(true);
            }
            else
            {
                if (doReload)
                {
                    SetControllerFromCoordinate(chaCtrl, coordinate);
                }
                return(false);
            }
        }