Example #1
0
    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;
        }
    }
Example #2
0
 public void Clear()
 {
     if (m_handle != null)
     {
         m_handle.Release();
         m_handle = null;
     }
 }
 private void Awake()
 { 
     // Asuming only one of each of the following
     swipeController = FindObjectOfType<SwipeController>();
     cameraHandle = FindObjectOfType<CameraHandle>();
     platformController = FindObjectOfType<PlatformController>();
     score = FindObjectOfType<Score>();
 }
Example #4
0
 public void RegisterCamera(CameraHandle camera)
 {
     CameraHandles[camera.CameraType] = camera;
     if (PendingActivations.Contains(camera.CameraType))
     {
         SetCameraStatus(camera.CameraType, true);
         PendingActivations.Remove(camera.CameraType);
     }
 }
Example #5
0
 void Clear()
 {
     if (m_handle != null)
     {
         m_handle.Release();
         m_handle = null;
     }
     foreach (CameraTrigger t in m_triggers)
     {
         t.Clear();
     }
 }
Example #6
0
    //如果durationInvalid=true则直接切
    //firstPriority !=-1的话则第一次用这个的优先级,否则用cameraInfo.durationPriority
    public CameraHandle Add(CameraInfo cameraInfo, bool firstDurationInvalid = false, int firstPriority = -1)
    {
        if (!m_cache)
        {
            return(null);
        }

        //如果是永久镜头,那么不允许叠加多个,这里给之前那个修改下优先级返回就可以了
        LinkedListNode <IShareThingHandle> node = m_share.m_handles.First;
        CameraHandle tempHandle;

        while (node != null)
        {
            tempHandle = node.Value as CameraHandle;
            if (tempHandle.m_info == cameraInfo && !tempHandle.m_info.isOverAfterDuration)
            {
                m_share.Change(tempHandle, firstPriority == -1 ? tempHandle.m_info.durationPriority : firstPriority);
                //这里如果已经置顶了,那么就不会立即切了,重置下
                if (firstDurationInvalid || tempHandle.m_info.isDurationInvalid)
                {
                    tempHandle.Reset(firstDurationInvalid);
                }

                return(tempHandle);
            }
            node = node.Next;
        }

        //创建一个新的镜头处理器
        CameraHandle handle = new CameraHandle(cameraInfo, firstDurationInvalid);

        m_share.Add(handle, firstPriority == -1 ? cameraInfo.durationPriority : firstPriority);
#if !ART_DEBUG
        if (cameraInfo.lookType == CameraInfo.enLookType.followBehind)
        {
            Role t = RoleMgr.instance.GetRoleByRoleId(cameraInfo.targetId);
            //if (t == null)
            //    Debug.LogError("创建盯住目标点相机时没有找到目标 目标id:" + cameraInfo.targetId);
            //else
            if (t != null)
            {
                Transform tran = string.IsNullOrEmpty(cameraInfo.bone) ? t.transform: t.transform.Find(cameraInfo.bone);
                if (tran == null)
                {
                    Debug.LogError("没有找到相应骨骼点 roleid:" + cameraInfo.targetId + " 骨骼路径:" + cameraInfo.bone);
                }
                handle.SetTarget(tran);
            }
        }
#endif
        return(handle);
    }
Example #7
0
    public CameraHandle Add(string name, CameraFx fx)
    {
        CameraHandle handle = new CameraHandle(name, fx, this);
        ShareThing   st     = m_fxs.GetNewIfNo(name);

        st.Add(handle);

        if (!this.enabled)
        {
            this.enabled = true;
        }
        return(handle);
    }
Example #8
0
    //直接切
    public CameraHandle Set(CameraInfo info, int firstPriority = -1)
    {
        Cache();
        CameraHandle handle = Add(info, true);

        if (handle.IsHandling)
        {
            m_lastLookPos       = handle.LookPos + m_lookPosOffset;//要先设置下,有些类型是相对的,需要一个lookPos
            m_lastLookPosOffset = Vector3.zero;
            m_lookPosOffset     = Vector3.zero;
            Sample();//马上sample下,不然这一帧可能没有sample过
        }
        return(handle);
    }
    void OnDrawGL(object obj)
    {
        if (CameraMgr.instance == null)
        {
            return;
        }
        CameraHandle handle = CameraMgr.instance.CurHandle;

        if (handle == null)
        {
            return;
        }

        DrawGL draw = (DrawGL)obj;

        handle.OnDrawGL(draw);
    }
