예제 #1
0
파일: RotatorSystem.cs 프로젝트: Noyau/ECS
        private IEnumerator Start()
        {
            if (m_template == null || m_templateSize < 1e-3F || m_gridSize < 1)
                yield break;

            enabled = false;

            m_template.SetActive(false);

            int _count = m_gridSize * m_gridSize * m_gridSize;

            m_onBeginLoading.Invoke(_count);

            yield return null;

            Transform _root = new GameObject("Rotators").transform;

            Vector3 _size = m_templateSize * Vector3.one;
            Vector3 _offset = m_gridSize * _size * .5F;

            int _chunkSize = m_chunkSize > 0F
                ? Mathf.RoundToInt(_count * m_chunkSize)
                : 0;

            for (int i = 0; i < _count; ++i)
            {
                int _x = i % m_gridSize;
                int _y = (i / m_gridSize) % m_gridSize;
                int _z = i / (m_gridSize * m_gridSize);

                Vector3 _position = new Vector3
                {
                    x = _size.x * _x - _offset.x,
                    y = _size.y * _y - _offset.y,
                    z = _size.z * _z - _offset.z,
                };

                Transform _chunk = Instantiate(m_template).transform;
                _chunk.name = $"{m_template.name} ({_x}x{_y}x{_z})";
                _chunk.SetParent(_root, false);
                _chunk.localPosition = _position;
                _chunk.gameObject.SetActive(true);

                if (_chunkSize == 0 || (i > 0 && (i % _chunkSize) == 0))
                {
                    m_onLoading.Invoke(i);
                    yield return null;
                }
            }

            m_onEndLoading.Invoke(_count);

            Destroy(m_template);

            enabled = true;
        }
예제 #2
0
        private void Update()
        {
            var done = Done;

            if (done >= 1)
            {
                mLoadEnd.Invoke();
                enabled = false;
                return;
            }
            mLoading.Invoke(this);
        }
 public void OnLoading(float _progress)
 {
     if (onLoading != null)
     {
         try
         {
             onLoading.Invoke(_progress);
         }
         catch (System.Exception exception)
         {
             Debug.LogError("Couldn't invoke event onLoading. Error: " + exception.Message);
         }
     }
 }