// // 初始化 (参数:内容类型,row) // public void Init(DisplayBehaviorConfig displayBehaviorConfig) { _displayBehaviorConfig = displayBehaviorConfig; _manager = _displayBehaviorConfig.Manager; _daoService = _manager.daoServiceFactory.GetDaoService(displayBehaviorConfig.sceneConfig.daoTypeEnum); flag = false; }
// // 初始化 (参数:内容类型,row) // public void Init(DisplayBehaviorConfig displayBehaviorConfig) { _displayBehaviorConfig = displayBehaviorConfig; _manager = displayBehaviorConfig.Manager; flag = false; }
// // Init // public void Init(MagicWallManager manager, SceneConfig sceneConfig, Action <DisplayBehaviorConfig> OnCreateAgentCompleted, Action OnEffectCompleted, Action OnDisplayStart) { // 初始化 manager _manager = manager; _sceneConfig = sceneConfig; _dataTypeEnum = sceneConfig.dataType; _onCreateAgentCompleted = OnCreateAgentCompleted; _onEffectCompleted = OnEffectCompleted; _onDisplayStart = OnDisplayStart; // 获取持续时间 _entranceDisplayTime = manager.cutEffectConfig.FrontBackDisplayDurTime; _startingTimeWithOutDelay = _entranceDisplayTime; // 初始化 config _displayBehaviorConfig = new DisplayBehaviorConfig(); }
private void OnCutEffectCreateAgentCompleted(DisplayBehaviorConfig displayBehaviorConfig) { _displayBehavior.Init(displayBehaviorConfig); }
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> 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); }