コード例 #1
0
        /// <summary>
        /// 创建代理
        /// </summary>
        private void CreateItem(DataTypeEnum dataType)
        {
            //  获取持续时间
            _entranceDisplayTime      = _manager.cutEffectConfig.UpDownDisplayDurTime;
            _startingTimeWithOutDelay = _entranceDisplayTime;

            //  初始化 config
            _displayBehaviorConfig = new DisplayBehaviorConfig();
            _sceneUtil             = new SceneUtils(_manager, _sceneConfig.isKinect);

            //int _column = _manager.managerConfig.Column;


            int _column = 0;

            if (_sceneConfig.isKinect == 0)
            {
                _column = _manager.managerConfig.Column;
            }
            else
            {
                _column = _manager.managerConfig.KinectColumn;
            }


            int   _itemWidth = _sceneUtil.GetFixedItemWidth();
            float gap        = _sceneUtil.GetGap();

            //从下往上,从左往右
            for (int j = 0; j < _column; j++)
            {
                int row = 0;
                // 获取该列的 gen_y

                ItemPositionInfoBean itemPositionInfoBean;
                if (_displayBehaviorConfig.columnAgentsDic.ContainsKey(j))
                {
                    itemPositionInfoBean = _displayBehaviorConfig.columnAgentsDic[j];
                }
                else
                {
                    itemPositionInfoBean = new ItemPositionInfoBean();
                    _displayBehaviorConfig.columnAgentsDic.Add(j, itemPositionInfoBean);
                }

                int gen_y_position = itemPositionInfoBean.yposition;

                while (gen_y_position < _manager.mainPanel.rect.height)
                {
                    // 获取数据
                    //FlockData data = _daoService.GetFlockData(dataType);
                    FlockData data = _daoService
                                     .GetFlockDataByScene(dataType, _manager.SceneIndex);

                    Sprite coverSprite = data.GetCoverSprite();
                    float  itemHeigth  = AppUtils.GetSpriteHeightByWidth(coverSprite, _itemWidth);

                    int ori_x = Mathf.RoundToInt(_sceneUtil.GetXPositionByFixedWidth(_itemWidth, j));
                    int ori_y = Mathf.RoundToInt(gen_y_position + itemHeigth / 2);

                    // 获取出生位置
                    float gen_x, gen_y;

                    // 计算移动的目标位置
                    if (j % 2 == 0)
                    {
                        //偶数列向下偏移itemHeight
                        gen_y = ori_y - (itemHeigth + gap);
                    }
                    else
                    {
                        //奇数列向上偏移itemHeight
                        gen_y = ori_y + itemHeigth + gap;
                    }
                    gen_x = ori_x; //横坐标不变

                    // 创建agent
                    //FlockAgent go = ItemsFactory.Generate(gen_x, gen_y, ori_x, ori_y, row, j,
                    //         _itemWidth, itemHeigth, data, AgentContainerType.MainPanel);
                    //go.NextVector2 = new Vector2(gen_x, gen_y);
                    FlockAgent go = FlockAgentFactoryInstance.Generate(_manager, new Vector2(gen_x, gen_y), AgentContainerType.MainPanel
                                                                       , ori_x, ori_y, row, j, _itemWidth, itemHeigth, data, _sceneConfig.daoTypeEnum);
                    go.flockStatus = FlockStatusEnum.RUNIN;

                    gen_y_position = Mathf.RoundToInt(gen_y_position + itemHeigth + gap);
                    _displayBehaviorConfig.columnAgentsDic[j].yposition    = gen_y_position;
                    _displayBehaviorConfig.columnAgentsDic[j].xPositionMin = Mathf.RoundToInt(0 - gap);
                    _displayBehaviorConfig.columnAgentsDic[j].yPositionMin = Mathf.RoundToInt(0 - gap);
                    _displayBehaviorConfig.columnAgentsDic[j].row          = row;
                    row++;
                }
            }

            _displayBehaviorConfig.dataType    = _dataTypeEnum;
            _displayBehaviorConfig.Manager     = _manager;
            _displayBehaviorConfig.sceneUtils  = _sceneUtil;
            _displayBehaviorConfig.sceneConfig = _sceneConfig;

            _onCreateAgentCompleted.Invoke(_displayBehaviorConfig);
        }
