Exemple #1
0
    protected override void OnSeparation(Fixture fixtureA, Fixture fixtureB, Contact contact)
    {
        if (null == b2Body)
        {
            return;
        }
        Fixture other = (fixtureA.Body == b2Body) ? fixtureB : fixtureA;

        //UnityEngine.Debug.Log("伤害体碰撞 Separation");
        MapCollider collider = other.Body.UserData as MapCollider;

        if (collider != null)
        {
            //UnityEngine.Debug.Log("  OnSeparation  collider  ");
        }
        // 分离受击
        MapRole role = other.Body.UserData as MapRole;

        if (role != null)
        {
            //UnityEngine.Debug.Log("  OnSeparation  MapRole  ");
            damageBody.RemoveDamageRole(role.m_strHandle);
        }

        //base.OnSeparation(fixtureA, fixtureB, contact);
    }
Exemple #2
0
    /// <summary>
    /// 地图角色绑定已有数据实例
    /// </summary>
    /// <param name="roleView"></param>
    /// <param name="role"></param>
    public static void BindRoleInstance(this MapRole roleView, RoleInstance role, Action callback = null)
    {
        if (role == null || roleView == null)
        {
            return;
        }

        //已经绑定过了,不需要再行绑定了。
        if (role.View == roleView && roleView.DataInstance == role)
        {
            return;
        }

        role.View = roleView;
        roleView.ForceSetAnimator(null);
        roleView.DataInstance = role;

        //JYX2 不刷新临时NPC外观
        if (roleView.m_RoleKey != "testman")
        {
            roleView.RefreshModel(callback);
        }
        else
        {
            if (callback != null)
            {
                callback();
            }
        }
    }
        private void BindRoles(Node origin, Node target, ManhattanGeometry geometry)
        {
            // Variable initialization
            _pathTo      = new Dictionary <Node, Node>();
            _origin      = origin;
            _destination = target;

            // Bind RolePlayers to Roles

            // Set the initial node as current.
            Current             = origin;
            CurrentIntersection = origin;
            DistanceGraph       = origin;

            Map = geometry;

            // A set of the unvisited nodes called the unvisited set consisting of all the nodes
            // except the initial node.
            Unvisited = new UnvisitedNodes(geometry.Nodes);
            Unvisited.Remove(origin);

            // Assign to every node a tentative distance value:
            // Set it to zero for our initial node and to infinity for all other nodes.
            TentativeDistance         = geometry.Nodes.ToDictionary(n => n, n => ManhattanGeometry.Infinity);
            TentativeDistance[origin] = 0;
        }
Exemple #4
0
    protected override void OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
    {
        Fixture other = (fixtureA.Body == b2Body) ? fixtureB : fixtureA;

        //UnityEngine.Debug.Log("伤害体碰撞 On");
        MapCollider collider = other.Body.UserData as MapCollider;

        if (collider != null)
        {
            //UnityEngine.Debug.Log("  OnCollision  collider  ");
            // 如果是Destroy类型的则应该设置速度为0,并发送回调(立即销毁/延迟销毁)
            // 如果是Bound类型的则应该根据速度,反弹,发送回调(原方向/法线对称)
            // 如果是Cross类型则应该已经在OnBeforeCollision中处理了
            if (false == collider.m_isSensor)
            {
                damageBody.OnColliderCollision(collider.m_strHandle);
            }
            // 场景物体受击 TODO
        }

        // 能执行到OnCollision说明角色可受击
        MapRole role = other.Body.UserData as MapRole;

        if (role != null)
        {
            //UnityEngine.Debug.Log("  OnCollision  MapRole  ");
            damageBody.AddDamageRole(role.m_strHandle);
        }

        //base.OnCollision(fixtureA, fixtureB, contact);
    }
Exemple #5
0
    public void SetPlayer(MapRole playerRoleView)
    {
        playerRoleView.BindRoleInstance(runtime.Player, () => {
            //由于这里是异步加载模型,所以必须加载完后才初始化出生点,因为初始化出生点里有描述玩家是否在船上,需要调用子节点的renderer

            //初始化出生点
            LoadSpawnPosition();
        });
        _playerView     = playerRoleView;
        _player         = playerRoleView.transform;
        _playerNavAgent = playerRoleView.GetComponent <NavMeshAgent>();

        SetPlayerSpeed(0);
        var gameMap = GetCurrentGameMap();

        if (gameMap != null && gameMap.Tags.Contains("WORLDMAP"))
        {
            _playerNavAgent.speed = 10; //大地图上放大一倍
        }
        else
        {
            _playerNavAgent.speed = MapRuntimeData.Instance.ExploreSpeed;
        }

        _playerNavAgent.angularSpeed = MapRuntimeData.Instance.ExploreAngularSpeed;
        _playerNavAgent.acceleration = MapRuntimeData.Instance.ExploreAcceleration;

        var playerCom = _player.GetComponent <Jyx2Player>();

        if (playerCom == null)
        {
            var player = _player.gameObject.AddComponent <Jyx2Player>();
            player.Init();
        }
    }
Exemple #6
0
 public MapDamage(DamageBody damageBody)
 {
     this.damageBody = damageBody;
     m_strHandle     = damageBody.m_sHandleName;
     skillID         = damageBody.m_iSkillID;
     hostMapRole     = damageBody.m_host.m_mapRole;
     boundType       = damageBody.m_eBoundType;
 }
