private static void LoadTranslationPresets()
    {
        var presets      = Resources.LoadAll <Preset>(resourceTranslationPath);
        var translations = Resources.LoadAll <PumkinsTranslation>(resourceTranslationPath);

        foreach (var p in presets)
        {
            var    mods     = p.PropertyModifications;
            string langName = mods.FirstOrDefault(m => m.propertyPath == "languageName").value;
            string author   = mods.FirstOrDefault(m => m.propertyPath == "author").value;

            if (Helpers.StringIsNullOrWhiteSpace(langName) || Helpers.StringIsNullOrWhiteSpace(author))
            {
                PumkinsAvatarTools.Log(Strings.Log.invalidTranslation, LogType.Error, p.name);
                continue;
            }

            var tr = translations.FirstOrDefault(t => t.author == author && t.languageName == langName);
            if (tr == default)
            {
                tr = ScriptableObjectUtility.CreateAndSaveAsset <PumkinsTranslation>("language_" + langName, translationPath);
            }

            if (p.CanBeAppliedTo(tr))
            {
                p.ApplyTo(tr);
            }
            else
            {
                PumkinsAvatarTools.Log(Strings.Log.cantApplyPreset, LogType.Error);
            }
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates new preset based on camera and reference, applies all settings from this object then saves it to assets
        /// </summary>
        public bool SavePreset(GameObject referenceObject, Camera camera, bool overwriteExisting)
        {
            PumkinsCameraPreset p = ScriptableObjectUtility.CreateAndSaveAsset <PumkinsCameraPreset>(name, PumkinsAvatarTools.MainFolderPath + "/Resources/Presets/Cameras/", overwriteExisting) as PumkinsCameraPreset;

            if (!p)
            {
                return(false);
            }

            p.name       = name;
            p.offsetMode = offsetMode;

            if (p.offsetMode == CameraOffsetMode.AvatarRoot)
            {
                CalculateOffsets(referenceObject.transform.root, camera);
            }
            else if (p.offsetMode == CameraOffsetMode.Transform)
            {
                CalculateOffsets(referenceObject.transform, camera);
            }
            else
            {
                CalculateOffsets(PumkinsAvatarTools.SelectedAvatar.GetComponent <VRC_AvatarDescriptor>(), camera);
            }

            p.positionOffset       = positionOffset;
            p.rotationAnglesOffset = rotationAnglesOffset;
            p.transformPath        = transformPath;

            p.useOverlay = PumkinsAvatarTools.Instance.bThumbnails_use_camera_overlay;

            if (p.useOverlay)
            {
                p.overlayImagePath = PumkinsAvatarTools.Instance._overlayPath;
                p.overlayImageTint = PumkinsAvatarTools.Instance.cameraOverlayImageTint;
            }

            p.useBackground  = PumkinsAvatarTools.Instance.bThumbnails_use_camera_background;
            p.backgroundType = PumkinsAvatarTools.Instance.cameraBackgroundType;

            if (p.useBackground)
            {
                switch (p.backgroundType)
                {
                case PumkinsAvatarTools.CameraBackgroundOverrideType.Color:
                    p.backgroundColor = PumkinsAvatarTools.Instance._thumbsCamBgColor;
                    break;

                case PumkinsAvatarTools.CameraBackgroundOverrideType.Image:
                    p.backgroundImagePath = PumkinsAvatarTools.Instance._backgroundPath;
                    p.backgroundImageTint = PumkinsAvatarTools.Instance.cameraBackgroundImageTint;
                    break;

                case PumkinsAvatarTools.CameraBackgroundOverrideType.Skybox:
                    p.backgroundMaterial = RenderSettings.skybox;
                    break;

                default:
                    break;
                }
            }
            EditorUtility.SetDirty(p);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            PumkinsPresetManager.LoadPresets <PumkinsCameraPreset>();
            return(true);
        }