public void addCheckLayer(int layer, CHECK_DIRECTION direction, float checkDistance, float minDistance)
    {
        CheckLayer checkLayer = new CheckLayer(layer, direction, checkDistance, minDistance);

        mCheckLayer.Add(checkLayer);
        if (!mCheckDirectionList.ContainsKey(direction))
        {
            mCheckDirectionList.Add(direction, new List <CheckLayer>());
        }
        mCheckDirectionList[direction].Add(checkLayer);
    }
Example #2
0
    public void addCheckLayer(int layer, CHECK_DIRECTION direction, float checkDistance, float minDistance)
    {
        CheckLayer checkLayer = new CheckLayer(layer, direction, checkDistance, minDistance);

        mCheckLayer.Add(checkLayer);
        if (!mCheckDirectionList.TryGetValue(direction, out List <CheckLayer> layerList))
        {
            layerList = new List <CheckLayer>();
            mCheckDirectionList.Add(direction, layerList);
        }
        layerList.Add(checkLayer);
    }
Example #3
0
    //---------------------------------------------------------------------------------------------------------
    protected override void updateLinker(float elapsedTime)
    {
        if (!isFloatEqual(mNormalSpeed, mFollowPositionSpeed))
        {
            mFollowPositionSpeed = lerp(mFollowPositionSpeed, mNormalSpeed, mSpeedRecover * elapsedTime);
        }
        Vector3 targetPos = mLinkObject.getWorldPosition();
        Vector3 relative  = rotateVector3(mRelativePosition, toRadian(mLinkObject.getRotation().y));
        Vector3 nextPos   = targetPos + relative;
        Ray     ray       = new Ray();

        // 判断与地面的交点,使摄像机始终位于地面上方
        if (mCheckLayer != null && mCheckLayer.Count > 0)
        {
            // 从摄像机目标点检测
            foreach (var item in mCheckDirectionList)
            {
                List <CheckLayer> layerList = item.Value;
                int count = layerList.Count;
                for (int i = 0; i < count; ++i)
                {
                    CheckLayer layer = layerList[i];
                    ray.origin    = nextPos - layer.mDirectionVector;
                    ray.direction = layer.mDirectionVector;
                    if (Physics.Raycast(ray, out RaycastHit hit, layer.mCheckDistance, 1 << layer.mLayerIndex))
                    {
                        // 如果有碰撞到物体,交点距离在一定范围内
                        Vector3 hitPoint = ray.origin + ray.direction * hit.distance;
                        if (lengthLess(nextPos - hitPoint, layer.mMinDistance))
                        {
                            nextPos = hitPoint - layer.mDirectionVector * layer.mMinDistance;
                        }
                    }
                }
            }
        }
        // 得到摄像机当前位置
        Vector3 cameraNewPos = lerp(mCamera.getPosition(), nextPos, mFollowPositionSpeed * elapsedTime, 0.01f);

        applyRelativePosition(cameraNewPos - targetPos);
    }
 public void removeCheckLayer(int layer, CHECK_DIRECTION direction)
 {
     if (mCheckDirectionList.ContainsKey(direction))
     {
         CheckLayer        checkLayer = null;
         List <CheckLayer> layerList  = mCheckDirectionList[direction];
         int count = layerList.Count;
         for (int i = 0; i < count; ++i)
         {
             if (layerList[i].mLayerIndex == layer)
             {
                 checkLayer = layerList[i];
                 layerList.RemoveAt(i);
                 break;
             }
         }
         if (checkLayer != null)
         {
             mCheckLayer.Remove(checkLayer);
         }
     }
 }