Example #10
0
    public override void OnLast(IShareThingHandle prev)
    {
        if (CameraMgr.instance)
        {
            CameraMgr.instance.m_curId         = m_id;
            CameraMgr.instance.m_curCameraInfo = m_info;
            CameraMgr.instance.m_isDuration    = true;
            CameraMgr.instance.m_samlpeCounter = 0;
        }

        CameraHandle prevHandle = prev as CameraHandle;

        //注意只有在被覆盖然后置顶的时候才需要重置相关东西和提升优先级
        if (m_isFirst || m_info.durationType == CameraInfo.enDurationType.overWhenOverlay)
        {
            return;
        }

        if (m_info.durationType == CameraInfo.enDurationType.resetWhenLast)
        {
            if (prevHandle != null && prevHandle.m_info.useOverDuration)
            {
                if (prevHandle.m_info.blur != 0 && prevHandle.m_info.blurDuration != 0)//推镜过程模糊
                {
                    CameraMgr.instance.PlayRadialBlur(prevHandle.m_info.blur, prevHandle.m_info.blurTarget, prevHandle.m_info.blurDuration, prevHandle.m_info.offset, prevHandle.m_info.blurBeginSmooth, prevHandle.m_info.blurEndSmooth);
                }

                Reset(prevHandle.m_info.isDurationInvalid, prevHandle.m_info.overDuationSmooth);
            }
            else
            {
                if (m_info.blur != 0 && m_info.blurDuration != 0)//推镜过程模糊
                {
                    CameraMgr.instance.PlayRadialBlur(m_info.blur, m_info.blurTarget, m_info.blurDuration, m_info.offset, m_info.blurBeginSmooth, m_info.blurEndSmooth);
                }
                Reset(false);
            }
        }
        else if (m_info.durationType == CameraInfo.enDurationType.keepOverTimeWhenLast)
        {
            ResetKeepOverTime();
        }

        //提升优先级
        this.m_shareThing.Change(this, m_info.durationPriority);
    }
Example #11
0
    public void SetGroupActive(bool active)
    {
        if (active)
        {
            Clear();

            gameObject.SetActive(false);

            //这里暂时用默认镜头的参考点作为出生点
            m_handle = CameraMgr.instance.Set(m_defaultInfo);

            gameObject.SetActive(true);
        }
        else
        {
            Clear();
            gameObject.SetActive(false);
        }
    }
Example #12
0
    public CameraHandle StillLook(Transform follow, float moveTime, float overDuration = -1)
    {
        CameraInfo cameraInfo = new CameraInfo();

        cameraInfo.lookType        = CameraInfo.enLookType.stillLook;
        cameraInfo.durationSmooth  = moveTime;
        cameraInfo.verticalAngle   = m_tran.eulerAngles.x;
        cameraInfo.horizontalAngle = m_tran.eulerAngles.y;
        cameraInfo.refPos          = SmoothLookPos - cameraInfo.offset;
        cameraInfo.distance        = Vector3.Distance(m_tran.position, SmoothLookPos);
        if (overDuration != -1)
        {
            cameraInfo.useOverDuration   = true;
            cameraInfo.overDuationSmooth = overDuration;
        }
        CameraHandle handle = Add(cameraInfo);

        handle.SetFollow(follow);
        return(handle);
    }
Example #13
0
    void OnTriggerEnter(Collider other)
    {
        if (other == null || other.gameObject == null || CameraMgr.instance == null || (CameraMgr.instance.GetFollow() != other.GetComponent <Transform>()))
        {
            return;
        }
#if !ART_DEBUG
        //有战斗镜头 没有结束前不能受区域碰撞切换其他镜头
        if (SceneMgr.instance.FightCamera != null)
        {
            return;
        }
#endif
        if (m_handle != null)
        {
            Debuger.LogError("重复进入??");
            return;
        }

        m_handle = CameraMgr.instance.Add(m_info);
    }
