Пример #1
0
        /// <summary>
        /// 初始化场景Cubes
        /// </summary>
        /// <param name="prefabCube"></param>
        /// <param name="row"></param>
        /// <param name="colomn"></param>
        private void InitCubes(UnityEngine.GameObject prefabCube)
        {
            Vector3 firstCubePosition = new Vector3(-GlobalConfig.ITEM_SIZE * 0.5f * (m_Colomn - 1), 0, GlobalConfig.ITEM_SIZE * 0.5f * (m_Row - 1));
            int     index             = 0;

            for (int i = 0; i < m_Row; i++)
            {
                for (int j = 0; j < m_Colomn; j++)
                {
                    Vector3 initPosition = new Vector3(firstCubePosition.x + GlobalConfig.ITEM_SIZE * j, 0,
                                                       firstCubePosition.z - GlobalConfig.ITEM_SIZE * i);
                    GameObject cube = UnityEngine.GameObject.Instantiate(prefabCube, initPosition, Quaternion.identity);
                    cube.transform.SetParent(m_CubeContainer);
                    cube.name = $"CubeItem{index}";
                    cube.transform.localEulerAngles = new Vector3(-90, 0, 0);

                    m_TempCubeItem = m_CubeItemPool.Alloc();
                    m_TempCubeItem.Init(i, j, cube.GetComponent <Transform>());
                    m_CubeItems.Add(m_TempCubeItem);
                    index++;
                }
            }
            m_FirstPosition = m_CubeItems[0].Transform.position;
            m_LastPosition  = m_CubeItems[m_CubeItems.Count - 1].Transform.position;
            Kernel.AssetManager.ReleaseGameObjectAsync(m_CubePrefab);
        }
Пример #2
0
        public override void OnRelease()
        {
            m_CubeItems.Clear();
            m_TargetList.Clear();
            m_SlideTransforms.Clear();
            m_SlideOriginPositions.Clear();
            Kernel.EventCenter.RemoveListen((int)SlideEventNames.CubeSlide, OnCubeSlide);

            ClearCubeContainer();
            m_CubeContainer = null;
            m_CurrentItem   = null;
            m_CubeItemPool.Release(m_TempCubeItem);
        }
Пример #3
0
        private List <CubeItem> GetTargetRowList(CubeItem item)
        {
            List <CubeItem> m_RetList = new List <CubeItem>();
            int             count     = m_CubeItems.Count;

            for (int i = 0; i < count; i++)
            {
                if (m_CubeItems[i].BelongRow == item.BelongRow)
                {
                    m_RetList.Add(m_CubeItems[i]);
                }
            }
            return(m_RetList);
        }
Пример #4
0
        /// <summary>
        /// Cube滑动事件
        /// </summary>
        /// <param name="eventId"></param>
        /// <param name="isImmediately"></param>
        /// <param name="data"></param>
        private void OnCubeSlide(int eventId, bool isImmediately, IUserData data)
        {
            if (m_CanSlide)
            {
                return;
            }
            SlideData slideData = (SlideData)data;

            if (CheckSlideCondition(slideData.startPosition, slideData.endPosition))
            {
                m_CurrentItem    = GetHitCubeItem(slideData.transform);
                m_SlideDirection = GetSlideDirection(slideData.startPosition, slideData.endPosition);
                if (m_CurrentItem == null)
                {
                    //Debug.Log("hit is null!");
                    return;
                }
                m_TargetList.Clear();
                m_SlideTransforms.Clear();
                m_SlideOriginPositions.Clear();

                if (m_SlideDirection == Vector3.left)
                {
                    m_TargetList = GetTargetRowList(m_CurrentItem);
                    DoLeftOrder(m_TargetList);
                }
                else if (m_SlideDirection == Vector3.right)
                {
                    m_TargetList = GetTargetRowList(m_CurrentItem);
                    DoRightOrder(m_TargetList);
                }
                else if (m_SlideDirection == Vector3.forward)
                {
                    m_TargetList = GetTargetColomnList(m_CurrentItem);
                    DoUpOrder(m_TargetList);
                }
                else
                {
                    m_TargetList = GetTargetColomnList(m_CurrentItem);
                    DoDownOrder(m_TargetList);
                }
            }
        }