public void Remove(CameraHandle h)
    {
        if (h.m_shareThing == null)//防止死锁
        {
            return;
        }
        ShareThing st = m_fxs.Get(h.name);

        if (st != h.m_shareThing)
        {
            Debuger.LogError("逻辑错误,找不到shareThing");
            h.m_shareThing = null;//防止死锁
            return;
        }
        st.Remove(h);
        if (st.m_handles.Count == 0)
        {
            m_fxs.Remove(h.name);
        }

        h.fx.Stop();

        if (m_fxs.Count == 0)
        {
            this.enabled = false;
        }
    }
 public void Release()
 {
     if (m_shareThing != null)
     {
         m_shareThing.Remove(this);
     }
 }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (IsPause)
        {
            m_logicTimeDelta = 0;
        }
        else
        {
            m_logicTimeDelta = Time.deltaTime;
            m_logicTime += m_logicTimeDelta;
        }

        System.DateTime now = System.DateTime.Now;
        //定时器回调
        lock (m_lock)
        {
            LinkedListNode<Timer> node = m_timers.First;
            Timer timer;
            LinkedListNode<Timer> cur;
            while (node != null)
            {
                timer = node.Value;
                cur = node;
                node = node.Next;
                System.TimeSpan span = now - timer.lastTime;
                if ((timer.counter != -1 && span.TotalSeconds >= timer.interval) ||
                    (timer.counter == -1 && span.TotalSeconds >= (timer.delay == -1 ? timer.interval : timer.delay)))
                {
                    ++timer.counter;
                    timer.lastTime = now;
                    //timer.onTimer(timer.param);回调中可能会删除别的定时器,所以移到外面回调
                    m_tempTimers.Add(timer);//回调中可能会删除别的定时器,所以移到外面回调
                    if (timer.num != -1 && (timer.counter + 1) >= timer.num)
                        RemoveTimer(cur);
                    //Debuger.Log("定时器触发:{0}",timer.ToString());
                }
            }
        }
        
        if (m_tempTimers.Count != 0)
        {
            for (int i = 0; i < m_tempTimers.Count; ++i)
                m_tempTimers[i].onTimer(m_tempTimers[i].param);
            
            m_tempTimers.Clear();
        }

        //时间缩放处理自动结束
        LinkedListNode<IShareThingHandle> handleNode = m_timeScale.m_handles.First;
        while(handleNode!= null)
        {
            if(((TimeScaleHandle)handleNode.Value).IsOver)
                m_removeTimeScaleHandles.Add(handleNode);
            handleNode = handleNode.Next;
        }
        if (m_removeTimeScaleHandles.Count != 0)
        {
            m_timeScale.Remove(m_removeTimeScaleHandles);
            m_removeTimeScaleHandles.Clear();
        }
    }