Example #14
0
    public void Stop()
    {
        if (this == null)
        {
            return;       //可能已经被销毁
        }
        if (!m_isPlaying) //防止死锁
        {
            return;
        }

        //1 必须先把这个值设置正确,不然可能造成死锁
        m_isPlaying = false;

        //Remove和stop可能会互相调用,内部已经防止死锁,这里不用判断
        m_handle.Release();
        m_handle = null;

        //DoDestroy和stop可能会互相调用,内部已经防止死锁,这里不用判断
        FxDestroy.DoDestroy(this.gameObject);
    }
Example #15
0
        public override async Task ReceiveAsync(Context context)
        {
            IAgentHandle handle;

            switch (context.HandleType)
            {
            case HandleType.Win32_CloseScreen:
                handle = new Win32Handle();
                break;

            case HandleType.Aforge_Camera:
                handle = new CameraHandle();
                break;

            default:
                handle = null;
                break;
            }
            await handle.ReceiveAsync(context);

            await handle.SendAsync(context);
        }
Example #16
0
    public void Play()
    {
        if (m_isPlaying)
        {
            Debuger.Log("还没结束就重新播放了");
            Stop();//先结束老的
        }


        if (CameraMgr.instance == null)
        {
            Debuger.Log("没有找到相机管理器");
            FxDestroy.DoDestroy(this.gameObject);
            return;
        }

        m_handle = CameraMgr.instance.Add(m_info);

        m_isPlaying   = true;
        m_beginTime   = Util.time;
        m_needDestroy = false;
    }
Example #17
0
    //推镜到一个静态的位置和方向,这里offset和horizontalAngle都是相对于refDir的
    public CameraHandle Still(Vector3 refPos, Vector3 refDir, Vector3 offset, float moveTime, float stayTime,
                              float fov, float horizontalAngle, float verticalAngle, float distance, float overDuration,
                              float blur, float blurDuration, float beginSmooth, float endSmooth, Vector3 blurOffset, Transform blurTarget, bool isBattleDisturb = false)
    {
        refDir.y = 0;
        Quaternion q = Quaternion.LookRotation(refDir);

        CameraInfo curInfo    = CameraMgr.instance.CurHandle.m_info;
        CameraInfo cameraInfo = new CameraInfo();

        cameraInfo.lookType        = CameraInfo.enLookType.still;
        cameraInfo.refPos          = refPos + q * offset;
        cameraInfo.duration        = moveTime + stayTime;
        cameraInfo.horizontalAngle = horizontalAngle == -1 ? curInfo.horizontalAngle : q.eulerAngles.y + horizontalAngle;
        cameraInfo.distance        = distance == -1 ? curInfo.distance : distance;
        cameraInfo.verticalAngle   = verticalAngle == -1 ? curInfo.verticalAngle : verticalAngle;
        cameraInfo.fov             = fov == -1 ? curInfo.fov: fov;
        cameraInfo.durationSmooth  = moveTime;
        cameraInfo.isBattleDisturb = isBattleDisturb;

        cameraInfo.blur            = blur;
        cameraInfo.blurDuration    = blurDuration;
        cameraInfo.blurTarget      = blurTarget;
        cameraInfo.blurOffset      = blurOffset;
        cameraInfo.blurBeginSmooth = beginSmooth;
        cameraInfo.blurEndSmooth   = endSmooth;

        if (overDuration != -1)
        {
            cameraInfo.useOverDuration   = true;
            cameraInfo.overDuationSmooth = overDuration;
        }

        CameraHandle handle = Add(cameraInfo);

        return(handle);
    }
