summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/MaterializeFX/Scripts/Utils/DemoPrefabController.cs
blob: d1c108bbf2f972485adbbe17702875f064c8c771 (plain)
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
using UnityEngine;

namespace Assets.MaterializeFX.Scripts.Utils
{
    internal sealed class DemoPrefabController : MonoBehaviour
    {
        public int StartNum;
        public GameObject[] Prefabs;

        private GameObject _currentInstance;
        private int _currentPrefabNum;

        public void Next()
        {
            if (Prefabs.Length == 0)
                return;

            _currentPrefabNum++;
            if (_currentPrefabNum >= Prefabs.Length)
                _currentPrefabNum = 0;

            ChangePrefab(_currentPrefabNum);
        }

        private void Start()
        {
            _currentPrefabNum = StartNum;

            ChangePrefab(_currentPrefabNum);
        }

        private void ChangePrefab(int num)
        {
            if (_currentInstance != null)
                Destroy(_currentInstance);
            var newPrefab = Prefabs[num];
            _currentInstance = Instantiate(newPrefab, newPrefab.transform.position, newPrefab.transform.transform.rotation);
            _currentInstance.SetActive(true);
        }
    }
}