コード例 #2
0
        private void CreateItem(DataTypeEnum dataType)
        {
            //  获取持续时间
            _entranceDisplayTime      = _manager.cutEffectConfig.LeftRightDisplayDurTime;
            _startingTimeWithOutDelay = _entranceDisplayTime;

            //  初始化 config
            _displayBehaviorConfig = new DisplayBehaviorConfig();
            _sceneUtil             = new SceneUtils(_manager, _sceneConfig.isKinect);

            List <FlockAgent> agents = new List <FlockAgent>();

            _displayBehaviorConfig.dataType   = dataType;
            _displayBehaviorConfig.sceneUtils = _sceneUtil;


            int _column = 0;

            if (_sceneConfig.isKinect == 0)
            {
                _column = _manager.managerConfig.Column;
            }
            else
            {
                _column = _manager.managerConfig.KinectColumn;
            }

            int   _itemWidth = _sceneUtil.GetFixedItemWidth();
            float gap        = _sceneUtil.GetGap();


            int middleX = _column / 2;

            //从下往上,从左往右
            for (int j = 0; j < _column; j++)
            {
                int row = 0;

                // 获取该列的 gen_y
                ItemPositionInfoBean itemPositionInfoBean;
                if (_displayBehaviorConfig.columnAgentsDic.ContainsKey(j))
                {
                    itemPositionInfoBean = _displayBehaviorConfig.columnAgentsDic[j];
                }
                else
                {
                    itemPositionInfoBean = new ItemPositionInfoBean();
                    _displayBehaviorConfig.columnAgentsDic.Add(j, itemPositionInfoBean);
                }

                int gen_y_position = itemPositionInfoBean.yposition;
                int ori_x          = Mathf.RoundToInt(_sceneUtil.GetXPositionByFixedWidth(_itemWidth, j));

                while (gen_y_position < _manager.mainPanel.rect.height)
                {
                    // 获取数据
                    //FlockData data = _daoService.GetFlockData(dataType);
                    FlockData data        = _daoService.GetFlockDataByScene(dataType, _manager.SceneIndex);
                    Sprite    coverSprite = data.GetCoverSprite();
                    float     itemHeigth  = AppUtils.GetSpriteHeightByWidth(coverSprite, _itemWidth);

                    int ori_y = Mathf.RoundToInt(gen_y_position + itemHeigth / 2);

                    float minDelay = 0;
                    //float maxDelay = middleX * 0.05f;
                    float maxDelay = _manager.cutEffectConfig.MidDisperseDelayMax;
                    int   offset   = Mathf.Abs(middleX - j);

                    float k = (float)offset / (float)middleX;
                    Func <float, float> easeFunction = EasingFunction.Get(_manager.cutEffectConfig.MidDisperseMoveEaseEnum);
                    k = easeFunction(k);

                    //float delay = Mathf.Lerp(minDelay, maxDelay, k);
                    float delay = 0;
                    float gen_x, gen_y;

                    gen_x = middleX * (_itemWidth + gap) + (_itemWidth / 2);
                    gen_y = ori_y + itemHeigth / 3
                            + itemHeigth * _manager.cutEffectConfig.MidDisperseHeightFactor;

                    // 创建agent
                    //FlockAgent go = ItemsFactory.Generate(gen_x, gen_y, ori_x, ori_y, row, j,
                    //         _itemWidth, itemHeigth, data, AgentContainerType.MainPanel);

                    FlockAgent go = FlockAgentFactoryInstance.Generate(_manager, new Vector2(gen_x, gen_y), AgentContainerType.MainPanel
                                                                       , ori_x, ori_y, row, j, _itemWidth, itemHeigth, data, _sceneConfig.daoTypeEnum);

                    go.flockStatus = FlockStatusEnum.RUNIN;

                    // 初始化透明度
                    go.UpdateImageAlpha(0.1f);

                    go.Delay = delay;
                    agents.Add(go);
                    //go.UpdateImageAlpha(1f - Mathf.Abs(j - middleX)*0.05f);
                    if (delay > _startDelayTime)
                    {
                        _startDelayTime = delay;
                    }

                    gen_y_position = Mathf.RoundToInt(gen_y_position + itemHeigth + gap);
                    _displayBehaviorConfig.columnAgentsDic[j].yposition = gen_y_position;
                    _displayBehaviorConfig.columnAgentsDic[j].row       = row;
                    row++;
                }
            }

            // 调整显示的前后
            agents.Sort((x, y) =>
            {
                return(Mathf.Abs(x.Y - middleX).CompareTo(Mathf.Abs(y.Y - middleX)));
            });

            for (int i = 0; i < agents.Count; i++)
            {
                agents[i].GetComponent <RectTransform>().SetAsFirstSibling();
            }


            // 调整启动动画的时间
            _entranceDisplayTime = _startingTimeWithOutDelay + _startDelayTime + 0.05f;

            _displayBehaviorConfig.dataType    = _dataTypeEnum;
            _displayBehaviorConfig.Manager     = _manager;
            _displayBehaviorConfig.sceneUtils  = _sceneUtil;
            _displayBehaviorConfig.sceneConfig = _sceneConfig;


            _onCreateAgentCompleted.Invoke(_displayBehaviorConfig);
        }