Exemple #1
0
        public override void CreateModel()
        {
            //AvatarModelData data = AvatarModelData.dataMap[1013];
            Debug.Log("TeleportPointSrcGearAgent create:" + ID);
            SubAssetCacheMgr.GetCharacterInstance("TeleportPointSrcGearAgent.prefab",
                                                  (prefab, guid, gameObject) =>
            {
                Transform = (gameObject as GameObject).transform;
                Vector3 point;
                if (MogoUtils.GetPointInTerrain(position.x, position.z, out point))
                {
                    Transform.position = point;
                }
                //Transform.position = position;
                Transform.eulerAngles = rotation;
                Transform.localScale  = scale;
                Transform.tag         = "Gear";

                TeleportPointSrcGear gear = Transform.GetComponent <TeleportPointSrcGear>();
                if (gear != null)
                {
                    gear.ID = ID;
                    Debug.Log("EntityTeleportSrc Gear ID: " + gear.ID);
                }
            }
                                                  );
        }
Exemple #2
0
    protected void AdjustPosition()
    {
        if (MogoWorld.isLoadingScene)
        {
            return;
        }
        return;

        if (transform.position.y < -100 && transform.position.y > -9000)
        {
            Vector3 temp;
            bool    hasHit = MogoUtils.GetPointInTerrain(transform.position.x, transform.position.z, out temp);
            if (!hasHit)
            {
                if (MogoWorld.inCity)
                {
                    foreach (EntityParent e in MogoWorld.Entities.Values)
                    {
                        if (e != null && e.Transform && e is EntityPlayer)
                        {
                            hasHit = MogoUtils.GetPointInTerrain(e.Transform.position.x, e.Transform.position.z, out temp);
                            if (!hasHit)
                            {
                                continue;
                            }
                            transform.position = e.Transform.position;
                            return;
                        }
                    }
                }
                else
                {
                    foreach (EntityParent e in MogoWorld.Entities.Values)
                    {
                        if (e != null && e.Transform && (e is EntityDummy || e is EntityMonster || e is EntityMercenary))
                        {
                            hasHit = MogoUtils.GetPointInTerrain(e.Transform.position.x, e.Transform.position.z, out temp);
                            if (!hasHit)
                            {
                                continue;
                            }
                            transform.position = e.Transform.position;
                            return;
                        }
                    }
                }
                float x = MapData.dataMap[MogoWorld.thePlayer.sceneId].enterX;
                float z = MapData.dataMap[MogoWorld.thePlayer.sceneId].enterY;
                MogoUtils.GetPointInTerrain(transform.position.x, transform.position.z, out temp);
                transform.position = temp;
            }
            else
            {
                transform.position = temp;
            }
        }
    }
Exemple #3
0
    public void MoveToWithoutNav(Vector3 v)
    {
        //Debug.LogError("move to:" + v);
        if (!canMove)
        {
            //Debug.LogError("!canmove");
            return;
        }
        bool hasHit = MogoUtils.GetPointInTerrain(v.x, v.z, out v);

        if (!hasHit)
        {
            //Debug.LogError("!hasHit");
            return;
        }
        isMovingToTarget = false;

        targetToMoveTo             = v;
        isMovingToTargetWithoutNav = true;
        //transform.LookAt(new Vector3(targetToMoveTo.x, transform.position.y, targetToMoveTo.z));

        Vector3 direction    = targetToMoveTo - transform.position;
        int     i            = direction.x > 0 ? 1 : -1;
        float   targetAngleY = i * Vector2.Angle(new Vector2(0, 1), new Vector2(direction.x, direction.z));// +Camera.main.transform.eulerAngles.y;

        base.ApplyRotation(targetAngleY);
        //transform.LookAt(new Vector3(targetToMoveTo.x, transform.position.y, targetToMoveTo.z));
        float dis = Vector3.Distance(transform.position, targetToMoveTo);
        //if (dis < 8 * speed * turnAroundTime * 2 + 1 && isTurning)//
        //{
        //    targetSpeed = 0;
        //}
        //else
        //{
        //    targetSpeed = moveSpeed;
        //}


        //direction = direction.normalized;
        //到达目的地
        float step = 30 * Time.deltaTime;

        //Debug.LogError("dis:" + dis);
        //Debug.LogError("step + 0.1f:" + (step + 0.1f));
        if (dis < step + 0.1f)
        {
            //Debug.LogError("StopMOve");
            StopMove();
        }
        else
        {
            // characterController.Move(direction * step);
            //transform.Translate(direction * step, Space.World);
        }
    }