Example #18
0
    //复制当前镜头的信息,然后对fov等进行缩放
    public CameraHandle ScaleFov(float moveTime, float stayTime, float overDuration, float fovRate, int priority,
                                 float blur, float blurDuration, float beginSmooth, float endSmooth, Vector3 blurOffset, Transform blurTarget, bool isBattleDisturb = false)
    {
        CameraInfo curInfo = CameraMgr.instance.CurHandle.m_info;

        if (curInfo.lookType == CameraInfo.enLookType.followBehind)//这种类型的暂时不能计算出推镜
        {
            return(null);
        }

        CameraInfo cameraInfo = new CameraInfo(curInfo);

        cameraInfo.duration         = moveTime + stayTime;
        cameraInfo.durationSmooth   = moveTime;
        cameraInfo.fov              = cameraInfo.fov * fovRate;
        cameraInfo.priority         = priority;
        cameraInfo.durationPriority = priority;
        cameraInfo.isBattleDisturb  = isBattleDisturb;

        cameraInfo.blur            = blur;
        cameraInfo.blurDuration    = blurDuration;
        cameraInfo.blurTarget      = blurTarget;
        cameraInfo.blurOffset      = blurOffset;
        cameraInfo.blurBeginSmooth = beginSmooth;
        cameraInfo.blurEndSmooth   = endSmooth;

        if (overDuration != -1)
        {
            cameraInfo.useOverDuration   = true;
            cameraInfo.overDuationSmooth = overDuration;
        }

        CameraHandle handle = Add(cameraInfo);

        return(handle);
    }
        public void InitLighting()
        {
            // Omni light (main light of the scene)
            Lights [(int)Light.Main] = new SCNNode {
                Name     = "omni",
                Position = new SCNVector3(0, 3, -13)
            };

            Lights [(int)Light.Main].Light = new SCNLight {
                LightType = SCNLightType.Omni,
                AttenuationStartDistance = 10,
                AttenuationEndDistance   = 50,
                Color = NSColor.Black
            };

            CameraHandle.AddChildNode(Lights [(int)Light.Main]);              //make all lights relative to the camera node


            // Front light
            Lights [(int)Light.Front] = new SCNNode {
                Name     = "front light",
                Position = new SCNVector3(0, 0, 0)
            };

            Lights [(int)Light.Front].Light = new SCNLight {
                LightType = SCNLightType.Directional,
                Color     = NSColor.Black
            };

            CameraHandle.AddChildNode(Lights [(int)Light.Front]);


            // Spot light
            Lights [(int)Light.Spot] = new SCNNode {
                Name      = "spot light",
                Transform = SCNMatrix4.Mult(SCNMatrix4.CreateFromAxisAngle(new SCNVector3(1, 0, 0), -(nfloat)(Math.PI / 2) * 0.8f), SCNMatrix4.CreateFromAxisAngle(new SCNVector3(0, 0, 1), -0.3f)),
                Position  = new SCNVector3(0, 30, -19),
                Rotation  = new SCNVector4(1, 0, 0, -(float)(Math.PI / 2))
            };

            Lights [(int)Light.Spot].Light = new SCNLight {
                LightType    = SCNLightType.Spot,
                ShadowRadius = 3,
                ZNear        = 20,
                ZFar         = 100,
                Color        = NSColor.Black,
                CastsShadow  = true
            };

            NarrowSpotlight(false);
            CameraHandle.AddChildNode(Lights [(int)Light.Spot]);


            // Left light
            Lights [(int)Light.Left] = new SCNNode {
                Name     = "left light",
                Position = new SCNVector3(-20, 10, -20),
                Rotation = new SCNVector4(0, 1, 0, (float)(Math.PI / 2))
            };

            Lights [(int)Light.Left].Light = new SCNLight {
                LightType = SCNLightType.Omni,
                AttenuationStartDistance = 30,
                AttenuationEndDistance   = 80,
                Color = NSColor.Black
            };

            CameraHandle.AddChildNode(Lights [(int)Light.Left]);


            // Right light
            Lights [(int)Light.Right] = new SCNNode {
                Name     = "right light",
                Position = new SCNVector3(20, 10, -20)
            };

            Lights [(int)Light.Right].Light = new SCNLight {
                LightType = SCNLightType.Omni,
                AttenuationStartDistance = 30,
                AttenuationEndDistance   = 80,
                Color = NSColor.Black
            };

            CameraHandle.AddChildNode(Lights [(int)Light.Right]);


            // Ambient light
            Lights [(int)Light.Ambient] = new SCNNode {
                Name = "ambient light"
            };

            Lights [(int)Light.Ambient].Light = new SCNLight {
                LightType = SCNLightType.Ambient,
                Color     = NSColor.FromCalibratedWhite(0.0f, 1.0f)
            };

            Scene.RootNode.AddChildNode(Lights [(int)Light.Ambient]);
        }
        public PresentationViewController(string path)
        {
            // Load the presentation settings from the plist file
            var settingsPath = NSBundle.MainBundle.PathForResource(path, "xml");

            SlideSettings = JsonConvert.DeserializeObject <Settings> (File.ReadAllText(settingsPath));

            SlideCache = new Dictionary <string, Slide> ();

            // Create a new empty scene
            Scene = new SCNScene();

            // Create and add a camera to the scene
            // We create three separate nodes to ease the manipulation of the global position, pitch (ie. orientation around the x axis) and relative position
            // - cameraHandle is used to control the global position in world space
            // - cameraPitch  is used to rotate the position around the x axis
            // - cameraNode   is sometimes manipulated by slides to move the camera relatively to the global position (cameraHandle). But this node is supposed to always be repositioned at (0, 0, 0) in the end of a slide.

            CameraHandle      = SCNNode.Create();
            CameraHandle.Name = "cameraHandle";
            Scene.RootNode.AddChildNode(CameraHandle);

            CameraPitch      = SCNNode.Create();
            CameraPitch.Name = "cameraPitch";
            CameraHandle.AddChildNode(CameraPitch);

            CameraNode        = SCNNode.Create();
            CameraNode.Name   = "cameraNode";
            CameraNode.Camera = new SCNCamera();

            // Set the default field of view to 70 degrees (a relatively strong perspective)
            CameraNode.Camera.XFov = 70.0;
            CameraNode.Camera.YFov = 42.0;
            CameraPitch.AddChildNode(CameraNode);

            // Setup the different lights
            InitLighting();

            // Create and add a reflective floor to the scene
            var floorMaterial = new SCNMaterial();

            floorMaterial.Ambient.Contents          = NSColor.Black;
            floorMaterial.Diffuse.Contents          = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/floor", "png"));
            floorMaterial.Diffuse.ContentsTransform = SCNMatrix4.CreateFromAxisAngle(new SCNVector3(0, 0, 1), NMath.PI / 4);
            floorMaterial.Specular.WrapS            =
                floorMaterial.Specular.WrapT        =
                    floorMaterial.Diffuse.WrapS     =
                        floorMaterial.Diffuse.WrapT = SCNWrapMode.Mirror;

            Floor = SCNFloor.Create();
            Floor.ReflectionFalloffEnd = 3.0f;
            Floor.FirstMaterial        = floorMaterial;

            var floorNode = SCNNode.Create();

            floorNode.Geometry = Floor;
            Scene.RootNode.AddChildNode(floorNode);

            floorNode.PhysicsBody    = SCNPhysicsBody.CreateStaticBody(); //make floor dynamic for physics slides
            Scene.PhysicsWorld.Speed = 0;                                 //pause physics to avoid continuous drawing

            // Use a shader modifier to support a secondary texture for some slides
            var shaderFile      = NSBundle.MainBundle.PathForResource("Shaders/floor", "shader");
            var surfaceModifier = File.ReadAllText(shaderFile);

            floorMaterial.ShaderModifiers = new SCNShaderModifiers {
                EntryPointSurface = surfaceModifier
            };

            // Set the scene to the view
            View = new SCNView(CGRect.Empty);
            ((SCNView)View).Scene           = Scene;
            ((SCNView)View).BackgroundColor = NSColor.Black;

            // black fog
            Scene.FogColor         = NSColor.FromCalibratedWhite(0, 1);
            Scene.FogEndDistance   = 45;
            Scene.FogStartDistance = 40;

            // Turn on jittering for better anti-aliasing when the scene is still
            ((SCNView)View).JitteringEnabled = true;

            // Start the presentation
            GoToSlide(0);
        }