Exemple #4
0
    List <LinkedListNode <IShareThingHandle> > temRemoves = new List <LinkedListNode <IShareThingHandle> >();//用于计算删除的临时变量
    void Sample()
    {
        CameraHandle handle = m_share.Get <CameraHandle>();

        if (handle == null || m_ca == null || !m_cache || Time.unscaledDeltaTime == 0)
        {
            return;
        }

        //当前镜头需要跟随者才能计算的话,返回
        if (m_follow == null && handle.NeedFollow)
        {
            return;
        }

        CameraInfo info = handle.m_info;

        //不受战斗镜头影响的要重置下参数
        if (!info.isBattleDisturb)
        {
            m_lookPosOffset     = Vector3.zero;
            m_lastLookPosOffset = Vector3.zero;
            m_disRate           = 1;
        }

        //相机位置、方向、fov计算
        //直接切的情况
        if (handle.m_isDuation && handle.IsDurationInvalid)
        {
            m_isSampleDurationInvalid = true;
            ResetVelocity();
            m_smoothLookPos = m_newLookPos = m_lastLookPos = (handle.LookPos + m_lookPosOffset);
            m_lastDistance  = handle.Distance * m_disRate;
            //m_lastLookPosOffset = m_lookPosOffset;
            m_tran.eulerAngles = handle.Euler;
            m_tran.position    = m_lastLookPos - m_tran.forward * m_lastDistance;
//             m_tran.position = handle.Pos;
//             m_tran.forward = m_newLookPos - m_tran.position;
            m_ca.fieldOfView = handle.Fov;
        }
        //渐变的情况
        else
        {
            m_isSampleDurationInvalid = false;
            float delta  = Time.unscaledDeltaTime;
            float factor = handle.m_isDuation? handle.Factor:1;

            //计算看的点
            m_newLookPos = handle.LookPos;

            //计算渐变速度
            float v1 = Mathf.Lerp(handle.m_duration, 0, info.animationCurve.Evaluate(factor));
            float v2 = 0;

            if (info.useDisSmooth)//渐变过程和距离渐变都有的情况
            {
                Vector3 link = m_newLookPos + m_lookPosOffset - m_lastLookPos;
                float   dis  = link.magnitude;
                v2 = MathUtil.easeInExpo(0, info.disSmooth, Mathf.Lerp(1, 0, dis / info.disSmoothLimit)); //这里用exp函数可以让过度更平滑
            }
            m_smoothVelocity = Mathf.Max(v1, v2);


            if (Mathf.Abs(m_smoothVelocity) > Distance_Smooth_Min) //非常小的时候会有抖动,要用直接设置的方式
            {
                m_smoothLookPos     = Vector3.SmoothDamp(m_lastLookPos, m_newLookPos + m_lookPosOffset, ref m_curLookPosVelocity, m_smoothVelocity, float.MaxValue, delta);
                m_lastLookPosOffset = m_lookPosOffset;
                //与主角的距离渐变
                m_lastDistance = Mathf.SmoothDamp(m_lastDistance, handle.Distance * m_disRate, ref m_curDistanceVelocity, v1, float.MaxValue, delta);
                //角度渐变
                m_tran.rotation = Quaternion.Slerp(m_tran.rotation, handle.Rotate, (delta * factor) / v1);

                //                 //看着的点渐变
                //                 m_smoothLookPos = Vector3.SmoothDamp(m_lastLookPos, m_newLookPos, ref m_curLookPosVelocity, m_smoothVelocity, float.MaxValue, delta);
                //
                //                 //相机的点渐变
                //                 m_tran.position = Vector3.SmoothDamp(m_tran.position, handle.Pos, ref m_curPosVelocity, m_smoothVelocity, float.MaxValue, delta);
                //
                //                 //由于上面两个点都渐变了,方向不用渐变
                //                 m_tran.forward = m_smoothLookPos - m_tran.position;
            }
            else    //直接设置
            {
                m_lastLookPosOffset = Vector3.Slerp(m_lastLookPosOffset, m_lookPosOffset, delta);
                m_smoothLookPos     = m_newLookPos + m_lastLookPosOffset;
                m_lastDistance      = handle.Distance * m_disRate;
                m_tran.rotation     = handle.Rotate;
                //                 m_smoothLookPos = m_newLookPos;
                //                 m_tran.position  = handle.Pos;
                //                 m_tran.forward = m_smoothLookPos - m_tran.position;
            }

            //位置渐变,注意这里不是当前位置渐变,是看着的点渐变、距离渐变、方向渐变,然后推导出当前的位置,这样看着才是渐变的。
            m_lastLookPos = m_smoothLookPos;

            m_tran.position = m_smoothLookPos - m_tran.forward * m_lastDistance;


            //视野渐变
            float newFov = handle.Fov;
            if (Mathf.Abs(newFov - m_ca.fieldOfView) > Fov_Smooth_Min)
            {
                m_ca.fieldOfView = Mathf.SmoothDampAngle(m_ca.fieldOfView, newFov, ref m_curFovVelocity, m_smoothVelocity, float.MaxValue, delta);
            }

            ++m_samlpeCounter;
        }


        //3 计算渐变结束(要修改优先级),计算需要删除的
        LinkedListNode <IShareThingHandle> node = m_share.m_handles.First;
        CameraHandle tempHandle;
        bool         needSort = false;

        do
        {
            tempHandle = node.Value as CameraHandle;
            //将置顶优先级降为不置顶优先级
            if (tempHandle.m_isDuation)
            {
                if (tempHandle.m_info.isDurationInvalid || tempHandle.m_firstDurationInvalid ||                    //立即切
                    (Time.unscaledTime - tempHandle.m_beginTime >= tempHandle.m_duration || handle != tempHandle)) //时间到或者不是置顶的handle
                {
                    needSort = true;
                    tempHandle.m_isDuation = false;
                    tempHandle.m_priority  = tempHandle.m_info.priority;

                    if (tempHandle == handle)
                    {
                        CameraMgr.instance.m_isDuration = false;
                    }
                }
            }

            //销毁片段
            if ((tempHandle == handle && !handle.m_isDuation && info.isOverAfterDuration) ||                             //不永久的时间到了
                (tempHandle != handle && tempHandle.m_info.durationType == CameraInfo.enDurationType.overWhenOverlay) || //不置顶就删除的
                (tempHandle.m_info.duration != -1 && tempHandle.CurTime >= tempHandle.m_info.duration)                   //时间到了
                )
            {
                temRemoves.Add(node);
            }
            node = node.Next;
        } while (node != null);
        if (needSort)
        {
            m_share.Sort();
        }
        if (temRemoves.Count != 0)
        {
            m_share.Remove(temRemoves);
            temRemoves.Clear();
        }
    }