Exemple #4
0
    void CreateModel(int id, int model, int mapx, int mapy, Vector3 vec, bool playBornFX = true)
    {
        EntityMonster entity = new EntityMonster();

        entity.ID    = (uint)id;
        entity.model = model;
        Vector3 Point = new Vector3();

        MogoUtils.GetPointInTerrain((float)mapx / 100, (float)mapy / 100, out Point);
        entity.PlayBornFX = playBornFX;
        entity.BillBoard  = false;
        entity.position   = Point;
        entity.rotation   = vec;
        entity.CreateModel();
        EventDispatcher.AddEventListener <GameObject, Vector3>(MogoMotor.ON_MOVE_TO, entity.OnMoveTo);
        m_entityList[id] = entity;
    }
Exemple #5
0
    /// <summary>
    /// ����Ҫ�ص�����Ŀ��ʱ�ĵط�ʹ�ã�EventDispatcher.AddEventListener<GameObject, Vector3>(ON_MOVE_TO, func);
    /// </summary>
    /// <param name="v"></param>
    /// <param name="space"></param>
    public override void MoveTo(Vector3 v, bool needToAdjustPosY = true)
    {
        if (!canMove)
        {
            return;
        }
        if (needToAdjustPosY)
        {
            //Debug.Log("MoveTo:" + v + ",speed:" + extraSpeed);
            bool hasHit = MogoUtils.GetPointInTerrain(v.x, v.z, out v);

            if (!hasHit)
            {
                return;
            }
        }

        //v = hitInfo.point;
        //Vector3 position = transform.position;
        //if (Mathf.Abs(v.x - position.x) < 0.1f && Mathf.Abs(v.y - position.y) < 0.1f)
        //{
        //    StopNav();
        //    return;
        //}
        targetToMoveTo   = v;
        isMovingToTarget = true;

        //transform.LookAt(new Vector3(targetToMoveTo.x, transform.position.y, targetToMoveTo.z));
        if (isNeedRotation)
        {
            RotateTo(targetToMoveTo);
        }


        float dis = Vector3.Distance(transform.position, targetToMoveTo);

        //������λ��ʱ��ת����Ҫ���ƶ�ͣ����
        //if (dis < extraSpeed * turnAroundTime * 2 + 1 && isTurning)//
        //{
        //    targetSpeed = 0;
        //    moveDirection = Vector3.zero;
        //}
        //else
        //{
        //    targetSpeed = moveSpeed;
        //    moveDirection = transform.forward.normalized;
        //}
        moveDirection = targetToMoveTo - transform.position;
        moveDirection = moveDirection.normalized;

        //����Ŀ�ĵ�
        float step = extraSpeed * Time.deltaTime;

        //Debug.Log("SPEED * speed:" + SPEED * speed);
        //Debug.Log("dis:" + dis);
        //Debug.Log("step+0.05f:" + (step + 0.05f));
        if (dis < step + 0.05f)
        {
            if (canTurn && isNeedRotation)
            {
                transform.LookAt(new Vector3(targetToMoveTo.x, transform.position.y, targetToMoveTo.z));
            }
            transform.position = new Vector3(targetToMoveTo.x, transform.position.y, targetToMoveTo.z);
            StopNav();
            EventDispatcher.TriggerEvent(ON_MOVE_TO, transform.gameObject, targetToMoveTo);
        }

        //else if (isTurning && dis < 0.5f)
        //{
        //    Debug.Log("is too close to turn around,so just stop it");
        //    transform.LookAt(new Vector3(targetToMoveTo.x, transform.position.y, targetToMoveTo.z));
        //    transform.position = new Vector3(targetToMoveTo.x, transform.position.y, targetToMoveTo.z);
        //    StopNav();
        //    EventDispatcher.TriggerEvent(ON_MOVE_TO, transform.gameObject, targetToMoveTo);
        //}
        //else
        //{
        //    characterController.Move(direction * step);
        //    //transform.Translate(direction * step, Space.World);
        //}
    }
