Example #1
0
        LightComponents GetOrAddLightComponents()
        {
            LightComponents recComponents;

            Assert.IsNotNull(this.go);
            if (null == this.light)
            {
                this.light = Misc.GetOrAddComponent <Light>(this.go);
            }
            Assert.IsNotNull(this.light);
            recComponents.LightComponent = this.light;

#if AT_USE_HDRP
            if (null == m_hdAdditionalLightData)
            {
                m_hdAdditionalLightData = Misc.GetOrAddComponent <HDAdditionalLightData>(this.go);
            }
            Assert.IsNotNull(m_hdAdditionalLightData);
            recComponents.HDAdditionalLightDataComponent = m_hdAdditionalLightData;
#endif

            return(recComponents);
        }
        internal bool ResetTimeAnimation()
        {
            if (m_sceneCache.sceneCount < 2)
            {
                return(false);
            }

            Animator      animator = Misc.GetOrAddComponent <Animator>(gameObject);
            AnimationClip clip     = null;

            if (animator.runtimeAnimatorController != null)
            {
                AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
                if (clips != null && clips.Length > 0)
                {
                    AnimationClip tmp = animator.runtimeAnimatorController.animationClips[0];
                    if (tmp != null)
                    {
                        clip = tmp;
                        Undo.RegisterCompleteObjectUndo(clip, "SceneCachePlayer");
                    }
                }
            }

            if (clip == null)
            {
                clip = new AnimationClip();

                string assetsFolder = GetAssetsFolder();

                string animPath       = string.Format("{0}/{1}.anim", assetsFolder, gameObject.name);
                string controllerPath = string.Format("{0}/{1}.controller", assetsFolder, gameObject.name);
                clip = Misc.SaveAsset(clip, animPath);
                if (clip == null)
                {
                    return(false);
                }

                animator.runtimeAnimatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPathWithClip(controllerPath, clip);
            }
            float sampleRate = m_sceneCache.sampleRate;

            if (sampleRate > 0.0f)
            {
                clip.frameRate = sampleRate;
            }

            Type tPlayer = typeof(SceneCachePlayer);

            clip.SetCurve("", tPlayer, "m_time", null);
            clip.SetCurve("", tPlayer, "m_frame", null);
            if (m_timeUnit == TimeUnit.Seconds)
            {
                AnimationCurve curve = m_sceneCache.GetTimeCurve(InterpolationMode.Constant);
                clip.SetCurve("", tPlayer, "m_time", curve);
            }
            else if (m_timeUnit == TimeUnit.Frames)
            {
                AnimationCurve curve = m_sceneCache.GetFrameCurve((int)m_baseFrame);
                clip.SetCurve("", tPlayer, "m_frame", curve);
            }

            AssetDatabase.SaveAssets();
            UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
            return(true);
        }