Example #1
0
        /// <summary>
        /// An overload for MeshInflate() that allows you to pass existing card data as the first param
        /// </summary>
        /// <param name="cardData">Some prexisting PregnancyPlusData that we want to activate</param>
        /// <param name="checkForNewMesh">Lets you force bypass the check for values changed to check for new meshes</param>
        /// <param name="pluginConfigSliderChanged">Will treat as if some slider values changed, which they did in global plugin config</param>
        public bool MeshInflate(PregnancyPlusData cardData, bool checkForNewMesh = false, bool forceRecalc = false, bool pluginConfigSliderChanged = false)
        {
            //Allow an initial size to be passed in, and sets it to the config
            infConfig = cardData;

            return(MeshInflate(checkForNewMesh, forceRecalc, pluginConfigSliderChanged));
        }
        /// <summary>
        /// Loads a blendshape from character card and sets it to the correct mesh
        /// </summary>
        /// <param name="data">The characters card data for this plugin</param>
        internal void LoadBlendShapes(PregnancyPlusData data)
        {
            if (data.meshBlendShape == null)
            {
                return;
            }
            if (PregnancyPlusPlugin.DebugLog.Value)
            {
                PregnancyPlusPlugin.Logger.LogInfo($" MeshBlendShape size > {data.meshBlendShape.Length/1024}KB ");
            }

            meshWithBlendShapes = new List <SkinnedMeshRenderer>();

            //Unserialize the blendshape from characters card
            var meshBlendShapes = MessagePack.LZ4MessagePackSerializer.Deserialize <List <MeshBlendShape> >(data.meshBlendShape);

            if (meshBlendShapes == null || meshBlendShapes.Count <= 0)
            {
                return;
            }

            //For each stores meshBlendShape
            foreach (var meshBlendShape in meshBlendShapes)
            {
                //Loop through all meshes and find matching name
                var clothRenderers = PregnancyPlusHelper.GetMeshRenderers(ChaControl.objClothes, true);
                LoopMeshAndAddExistingBlendShape(clothRenderers, meshBlendShape, true);

                //do the same for body meshs
                var bodyRenderers = PregnancyPlusHelper.GetMeshRenderers(ChaControl.objBody, true);
                LoopMeshAndAddExistingBlendShape(bodyRenderers, meshBlendShape);
            }
        }
