private void FillAgents(DataTypeEnum dataType) { //Debug.Log("Fill Agents"); float gap = _displayBehaviorConfig.sceneUtils.GetGap(); // 获取右侧最小的距离 var columnAgentsDic = _displayBehaviorConfig.columnAgentsDic; // 查看每一列顶部是否已低于阈值 int column = 0; // 最短的列下表 int last_y = int.MaxValue; ItemPositionInfoBean bean = new ItemPositionInfoBean(); foreach (KeyValuePair <int, ItemPositionInfoBean> keyValuePair in columnAgentsDic) { if (keyValuePair.Value.yposition < last_y) { last_y = keyValuePair.Value.yposition; column = keyValuePair.Key; bean = keyValuePair.Value; } } // 定义偏差值 (因实际运行时会出现延时) float deviationValue = _displayBehaviorConfig.sceneUtils.GetFixedItemWidth() / 2; // 超过屏幕的距离 float overDistense = last_y - Screen.height - deviationValue; if ((overDistense - _manager.PanelOffsetY) < 0) { if (flag == false) { flag = true; int itemwidth = _displayBehaviorConfig.sceneUtils.GetFixedItemWidth(); //在该列上补充一个 //FlockData data = _daoService.GetFlockData(dataType); FlockData data = _daoService.GetFlockDataByScene(dataType, _manager.SceneIndex); Sprite coverSprite = data.GetCoverSprite(); int itemHeight = Mathf.RoundToInt(AppUtils.GetSpriteHeightByWidth(coverSprite, itemwidth)); float ori_x = _displayBehaviorConfig.sceneUtils.GetXPositionByFixedWidth(itemwidth, column); float ori_y = Mathf.RoundToInt(last_y + itemHeight / 2); int row = bean.row + 1; // 创建agent //FlockAgent go = _displayBehaviorConfig.ItemsFactory.Generate(ori_x, ori_y, ori_x, ori_y, row, column, // itemwidth, itemHeight, data, AgentContainerType.MainPanel); FlockAgent go = FlockAgentFactoryInstance.Generate(_manager, new Vector2(ori_x, ori_y), AgentContainerType.MainPanel , ori_x, ori_y, row, column, itemwidth, itemHeight, data, _displayBehaviorConfig.sceneConfig.daoTypeEnum); go.flockStatus = FlockStatusEnum.NORMAL; go.NextVector2 = new Vector2(ori_x, ori_y); // 完成创建更新字典 last_y = Mathf.RoundToInt(last_y + itemHeight + gap); _displayBehaviorConfig.columnAgentsDic[column].yposition = last_y; _displayBehaviorConfig.columnAgentsDic[column].row = row; flag = false; } } }
private FlockAgent CreateNewAgent(bool randomZ) { if (!randomZ) { //Debug.Log("添加星空块。"); } // 获取数据 //FlockData data = _daoService.GetFlockData(_dataType,_manager);\ FlockData data = _daoService.GetFlockDataByScene(_dataType, _manager.SceneIndex); // 获取出生位置 Vector2 randomPosition = UnityEngine.Random.insideUnitSphere; Vector3 position = new Vector3(); position.x = (randomPosition.x / 2 + 0.5f) * _manager.GetScreenRect().x; position.y = (randomPosition.y / 2 + 0.5f) * _manager.GetScreenRect().y; // 获取长宽 Sprite logoSprite = data.GetCoverSprite(); float width = _sceneUtil.ResetTexture(new Vector2(logoSprite.rect.width, logoSprite.rect.height)).x; float height = _sceneUtil.ResetTexture(new Vector2(logoSprite.rect.width, logoSprite.rect.height)).y; //FlockAgent go = _itemFactory.Generate(position.x, position.y, position.x, position.y, 0, 0, // width, height, data, AgentContainerType.StarContainer); FlockAgent go = FlockAgentFactoryInstance.Generate(_manager, position, AgentContainerType.StarContainer, position.x, position.y, 0, 0, width, height, data, _sceneConfig.daoTypeEnum); go.UpdateImageAlpha(0); // 星空效果不会被物理特效影响 //go.CanEffected = false; go.flockStatus = FlockStatusEnum.STAR; go.isStarEffect = true; // 设置Z轴 float z; if (randomZ) { z = Mathf.Lerp(_manager.cutEffectConfig.StarEffectOriginPoint, _manager.cutEffectConfig.StarEffectEndPoint, UnityEngine.Random.Range(0f, 1f)); } else { z = _manager.cutEffectConfig.StarEffectOriginPoint; } go.GetComponent <RectTransform>().anchoredPosition3D = go.GetComponent <RectTransform>().anchoredPosition3D + new Vector3(0, 0, z); go.Z = z; go.name = "Agent-" + Mathf.RoundToInt(go.Z); _activeAgents.Add(go); return(go); }
/// <summary> /// 当条件达成时,补一列 /// </summary> /// <param name="dataType"></param> private void FillItem(DataTypeEnum dataType) { int generatePositionX = _displayBehaviorConfig.generatePositionX; int generatePositionXInBack = _displayBehaviorConfig.generatePositionXInBack; int row = _manager.cutEffectConfig.FrontBackRow; // 补充前排 if ((generatePositionX - _manager.mainPanel.rect.width) < _manager.PanelOffsetX) { int itemHeight = _displayBehaviorConfig.sceneUtils.GetFixedItemHeight(); int gap = _displayBehaviorConfig.sceneUtils.GetGap(); int generate_x_temp = 0; // 创造一列前排 int column = _displayBehaviorConfig.Column; bool isOddColumn = column % 2 == 0; for (int i = 0; i < row; i++) { // 获取行数奇数状态 bool isOddRow = i % 2 == 0; if ((isOddColumn && isOddRow) || (!isOddRow && !isOddColumn)) { // 获取要创建的内容 //FlockData agent = _daoService.GetFlockData(dataType); FlockData agent = _daoService.GetFlockDataByScene(dataType, _manager.SceneIndex); Sprite coverSprite = agent.GetCoverSprite(); float imageWidth = coverSprite.rect.width; float imageHeight = coverSprite.rect.height; // 得到调整后的长宽 Vector2 imageSize = _displayBehaviorConfig.sceneUtils.ResetTexture(new Vector2(imageWidth, imageHeight)); imageSize.x = (imageSize.x * 1.5f); imageSize.y = (imageSize.y * 1.5f); FlockAgent go; float ori_y = _displayBehaviorConfig.sceneUtils.GetYPositionByFixedHeight(itemHeight, i); float ori_x = generatePositionX + gap + imageSize.x / 2; if (ori_x + gap + imageSize.x / 2 > generate_x_temp) { generate_x_temp = Mathf.RoundToInt(ori_x + gap + imageSize.x / 2); } // 创建前排 //go = _displayBehaviorConfig.ItemsFactory.Generate(ori_x, ori_y, ori_x, ori_y, i, column, // imageSize.x, imageSize.y, agent, AgentContainerType.MainPanel); go = FlockAgentFactoryInstance.Generate(_manager, new Vector2(ori_x, ori_y), AgentContainerType.MainPanel , ori_x, ori_y, i, column, imageSize.x, imageSize.y, agent, _displayBehaviorConfig.sceneConfig.daoTypeEnum); go.flockStatus = FlockStatusEnum.NORMAL; } else { continue; } } // 更新 generate_x 的值 int generate_x = Mathf.RoundToInt(generate_x_temp); _displayBehaviorConfig.generatePositionX = generate_x; //_displayBehaviorConfig.generatePositionXInBack = generate_x; _displayBehaviorConfig.Column = column + 1; } // 补充后排 if ((generatePositionXInBack - _manager.mainPanel.rect.width) < _manager.PanelBackOffsetX) { int itemHeight = _displayBehaviorConfig.sceneUtils.GetFixedItemHeight(); int gap = _displayBehaviorConfig.sceneUtils.GetGap(); int generate_x_temp = 0; // 创造一列前排 int column = _displayBehaviorConfig.ColumnInBack; bool isOddColumn = column % 2 == 0; for (int i = 0; i < row; i++) { // 获取行数奇数状态 bool isOddRow = i % 2 == 0; if ((isOddColumn && isOddRow) || (!isOddRow && !isOddColumn)) { continue; } else { // 获取要创建的内容 //FlockData agent = _daoService.GetFlockData(dataType); FlockData agent = _daoService.GetFlockDataByScene(dataType, _manager.SceneIndex); Sprite coverSprite = agent.GetCoverSprite(); float imageWidth = coverSprite.rect.width; float imageHeight = coverSprite.rect.height; // 得到调整后的长宽 Vector2 imageSize = _displayBehaviorConfig.sceneUtils.ResetTexture(new Vector2(imageWidth, imageHeight)); imageSize.x = (imageSize.x * 1.5f); imageSize.y = (imageSize.y * 1.5f); FlockAgent go; float ori_y = _displayBehaviorConfig.sceneUtils.GetYPositionByFixedHeight(itemHeight, i); float ori_x = generatePositionXInBack + gap + imageSize.x / 2; if (ori_x + gap + imageSize.x / 2 > generate_x_temp) { generate_x_temp = Mathf.RoundToInt(ori_x + gap + imageSize.x / 2); } // 创建后排 float width = imageSize.x * 0.6f; float height = imageSize.y * 0.6f; // 创建前排 //go = _displayBehaviorConfig.ItemsFactory.Generate(ori_x, ori_y, ori_x, ori_y, i, column, // width, height, agent, AgentContainerType.BackPanel); go = FlockAgentFactoryInstance.Generate(_manager, new Vector2(ori_x, ori_y), AgentContainerType.BackPanel , ori_x, ori_y, i, column, width, height, agent, _displayBehaviorConfig.sceneConfig.daoTypeEnum); go.flockStatus = FlockStatusEnum.NORMAL; go.NextVector2 = new Vector2(ori_x, ori_y); //go.UpdateImageAlpha(0.2f); } } // 更新 generate_x 的值 int generate_x = Mathf.RoundToInt(generate_x_temp); _displayBehaviorConfig.generatePositionXInBack = generate_x; _displayBehaviorConfig.ColumnInBack = column + 1; } }
private void CreateItem(DataTypeEnum dataType) { // 获取持续时间 _entranceDisplayTime = _manager.cutEffectConfig.CurveStaggerDisplayDurTime; _startingTimeWithOutDelay = _entranceDisplayTime; // 初始化 config _displayBehaviorConfig = new DisplayBehaviorConfig(); _sceneUtil = new SceneUtils(_manager, _sceneConfig.isKinect); // 固定高度 int _row = _manager.managerConfig.Row; if (_sceneConfig.isKinect == 1) { _row = _manager.managerConfig.KinectRow; } int _itemHeight = _sceneUtil.GetFixedItemHeight(); float gap = _sceneUtil.GetGap(); int _nearColumn = Mathf.RoundToInt(_manager.mainPanel.rect.width / (_itemHeight + gap)); float w = _manager.mainPanel.rect.width; // 从上至下,生成 for (int row = 0; row < _row; row++) { int column = 0; ItemPositionInfoBean itemPositionInfoBean; if (_displayBehaviorConfig.rowAgentsDic.ContainsKey(row)) { itemPositionInfoBean = _displayBehaviorConfig.rowAgentsDic[row]; } else { itemPositionInfoBean = new ItemPositionInfoBean(); _displayBehaviorConfig.rowAgentsDic.Add(row, itemPositionInfoBean); } int gen_x_position = itemPositionInfoBean.xposition; while (gen_x_position < _manager.mainPanel.rect.width) { // 获取数据 //FlockData data = _daoService.GetFlockData(dataType); FlockData data = _daoService.GetFlockDataByScene(dataType, _manager.SceneIndex); Sprite coverSprite = data.GetCoverSprite(); float itemWidth = AppUtils.GetSpriteWidthByHeight(coverSprite, _itemHeight); int ori_y = Mathf.RoundToInt(_sceneUtil.GetYPositionByFixedHeight(_itemHeight, row)); int ori_x = Mathf.RoundToInt(gen_x_position + itemWidth / 2 + gap / 2); int middleY = _row / 2; int middleX = _nearColumn / 2; float delayX = column * 0.06f; float delayY; // 定义源位置 float gen_x, gen_y; if (row < middleY) { delayY = System.Math.Abs(middleY - row) * 0.3f; gen_x = w + (middleY - row) * 500; gen_y = w - ori_x + (_row - 1) * _itemHeight; } else { delayY = (System.Math.Abs(middleY - row) + 1) * 0.3f; gen_x = w + (row - middleY + 1) * 500; gen_y = -(w - ori_x) + 2 * _itemHeight; } //生成 agent Vector2 genPosition = new Vector2(gen_x, gen_y); FlockAgent go = FlockAgentFactoryInstance.Generate(_manager, genPosition, AgentContainerType.MainPanel , ori_x, ori_y, row, column, itemWidth, _itemHeight, data, _sceneConfig.daoTypeEnum); go.flockStatus = FlockStatusEnum.RUNIN; // 装载延迟参数 go.DelayX = delayX; go.DelayY = delayY; // 生成透明度动画 go.GetComponentInChildren <Image>().DOFade(0, _entranceDisplayTime - delayX + delayY).From(); // 获取启动动画的延迟时间 if ((delayY - delayX) > _startDelayTime) { _startDelayTime = delayY - delayX; } gen_x_position = Mathf.RoundToInt(gen_x_position + itemWidth + gap / 2); _displayBehaviorConfig.rowAgentsDic[row].xposition = gen_x_position; _displayBehaviorConfig.rowAgentsDic[row].xPositionMin = 0; _displayBehaviorConfig.rowAgentsDic[row].column = column; column++; } } _entranceDisplayTime += _startDelayTime; _displayBehaviorConfig.dataType = _dataTypeEnum; _displayBehaviorConfig.Manager = _manager; _displayBehaviorConfig.sceneUtils = _sceneUtil; _displayBehaviorConfig.sceneConfig = _sceneConfig; _onCreateAgentCompleted.Invoke(_displayBehaviorConfig); }
/// <summary> /// 创建的代理 /// </summary> private void CreateItem(DataTypeEnum type) { // 初始化 config _displayBehaviorConfig = new DisplayBehaviorConfig(); _sceneUtil = new SceneUtils(_manager, _sceneConfig.isKinect); _row = _manager.cutEffectConfig.FrontBackRow; int itemHeight = _sceneUtil.GetFixedItemHeight(); float gap = _sceneUtil.GetGap(); float w = _manager.mainPanel.rect.width; // 获取总宽度 int column = 0; // 列数 int generate_x = 0; // 生成新 agent 的位置 // 按列创建, 隔行创建 while (generate_x < w) { // 获取列数奇数状态 bool isOddColumn = column % 2 == 0; float generate_x_temp = 0; for (int i = 0; i < _row; i++) { // 获取行数奇数状态 bool isOddRow = i % 2 == 0; // 获取要创建的内容 FlockData agent = _manager.daoServiceFactory.GetDaoService(_sceneConfig.daoTypeEnum).GetFlockDataByScene(type, _manager.SceneIndex); Sprite coverSprite = agent.GetCoverSprite(); float imageWidth = coverSprite.rect.width; float imageHeight = coverSprite.rect.height; // 得到调整后的长宽 Vector2 imageSize = _sceneUtil.ResetTexture(new Vector2(imageWidth, imageHeight)); imageSize.x = (imageSize.x * 1.5f); imageSize.y = (imageSize.y * 1.5f); //Vector2 imageSize = AppUtils.ResetTexture(new Vector2(imageWidth, imageHeight), // _manager.displayFactor); FlockAgent go; float ori_y = _sceneUtil.GetYPositionByFixedHeight(itemHeight, i); float ori_x = generate_x + gap + imageSize.x / 2; if (ori_x + gap + imageSize.x / 2 > generate_x_temp) { generate_x_temp = ori_x + gap + imageSize.x / 2; } // 定义生成位置 float gen_x, gen_y; gen_x = _manager.mainPanel.rect.width + imageSize.x + gap; gen_y = ori_y; if ((isOddColumn && isOddRow) || (!isOddRow && !isOddColumn)) { // 创建前排 //go = ItemsFactory.Generate(gen_x, gen_y, ori_x, ori_y, i, column, // imageSize.x, imageSize.y, agent, AgentContainerType.MainPanel); go = FlockAgentFactoryInstance.Generate(_manager, new Vector2(gen_x, gen_y), AgentContainerType.MainPanel , ori_x, ori_y, i, column, imageSize.x, imageSize.y, agent, _sceneConfig.daoTypeEnum); } else { // 创建后排 float width = imageSize.x * 0.6f; float height = imageSize.y * 0.6f; //go = ItemsFactory.Generate(gen_x, gen_y, ori_x, ori_y, i, column, // imageSize.x, imageSize.y, agent, AgentContainerType.BackPanel); //go = ItemsFactory.Generate(gen_x, gen_y, ori_x, ori_y, i, column, // width, height, agent, AgentContainerType.BackPanel); go = FlockAgentFactoryInstance.Generate(_manager, new Vector2(gen_x, gen_y), AgentContainerType.BackPanel , ori_x, ori_y, i, column, width, height, agent, _sceneConfig.daoTypeEnum); } //go.NextVector2 = new Vector2(gen_x, gen_y); go.flockStatus = FlockStatusEnum.RUNIN; // 装载延迟参数 go.DelayX = 0; go.DelayY = 0; } // 更新 generate_x 的值 generate_x = Mathf.RoundToInt(generate_x_temp); // 第二列的开始在第一列的最右侧 column++; } _displayBehaviorConfig.generatePositionX = generate_x; _displayBehaviorConfig.generatePositionXInBack = generate_x; _displayBehaviorConfig.Column = column; _displayBehaviorConfig.ColumnInBack = column; // 调整启动动画的时间 _entranceDisplayTime += _startDelayTime; // 创建结束 _displayBehaviorConfig.dataType = _dataTypeEnum; _displayBehaviorConfig.Manager = _manager; _displayBehaviorConfig.sceneUtils = _sceneUtil; _displayBehaviorConfig.sceneConfig = _sceneConfig; _onCreateAgentCompleted.Invoke(_displayBehaviorConfig); }
/// <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); }
/// <summary> /// 补充内容 /// </summary> /// <param name="dataType"></param> private void FillItem(DataTypeEnum dataType) { float gap = _displayBehaviorConfig.sceneUtils.GetGap(); // 获取右侧最小的距离 var rowDic = _displayBehaviorConfig.rowAgentsDic; int row = 0; // 最短行长的行值 int last_x = int.MaxValue; ItemPositionInfoBean bean = new ItemPositionInfoBean(); foreach (KeyValuePair <int, ItemPositionInfoBean> keyValuePair in rowDic) { if (keyValuePair.Value.xposition < last_x) { last_x = keyValuePair.Value.xposition; row = keyValuePair.Key; bean = keyValuePair.Value; } } float deviationValue = _displayBehaviorConfig.sceneUtils.GetFixedItemHeight() / 2; // 超过屏幕的距离 float overDistense = last_x - deviationValue - _manager.mainPanel.rect.width; if ((overDistense - _manager.PanelOffsetX) < 0) { if (flag == false) { // 该行添加内容 //FlockData data = _manager.daoService.GetFlockData(dataType); FlockData data = _daoService.GetFlockDataByScene(dataType, _manager.SceneIndex); Sprite spriteImage = data.GetCoverSprite(); int itemHeight = _displayBehaviorConfig.sceneUtils.GetFixedItemHeight(); int itemWidth = Mathf.RoundToInt(AppUtils.GetSpriteWidthByHeight(spriteImage, itemHeight)); // 拿位置 float gen_y = _displayBehaviorConfig.sceneUtils.GetYPositionByFixedHeight(itemHeight, row); float gen_x = last_x + itemWidth / 2 + gap / 2; // 生成 agent //FlockAgent go = _displayBehaviorConfig.ItemsFactory.Generate(gen_x, gen_y, gen_x, gen_y // , row, bean.column + 1, itemWidth, itemHeight, data, AgentContainerType.MainPanel); FlockAgent go = FlockAgentFactoryInstance.Generate(_manager, new Vector2(gen_x, gen_y), AgentContainerType.MainPanel , gen_x, gen_y, row, bean.column + 1, itemWidth, itemHeight, data, _displayBehaviorConfig.sceneConfig.daoTypeEnum); go.flockStatus = FlockStatusEnum.NORMAL; go.NextVector2 = new Vector2(gen_x, gen_y); last_x = Mathf.RoundToInt(last_x + itemWidth + gap / 2); rowDic[row].column = bean.column + 1; rowDic[row].xposition = last_x; } } }
/// <summary> /// 创建代理 /// </summary> private void CreateItem(DataTypeEnum dataType) { //Debug.Log("开始加载左右动画"); // 获取持续时间 _entranceDisplayTime = _manager.cutEffectConfig.LeftRightDisplayDurTime; _startingTimeWithOutDelay = _entranceDisplayTime; // 初始化 config _displayBehaviorConfig = new DisplayBehaviorConfig(); _sceneUtil = new SceneUtils(_manager, _sceneConfig.isKinect); // 固定高度 int _row = row_set; int _itemHeight = _sceneUtil.GetFixedItemHeight(); float gap = _sceneUtil.GetGap(); int _nearColumn = Mathf.RoundToInt(_manager.mainPanel.rect.width / (_itemHeight + gap)); float w = _manager.mainPanel.rect.width; float _maxDelayTime = 0f; // 从上至下,生成 for (int row = 0; row < _row; row++) { int column = 0; ItemPositionInfoBean itemPositionInfoBean; if (_displayBehaviorConfig.rowAgentsDic.ContainsKey(row)) { itemPositionInfoBean = _displayBehaviorConfig.rowAgentsDic[row]; } else { itemPositionInfoBean = new ItemPositionInfoBean(); _displayBehaviorConfig.rowAgentsDic.Add(row, itemPositionInfoBean); } int gen_x_position = itemPositionInfoBean.xposition; while (gen_x_position < _manager.mainPanel.rect.width) { // 获取数据 //FlockData data = _daoService.GetFlockData(dataType); FlockData data = _daoService.GetFlockDataByScene(dataType, _manager.SceneIndex); Sprite coverSprite = data.GetCoverSprite(); float itemWidth = AppUtils.GetSpriteWidthByHeight(coverSprite, _itemHeight); int ori_y = Mathf.RoundToInt(_sceneUtil.GetYPositionByFixedHeight(_itemHeight, row)); int ori_x = Mathf.RoundToInt(gen_x_position + itemWidth / 2 + gap / 2); // 获取参照点 int middleY = _row / 2; int middleX = _nearColumn / 2; // 定义出生位置 float gen_x, gen_y; // 计算出生位置与延时时间 float delay; int maxYOffset = System.Math.Abs(middleY - _row); int nowYOffset; if (row < middleY) { nowYOffset = System.Math.Abs(middleY - row); //delay = (System.Math.Abs(middleY - row)) * _manager.cutEffectConfig.LeftRightGapTime; gen_x = ori_x + w; } else { nowYOffset = System.Math.Abs(middleY - row) + 1; //delay = (System.Math.Abs(middleY - row) + 1) * _manager.cutEffectConfig.LeftRightGapTime; gen_x = ori_x - w - 500; } float f = (float )nowYOffset / (float)maxYOffset; //Debug.Log("f : " + f); Func <float, float> lrfun = EasingFunction.Get(_manager.cutEffectConfig.LeftRightGapEaseEnum); f = lrfun(f); delay = Mathf.Lerp(0, maxYOffset * _manager.cutEffectConfig.LeftRightGapTime, f); gen_y = ori_y; //纵坐标不变 //生成 agent Vector2 genPosition = new Vector2(gen_x, gen_y); FlockAgent go = FlockAgentFactoryInstance.Generate(_manager, genPosition, AgentContainerType.MainPanel , ori_x, ori_y, row, column, itemWidth, _itemHeight, data, _sceneConfig.daoTypeEnum); go.flockStatus = FlockStatusEnum.RUNIN; go.Delay = delay; go.DelayTime = delay; if (delay > _maxDelayTime) { _maxDelayTime = delay; } gen_x_position = Mathf.RoundToInt(gen_x_position + itemWidth + gap / 2); _displayBehaviorConfig.rowAgentsDic[row].xposition = gen_x_position; _displayBehaviorConfig.rowAgentsDic[row].xPositionMin = 0; _displayBehaviorConfig.rowAgentsDic[row].column = column; column++; } } _entranceDisplayTime += _startDelayTime; _displayBehaviorConfig.dataType = _dataTypeEnum; _displayBehaviorConfig.Manager = _manager; _displayBehaviorConfig.sceneUtils = _sceneUtil; _displayBehaviorConfig.sceneConfig = _sceneConfig; _onCreateAgentCompleted.Invoke(_displayBehaviorConfig); }
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); }