示例#1
0
//----------------------------------------------------------------------------------------------------------------------

        private void UpdatePlayerConfigUIElements(MeshSyncPlayerType playerType)
        {
            MeshSyncProjectSettings projectSettings = MeshSyncProjectSettings.GetOrCreateSettings();
            MeshSyncPlayerConfig    config          = projectSettings.GetDefaultPlayerConfig(playerType);

            //sync
            m_syncVisibilityToggle.SetValueWithoutNotify(config.SyncVisibility);
            m_syncTransformToggle.SetValueWithoutNotify(config.SyncTransform);
            m_syncCamerasToggle.SetValueWithoutNotify(config.SyncCameras);
            m_syncLightsToggle.SetValueWithoutNotify(config.SyncLights);
            m_syncMeshesToggle.SetValueWithoutNotify(config.SyncMeshes);
            m_updateMeshCollidersToggle.SetValueWithoutNotify(config.UpdateMeshColliders);
            m_syncMaterialsToggle.SetValueWithoutNotify(config.SyncMaterials);
            m_findMaterialFromAssetsToggle.SetValueWithoutNotify(config.FindMaterialFromAssets);

            //Import
            m_animationInterpolationPopup.SetValueWithoutNotify(m_animationInterpolationEnums[config.AnimationInterpolation]);
            m_keyframeReductionToggle.SetValueWithoutNotify(config.KeyframeReduction);
            m_reductionThresholdField.SetValueWithoutNotify(config.ReductionThreshold);
            m_reductionEraseFlatCurves.SetValueWithoutNotify(config.ReductionEraseFlatCurves);
            m_zUpCorrectionPopup.SetValueWithoutNotify(m_zUpCorrectionEnums[config.ZUpCorrection]);

            //Misc
            m_syncMaterialListToggle.SetValueWithoutNotify(config.SyncMaterialList);
            m_progressiveDisplayToggle.SetValueWithoutNotify(config.ProgressiveDisplay);
            m_loggingToggle.SetValueWithoutNotify(config.Logging);
            m_profilingToggle.SetValueWithoutNotify(config.Profiling);

            //Animation Tweak
            AnimationTweakSettings animationTweakSettings = config.GetAnimationTweakSettings();

            m_animationTweakTimeScaleField.SetValueWithoutNotify(animationTweakSettings.TimeScale);
            m_animationTweakTimeOffsetField.SetValueWithoutNotify(animationTweakSettings.TimeOffset);
            m_animationTweakDropStepField.SetValueWithoutNotify(animationTweakSettings.DropStep);
            m_animationTweakReductionThresholdField.SetValueWithoutNotify(animationTweakSettings.ReductionThreshold);
            m_animationTweakEraseFlatCurvesToggle.SetValueWithoutNotify(animationTweakSettings.EraseFlatCurves);

            //userData
            foreach (VisualElement uiElement in m_playerConfigUIElements)
            {
                uiElement.userData = config;
            }


            m_selectedPlayerType = playerType;
        }
