Example #1
0
        /// <summary>
        /// 返回一个最合理的拾取位置
        /// </summary>
        public Vector3 GenerateDropPosition(Vector3 pos, int count)
        {
            //if(count > 3)
            //    return pos;

            Vector3 retPos = Vector3.zero;

            // 先对位置进行简单随机
            //            const float dropPosMaxOffset = 2f;
            //            float offsetX = Maths.Random_.Range(-dropPosMaxOffset, dropPosMaxOffset);
            //            float offsetZ = Maths.Random_.Range(-dropPosMaxOffset, dropPosMaxOffset);
            //            retPos.x =  pos.x + offsetX;
            //            retPos.y =  pos.y;
            //            retPos.x =  pos.z + offsetZ;

            Actor localPlayer = Game.GetInstance().GetLocalPlayer();

            if (pos.Equals(Vector3.zero) == true && localPlayer != null)
            {
                pos = localPlayer.transform.position;
            }

            int   dropCnt = DropNum + 10;
            float r       = dropCnt * 0.1f;
            float degrees = dropCnt * 1f;

            retPos.x = pos.x + r * (float)Math.Cos(degrees);
            retPos.z = pos.z + r * (float)Math.Sin(degrees);

            if (localPlayer != null)
            {
                retPos.y = localPlayer.transform.position.y;
            }

            //GameDebug.LogWarning("Drop pos: " + retPos);

            // 限制在副本场景内
            retPos = InstanceHelper.ClampInWalkableRange(retPos);
            // 获取地形高度
            retPos.y = PhysicsHelp.GetHeight(retPos.x, retPos.z);
            // 如果地形太低、则取本地玩家的高度
            if (retPos.y <= -19f)
            {
                var local_player = Game.GetInstance().GetLocalPlayer();
                if (local_player != null)
                {
                    retPos.y = local_player.transform.position.y;
                }
            }

            /*foreach (DropColliderComponent drop in mDrops)
             * {
             *  if (drop != null && (retPos - drop.transform.position).sqrMagnitude < 3f)
             *  {
             *      return GenerateDropPosition(retPos, count+1);
             *  }
             * }*/

            return(retPos);
        }
Example #2
0
        public IEnumerator SetFootprintId(uint footprintId)
        {
            if (footprintId <= 0)
            {
                Clear();
                yield break;
            }

            if (mFootprintId == footprintId)
            {
                yield break;
            }

            DBFootprint.DBFootprintItem item = DBFootprint.GetFootprintItem(footprintId);
            if (item == null)
            {
                yield break;
            }
            mSceneEffectFile      = item.SuitablePath(true);
            mSceneEffectDelayTime = item.DelayTime;
            mCDTime      = item.CDTime;
            mMinDistance = item.MinDistance;
            mCreateTime  = 0;

            //var avatarPart = DBManager.Instance.GetDB<DBAvatarPart>().mData[footprintId];
            var avatarPart = DBAvatarPart.GetAvatarPartData(footprintId);

            if (avatarPart == null)
            {
                yield break;
            }
            mStandEffectFile = avatarPart.SuitablePath(true);

            if (mOwner == null || mOwner.transform == null)
            {
                yield break;
            }
            Vector3 pos = mOwner.transform.position;

            pos.y          = PhysicsHelp.GetHeight(pos.x, pos.z);
            mLastEffectPos = pos;
            mFootprintId   = footprintId;

            if (mOwner.IsUIModel())
            {
                yield return(ResourceLoader.Instance.StartCoroutine(LoadStandEffect(mStandEffectFile)));
            }
        }
Example #3
0
        void CheckCreateEffect()
        {
            mCreateTime += Time.deltaTime;
            if (mCreateTime > mCDTime)
            {
                Vector3 pos = mOwner.transform.position;
                pos.y = PhysicsHelp.GetHeight(pos.x, pos.z);

                if (Vector3.Distance(pos, mLastEffectPos) >= mMinDistance)
                {
                    mCreateTime = 0;
                    CreateSceneEffect(pos);
                    mLastEffectPos = pos;
                }
            }
        }
Example #4
0
        /// <summary>
        /// 通过角色id来获取角色在场景里面的偏移位置
        /// </summary>
        /// <param name="type_id"></param>
        /// <returns></returns>
        public static float GetHeightInScene(uint type_id, float x, float z)
        {
            float height = PhysicsHelp.GetHeight(x, z);

            return(height);
        }