Exemple #6
0
    override public bool MoveToByNav(Vector3 _v, float _stopDistance = 0f, bool needToAdjustPosY = true)
    {
        if (!canMove)
        {
            return(false);
        }
        if (needToAdjustPosY)
        {
            bool hasHit = MogoUtils.GetPointInTerrain(_v.x, _v.z, out _v);

            if (!hasHit)
            {
                EventDispatcher.TriggerEvent(ON_MOVE_TO_FALSE, transform.gameObject, targetToMoveTo, 0f);
                Debug.LogWarning("!hasHit:" + _v);
                return(false);
            }
        }

        //����·��
        if (!isNaving || needToAdjustPosY)//|| (targetToMoveTo - v).magnitude < 0.05f
        {
            if (m_navHelper != null)
            {
                //Debug.LogError("targetToMoveTO:" + _v);
                path           = m_navHelper.GetPathByTarget(_v);
                targetToMoveTo = _v;
                m_cornersIdx   = 1;
                m_stopDistance = _stopDistance;
            }
            else
            {
                EventDispatcher.TriggerEvent(ON_MOVE_TO_FALSE, transform.gameObject, targetToMoveTo, 0f);
                return(false);
            }
        }

        //Debug.Log("path.corners.Length:" + path.corners.Length);
        if (path == null)
        {
            StopNav();
            EventDispatcher.TriggerEvent(ON_MOVE_TO_FALSE, transform.gameObject, targetToMoveTo, 0f);
            return(false);
        }
        if (path.corners.Length < 2)
        {
            EventDispatcher.TriggerEvent(ON_MOVE_TO_FALSE, transform.gameObject, targetToMoveTo, 0f);
            Debug.LogWarning("path.corners.Length < 2:" + targetToMoveTo);
            StopNav();
            //EventDispatcher.TriggerEvent(ON_MOVE_TO, transform.gameObject, targetToMoveTo);
            return(false);
        }

        isNaving      = true;
        moveDirection = (path.corners[m_cornersIdx] - transform.position).normalized;
        RotateTo(path.corners[m_cornersIdx]);
        //transform.LookAt(new Vector3(path.corners[m_cornersIdx].x, transform.position.y, path.corners[m_cornersIdx].z));
        float dis  = Vector3.Distance(transform.position, path.corners[m_cornersIdx]);
        float step = extraSpeed * Time.deltaTime;

        if (step + 0.1f > dis && m_cornersIdx < path.corners.Length - 1)
        {
            collisionFlags = characterController.Move(path.corners[m_cornersIdx] - transform.position);
            if ((path.corners[m_cornersIdx] - transform.position).magnitude > 0.3f)
            {
                path         = m_navHelper.GetPathByTarget(targetToMoveTo);
                m_cornersIdx = 1;
            }
            else
            {
                m_cornersIdx++;
            }

            moveDirection = Vector3.zero;
            //transform.LookAt(new Vector3(path.corners[m_cornersIdx].x, transform.position.y, path.corners[m_cornersIdx].z));
            //collisionFlags = characterController.Move(moveDirection * dis);

            //transform.position = new Vector3(path.corners[m_cornersIdx].x, transform.position.y, path.corners[m_cornersIdx].z);
            //m_cornersIdx++;
        }
        else if (m_cornersIdx == path.corners.Length - 1 && step + 0.1f + m_stopDistance > dis)
        {
            //Debug.LogError("StopNav");
            float tempDis;
            //for (int i = 0; i < 5 && tempDis > 0.1; i++, dis = Vector3.Distance(transform.position, targetToMoveTo))
            //{
            tempDis        = dis - m_stopDistance;
            tempDis        = tempDis > 0 ? tempDis : 0;
            collisionFlags = characterController.Move((path.corners[m_cornersIdx] - transform.position).normalized * tempDis);
            //}
            StopNav();
            tempDis = Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(targetToMoveTo.x, targetToMoveTo.z));
            if (tempDis > 0.2 + m_stopDistance)
            {
                //MogoWorld.thePlayer.Idle();
                EventDispatcher.TriggerEvent(ON_MOVE_TO_FALSE, transform.gameObject, targetToMoveTo, tempDis);
            }
            else
            {
                EventDispatcher.TriggerEvent(ON_MOVE_TO, transform.gameObject, targetToMoveTo);
            }
        }
        return(true);
    }
    public NavMeshPath GetPathByTarget(Vector3 target)
    {
        if (m_navGo == null)
        {
            m_navGo = new GameObject();
        }



        //m_navAgent.Stop();
        //防止因为位置不对而抛出"无效navMesh"的错,在位置调整后设回true
        //m_navAgent.enabled = false;

        //Vector3 sourcePostion = m_parent.position;//The position to place agent
        //NavMeshHit closestHit;
        //if (NavMesh.SamplePosition(sourcePostion, out closestHit, 500, 1))
        //{

        //    m_navGo.transform.position = closestHit.position;
        //}
        //else
        //{

        //}
        //m_navAgent.enabled = true;

        NavMeshPath path = new NavMeshPath();

        //LoggerHelper.Error("before target:" + target);
        target = GetPointCloseToTheMesh(target);
        //LoggerHelper.Error("after target:" + target);
        if (!ResetPositionToCLoseToNavMesh())
        {
            LoggerHelper.Warning("can not find the navmesh!");
            return(path);
        }

        //if (NavMesh.SamplePosition(target, out closestHit, 500, 1))
        //{

        //    target = closestHit.position;
        //}

        try
        {
            NavMesh.CalculatePath(m_navGo.transform.position, target, -1, path);
            //m_navAgent.CalculatePath(target, path);

            if (path.corners.Length <= 0)
            {
                //LoggerHelper.Debug("path.corners.Length <= 0:"+1);
                m_navAgent.enabled = true;

                m_navAgent.SetDestination(target);
                path = m_navAgent.path;
                if (path.corners.Length <= 0)
                {
                    //LoggerHelper.Error("path.corners.Length <= 0:" + 2);
                }
                m_navAgent.Stop();
                //m_navAgent.enabled = false;
            }
        }
        catch
        {
            //LoggerHelper.Error("f**k!");
        }
        //foreach (Vector3 v in path.corners)
        //{
        //LoggerHelper.Error(v);
        //}
        // 为去除警告暂时屏蔽以下代码
        //bool hasHit;
        for (int i = 0; i < path.corners.Length; i++)
        {
            MogoUtils.GetPointInTerrain(path.corners[i].x, path.corners[i].z, out path.corners[i]);
        }

        return(path);
    }