//----------------------------------------------------------------------------------------------------------------------

        protected static void DrawAnimationTweak(MeshSyncPlayer player)
        {
            GUIStyle styleFold = EditorStyles.foldout;

            styleFold.fontStyle       = FontStyle.Bold;
            player.foldAnimationTweak = EditorGUILayout.Foldout(player.foldAnimationTweak, "Animation Tweak", true, styleFold);
            if (player.foldAnimationTweak)
            {
                MeshSyncPlayerConfig   config = player.GetConfig();
                AnimationTweakSettings animationTweakSettings = config.GetAnimationTweakSettings();

                float frameRate            = 30.0f;
                List <AnimationClip> clips = player.GetAnimationClips();
                if (clips.Count > 0)
                {
                    frameRate = clips[0].frameRate;
                }

                {
                    // Override Frame Rate
                    GUILayout.BeginVertical("Box");
                    EditorGUILayout.LabelField("Override Frame Rate", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;
                    float prevFrameRate = frameRate;
                    frameRate = EditorGUILayout.FloatField("Frame Rate", frameRate);
                    if (!Mathf.Approximately(prevFrameRate, frameRate) && frameRate > 0)
                    {
                        ApplyFrameRate(clips, frameRate);
                    }
                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }



                // Time Scale
                {
                    GUILayout.BeginVertical("Box");
                    EditorGUILayout.LabelField("Time Scale", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;
                    float prevTimeScale  = animationTweakSettings.TimeScale;
                    float prevTimeOffset = animationTweakSettings.TimeOffset;
                    EditorGUIFloatField("Scale", ref animationTweakSettings.TimeScale);
                    EditorGUIFloatField("Offset", ref animationTweakSettings.TimeOffset);
                    if (!Mathf.Approximately(prevTimeScale, animationTweakSettings.TimeScale) ||
                        !Mathf.Approximately(prevTimeOffset, animationTweakSettings.TimeOffset)
                        )
                    {
                        ApplyTimeScale(clips, animationTweakSettings.TimeScale,
                                       animationTweakSettings.TimeOffset
                                       );
                    }
                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }

                // Drop Keyframes
                {
                    GUILayout.BeginVertical("Box");
                    EditorGUILayout.LabelField("Drop Keyframes", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;
                    int prevDropStep = animationTweakSettings.DropStep;
                    EditorGUIIntField("Step", ref animationTweakSettings.DropStep);
                    if (prevDropStep != animationTweakSettings.DropStep && animationTweakSettings.DropStep > 1)
                    {
                        ApplyDropKeyframes(clips, animationTweakSettings.DropStep);
                    }
                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }

                // Keyframe Reduction
                {
                    GUILayout.BeginVertical("Box");
                    EditorGUILayout.LabelField("Keyframe Reduction", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;
                    float prevReductionThreshold = animationTweakSettings.ReductionThreshold;
                    bool  prevEraseFlatCurves    = animationTweakSettings.EraseFlatCurves;
                    EditorGUIFloatField("Threshold", ref animationTweakSettings.ReductionThreshold);
                    EditorGUIToggle("Erase Flat Curves", ref animationTweakSettings.EraseFlatCurves);
                    if (!Mathf.Approximately(prevReductionThreshold, animationTweakSettings.ReductionThreshold) ||
                        prevEraseFlatCurves != animationTweakSettings.EraseFlatCurves)
                    {
                        ApplyKeyframeReduction(clips, animationTweakSettings.ReductionThreshold,
                                               animationTweakSettings.EraseFlatCurves
                                               );
                    }
                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }

                EditorGUILayout.Space();
            }
        }
示例#3
0
//----------------------------------------------------------------------------------------------------------------------

        protected static bool DrawAnimationTweak(BaseMeshSync player)
        {
            bool changed = false;

            GUIStyle styleFold = EditorStyles.foldout;

            styleFold.fontStyle       = FontStyle.Bold;
            player.foldAnimationTweak = EditorGUILayout.Foldout(player.foldAnimationTweak, "Animation Tweak", true, styleFold);
            if (player.foldAnimationTweak)
            {
                MeshSyncPlayerConfig   config = player.GetConfigV();
                AnimationTweakSettings animationTweakSettings = config.GetAnimationTweakSettings();

                float frameRate            = 30.0f;
                List <AnimationClip> clips = player.GetAnimationClips();
                if (clips.Count > 0)
                {
                    frameRate = clips[0].frameRate;
                }

                {
                    // Override Frame Rate
                    GUILayout.BeginVertical("Box");
                    EditorGUILayout.LabelField("Override Frame Rate", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;

                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(player, "MeshSync: Frame Rate",
                                                                      guiFunc: () => EditorGUILayout.FloatField("Frame Rate", frameRate),
                                                                      updateFunc: (float val) => {
                        if (val > 0)
                        {
                            ApplyFrameRate(clips, val);
                        }
                    }
                                                                      );
                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }



                // Time Scale
                {
                    GUILayout.BeginVertical("Box");
                    EditorGUILayout.LabelField("Time Scale", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;
                    float prevTimeScale  = animationTweakSettings.TimeScale;
                    float prevTimeOffset = animationTweakSettings.TimeOffset;

                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(player, "MeshSync: Scale",
                                                                      guiFunc: () => EditorGUILayout.FloatField("Scale", animationTweakSettings.TimeScale),
                                                                      updateFunc: (float val) => { animationTweakSettings.TimeScale = val; }
                                                                      );


                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(player, "MeshSync: Offset",
                                                                      guiFunc: () => EditorGUILayout.FloatField("Offset", animationTweakSettings.TimeOffset),
                                                                      updateFunc: (float val) => { animationTweakSettings.TimeOffset = val; }
                                                                      );
                    if (!Mathf.Approximately(prevTimeScale, animationTweakSettings.TimeScale) ||
                        !Mathf.Approximately(prevTimeOffset, animationTweakSettings.TimeOffset)
                        )
                    {
                        ApplyTimeScale(clips, animationTweakSettings.TimeScale,
                                       animationTweakSettings.TimeOffset
                                       );
                    }
                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }

                // Drop Keyframes
                {
                    GUILayout.BeginVertical("Box");
                    EditorGUILayout.LabelField("Drop Keyframes", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;
                    int prevDropStep = animationTweakSettings.DropStep;

                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(player, "MeshSync: Step",
                                                                      guiFunc: () => EditorGUILayout.IntField("Step", animationTweakSettings.DropStep),
                                                                      updateFunc: (int val) => { animationTweakSettings.DropStep = val; }
                                                                      );

                    if (prevDropStep != animationTweakSettings.DropStep && animationTweakSettings.DropStep > 1)
                    {
                        ApplyDropKeyframes(clips, animationTweakSettings.DropStep);
                    }
                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }

                // Keyframe Reduction
                {
                    GUILayout.BeginVertical("Box");
                    EditorGUILayout.LabelField("Keyframe Reduction", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;
                    float prevReductionThreshold = animationTweakSettings.ReductionThreshold;
                    bool  prevEraseFlatCurves    = animationTweakSettings.EraseFlatCurves;

                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(player, "MeshSync: Threshold",
                                                                      guiFunc: () => EditorGUILayout.FloatField("Threshold", animationTweakSettings.ReductionThreshold),
                                                                      updateFunc: (float val) => {
                        animationTweakSettings.ReductionThreshold = val;
                        ApplyKeyframeReduction(clips, val, animationTweakSettings.EraseFlatCurves);
                    }
                                                                      );

                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(player, "MeshSync: Erase Flat Curves",
                                                                      guiFunc: () => EditorGUILayout.Toggle("Erase Flat Curves", animationTweakSettings.EraseFlatCurves),
                                                                      updateFunc: (bool toggle) => {
                        animationTweakSettings.EraseFlatCurves = toggle;
                        ApplyKeyframeReduction(clips, animationTweakSettings.ReductionThreshold, toggle);
                    }
                                                                      );

                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }

                EditorGUILayout.Space();
            }

            return(changed);
        }
        public void DrawAnimationTweak(MeshSyncPlayer t)
        {
            var styleFold = EditorStyles.foldout;

            styleFold.fontStyle  = FontStyle.Bold;
            t.foldAnimationTweak = EditorGUILayout.Foldout(t.foldAnimationTweak, "Animation Tweak", true, styleFold);
            if (t.foldAnimationTweak)
            {
                MeshSyncPlayerConfig   config = m_asset.GetConfig();
                AnimationTweakSettings animationTweakSettings = config.GetAnimationTweakSettings();


                // Override Frame Rate
                GUILayout.BeginVertical("Box");
                EditorGUILayout.LabelField("Override Frame Rate", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                m_animationFrameRate = EditorGUILayout.FloatField("Frame Rate", m_animationFrameRate);
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Apply", GUILayout.Width(120.0f)))
                {
                    ApplyFrameRate(t.GetAnimationClips(), m_animationFrameRate);
                }
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                GUILayout.EndVertical();

                // Time Scale
                GUILayout.BeginVertical("Box");
                EditorGUILayout.LabelField("Time Scale", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                EditorGUIFloatField("Scale", ref animationTweakSettings.TimeScale);
                EditorGUIFloatField("Offset", ref animationTweakSettings.TimeOffset);
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Apply", GUILayout.Width(120.0f)))
                {
                    ApplyTimeScale(t.GetAnimationClips(), animationTweakSettings.TimeScale,
                                   animationTweakSettings.TimeOffset
                                   );
                }
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                GUILayout.EndVertical();

                // Drop Keyframes
                GUILayout.BeginVertical("Box");
                EditorGUILayout.LabelField("Drop Keyframes", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                EditorGUIIntField("Step", ref animationTweakSettings.DropStep);
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Apply", GUILayout.Width(120.0f)))
                {
                    ApplyDropKeyframes(t.GetAnimationClips(), animationTweakSettings.DropStep);
                }
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                GUILayout.EndVertical();

                // Keyframe Reduction
                GUILayout.BeginVertical("Box");
                EditorGUILayout.LabelField("Keyframe Reduction", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                EditorGUIFloatField("Threshold", ref animationTweakSettings.ReductionThreshold);
                EditorGUIToggle("Erase Flat Curves", ref animationTweakSettings.EraseFlatCurves);
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Apply", GUILayout.Width(120.0f)))
                {
                    ApplyKeyframeReduction(t.GetAnimationClips(), animationTweakSettings.ReductionThreshold,
                                           animationTweakSettings.EraseFlatCurves
                                           );
                }
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
                GUILayout.EndVertical();

                EditorGUILayout.Space();
            }
        }
示例#5
0
//----------------------------------------------------------------------------------------------------------------------
        internal void Setup(VisualElement parent)
        {
            bool isSceneCachePlayerConfig = (m_playerType == MeshSyncPlayerType.CACHE_PLAYER);
            MeshSyncPlayerConfig config   = null;

            if (isSceneCachePlayerConfig)
            {
                config = MeshSyncProjectSettings.GetOrCreateSettings().GetDefaultSceneCachePlayerConfig();
            }
            else
            {
                config = MeshSyncProjectSettings.GetOrCreateSettings().GetDefaultServerConfig();
            }


            TemplateContainer containerInstance = InstantiateContainer(m_playerType);

            parent.Add(containerInstance);

            //Add server port
            Foldout syncSettingsFoldout = containerInstance.Query <Foldout>("SyncSettingsFoldout").First();

            //Sync
            AddPlayerConfigField <Toggle, bool>(syncSettingsFoldout, Contents.UpdateTransform, config.SyncTransform,
                                                (bool newValue) => { config.SyncTransform = newValue; }
                                                );

            {
                int i = MeshSyncPlayerConfig.SYNC_CAMERA;
                ComponentSyncSettings componentSyncSettings = config.GetComponentSyncSettings(i);
                AddComponentSyncSettingFields(syncSettingsFoldout, Contents.ComponentSyncs[i], componentSyncSettings);
            }

            AddPlayerConfigField <Toggle, bool>(syncSettingsFoldout, Contents.UsePhysicalCameraParams, config.IsPhysicalCameraParamsUsed(),
                                                (bool newValue) => { config.UsePhysicalCameraParams(newValue); },
                                                "inner-field-container"
                                                );

            {
                int i = MeshSyncPlayerConfig.SYNC_LIGHTS;
                ComponentSyncSettings componentSyncSettings = config.GetComponentSyncSettings(i);
                AddComponentSyncSettingFields(syncSettingsFoldout, Contents.ComponentSyncs[i], componentSyncSettings);
            }


            AddPlayerConfigField <Toggle, bool>(syncSettingsFoldout, Contents.Meshes, config.SyncMeshes,
                                                (bool newValue) => { config.SyncMeshes = newValue; }
                                                );
            AddPlayerConfigField <Toggle, bool>(syncSettingsFoldout, Contents.UpdateMeshColliders, config.UpdateMeshColliders,
                                                (bool newValue) => { config.UpdateMeshColliders = newValue; },
                                                "inner-field-container"
                                                );

            AddPlayerConfigField <Toggle, bool>(syncSettingsFoldout, Contents.Visibility, config.SyncVisibility,
                                                (bool newValue) => { config.SyncVisibility = newValue; }
                                                );

            //import
            Foldout importSettingsFoldout = containerInstance.Query <Foldout>("ImportSettingsFoldout").First();
            ModelImporterSettings modelImporterSettings = config.GetModelImporterSettings();

            AddPlayerConfigField <Toggle, bool>(importSettingsFoldout,
                                                Contents.CreateMaterials, modelImporterSettings.CreateMaterials,
                                                (bool newValue) => { modelImporterSettings.CreateMaterials = newValue; }
                                                );
            AddPlayerConfigPopupField(importSettingsFoldout, Contents.MaterialSearchMode, m_assetSearchModeEnums,
                                      m_assetSearchModeEnums[(int)modelImporterSettings.MaterialSearchMode],
                                      (int newValue) => { modelImporterSettings.MaterialSearchMode = (AssetSearchMode)newValue; },
                                      "inner-field-container"
                                      );

            AddPlayerConfigPopupField(importSettingsFoldout, Contents.AnimationInterpolation, m_animationInterpolationEnums,
                                      m_animationInterpolationEnums[config.AnimationInterpolation],
                                      (int newValue) => { config.AnimationInterpolation = newValue; }
                                      );
            AddPlayerConfigField <Toggle, bool>(importSettingsFoldout, Contents.KeyframeReduction, config.KeyframeReduction,
                                                (bool newValue) => { config.KeyframeReduction = newValue; }
                                                );
            AddPlayerConfigField <FloatField, float>(importSettingsFoldout,
                                                     Contents.ReductionThreshold, config.ReductionThreshold,
                                                     (float newValue) => { config.ReductionThreshold = newValue; }
                                                     );
            AddPlayerConfigField <Toggle, bool>(importSettingsFoldout,
                                                Contents.ReductionEraseFlatCurves, config.ReductionEraseFlatCurves,
                                                (bool newValue) => { config.ReductionEraseFlatCurves = newValue; }
                                                );
            AddPlayerConfigPopupField(importSettingsFoldout,
                                      Contents.ZUpCorrection, m_zUpCorrectionEnums, m_zUpCorrectionEnums[config.ZUpCorrection],
                                      (int newValue) => { config.ZUpCorrection = newValue; }
                                      );

            //Misc
            Foldout miscSettingsFoldout = containerInstance.Query <Foldout>("MiscSettingsFoldout").First();

            AddPlayerConfigField <Toggle, bool>(miscSettingsFoldout,
                                                Contents.SyncMaterialList, config.SyncMaterialList,
                                                (bool newValue) => { config.SyncMaterialList = newValue; }
                                                );
            AddPlayerConfigField <Toggle, bool>(miscSettingsFoldout, Contents.ProgressiveDisplay, config.ProgressiveDisplay,
                                                (bool newValue) => { config.ProgressiveDisplay = newValue; }
                                                );
            AddPlayerConfigField <Toggle, bool>(miscSettingsFoldout, Contents.Logging, config.Logging,
                                                (bool newValue) => { config.Logging = newValue; }
                                                );
            AddPlayerConfigField <Toggle, bool>(miscSettingsFoldout, Contents.Profiling, config.Profiling,
                                                (bool newValue) => { config.Profiling = newValue; }
                                                );

            //Animation Tweak
            Foldout atsFoldout         = containerInstance.Query <Foldout>("AnimationTweakSettingsFoldout").First();
            AnimationTweakSettings ats = config.GetAnimationTweakSettings();

            AddPlayerConfigField <FloatField, float>(atsFoldout, Contents.TweakTimeScale, ats.TimeScale,
                                                     (float newValue) => { ats.TimeScale = newValue; }
                                                     );
            AddPlayerConfigField <FloatField, float>(atsFoldout, Contents.TweakTimeOffset, ats.TimeOffset,
                                                     (float newValue) => { ats.TimeOffset = newValue; }
                                                     );
            AddPlayerConfigField <IntegerField, int>(atsFoldout, Contents.TweakDropStep, ats.DropStep,
                                                     (int newValue) => { ats.DropStep = newValue; }
                                                     );
            AddPlayerConfigField <FloatField, float>(atsFoldout, Contents.TweakReductionThreshold, ats.ReductionThreshold,
                                                     (float newValue) => { ats.ReductionThreshold = newValue; }
                                                     );
            AddPlayerConfigField <Toggle, bool>(atsFoldout, Contents.TweakEraseFlatCurves, ats.EraseFlatCurves,
                                                (bool newValue) => { ats.EraseFlatCurves = newValue; }
                                                );

            if (!isSceneCachePlayerConfig)
            {
                return;
            }

            //Additional UI for SceneCache
            SceneCachePlayerConfig scPlayerConfig = config as SceneCachePlayerConfig;

            Assert.IsNotNull(scPlayerConfig);
            Foldout timelineSettingsFoldout = containerInstance.Query <Foldout>("TimelineSettingsFoldout").First();

            AddPlayerConfigPopupField(timelineSettingsFoldout,
                                      Contents.TimelineSnapToFrame, m_snapToFrameEnums, m_snapToFrameEnums[scPlayerConfig.TimelineSnapToFrame],
                                      (int newValue) => { scPlayerConfig.TimelineSnapToFrame = newValue; }
                                      );
        }