Exemple #7
0
    /// <summary>
    /// 设置Role初始数据 创建gameObject
    /// </summary>
    /// <param name="baseInfo"></param>
    /// <param name="initInfo"></param>
    public bool InitBaseRole(string handleName, BaseRoleInfo baseInfo, MapRoleInfo initInfo)
    {
        if (baseInfo == null || initInfo == null)
        {
            m_bStarted = false;
            return(false);
        }
        // 初始化数据
        m_sHandleName = handleName;
        m_eRoleType   = (eRoleType)initInfo.RoleType;
        m_baseInfo    = baseInfo;
        m_initInfo    = initInfo;
        m_fWidth      = baseInfo.Width;
        m_fHeight     = baseInfo.Height;
        m_fPosX       = initInfo.InitPosX;
        m_fPosY       = initInfo.InitPosY;
        int curHp = initInfo.InitHP;

        if (curHp == -1)
        {
            m_iCurHp = m_baseInfo.MaxHp;
        }
        else
        {
            m_iCurHp = curHp;
        }
        m_ulAction  = (ulong)initInfo.InitStatus;
        m_curStatus = (ePhtatus)m_ulAction;
        m_bIsStatic = initInfo.IsStatic;
        m_bCanMove  = initInfo.CanMove;

        // 初始化ShowObject
        GameObject prefabObj = Resource.LoadObj(m_baseInfo.PrefabName) as GameObject;

        if (null == prefabObj)
        {
            m_bStarted = false;
            return(false);
        }
        GameObject showObj = GameObject.Instantiate(prefabObj);

        showObj.name = "actor";
        GlobalVarFun.AttachChild(gameObject, showObj);
        m_showObj = showObj;

        // 初始化m_mapRole
        if (m_mapRole == null)
        {
            m_mapRole = new MapRole(this);
        }
        m_mapRole.OnChangeMap(MapManager.Instance.curMapWorld, m_fPosX, m_fPosY, m_fWidth, m_fHeight);
        m_mapRole.SetInitData(m_baseInfo, m_initInfo);


        Clear();
        m_bStarted = true;
        return(true);
    }
Exemple #8
0
    private void Awake()
    {
        //实例化LevelMaster
        MapRole player = Jyx2ResourceHelper.CreatePrefabInstance(ConStr.Player).GetComponent <MapRole>();

        player.name = "Player";
        player.transform.SetParent(transform, false);
        player.transform.localPosition = Vector3.zero;
    }
Exemple #9
0
    // 当伤害体碰撞到Collider时:
    // 如果是Destroy类型的则应该设置速度为0,并发送回调(立即销毁/延迟销毁)
    // 如果是Bound类型的则应该根据速度,反弹,发送回调(原方向/法线对称)
    // 如果是Cross类型则应该已经在OnBeforeCollision中处理了

    protected override bool OnBeforeCollision(Fixture fixtureA, Fixture fixtureB)
    {
        if (null == b2Body)
        {
            return(false);
        }
        if (!m_isActive)
        {
            return(false);
        }
        Fixture other = (fixtureA.Body == b2Body) ? fixtureB : fixtureA;

        //UnityEngine.Debug.Log("伤害体碰撞 Before");
        MapCollider collider = other.Body.UserData as MapCollider;

        if (collider != null)
        {
            //UnityEngine.Debug.Log("  OnBeforeCollision  collider  ");
            if (boundType == eDamageBoundType.Cross)
            {
                return(false); // Cross类型直接通过
            }
            if (collider.m_isSensor == true)
            {
                return(false);
            }
        }

        MapRole role = other.Body.UserData as MapRole;

        if (role != null)
        {
            if (role == hostMapRole)
            {
                return(false);                    // 是主人放出来的 不发生碰撞
            }
            return(role.OnCanDamage(damageBody)); // 角色是否可以受击
        }
        // 场景物体是否可以受击 TODO
        return(true);
        //return base.OnBeforeCollision(fixtureA, fixtureB);
    }
Exemple #10
0
    IEnumerator DoPlayerMove(MapRole player, List <Vector3> path, Action callback)
    {
        IsBattleMoving = true;
        var count = path.Count;

        player.IsPlayingMovingAnimation = false;
        for (int i = 0; i < count; i++)
        {
            var pos  = path[i];
            var temp = new Vector3(pos.x, pos.y, pos.z);
            yield return(DoPlayerMove(player, temp));
        }

        //yield return new WaitForSeconds(0.2f); //有个切换动作的时间?否则在漂移?
        //player.m_Animator.SetTrigger("Idle");
        IsBattleMoving = false;
        //yield return new WaitForSeconds(0.05f); //有个切换动作的时间?否则在漂移?

        callback?.Invoke();
    }
Exemple #11
0
    IEnumerator DoPlayerMove(MapRole player, Vector3 target)
    {
        var dist = (target - player.transform.position).magnitude;

        if (dist < 0.1f) //eqaul zero
        {
            yield break;
        }

        float time = (float)(dist / m_BattleMoveSpeed);

        if (!player.IsPlayingMovingAnimation)
        {
            player.Run(); //如果不是这样,则每次移动一格,移动动画会重新开始播放
            player.IsPlayingMovingAnimation = true;
        }

        player.transform.LookAt(new Vector3(target.x, player.transform.position.y, target.z)); //转身
        var tweener = player.transform.DOMove(target, time).SetEase(Ease.Linear).OnComplete(() => { });

        yield return(new WaitForSeconds(time));
    }
Exemple #12
0
 /// <summary>
 /// 地图角色绑定新的数据实例
 /// </summary>
 /// <param name="roleKey"></param>
 /// <param name="roleView"></param>
 public static void CreateRoleInstance(this MapRole roleView, string roleKey)
 {
     roleView.BindRoleInstance(new RoleInstance(roleKey));
     roleView.DataInstance.Hp = roleView.DataInstance.MaxHp; //默认满血
 }
Exemple #13
0
 // Use this for initialization
 void Start()
 {
     mapRole = GetComponent <MapRole>();
     InvokeRepeating("RandomTalk", 5, 5);
 }