Exemple #8
0
    /// <summary>
    /// 私有的函数执行过程
    /// </summary>
    /// <param name="commands"></param>
    private void executeCommand(string[] commands)
    {
        LoggerHelper.Warning("executeCommand :" + commands.PackArray());
        switch (commands[0])
        {
        case "CreateModel":
        {
            var     list1 = commands[5].Split(new char[] { ',' });
            Vector3 vec   = new Vector3(float.Parse(list1[0]), float.Parse(list1[1]), float.Parse(list1[2]));
            if (commands.Length > 6 && commands[6].Equals("false"))
            {
                CreateModel(Int32.Parse(commands[1]), Int32.Parse(commands[2]), Int32.Parse(commands[3]), Int32.Parse(commands[4]), vec, false);
            }
            else
            {
                CreateModel(Int32.Parse(commands[1]), Int32.Parse(commands[2]), Int32.Parse(commands[3]), Int32.Parse(commands[4]), vec);
            }

            break;
        }

        case "DestroyModel":
        {
            int id = Int32.Parse(commands[1]);
            AssetCacheMgr.ReleaseInstance(m_entityList[id].GameObject);
            BillboardLogicManager.Instance.RemoveBillboard(m_entityList[Int32.Parse(commands[1])].ID);
            EventDispatcher.RemoveEventListener <GameObject, Vector3>(MogoMotor.ON_MOVE_TO, m_entityList[Int32.Parse(commands[1])].OnMoveTo);
            m_entityList.Remove(id);
            break;
        }

        case "PlayAction":
        {
            int id = Int32.Parse(commands[1]);
            PlayAction(id, Int32.Parse(commands[2]));
            break;
        }

        case "PlayOneAction":
        {
            int id = Int32.Parse(commands[1]);
            PlayAction(id, Int32.Parse(commands[2]));
            m_entityList[id].AddCallbackInFrames <EntityParent>((ent) => { ent.SetAction(0); }, m_entityList[id]);
            break;
        }

        case "StopAction":
        {
            int id = Int32.Parse(commands[1]);
            m_entityList[id].AddCallbackInFrames <EntityParent>((ent) => { ent.SetAction(0); }, m_entityList[id]);
            break;
        }

        case "PlaySfx":
        {
            if (commands.Length > 3)
            {
                var     list1 = commands[4].Split(new char[] { ',' });
                Vector3 vec   = new Vector3(float.Parse(list1[0]), float.Parse(list1[1]), float.Parse(list1[2]));
                PlaySfx(Int32.Parse(commands[1]), Int32.Parse(commands[2]), Int32.Parse(commands[3]), vec);
            }
            else
            {
                PlaySfx(Int32.Parse(commands[1]), Int32.Parse(commands[2]));
            }

            break;
        }

        case "StopSfx":
            if (commands.Length > 2)
            {
                StopSfx(Int32.Parse(commands[1]), Int32.Parse(commands[2]));
            }
            else
            {
                StopSfx(Int32.Parse(commands[1]));
            }
            break;

        case "MoveCamera":
            if (commands.Length == 5)
            {
                var list1 = commands[2].Split(new char[] { ',' });
                var list2 = commands[3].Split(new char[] { ',' });
                MoveCamera(Int32.Parse(commands[1]), float.Parse(list1[0]), float.Parse(list2[0]), float.Parse(list1[1]), float.Parse(list2[1]),
                           float.Parse(list1[2]), float.Parse(list2[2]), float.Parse(list1[3]), float.Parse(list2[3]), float.Parse(commands[4]));
            }
            else if (commands.Length == 6)
            {
                var     list1 = commands[2].Split(new char[] { ',' });
                var     list2 = commands[3].Split(new char[] { ',' });
                var     list3 = commands[5].Split(new char[] { ',' });
                Vector3 vec   = new Vector3(float.Parse(list3[0]), float.Parse(list3[1]), float.Parse(list3[2]));
                MoveCamera(Int32.Parse(commands[1]), float.Parse(list1[0]), float.Parse(list2[0]), float.Parse(list1[1]), float.Parse(list2[1]),
                           float.Parse(list1[2]), float.Parse(list2[2]), float.Parse(list1[3]), float.Parse(list2[3]), float.Parse(commands[4]), vec);
            }
            else
            {
                MogoMainCamera.Instance.PlayCGAnim(commands[1]);
            }
            break;

        case "SetPosition":
        {
            int id = Int32.Parse(commands[1]);
            if (!m_entityList.ContainsKey(id))
            {
                LoggerHelper.Debug("id not exist in list");
            }
            else
            {
                var list1 = commands[2].Split(new char[] { ',' });
                m_entityList[id].SetPositon(float.Parse(list1[0]), float.Parse(list1[1]), float.Parse(list1[2]));
            }
            break;
        }

        case "SetRotation":
        {
            int id = Int32.Parse(commands[1]);
            if (!m_entityList.ContainsKey(id))
            {
                LoggerHelper.Debug("id not exist in list");
            }
            else
            {
                var list1 = commands[2].Split(new char[] { ',' });
                m_entityList[id].SetRotation(float.Parse(list1[0]), float.Parse(list1[1]), float.Parse(list1[2]));
            }
            break;
        }

        case "ShakeCamera":
            if (commands.Length > 3)
            {
                var list1 = commands[1].Split(new char[] { ',' });
                var vec   = new Vector3(float.Parse(list1[0]), float.Parse(list1[1]), float.Parse(list1[2]));
                var list2 = commands[2].Split(new char[] { ',' });
                ShakeCamera(vec, Int32.Parse(list2[0]), Int32.Parse(list2[1]), Int32.Parse(list2[2]), float.Parse(commands[3]) / 1000);
            }
            else
            {
                ShakeCamera(Int32.Parse(commands[1]), float.Parse(commands[2]) / 1000);
            }
            break;

        case "WhiteCamera":
        {
            var     list1 = commands[1].Split(new char[] { ',' });
            Vector2 vec   = new Vector2(float.Parse(list1[0]), float.Parse(list1[1]));
            MogoMainCamera.Instance.FadeToAllWhite(vec, float.Parse(commands[2]) / 1000);
            break;
        }

        case "NormalCamera":
        {
            var     list1 = commands[1].Split(new char[] { ',' });
            Vector2 vec   = new Vector2(float.Parse(list1[0]), float.Parse(list1[1]));
            MogoMainCamera.Instance.FadeToNoneWhite(vec, float.Parse(commands[2]) / 1000);
            break;
        }

        case "MoveTo":
        {
            int id    = Int32.Parse(commands[1]);
            var list1 = commands[2].Split(new char[] { ',' });
            m_entityList[id].MoveTo(float.Parse(list1[0]), float.Parse(list1[1]), float.Parse(list1[2]));
            break;
        }

        case "ShowDialog":
        {
            var list1 = (from x in commands[1].Split(new char[] { ',' }) select LanguageData.GetContent(Int32.Parse(x)).Replace("{0}", MogoWorld.thePlayer.name)).ToArray();
            var list2 = (from x in commands[2].Replace("{0}", IconData.GetPortraitByVocation(MogoWorld.thePlayer.vocation)).Split(new char[] { ',' }) select IconData.dataMap.Get(Int32.Parse(x)).path).ToArray();
            var list3 = (from x in commands[3].Split(new char[] { ',' }) select FormatTaskText(LanguageData.GetContent(Int32.Parse(x)))).ToArray();
            GuideSystem.Instance.IsGuideDialog = true;
            if (m_currentStoryID != 0)
            {
                //CG
                MogoUIManager.Instance.ShowMogoTaskUI(TaskUILogicManager.Instance.SetTaskInfo, list1, list2, list3, MogoUIManager.Instance.m_MainUI);
            }
            else
            {
                MogoUIManager.Instance.ShowGuideTaskUI(DialogUILogicManager.Instance.SetDialogInfo, list1, list2, list3);
            }
            break;
        }

        case "Subtitle":
        {
            MogoUIManager.Instance.ShowSubtitle(LanguageData.GetContent(Int32.Parse(commands[1])), float.Parse(commands[2]), float.Parse(commands[3]));
            break;
        }

        case "ZoomCamera":
        {
            int id   = Int32.Parse(commands[1]);
            var list = commands[3].Split(new char[] { ',' });
            MogoMainCamera.Instance.CloseToTarget(m_entityList[id].Transform, float.Parse(commands[2]), float.Parse(list[1]), float.Parse(list[0]), float.Parse(commands[4]) / 1000, float.Parse(commands[5]) / 1000);
            break;
        }

        case "LockSight":
        {
            MogoMainCamera.Instance.LockSight();
            break;
        }

        case "SetFocus":
        {
            if (commands.Length > 4)
            {
                TeachUILogicManager.Instance.SetTeachUIFocus(Int32.Parse(commands[1]), LanguageData.GetContent(Int32.Parse(commands[2])), false, Int32.Parse(commands[3]), MogoUIManager.Instance.m_MainUI);
                //TeachUILogicManager.Instance.ShowFingerAnim(true);
            }
            else
            {
                TeachUILogicManager.Instance.SetTeachUIFocus(Int32.Parse(commands[1]), LanguageData.GetContent(Int32.Parse(commands[2])), false, Int32.Parse(commands[3]));
                //TeachUILogicManager.Instance.ShowFingerAnim(true);
            }
            break;
        }

        case "SetItemFocus":
        {
            var itemIDs = commands[1].Split(new char[] { ',' }).Select(x => Int32.Parse(x));
            foreach (var item in itemIDs)
            {
                if (InventoryManager.Instance.GetItemNumById(item) > 0)
                {
                    LoggerHelper.Warning("SetItemFocus" + item);
                    TeachUILogicManager.Instance.SetItemFocus(item, LanguageData.GetContent(Int32.Parse(commands[2])), Int32.Parse(commands[3]));
                    break;
                }
            }
            //TeachUILogicManager.Instance.ShowFingerAnim(true);
            break;
        }

        case "SetNonFocus":
        {
            if (commands.Length > 4)
            {
                TeachUILogicManager.Instance.SetTeachUIFocus(Int32.Parse(commands[1]), LanguageData.GetContent(Int32.Parse(commands[2])), true, Int32.Parse(commands[3]), MogoUIManager.Instance.m_MainUI);
                TeachUILogicManager.Instance.ShowFingerAnim(true);
            }
            else
            {
                TeachUILogicManager.Instance.SetTeachUIFocus(Int32.Parse(commands[1]), LanguageData.GetContent(Int32.Parse(commands[2])), true, Int32.Parse(commands[3]));
                TeachUILogicManager.Instance.ShowFingerAnim(true);
            }

            break;
        }

        case "OpenBillboard":
        {
            MogoUIManager.Instance.ShowBillboardList(true);
            break;
        }

        case "CloseBillboard":
        {
            MogoUIManager.Instance.ShowBillboardList(false);
            break;
        }

        case "OpenUI":
        {
            if (commands.Length == 2)
            {
                var type   = typeof(MainUIViewManager);
                var method = type.GetMethod("Show" + commands[1]);
                method.Invoke(MainUIViewManager.Instance, new object[] { true });
            }
            else if (commands.Length == 3)
            {
                var type   = typeof(MainUIViewManager);
                var method = type.GetMethod("Show" + commands[1]);
                method.Invoke(MainUIViewManager.Instance, new object[] { true, Int32.Parse(commands[2]) });
            }
            else
            {
                MogoUIManager.Instance.ShowUI(true);
            }

            break;
        }

        case "CloseUI":
        {
            if (commands.Length == 2)
            {
                var type   = typeof(MainUIViewManager);
                var method = type.GetMethod("Show" + commands[1]);
                method.Invoke(MainUIViewManager.Instance, new object[] { false });
            }
            else if (commands.Length == 3)
            {
                var type   = typeof(MainUIViewManager);
                var method = type.GetMethod("Show" + commands[1]);
                method.Invoke(MainUIViewManager.Instance, new object[] { false, Int32.Parse(commands[2]) });
            }
            else
            {
                MogoUIManager.Instance.ShowUI(false);
                MogoUIManager.Instance.ShowBillboardList(false);
            }

            break;
        }

        case "AddPointer":
        {
            LoggerHelper.Debug("AddPointerToTarget");
            Vector3 point = new Vector3();
            MogoUtils.GetPointInTerrain(float.Parse(commands[1]), float.Parse(commands[2]), out point);
            MogoFXManager.Instance.AddPointerToTarget(MogoWorld.thePlayer.Transform.gameObject, MogoWorld.thePlayer.ID, point);
            break;
        }

        case "Sleep":
        {
            TimerHeap.AddTimer(UInt32.Parse(commands[1]), 0, () => { EventDispatcher.TriggerEvent <SignalEvents>(Events.CommandEvent.CommandEnd, SignalEvents.Sleep); });
            break;
        }

        case "End":
        {
            //结束CG
            FinishCG();
            break;
        }

        case "UnlockQueue":
        {
            MogoUIQueue.Instance.IsLocking = false;
            MogoUIQueue.Instance.Locked    = false;
            MogoUIQueue.Instance.CheckQueue();
            Debug.Log("Unlocking by StoryManager...................................");
            break;
        }

        case "StartGuideUI":
        {
            Mogo.Util.LoggerHelper.Debug("Start GuideUI @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            TeachUIViewManager.Instance.PrepareShowTeachUI();
            break;
        }

        case "ResetControlStick":
        {
            if (ControlStick.instance != null)
            {
                MogoWorld.thePlayer.Idle();
                MogoWorld.thePlayer.motor.StopNav();
                ControlStick.instance.Reset();
            }
            else
            {
                MogoWorld.thePlayer.Idle();
                MogoWorld.thePlayer.motor.StopNav();
            }
            break;
        }

        case "Gear":
        {
            ClientEventData.TriggerGearEvent(Int32.Parse(commands[1]));
            break;
        }

        case "RemoveEntities":
        {
            MogoWorld.RemoveEntitiesPos();
            break;
        }

        case "ResetEntities":
        {
            MogoWorld.ResetEntitiesPos();
            break;
        }

        default:
            break;
        }
    }
Exemple #9
0
    public override void MoveTo(Vector3 v, bool needToAdjustPosY = true)
    {
        //Debug.LogError("MoveTo:" + v);
        if (path != null && m_cornersIdx < path.corners.Length)
        {
            //Mogo.Util.LoggerHelper.Error("path.corners[m_cornersIdx]:" + path.corners[m_cornersIdx]);
            if (!canMove)
            {
                return;
            }
        }
        if (m_isMovingOn && !needToAdjustPosY)
        {
            return;
        }
        else
        {
            StopNav();
        }

        if (needToAdjustPosY)
        {
            bool hasHit = MogoUtils.GetPointInTerrain(v.x, v.z, out v);

            if (!hasHit)
            {
                LoggerHelper.Error("there is no Hit!目测没把场景碰撞层设为Terrain:" + v + " at " + MogoWorld.thePlayer.sceneId + " 求美术看看");
                return;
            }
        }
        //Mogo.Util.LoggerHelper.Debug("v:" + v);
        //计算路线
        if (!isMovingToTarget)//|| (targetToMoveTo - v).magnitude < 0.05f
        {
            //Mogo.Util.LoggerHelper.Debug("IsSideCrash!");
            path = m_navHelper.GetPathByTarget(v);
            //Mogo.Util.LoggerHelper.Debug("path:" + path.corners.Length);
            targetToMoveTo = v;
            m_cornersIdx   = 1;
        }

        //Mogo.Util.LoggerHelper.Debug("path.corners.Length:" + path.corners.Length);
        if (path.corners.Length < 2)
        {
            //Mogo.Util.LoggerHelper.Error("path.corners.Length < 2");
            StopNav();
            MogoWorld.thePlayer.Idle();
            //Debug.LogError("path.corners.Length < 2");
            //EventDispatcher.TriggerEvent(ON_MOVE_TO, transform.gameObject, targetToMoveTo);
            return;
        }

        isMovingToTarget = true;
        moveDirection    = (path.corners[m_cornersIdx] - transform.position).normalized;
        //Mogo.Util.LoggerHelper.Error("MoveTo:" + path.corners[m_cornersIdx]);
        //RotateTo(path.corners[m_cornersIdx]);
        transform.LookAt(new Vector3(path.corners[m_cornersIdx].x, transform.position.y, path.corners[m_cornersIdx].z));
        float dis  = Vector3.Distance(transform.position, path.corners[m_cornersIdx]);
        float step = 8 * Time.deltaTime;

        //Mogo.Util.LoggerHelper.Debug("dis:" + dis);
        //Mogo.Util.LoggerHelper.Debug("step:" + step);
        if (step + 0.1f > dis && m_cornersIdx < path.corners.Length - 1)
        {
            //collisionFlags = characterController.Move(transform.forward * dis);
            //Mogo.Util.LoggerHelper.Debug("m_isMovingOn = true;");
            //StopNav();
            //m_isMovingOn = true;

            //m_timerIdForNav = TimerHeap.AddTimer(900, 0, () =>
            // {
            //     m_isMovingOn = false;
            //     MoveTo(targetToMoveTo, false);

            // });
            //return;
            collisionFlags = characterController.Move(transform.forward * dis);

            //transform.position = new Vector3(path.corners[m_cornersIdx].x, transform.position.y, path.corners[m_cornersIdx].z);
            m_cornersIdx++;
            transform.LookAt(new Vector3(path.corners[m_cornersIdx].x, transform.position.y, path.corners[m_cornersIdx].z));
            //path = m_navHelper.GetPathByTarget(v);
            //m_cornersIdx = 1;
        }
        else if (m_cornersIdx == path.corners.Length - 1 && step + 0.1f + m_stopDistance > dis)
        {
            ////Debug.LogError("StopNav");
            //float tempDis = 10;
            //for (int i = 0; i < 5 && tempDis > 0.1; i++, dis = Vector3.Distance(transform.position, targetToMoveTo))
            //{
            //    tempDis = dis - m_stopDistance;
            //    tempDis = tempDis > 0 ? tempDis : 0;
            //    collisionFlags = characterController.Move((targetToMoveTo - transform.position).normalized * tempDis);
            //}
            //StopNav();

            //if (tempDis > 0.3)
            //{
            //    MogoWorld.thePlayer.Idle();
            //    EventDispatcher.TriggerEvent(ON_MOVE_TO_FALSE, transform.gameObject, targetToMoveTo, tempDis);
            //}

            //EventDispatcher.TriggerEvent(ON_MOVE_TO, transform.gameObject, targetToMoveTo);


            //Debug.LogError("StopNav");
            float tempDis;
            //for (int i = 0; i < 5 && tempDis > 0.1; i++, dis = Vector3.Distance(transform.position, targetToMoveTo))
            //{
            tempDis        = dis - m_stopDistance;
            tempDis        = tempDis > 0 ? tempDis : 0;
            collisionFlags = characterController.Move((path.corners[m_cornersIdx] - transform.position).normalized * tempDis);
            //}
            StopNav();
            tempDis = Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(targetToMoveTo.x, targetToMoveTo.z));
            if (tempDis > 0.2 + m_stopDistance)
            {
                MogoWorld.thePlayer.Idle();
                EventDispatcher.TriggerEvent(ON_MOVE_TO_FALSE, transform.gameObject, targetToMoveTo, tempDis);
            }
            else
            {
                EventDispatcher.TriggerEvent(ON_MOVE_TO, transform.gameObject, targetToMoveTo);
            }
        }
        //}
    }
