コード例 #1
0
ファイル: BallsManager.cs プロジェクト: xu509/scdesktop
        /// <summary>
        /// 获取可用的 参考标记点
        /// 获取逻辑: https://www.yuque.com/u314548/lbo6va/phnmy7
        /// </summary>
        /// <param name="position">世界坐标</param>
        /// <returns></returns>
        public RefPointAgent GetAvailableRefPoint(Vector3 position)
        {
            RefPointAgent nearAvailableAgent = _refPointAgents[0];
            float         shortestDistance   = 100000;


            // 计算最近的参照点
            for (int i = 0; i < _refPointAgents.Length; i++)
            {
                var agentPosition = _refPointAgents[i].gameObject.transform.position;
                var distance      = Vector3.Distance(agentPosition, position);
                //Debug.Log("R - " + _refPointAgents[i].gameObject.name + "  distances : " + distance);

                if (distance < shortestDistance)
                {
                    shortestDistance   = distance;
                    nearAvailableAgent = _refPointAgents[i];
                }
            }

            //Debug.Log("Near Ref is : " + nearAvailableAgent.gameObject.name);

            return(nearAvailableAgent);



            // 空闲时则直接返回
            if (nearAvailableAgent.refPointStatus == RefPointAgent.RefPointStatusEnum.vacant)
            {
                return(nearAvailableAgent);
            }
            else
            {
                // 检查该参照点的最近点是否已经使用
                RefPointAgent nearAgent = null;

                var nearlyAgents = nearAvailableAgent.nearlyRefPointAgents;
                for (int i = 0; i < nearlyAgents.Length; i++)
                {
                    if (nearlyAgents[i].refPointStatus == RefPointAgent.RefPointStatusEnum.vacant)
                    {
                        nearAgent = nearlyAgents[i];
                        break;
                    }
                }

                if (nearAgent != null)
                {
                    // 找到了调整的参照点
                    return(nearAgent);
                }
                else
                {
                    nearAvailableAgent.ballAgent.refCardAgent.DirectClose();

                    return(nearAvailableAgent);
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="birthWorldPosition">世界坐标</param>
        public void Init(Vector3 birthWorldPosition, BallAgent ballAgent, RefPointAgent refPointAgent)
        {
            GetComponent <Transform>().position = birthWorldPosition;
            Vector3 oriScale = new Vector3(0.2f, 0.2f, 1);

            GetComponent <Transform>().localScale = oriScale;

            _refBallAgent  = ballAgent;
            _refPointAgent = refPointAgent;



            // 设置图片
            string detailCoverStr = "data/" + ballAgent.ballData.detailCover;

            _detailCover.sprite = Resources.Load <Sprite>(detailCoverStr);
        }
コード例 #3
0
ファイル: BallsManager.cs プロジェクト: xu509/scdesktop
        /// <summary>
        /// 获取可用的 参考标记点
        /// 获取逻辑: https://www.yuque.com/u314548/lbo6va/phnmy7
        /// </summary>
        /// <param name="position">世界坐标</param>
        /// <returns></returns>
        public RefPointAgent GetAvailableRefPoint2(Vector3 position)
        {
            RefPointAgent nearAvailableAgent = _refPointAgents[0];
            float         shortestDistance   = 100000;


            // 计算最近的参照点
            for (int i = 0; i < _refPointAgents.Length; i++)
            {
                var agentPosition = _refPointAgents[i].gameObject.transform.position;
                var distance      = Vector3.Distance(agentPosition, position);
                //Debug.Log("R - " + _refPointAgents[i].gameObject.name + "  distances : " + distance);
                if (distance < shortestDistance)
                {
                    shortestDistance   = distance;
                    nearAvailableAgent = _refPointAgents[i];
                }
            }


            return(nearAvailableAgent);
        }
コード例 #4
0
ファイル: BallsManager.cs プロジェクト: xu509/scdesktop
        /// <summary>
        ///     打开卡片
        /// </summary>
        /// <param name="refPointAgent"></param>
        /// <param name="ballAgent"></param>
        public void OpenCard(RefPointAgent refPointAgent, BallAgent ballAgent)
        {
            //if (refPointAgent.refPointStatus == RefPointAgent.RefPointStatusEnum.busy)
            //{
            //    var oriBallAgent = refPointAgent.ballAgent;

            //    //  关闭原有卡片
            //    if (oriBallAgent.refCardAgent == null)
            //    {
            //        // 关闭数据球
            //        oriBallAgent.DestoryIt();

            //        refPointAgent.Clear();
            //    }
            //    else {

            //        // 关闭数据球、关闭卡片
            //        oriBallAgent.refCardAgent.DirectClose();
            //        oriBallAgent.DestoryIt();

            //        refPointAgent.Clear();
            //    }

            //}

            // 打开卡片

            // agent 移动到 refpoint 的位置
            refPointAgent.ballAgent      = ballAgent;
            refPointAgent.refPointStatus = RefPointAgent.RefPointStatusEnum.busy;


            var to = refPointAgent.GetComponent <Transform>().position;

            var tweenerMove = ballAgent.GetComponent <Transform>().DOMove(to, 0.5f).OnComplete(() => {
                // 缩小到一定比例
                Vector3 toScale  = new Vector3(0.2f, 0.2f, 1f);
                var tweenerSmall = ballAgent.GetComponent <Transform>().DOScale(toScale, 1f).OnComplete(() => {
                    // 创建卡片走向幕前
                    ballAgent.ballStatus = BallStatusEnum.opened;
                    ballAgent.gameObject.SetActive(false);

                    CardAgent cardAgent;


                    if (refPointAgent.needReversal)
                    {
                        cardAgent = Instantiate(_cardAgentRePrefab, _cardContainer);
                    }
                    else
                    {
                        cardAgent = Instantiate(_cardAgentPrefab, _cardContainer);
                    }

                    //cardAgent
                    var genWorldPosition = ballAgent.GetComponent <Transform>().position;
                    cardAgent.Init(genWorldPosition, ballAgent, refPointAgent);



                    //if (cardAgent.refPointAgent.needReversal)
                    //{
                    //    cardAgent.GetComponent<RectTransform>().Rotate(new Vector3(180, 180, 0), Space.Self);

                    //    //.DORotate(new Vector3(180, 180, 0), Time.deltaTime);
                    //}


                    // 放大
                    Vector3 cardToScale   = new Vector3(1.6f, 1.6f, 1.6f);
                    cardAgent.OpenTweener = cardAgent.GetComponent <Transform>().DOScale(cardToScale, 1f);

                    ballAgent.refCardAgent = cardAgent;
                    _cardAgents.Add(cardAgent);
                });

                ballAgent.SmallTweener = tweenerSmall;
            });

            ballAgent.MoveTweener = tweenerMove;



            refPointAgent.Mark();
        }