wangguan
2020-12-02 cf99ef52be344ac7dd3ba28dd51c63dd5de38a4b
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using UnityEngine;
 
namespace Core.UI
{
    /// <summary>
    /// Abstract base class for menu pages which animates the process of enabling and disabling
    /// Handles activation/deactivation of the page
    /// </summary>
    public abstract class AnimatingMainMenuPage : MonoBehaviour, IMainMenuPage
    {
        /// <summary>
        /// Canvas to disable. If this object is set, then the canvas is disabled instead of the game object 
        /// </summary>
        public Canvas canvas;
        
        /// <summary>
        /// Deactivates this page
        /// </summary>
        public virtual void Hide()
        {
            BeginDeactivatingPage();
        }
 
        /// <summary>
        /// Activates this page
        /// </summary>
        public virtual void Show()
        {
            BeginActivatingPage();
        }
 
        /// <summary>
        /// Starts the deactivation process. e.g. begins fading page out. Call FinishedDeactivatingPage when done
        /// </summary>
        protected abstract void BeginDeactivatingPage();
 
        /// <summary>
        /// Ends the deactivation process and turns off the associated gameObject/canvas
        /// </summary>
        protected virtual void FinishedDeactivatingPage()
        {
            if (canvas != null)
            {
                canvas.enabled = false;
            }
            else
            {
                gameObject.SetActive(false);
            }
        }
 
        /// <summary>
        /// Starts the activation process by turning on the associated gameObject/canvas.  Call FinishedActivatingPage when done
        /// </summary>
        protected virtual void BeginActivatingPage()
        {
            if (canvas != null)
            {
                canvas.enabled = true;
            }
            else
            {
                gameObject.SetActive(true);
            }
        }
 
        /// <summary>
        /// Finishes the activation process. e.g. Turning on input
        /// </summary>
        protected abstract void FinishedActivatingPage();
    }
}