Exemple #10
0
    public override bool MoveToByNav(Vector3 v, float stopDistance = 0f, bool needToAdjustPosY = true)
    {
        //Mogo.Util.LoggerHelper.Error("MoveToByNav v:" + v);
        if (!canMove)
        {
            return(false);
        }
        if (m_isMovingOn)
        {
            return(false);
        }

        Mogo.Util.LoggerHelper.Debug("v:" + v);
        if (needToAdjustPosY)
        {
            bool hasHit = MogoUtils.GetPointInTerrain(v.x, v.z, out v);

            if (!hasHit)
            {
                return(false);
            }
        }
        Mogo.Util.LoggerHelper.Debug("v:" + v);
        //计算路线
        if (!isMovingToTarget || IsSideCrash())//|| (targetToMoveTo - v).magnitude < 0.05f
        {
            Mogo.Util.LoggerHelper.Debug("IsSideCrash!");
            path = m_navHelper.GetPathByTarget(v);
            Mogo.Util.LoggerHelper.Debug("path:" + path.corners.Length);
            targetToMoveTo = v;
            m_cornersIdx   = 1;
        }

        //Mogo.Util.LoggerHelper.Debug("path.corners.Length:" + path.corners.Length);
        if (path.corners.Length < 2)
        {
            Mogo.Util.LoggerHelper.Debug("path.corners.Length < 2");
            StopNav();
            return(false);
        }

        isMovingToTarget = true;
        moveDirection    = (path.corners[m_cornersIdx] - transform.position).normalized;
        //RotateTo(path.corners[m_cornersIdx]);
        transform.LookAt(new Vector3(path.corners[m_cornersIdx].x, transform.position.y, path.corners[m_cornersIdx].z));
        float dis  = Vector3.Distance(transform.position, path.corners[m_cornersIdx]);
        float step = 8 * Time.deltaTime;

        Mogo.Util.LoggerHelper.Debug("dis:" + dis);
        Mogo.Util.LoggerHelper.Debug("step:" + step);
        if (step + 1f > dis && m_cornersIdx < path.corners.Length - 1)
        {
            //collisionFlags = characterController.Move(transform.forward * dis);
            Mogo.Util.LoggerHelper.Debug("m_isMovingOn = true;");
            m_isMovingOn = true;
            StopNav();

            m_timerIdForNav = TimerHeap.AddTimer(400, 0, () =>
            {
                m_isMovingOn = false;
                MoveTo(targetToMoveTo, false);
            });
            return(true);
            //collisionFlags = characterController.Move(transform.forward * dis);

            //transform.position = new Vector3(path.corners[m_cornersIdx].x, transform.position.y, path.corners[m_cornersIdx].z);
            //m_cornersIdx++;
            //path = m_navHelper.GetPathByTarget(v);
            //m_cornersIdx = 1;
        }
        else if (m_cornersIdx == path.corners.Length - 1 && step + 0.2f + m_stopDistance > dis)
        {
            Mogo.Util.LoggerHelper.Debug("StopNav");
            float tempDis = 10;

            for (int i = 0; i < 10 && tempDis > 0.1; i++, dis = Vector3.Distance(transform.position, path.corners[m_cornersIdx]))
            {
                transform.LookAt(new Vector3(targetToMoveTo.x, transform.position.y, targetToMoveTo.z));
                tempDis        = dis - m_stopDistance;
                tempDis        = tempDis > 0 ? tempDis : 0;
                collisionFlags = characterController.Move((path.corners[m_cornersIdx] - transform.position).normalized * tempDis);
            }
            StopNav();
            if (tempDis < 0.3)
            {
                EventDispatcher.TriggerEvent(ON_MOVE_TO, transform.gameObject, targetToMoveTo);
            }
        }
        return(true);
    }