chenxin
2020-11-25 b2722bf84115092dcf61a0f612b737c20eb11f27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using UnityEngine;
 
namespace Core.Camera
{
    /// <summary>
    /// Simple class to set some initial state values for the camera
    /// </summary>
    [RequireComponent(typeof(CameraRig))]
    public class CameraInitialState : MonoBehaviour
    {
        public enum StartZoomMode
        {
            NoChange,
            FurthestZoom,
            NearestZoom
        }
 
        /// <summary>
        /// Determines the starting zoom level for the camera
        /// </summary>
        public StartZoomMode startZoomMode;
        
        /// <summary>
        /// Object for the camera to look at initially
        /// </summary>
        public Transform initialLookAt;
        
        /// <summary>
        /// On start, set camera parameters
        /// </summary>
        protected virtual void Start()
        {
            var rig = GetComponent<CameraRig>();
 
            switch (startZoomMode)
            {
                case StartZoomMode.FurthestZoom:
                    rig.SetZoom(rig.furthestZoom);
                    break;
                case StartZoomMode.NearestZoom:
                    rig.SetZoom(rig.nearestZoom);
                    break;
            }
 
            if (initialLookAt != null)
            {
                rig.PanTo(initialLookAt.transform.position);
            }
        }
    }
}