Example #5
0
        void HandleServerData(ushort pro, byte[] data)
        {
            switch (pro)
            {
            case NetMsg.MSG_MWAR_DEBUG_BULLET:     // 响应服务端的子弹位置调试的消息
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }
            }
            break;

            case NetMsg.MSG_MWAR_DEBUG_WORD:     // 绘制服务端发来的文字
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }

                S2CMwarDebugWord debugWord = S2CPackBase.DeserializePack <S2CMwarDebugWord>(data);

                Vector3    pos    = PhysicsHelp.GetPosition(debugWord.px / 100.0f, debugWord.py / 100.0f);
                Object     prefab = Resources.Load("core/prefabs/AttackSphere");
                GameObject testGo = GameObject.Instantiate(prefab, pos, Quaternion.identity) as GameObject;
                testGo.transform.localScale = Vector3.one * (1.0f) / 100.0f * 2;
                testGo.transform.parent     = MainGame.CoreObject.transform;

                Color col = GetColor(debugWord.color);
                testGo.GetComponent <Renderer>().material.SetColor("_Color", col);

                testGo.AddComponent <DelayDestroyComponent>().DelayTime = debugWord.time;

                UI3DText ui3dText = testGo.AddComponent <UI3DText>();
                ui3dText.Text      = System.Text.Encoding.UTF8.GetString(debugWord.word);
                ui3dText.TextColor = col;
                ui3dText.FontSize  = (int)debugWord.size;
                ui3dText.UpdatePosition(pos, Vector3.zero, Vector3.zero);
                //ui3dText.SetOwnerTrans(null);

                break;
            }

            case NetMsg.MSG_MWAR_DEBUG_POS:     // 绘制服务端发送过来的位置
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }

                var debugPos = S2CPackBase.DeserializePack <S2CMwarDebugPos>(data);

                Vector3    pos    = PhysicsHelp.GetPosition(debugPos.px / 100.0f, debugPos.py / 100.0f);
                Object     prefab = Resources.Load("core/prefabs/AttackSphere");
                GameObject testGo = GameObject.Instantiate(prefab, pos, Quaternion.identity) as GameObject;
                testGo.transform.localScale = Vector3.one * debugPos.radius / 100.0f * 2;
                testGo.transform.parent     = MainGame.CoreObject.transform;

                Color col = GetColor(debugPos.color);
                testGo.GetComponent <Renderer>().material.SetColor("_Color", col);

                testGo.AddComponent <DelayDestroyComponent>().DelayTime = 0.5f;
            }
            break;

            case NetMsg.MSG_MWAR_DEBUG_LINE:     // 绘制服务端发送过来的线段
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }

                S2CMwarDebugLine debugLine = S2CPackBase.DeserializePack <S2CMwarDebugLine>(data);

                float   height    = PhysicsHelp.GetHeight(debugLine.px1 / 100.0f, debugLine.py1 / 100.0f);
                Vector3 pos1      = new Vector3(debugLine.px1 / 100.0f, height, debugLine.py1 / 100.0f);
                Vector3 pos2      = new Vector3(debugLine.px2 / 100.0f, height, debugLine.py2 / 100.0f);
                Vector3 dir       = (pos2 - pos1);
                Vector3 dirNormal = dir.normalized;
                if (dirNormal == Vector3.zero)
                {
                    return;
                }

                Vector3 middlePos = (pos1 + pos2) / 2.0f;

                Object     prefab = Resources.Load("core/prefabs/AttackCube");
                GameObject testGo = GameObject.Instantiate(prefab, middlePos, Quaternion.identity) as GameObject;

                testGo.transform.localScale = new Vector3(debugLine.radius * 2.0f / 100.0f, debugLine.radius * 2.0f / 100.0f, (pos2 - pos1).magnitude);
                testGo.transform.rotation   = Quaternion.LookRotation(dirNormal, Vector3.up);
                testGo.transform.parent     = MainGame.CoreObject.transform;

                Color col = GetColor(debugLine.color);
                testGo.GetComponent <Renderer>().material.SetColor("_Color", col);

                testGo.AddComponent <DelayDestroyComponent>().DelayTime = debugLine.time;
            }
            break;

            case NetMsg.MSG_MWAR_DEBUG_CIRCLE:    // 绘制服务端发送过来的圆环
            {
                if (TestUnit.DisplayDebugDraw == false)
                {
                    return;
                }

                var     debugCircle = S2CPackBase.DeserializePack <S2CMwarDebugCircle>(data);
                float   height      = PhysicsHelp.GetHeight(debugCircle.px / 100.0f, debugCircle.py / 100.0f);
                Vector3 pos         = new Vector3(debugCircle.px / 100.0f, height, debugCircle.py / 100.0f);

                Object     prefab = Resources.Load("Core/Prefabs/AttackCircle");
                GameObject testGo = GameObject.Instantiate(prefab, pos, Quaternion.identity) as GameObject;

                testGo.transform.localScale = new Vector3(debugCircle.size / 100.0f, 1.0f, debugCircle.size / 100.0f);
                testGo.transform.rotation   = Quaternion.identity;
                testGo.transform.parent     = MainGame.CoreObject.transform;

                Color col = GetColor(debugCircle.color);
                testGo.GetComponentInChildren <Renderer>().material.SetColor("Tint Color", col);
                testGo.AddComponent <DelayDestroyComponent>().DelayTime = debugCircle.time * GlobalConst.MilliToSecond;
            } break;
            }
        }