Exemple #5
0
    public void Remove(MaterialHandle h)
    {
        if (this == null)
        {
            return;                 //可能已经被销毁
        }
        if (h.m_shareThing == null) //防止死锁
        {
            return;
        }

        Cache();

        int idx = m_materials.IndexOf(h.m_shareThing);

        if (idx == -1)
        {
            Debuger.LogError("逻辑错误,找不到shareThing");
            h.m_shareThing = null;//防止死锁
            return;
        }


        //从shareThing中删除
        ShareThing st         = m_materials[idx];
        bool       needChange = st.Get() == h; //如果最顶的不是h,那么肯定是不用改变render的材质的

        st.Remove(h);                          //remove里执行了h.m_shareThing = null,必须保证在h.fx.Stop()之前执行,不然可能造成死锁

        //Remove和stop可能会互相调用,要判断下内部已经做了判断
        h.fx.Stop();

        //不需要改材质
        if (!needChange)
        {
            return;
        }

        //计算要改的材质
        bool           remove = false;
        Material       newMat = null;
        MaterialHandle newH   = st.Get <MaterialHandle>();

        if (newH == null)//已经没有特效材质的情况,这个时候有原始材质就换回原始材质,没有就删除
        {
            if ((bool)st.m_param2)
            {
                newMat = (Material)st.m_param;
            }
            else
            {
                m_materials.RemoveAt(idx);
                remove = true;
            }
        }
        else//有别的特效材质的情况
        {
            newMat = newH.mat;
        }

        //真正把材质放到Render上
        Material[] mats   = m_render.sharedMaterials;
        int        length = remove ? mats.Length - 1 : mats.Length;

        Material[] newMats = new Material[length];
        int        curIdx  = 0;

        for (int i = 0; i < mats.Length; ++i)
        {
            if (i == idx)
            {
                if (remove == false)
                {
                    newMats[curIdx] = newMat;
                }
            }
            else
            {
                newMats[curIdx] = mats[i];
            }

            if (i != idx || remove == false)
            {
                ++curIdx;
            }
        }
        m_render.sharedMaterials = newMats;
    }