Example #3
0
        public static PregnancyPlusData Load(PluginData data)
        {
            if (data?.data == null)
            {
                return(null);
            }

            var result = new PregnancyPlusData();

            foreach (var fieldInfo in _serializedFields)
            {
                if (data.data.TryGetValue(fieldInfo.Name, out var val))
                {
                    try
                    {
                        if (fieldInfo.FieldType.IsEnum)
                        {
                            val = (int)val;
                        }
                        fieldInfo.SetValue(result, val);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// Get card data and update this characters infConfig with it
        /// </summary>
        internal void ReadAndSetCardData()
        {
            infConfig = GetCardData();
            if (PregnancyPlusPlugin.DebugLog.Value)
            {
                PregnancyPlusPlugin.Logger.LogInfo($" ReadAndSetCardData > {infConfig.ValuesToString()}");
            }

            //Load any blendshapes from card
            LoadBlendShapes(infConfig);
            initialized = true;
        }
            //Determine if we need to recalculate the sphere radius (hopefully to avoid change in hip bones causing belly size to sudenly change)
            internal bool NeedsSphereRecalc(PregnancyPlusData data, float newMultiplier)
            {
                if (!IsInitialized)
                {
                    return(true);
                }
                if (CurrentMultiplier != newMultiplier)
                {
                    return(true);
                }

                return(false);
            }
Example #6
0
        //Restore sliders to last non zero config
        internal static void RestoreSliders(PregnancyPlusData _infConfig)
        {
            if (cat == null)
            {
                return;
            }

            //For each ui item check if its a slider
            foreach (CurrentStateCategorySubItemBase subItem in cat.SubItems)
            {
                if (!subItem.Created)
                {
                    continue;
                }
                var itemGo  = subItem.RootGameObject;
                var sliders = itemGo.GetComponentsInChildren <UnityEngine.UI.Slider>();

                //For each slider component (should just be one per subItem) set to last good value
                foreach (var slider in sliders)
                {
                    if (PregnancyPlusPlugin.DebugLog.Value)
                    {
                        PregnancyPlusPlugin.Logger.LogInfo($" Restoring slider > {slider.name}");
                    }

                    //Set the correct slider with it's old config value
                    switch (slider.name)
                    {
                        #region Look away! im being lazy
                    case "Slider " + inflationSize:
                        slider.value = _infConfig.inflationSize;
                        continue;

                    case "Slider " + inflationMultiplier:
                        slider.value = _infConfig.inflationMultiplier;
                        continue;

                    case "Slider " + inflationMoveY:
                        slider.value = _infConfig.inflationMoveY;
                        continue;

                    case "Slider " + inflationMoveZ:
                        slider.value = _infConfig.inflationMoveZ;
                        continue;

                    case "Slider " + inflationStretchX:
                        slider.value = _infConfig.inflationStretchX;
                        continue;

                    case "Slider " + inflationStretchY:
                        slider.value = _infConfig.inflationStretchY;
                        continue;

                    case "Slider " + inflationShiftY:
                        slider.value = _infConfig.inflationShiftY;
                        continue;

                    case "Slider " + inflationShiftZ:
                        slider.value = _infConfig.inflationShiftZ;
                        continue;

                    case "Slider " + inflationTaperY:
                        slider.value = _infConfig.inflationTaperY;
                        continue;

                    case "Slider " + inflationTaperZ:
                        slider.value = _infConfig.inflationTaperZ;
                        continue;

                    case "Slider " + inflationClothOffset:
                        slider.value = _infConfig.inflationClothOffset;
                        continue;

                    case "Slider " + inflationFatFold:
                        slider.value = _infConfig.inflationFatFold;
                        continue;

                    case "Slider " + inflationRoundness:
                        slider.value = _infConfig.inflationRoundness;
                        continue;

                    default:
                        continue;
                        #endregion
                    }
                }
            }
        }
        /// <summary>
        /// Just fetch the data for comparison
        /// </summary>
        internal PregnancyPlusData GetCardData()
        {
            var data = GetExtendedData();

            return(PregnancyPlusData.Load(data) ?? new PregnancyPlusData());
        }
Example #8
0
        /// <summary>
        /// On Restore, set sliders to last non zero shape, and set characters belly state
        /// </summary>
        public static void OnRestore(List <MakerSlider> _sliders, PregnancyPlusData restoreToState = null)
        {
            if (!MakerAPI.InsideAndLoaded)
            {
                return;
            }
            if (_sliders == null || _sliders.Count <= 0 || !_sliders[0].Exists)
            {
                return;
            }

            var chaControl      = MakerAPI.GetCharacterControl();
            var charCustFunCtrl = PregnancyPlusHelper.GetCharacterBehaviorController <PregnancyPlusCharaController>(chaControl, PregnancyPlusPlugin.GUID);

            if (charCustFunCtrl == null)
            {
                return;
            }

            var _infConfig = restoreToState != null ? restoreToState : PregnancyPlusPlugin.lastBellyState;

            //For each slider, set to default which will reset the belly shape
            foreach (var slider in _sliders)
            {
                //Get the private slider object name from the game GUI
                var settingName = Traverse.Create(slider).Field("_settingName").GetValue <string>();
                if (settingName == null)
                {
                    continue;
                }

                if (PregnancyPlusPlugin.DebugLog.Value)
                {
                    PregnancyPlusPlugin.Logger.LogInfo($" Restoring slider > {settingName}");
                }

                //Set the correct slider with it's old config value
                switch (settingName)
                {
                    #region Look away! im being lazy again
                case var _ when settingName == inflationSizeMaker:    //Ohh boy, cant have const and static strings in switch case, thus this was created!
                    slider.SetValue(_infConfig.inflationSize);
                    continue;

                case var _ when settingName == inflationMultiplierMaker:
                    slider.SetValue(_infConfig.inflationMultiplier);
                    continue;

                case var _ when settingName == inflationMoveYMaker:
                    slider.SetValue(_infConfig.inflationMoveY);
                    continue;

                case var _ when settingName == inflationMoveZMaker:
                    slider.SetValue(_infConfig.inflationMoveZ);
                    continue;

                case var _ when settingName == inflationStretchXMaker:
                    slider.SetValue(_infConfig.inflationStretchX);
                    continue;

                case var _ when settingName == inflationStretchYMaker:
                    slider.SetValue(_infConfig.inflationStretchY);
                    continue;

                case var _ when settingName == inflationShiftYMaker:
                    slider.SetValue(_infConfig.inflationShiftY);
                    continue;

                case var _ when settingName == inflationShiftZMaker:
                    slider.SetValue(_infConfig.inflationShiftZ);
                    continue;

                case var _ when settingName == inflationTaperYMaker:
                    slider.SetValue(_infConfig.inflationTaperY);
                    continue;

                case var _ when settingName == inflationTaperZMaker:
                    slider.SetValue(_infConfig.inflationTaperZ);
                    continue;

                case var _ when settingName == inflationClothOffsetMaker:
                    slider.SetValue(_infConfig.inflationClothOffset);
                    continue;

                case var _ when settingName == inflationFatFoldMaker:
                    slider.SetValue(_infConfig.inflationFatFold);
                    continue;

                case var _ when settingName == inflationRoundnessMaker:
                    slider.SetValue(_infConfig.inflationRoundness);
                    continue;

                default:
                    continue;
                    #endregion
                }
            }
        }