Ejemplo n.º 1
0
    private void AddMapPlacementComponents()
    {
        if (!mapPlacement)
        {
            mapPlacement = new GameObject("MapPlacement");
            var ObstacleCamera = new GameObject("XYObstacleCamera");
            ObstacleCamera.tag = XYDefines.Tag.MainCamera;

            ObstacleCamera.transform.parent           = mapPlacement.transform;
            mapPlacement.transform.localPosition      = Vector3.zero;
            ObstacleCamera.transform.localPosition    = Vector3.zero;
            ObstacleCamera.transform.localEulerAngles = new Vector3(45.0f, 0.0f, 0.0f);

            var fc = mapPlacement.AddComponent <XYFreeCamera>();
            fc.NormalSpeed = 5;
            fc.FastSpeed   = 5;

            var camera = ObstacleCamera.AddComponent <Camera>();
            obstacleCamera_        = ObstacleCamera.AddComponent <XYObstacleCamera>();
            camera.clearFlags      = CameraClearFlags.Skybox;
            camera.backgroundColor = Color.gray;
            camera.fieldOfView     = 60;
            camera.nearClipPlane   = 0.3f;
            camera.farClipPlane    = 1000;
        }
    }
Ejemplo n.º 2
0
    void OnDrawGizmos()
    {
        GridSize = Mathf.Clamp(GridSize, 2, 24);
        if (!target_)
        {
            return;
        }
        if (!ShowBounds && !ShowGrid)
        {
            return;
        }
        bool hasBounds = GetTargetWorldBounds();

        // 绘制Grid
        if (ShowGrid)
        {
            // 将位置对齐到网格交叉点
            Vector3 pos = target_.transform.position;
            pos.x = Mathf.Floor(pos.x * 2) * 0.5f;
            pos.z = Mathf.Floor(pos.z * 2) * 0.5f;
            if (hasBounds)
            {
                pos.y = this.targetBounds_.min.y;
            }
            else
            {
                pos.y = XYObstacleCamera.GetTerrainHeight(pos);
            }
            int     halfGridCount = GridSize / 2;
            Vector3 p1            = pos;
            p1.x -= halfGridCount;
            p1.z -= halfGridCount;
            Vector3 p2 = pos;
            p2.x        += halfGridCount;
            p2.z        += halfGridCount;
            Gizmos.color = GridColor;
            for (float x = p1.x; x <= p2.x; x += 0.5f)
            {
                Gizmos.DrawLine(new Vector3(x, pos.y, p1.z), new Vector3(x, pos.y, p2.z));
            }
            for (float z = p1.z; z <= p2.z; z += 0.5f)
            {
                Gizmos.DrawLine(new Vector3(p1.x, pos.y, z), new Vector3(p2.x, pos.y, z));
            }
        }
        // 绘制Bounds
        if (hasBounds && ShowBounds)
        {
            Gizmos.color = BoundsColor;
            Gizmos.DrawWireCube(targetBounds_.center, targetBounds_.size);
        }
    }