예제 #1
0
        /// <summary>
        ///     更新透明度
        /// </summary>
        /// <param name="agent"></param>
        private void UpdateAlpha(FlockAgent agent)
        {
            float z = agent.GetComponent <RectTransform>().anchoredPosition3D.z;

            // 判断Z在距离中的位置
            float distance = Mathf.Abs(_manager.cutEffectConfig.StarEffectOriginPoint - _manager.cutEffectConfig.StarEffectEndPoint);
            float offset   = Mathf.Abs(z - _manager.cutEffectConfig.StarEffectOriginPoint) / distance;

            // 当OFFSET 位于前 1/10 或后 1/10 时,更新透明度
            if (offset < 0.05)
            {
                float k     = Mathf.Abs(offset - 0.05f);
                float alpha = Mathf.Lerp(1, 0, k / 0.05f);
                agent.UpdateImageAlpha(alpha);
            }
            else if (offset > 0.95)
            {
                float k     = Mathf.Abs(1 - offset);
                float alpha = Mathf.Lerp(0, 1, k / 0.05f);
                agent.UpdateImageAlpha(alpha);
            }
            else
            {
                agent.UpdateImageAlpha(1);
            }
        }
예제 #2
0
        public void Starting()
        {
            float time = Time.time - _startTime;  // 当前已运行的时间;

            for (int i = 0; i < _manager.agentManager.Agents.Count; i++)
            {
                FlockAgent agent         = _manager.agentManager.Agents[i];
                Vector2    agent_vector2 = agent.GenVector2;
                Vector2    ori_vector2   = agent.OriVector2;

                // 获取总运行时间
                float run_time = _startingTimeWithOutDelay + agent.Delay;


                if (time > run_time)
                {
                    // 此时可能未走完动画
                    if (!agent.isCreateSuccess)
                    {
                        agent.SetChangedPosition(ori_vector2);
                        agent.flockStatus = FlockStatusEnum.NORMAL;

                        agent.isCreateSuccess = true;
                    }
                    continue;
                }

                float t = time / run_time;

                Func <float, float> moveEase = EasingFunction.Get(_manager.cutEffectConfig.MidDisperseMoveEaseEnum);
                t = moveEase(t);


                Vector2 to = Vector2.Lerp(agent_vector2, ori_vector2, t);
                agent.SetChangedPosition(to);


                // 透明度动画
                var distance = Vector2.Distance(ori_vector2, to);

                var agentHeight = agent.GetComponent <RectTransform>().rect.height;


                var maxDistance = agentHeight * _manager.cutEffectConfig.MidDisperseAlphaMinDistanceFactor;

                if (distance < maxDistance)
                {
                    float min_alpha = 0.1f;
                    float max_alpha = 1f;
                    float k         = distance / maxDistance;
                    Func <float, float> easeFunction = EasingFunction.Get(_manager.cutEffectConfig.MidDisperseAlphaEaseEnum);
                    k = easeFunction(k);
                    float newAlpha = Mathf.Lerp(max_alpha, min_alpha, k);
                    agent.UpdateImageAlpha(newAlpha);
                }
            }

            if ((time - _entranceDisplayTime * 0.5f) > 0)
            {
                if (!_hasCallDisplay)
                {
                    _hasCallDisplay = true;
                    _onDisplayStart.Invoke();
                }
            }

            if ((time - _entranceDisplayTime) > 0)
            {
                Reset();
                _onEffectCompleted.Invoke();
            }
        }
예제 #3
0
        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);
        }
예제 #4
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);
        }