Example #21
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();
        }
    }
        public void InitLighting()
        {
            // Omni light (main light of the scene)
            Lights [(int)Light.Main] = new SCNNode {
                Name     = "omni",
                Position = new SCNVector3(0, 3, -13)
            };

            Lights [(int)Light.Main].Light = new SCNLight {
                LightType = SCNLightType.Omni
            };

            Lights [(int)Light.Main].Light.SetAttribute(new NSNumber(10), SCNLightAttribute.AttenuationStartKey);
            Lights [(int)Light.Main].Light.SetAttribute(new NSNumber(50), SCNLightAttribute.AttenuationEndKey);
            CameraHandle.AddChildNode(Lights [(int)Light.Main]);              //make all lights relative to the camera node

            // Front light
            Lights [(int)Light.Front] = new SCNNode {
                Name     = "front light",
                Position = new SCNVector3(0, 0, 0)
            };

            Lights [(int)Light.Front].Light = new SCNLight {
                LightType = SCNLightType.Directional
            };

            CameraHandle.AddChildNode(Lights [(int)Light.Front]);

            // Spot light
            Lights [(int)Light.Spot] = new SCNNode {
                Name     = "spot light",
                Position = new SCNVector3(0, 30, -19),
                Rotation = new SCNVector4(1, 0, 0, (float)-(Math.PI / 2))
            };

            Lights [(int)Light.Spot].Light = new SCNLight {
                LightType    = SCNLightType.Spot,
                ShadowRadius = 10
            };

            Lights [(int)Light.Spot].Light.SetAttribute(new NSNumber(30), SCNLightAttribute.ShadowNearClippingKey);
            Lights [(int)Light.Spot].Light.SetAttribute(new NSNumber(50), SCNLightAttribute.ShadowFarClippingKey);
            Lights [(int)Light.Spot].Light.SetAttribute(new NSNumber(10), SCNLightAttribute.SpotInnerAngleKey);
            Lights [(int)Light.Spot].Light.SetAttribute(new NSNumber(45), SCNLightAttribute.SpotOuterAngleKey);
            CameraHandle.AddChildNode(Lights [(int)Light.Spot]);

            // Left light
            Lights [(int)Light.Left] = new SCNNode {
                Name     = "left light",
                Position = new SCNVector3(-20, 10, -5)
            };

            Lights [(int)Light.Left].Light = new SCNLight {
                LightType = SCNLightType.Omni
            };

            Lights [(int)Light.Left].Light.SetAttribute(new NSNumber(30), SCNLightAttribute.AttenuationStartKey);
            Lights [(int)Light.Left].Light.SetAttribute(new NSNumber(80), SCNLightAttribute.AttenuationEndKey);
            CameraHandle.AddChildNode(Lights [(int)Light.Left]);

            // Right light
            Lights [(int)Light.Right] = new SCNNode {
                Name     = "right light",
                Position = new SCNVector3(20, 10, -5)
            };

            Lights [(int)Light.Right].Light = new SCNLight {
                LightType = SCNLightType.Omni
            };

            Lights [(int)Light.Right].Light.SetAttribute(new NSNumber(30), SCNLightAttribute.AttenuationStartKey);
            Lights [(int)Light.Right].Light.SetAttribute(new NSNumber(80), SCNLightAttribute.AttenuationEndKey);
            CameraHandle.AddChildNode(Lights [(int)Light.Right]);

            // Ambient light
            Lights [(int)Light.Ambient] = new SCNNode {
                Name = "ambient light"
            };

            Lights [(int)Light.Ambient].Light = new SCNLight {
                LightType = SCNLightType.Ambient
            };

            Scene.RootNode.AddChildNode(Lights [(int)Light.Ambient]);

            // Switch off all the lights
            for (int i = 0; i < (int)Light.Count; i++)
            {
                Lights [i].Light.Color = NSColor.Black;
            }
        }
    public static void DrawCameraInfo(CameraInfo info, string name = "", bool isDefault = false, bool sync = false)
    {
        EditorGUILayoutEx.FadeArea area;
        Color tmp1 = GUI.color;
        Color tmp2;

        if (isDefault)
        {
            area      = EditorGUILayoutEx.instance.BeginFadeArea(info.isExpand, "", name + "_camera", EditorStyleEx.BoxStyle); //
            tmp2      = GUI.color;                                                                                             //BeginFadeArea 需要
            GUI.color = tmp1;                                                                                                  //BeginFadeArea 需要
            using (new AutoBeginHorizontal())
            {
                if (GUILayout.Button(name, EditorGUILayoutEx.defaultLabelStyle))
                {
                    info.isExpand = !info.isExpand;
                }

                if (isDefault && GUILayout.Button(EditorGUIUtility.IconContent(CameraMgr.instance.m_curCameraInfo == info ? "preAudioLoopOn" : "preAudioLoopOff"), EditorStyles.toolbarButton, GUILayout.Width(25)))
                {
                    CameraMgr.instance.Add(info, false, CameraInfo.Camera_Editor_Priority);//优先级要提高点
                    return;
                }
            }
        }
        else
        {
            area          = EditorGUILayoutEx.instance.BeginFadeArea(info.isExpand, "镜头参数", name + "_camera", EditorStyleEx.BoxStyle); //
            info.isExpand = area.open;
            tmp2          = GUI.color;                                                                                                 //BeginFadeArea 需要
            GUI.color     = tmp1;                                                                                                      //BeginFadeArea 需要
        }


        if (area.Show())      //using (AutoEditorToggleGroup tg = new AutoEditorToggleGroup(info.isExpand, "默认镜头"))
        {
            GUI.color = tmp2; //BeginFadeArea 需要

            bool needSample = false;
            //1 镜头变化相关参数

            EditorGUI.BeginChangeCheck();
            info.lookType = (CameraInfo.enLookType)EditorGUILayout.Popup("类型", (int)info.lookType, CameraInfo.LookTypeName);
            if (info.NeedShowRefPos)
            {
                using (new AutoBeginHorizontal())
                {
                    EditorGUILayout.LabelField("看的点(白)", info.refPos.ToString());

                    //在某些状态下参考点不能自动计算,这个增加一个同步按钮
                    if (GUILayout.Button("同步到跟随者", GUILayout.Width(100)))
                    {
                        info.refPos = CameraMgr.instance.GetFollowPos();
                    }
                }
            }

            using (new AutoBeginHorizontal())
            {
                EditorGUILayout.PrefixLabel(info.NeedShowRefPos ? "偏移(黄)" : "偏移");
                info.offset = EditorGUILayout.Vector3Field(GUIContent.none, info.offset, GUILayout.Height(18));
            }
            info.verticalAngle   = EditorGUILayout.Slider("高度角", info.verticalAngle, -90f, 90f);
            info.horizontalAngle = EditorGUILayout.Slider("水平角", info.horizontalAngle, 0f, 360f);
            info.fov             = EditorGUILayout.Slider("视野", info.fov, 30f, 90f);
            info.distance        = EditorGUILayout.Slider("距离", info.distance, 3f, 50f);

            info.blur            = EditorGUILayout.Slider("模糊程度", info.blur, 0f, 5f);
            info.blurDuration    = EditorGUILayout.Slider("模糊总时间", info.blurDuration, 0f, 50f);
            info.blurBeginSmooth = EditorGUILayout.Slider("开始模糊时间", info.blurBeginSmooth, 0f, 1f);
            info.blurEndSmooth   = EditorGUILayout.Slider("结束模糊时间", info.blurEndSmooth, 0f, 1f);
            using (new AutoBeginHorizontal())
            {
                EditorGUILayout.PrefixLabel("模糊偏移");
                info.blurOffset = EditorGUILayout.Vector3Field(GUIContent.none, info.blurOffset, GUILayout.Height(18));
            }


            //跟随对象和敌人之间的特有参数
            if (info.lookType == CameraInfo.enLookType.betweenTwo)
            {
                using (new AutoBeginHorizontal())
                {
                    info.useBetweenTwoLimit = EditorGUILayout.Toggle("两者距离限制", info.useBetweenTwoLimit, GUILayout.ExpandWidth(false));
                    if (info.useBetweenTwoLimit)
                    {
                        info.betweenTwoLimit = EditorGUILayout.Slider(GUIContent.none, info.betweenTwoLimit, 0f, 30f);
                    }
                }
            }
            //盯着的特有参数
            if (info.lookType == CameraInfo.enLookType.stillLook)
            {
                using (new AutoBeginHorizontal())
                {
                    info.useStilllookLimit = EditorGUILayout.Toggle("盯着最远距离", info.useStilllookLimit, GUILayout.ExpandWidth(false));
                    if (info.useStilllookLimit)
                    {
                        info.stillLookLimit = EditorGUILayout.Slider(GUIContent.none, info.stillLookLimit, 0f, 30f);
                    }
                }
            }
            //镜头轨道
            if (info.lookType == CameraInfo.enLookType.path)
            {
                info.cameraPath = (CameraPath)EditorGUILayout.ObjectField("轨道", info.cameraPath, typeof(CameraPath), true);
                info.pathLag    = EditorGUILayout.Slider("轨道镜头偏移", info.pathLag, -10, 10);
            }

            //跟随对象盯住目标
            if (info.lookType == CameraInfo.enLookType.followBehind)
            {
                info.targetId = EditorGUILayout.TextField("目标的角色id", info.targetId);
                info.bone     = EditorGUILayout.TextField("骨骼路径", info.bone);

                using (new AutoBeginHorizontal())
                {
                    EditorGUILayout.PrefixLabel("偏移");
                    info.bornOffset = EditorGUILayout.Vector3Field(GUIContent.none, info.bornOffset, GUILayout.Height(18));
                }
            }

            needSample = EditorGUI.EndChangeCheck();//改变的话要sample下

            //2 渐变和跟随控制相关
            if (!isDefault)
            {
                info.durationType = (CameraInfo.enDurationType)EditorGUILayout.Popup("置顶时渐变策略", (int)info.durationType, CameraInfo.DuratioTypeName);
            }
            info.isDurationInvalid = EditorGUILayout.Toggle("不渐变", info.isDurationInvalid);
            if (!info.isDurationInvalid)
            {
                info.durationSmooth = EditorGUILayout.Slider("渐变时间", info.durationSmooth, 0f, 10f);
                info.animationCurve = EditorGUILayout.CurveField("渐变曲线", info.animationCurve, GUILayout.Width(300f), GUILayout.Height(30f));
            }

            if (!isDefault)
            {
                info.isOverAfterDuration = EditorGUILayout.Toggle("渐变完结束", info.isOverAfterDuration);
                info.duration            = EditorGUILayout.FloatField("结束时间", info.duration);
                using (new AutoBeginHorizontal())
                {
                    info.useOverDuration = EditorGUILayout.Toggle("结束渐变时间", info.useOverDuration, GUILayout.ExpandWidth(false));
                    if (info.useOverDuration)
                    {
                        info.overDuationSmooth = EditorGUILayout.Slider(GUIContent.none, info.overDuationSmooth, 0f, 10f);
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            using (new AutoBeginHorizontal())
            {
                info.uselock = EditorGUILayout.Toggle(info.uselock ? "锁定方向(黄线)" : "锁定方向", info.uselock, GUILayout.ExpandWidth(false));
                if (info.uselock)
                {
                    //info.m_lockEuler = EditorGUILayout.Vector3Field(GUIContent.none, info.m_lockEuler, GUILayout.Height(18),GUILayout.ExpandWidth(true));
                    float yEuler = EditorGUILayout.Slider(GUIContent.none, info.lockEuler.y, 0f, 360f);
                    if (yEuler != info.lockEuler.y)
                    {
                        info.lockEuler = new Vector3(info.lockEuler.x, yEuler, info.lockEuler.z);
                    }
                }
            }
            using (new AutoEditorTipButton("看着的点距离衰减计算出的渐变速度(目的是为了让跟随对象离相机越远相机跟随越快,而离相机越进则跟随越慢),注意和渐变过程的计算出的渐变速度是取两者的最大值(也就是取慢的那个)"))
                info.useDisSmooth = EditorGUILayout.Toggle("距离渐变", info.useDisSmooth);
            if (info.useDisSmooth)
            {
                info.disSmooth      = EditorGUILayout.FloatField("距离渐变值", info.disSmooth);
                info.disSmoothLimit = EditorGUILayout.FloatField("距离渐变距离", info.disSmoothLimit);
            }
            needSample = EditorGUI.EndChangeCheck() || needSample;//锁定的相关参数变化也要同步下


            //3 sample下
            if (needSample && sync)
            {
                CameraHandle handle = CameraMgr.instance.Set(info, CameraInfo.Camera_Editor_Priority);//优先级要提高点
            }
        }
        EditorGUILayoutEx.instance.EndFadeArea();
    }