Ejemplo n.º 1
0
    private void LateUpdate()
    {
        if (this.character == null || !character.ready)//----
        {
            return;
        }

        Vector3 offset = this.rb.transform.position - lastPos;

        this.speed = (int)(offset.magnitude * 100f / Time.deltaTime);
        //Debug.LogFormat("LateUpdate velocity {0} : {1}", this.rb.velocity.magnitude, this.speed);
        this.lastPos = this.rb.transform.position;

        Vector3Int goLogicPos  = GameObjectTool.WorldToLogic(this.rb.transform.position);
        float      logicOffset = (goLogicPos - this.character.position).magnitude;

        if (logicOffset > 100)
        {
            this.character.SetPosition(GameObjectTool.WorldToLogic(this.rb.transform.position));
            this.SendEntityEvent(EntityEvent.None);
        }
        this.transform.position = this.rb.transform.position;
        Vector3    dir = GameObjectTool.LogicToWorld(this.character.direction);
        Quaternion rot = new Quaternion();

        rot.SetFromToRotation(dir, this.transform.forward);
        if (rot.eulerAngles.y > this.turnAngle && rot.eulerAngles.y < (360 - this.turnAngle))
        {
            character.SetDirection(GameObjectTool.WorldToLogic(this.transform.forward));
            this.SendEntityEvent(EntityEvent.None);
        }
    }
Ejemplo n.º 2
0
        private void InitGameObject(Character character, GameObject go)
        {
            go.transform.position = GameObjectTool.LogicToWorld(character.position);
            go.transform.forward  = GameObjectTool.LogicToWorld(character.direction);
            EntityController ec = go.GetComponent <EntityController>();

            if (ec != null)
            {
                ec.isCurrentPlayer = character.IsCurrentPlayer;
                ec.entity          = character;
                ec.enabled         = true;
            }

            PlayerController pc = go.GetComponent <PlayerController>();

            if (character.IsCurrentPlayer && pc != null)
            {
                User.Instance.CurrentCharacterObject = go;
                pc.ec        = ec;
                pc.character = character;
                GameObject playModule = ResMgr.GetPrefab("playModule", "module/common/PlayModule.prefab");
                playModule = Instantiate(playModule);
                DontDestroyOnLoad(playModule);
                Transform player = go.transform;
                playModule.transform.position = player.position;
                playModule.transform.rotation = player.rotation;
                player.SetParent(playModule.transform);
                player.localPosition = Vector3.zero;
                MainPlayerCamera.Instance.SetCurrentPlayer(player, playModule, playModule.GetComponent <CharacterController>());
            }
        }
Ejemplo n.º 3
0
    public void OnEntityChanged(NEntity nEntity)
    {
        //Debug.LogFormat("Postion{0}", GameObjectTool.LogicToWorld(nEntity.Position));
        this.transform.position = GameObjectTool.LogicToWorld(nEntity.Position);

        this.transform.rotation = Quaternion.Euler((GameObjectTool.LogicToWorld(nEntity.Direction)));
    }
Ejemplo n.º 4
0
    private void InitGameObject(GameObject go, Character character)
    {
        go.transform.position = GameObjectTool.LogicToWorld(character.position);
        go.transform.forward  = GameObjectTool.LogicToWorld(character.direction);
        EntityController ec = go.GetComponent <EntityController>();

        if (ec != null)
        {
            ec.entity   = character;
            ec.isPlayer = character.IsCurrentPlayer;
            ec.Ride(character.Info.Ride);
            character.Controller = ec;
        }
        PlayerInputController pc = go.GetComponent <PlayerInputController>();

        if (pc != null)
        {
            if (character.IsCurrentPlayer)
            {
                User.Instance.CurrentCharacterObject = pc;
                MainPlayerCamera.Instance.player     = go;
                pc.enabled          = true;
                pc.character        = character;
                pc.entityController = ec;
            }
            else
            {
                pc.enabled = false;
            }
        }
    }
Ejemplo n.º 5
0
    public void UpdateTransform()//------
    {
        this.position = GameObjectTool.LogicToWorld(entity.position);
        this.rb.MovePosition(this.position);
        this.lastPosition = this.position;

        UpdateDirection();
    }
Ejemplo n.º 6
0
 void UpdateTransform()
 {
     position           = GameObjectTool.LogicToWorld(entity.position);
     direction          = GameObjectTool.LogicToWorld(entity.direction);
     transform.position = position;
     transform.forward  = direction;
     lastPosition       = position;
     lastRotation       = rotation;
 }
Ejemplo n.º 7
0
 internal void FaceTo(Vector3Int position)
 {
     this.SetDirection(GameObjectTool.WorldToLogic(GameObjectTool.LogicToWorld(position - this.position).normalized));
     this.UpdateEntityData();
     if (this.Controller != null)
     {
         this.Controller.UpdateDirection();
     }
 }
Ejemplo n.º 8
0
    void UpdateTransform()
    {
        this.Position  = GameObjectTool.LogicToWorld(Entity.position);
        this.Direction = GameObjectTool.LogicToWorld(Entity.direction);

        this.m_Rigibody.MovePosition(this.Position);
        this.transform.forward = this.Direction;
        this.LastPosition      = this.Position;
        this.m_LastRotation    = this.m_Rotation;
    }
Ejemplo n.º 9
0
    void UpdateTransform()
    {
        this.position  = GameObjectTool.LogicToWorld(entity.position);
        this.direction = GameObjectTool.LogicToWorld(entity.direction);

        this.rb.MovePosition(this.position);
        this.transform.forward = this.direction;
        this.lastPosition      = this.position;
        this.lastRotation      = this.rotation;
    }
Ejemplo n.º 10
0
 public void PlayEffect(EffectType type, string name, NVector3 postion, float duration)
 {
     if (type == EffectType.Position || type == EffectType.Hit)
     {
         FXManager.Instance.PlayEffect(type, name, null, GameObjectTool.LogicToWorld(postion), duration);
     }
     else
     {
         this.EffectMgr.PlayEffect(type, name, null, GameObjectTool.LogicToWorld(postion), duration);
     }
 }
Ejemplo n.º 11
0
 public static void ShowSelector(Vector3Int center, float range, float size, Action <Vector3> onPostionSelected)
 {
     if (TargetSelector.Instance == null)
     {
         return;
     }
     TargetSelector.Instance.center      = GameObjectTool.LogicToWorld(center);
     TargetSelector.Instance.range       = GameObjectTool.LogicToWorld(range);
     TargetSelector.Instance.size        = GameObjectTool.LogicToWorld(size);
     TargetSelector.Instance.selectPoint = onPostionSelected;
     TargetSelector.Instance.Active(true);
 }
Ejemplo n.º 12
0
    /// <summary>
    /// update controller's fields
    /// </summary>
    private void UpdateTransform()
    {
        //update transform to be the same with what stored in entity
        mPosition  = GameObjectTool.LogicToWorld(entity.position);
        mDirection = GameObjectTool.LogicToWorld(entity.direction);
        mSpeed     = entity.speed;

        mRigidbody.MovePosition(mPosition);
        this.transform.forward = mDirection;

        mLastPosition = mPosition;
        mLastPosition = mDirection;
    }
Ejemplo n.º 13
0
    private void CreateCharacterObject(Character character)
    {
        if (!Characters.ContainsKey(character.entityId) || Characters[character.entityId] == null)
        {
            Object obj = Resloader.Load <Object>(character.Define.Resource);
            if (obj == null)
            {
                Debug.LogErrorFormat("Character[{0}] Resource[{1}] not existed.", character.Define.TID, character.Define.Resource);
                return;
            }
            GameObject go = (GameObject)Instantiate(obj);
            go.name = "Character_" + character.entityId + "_" + character.Info.Name;

            go.transform.position = GameObjectTool.LogicToWorld(character.position);
            go.transform.forward  = GameObjectTool.LogicToWorld(character.direction);
            go.transform.SetParent(_parent);
            Characters[character.entityId] = go;
            EntityController ec = go.GetComponent <EntityController>();
            if (ec != null)
            {
                ec.entity   = character;
                ec.isPlayer = character.IsPlayer;
                EntityManager.Instance.RegisterEntityChangeNotify(character.entityId, ec);
            }

            PlayerInputController pc = go.GetComponent <PlayerInputController>();
            if (pc != null)
            {
                if (character.Info.Id == Models.User.Instance.CurrentCharacter.Id)
                {
                    User.Instance.CurrentCharacterObject = go;
                    GameManager.CameraMgr.player         = go;
                    pc.enabled          = true;
                    pc.character        = character;
                    pc.entityController = ec;
                }
                else
                {
                    pc.enabled = false;
                }
            }
            GameManager.NameMgr.AddHeadBar(go.transform, character);
        }
    }
Ejemplo n.º 14
0
    private void CreateCharacter(Entities.Character character)
    {
        if (!Characters.ContainsKey(character.entityId) || Characters[character.entityId] == null)
        {
            UnityEngine.Object obj = Resloader.Load <UnityEngine.Object>(character.Define.Resource);
            if (obj == null)
            {
                Debug.LogErrorFormat("Character[{0}] Resource[{1}] not existed.", character.Define.TID, character.Define.Resource);
                return;
            }
            GameObject go = (GameObject)Instantiate(obj, this.transform);
            go.name = "Character_" + character.Info.Id + "_" + character.Info.Name;

            go.transform.position          = GameObjectTool.LogicToWorld(character.position);
            go.transform.forward           = GameObjectTool.LogicToWorld(character.direction);
            Characters[character.entityId] = go;
            UIWorldElementManager.Instance.AddCharacterNameBar(go.transform, character);
        }
        InitGameObj(character, Characters[character.entityId]);
    }
Ejemplo n.º 15
0
    private void InitCharacter(GameObject obj, Character cha)
    {
        Debug.LogFormat("GameObjectManager->InitCharacter()");
        obj.name = cha.Name;
        obj.transform.position = GameObjectTool.LogicToWorld(cha.position);
        obj.transform.forward  = GameObjectTool.LogicToWorld(cha.direction);

        EntityController entityController = obj.GetComponent <EntityController>();

        if (entityController != null)
        {
            entityController.isPlayer = cha.IsCurrentPlayer;
            entityController.entity   = cha;
            EntityManager.Instance.RegisterEntityNotifier(cha.entityID, entityController);
        }

        PlayerInputController playerController = obj.GetComponent <PlayerInputController>();

        if (entityController.isPlayer)
        {
            if (playerController != null)
            {
                playerController.character = cha;
            }

            //if (mainPlayerCamera != null)
            //{
            //    mainPlayerCamera.transform.parent = obj.transform;
            //    mainPlayerCamera.transform.localPosition = Vector3.zero;
            //    mainPlayerCamera.transform.localRotation = Quaternion.identity;
            //    mainPlayerCamera.transform.localScale = Vector3.one;
            //}

            Models.User.Instance.currentPlayerObject = obj;
        }
        else
        {
            playerController.enabled = false;
        }
    }
Ejemplo n.º 16
0
    /// <summary>
    /// use fixed update to deal with user inputs
    /// When receive input, update 3 things: (1)Character data, (2)rigidbody, (3)animator
    /// </summary>
    void Update()
    {
        //if controller hasnt been assigned with a character, dont read user input
        if (character == null)
        {
            return;
        }

        //get user input on vertical axis
        float v = Input.GetAxis("Vertical");

        //if user wants to move forward
        if (v > 0.01f)
        {
            //send synchronization message only when state changes
            if (mState != SkillBridge.Message.CharacterState.Move)
            {
                mState = CharacterState.Move;
                character.MoveForward();

                SendEntityEvent(EntityEvent.MoveFwd);
            }

            mRigidbody.velocity = this.mRigidbody.velocity.y * Vector3.up + GameObjectTool.LogicToWorld(character.direction) * (character.speed + 9.81f) / 100f;
        }

        //if user wants to move backward
        else if (v < -0.01f)
        {
            if (mState != SkillBridge.Message.CharacterState.Move)
            {
                mState = CharacterState.Move;
                character.MoveBackward();

                SendEntityEvent(EntityEvent.MoveBack);
            }

            mRigidbody.velocity = this.mRigidbody.velocity.y * Vector3.up + GameObjectTool.LogicToWorld(character.direction) * (this.character.speed + 9.81f) / 100f;
        }

        //if user is not moving
        else
        {
            character.Stop();
            if (mState != SkillBridge.Message.CharacterState.Idle)
            {
                mState = CharacterState.Idle;
                mRigidbody.velocity = Vector3.zero;

                SendEntityEvent(EntityEvent.Idle);
            }
        }

        //player jump input detection
        //jump is not considered a movement, only display animation
        if (Input.GetButtonDown("Jump"))
        {
            SendEntityEvent(EntityEvent.Jump);
        }

        //horizontal input are consider as rotation
        float h = Input.GetAxis("Horizontal");

        if (h > 0.1f || h < -0.1f)
        {
            //perform rotation on gameobject
            this.transform.Rotate(0, h * mRotateSpeed, 0);
            Vector3 dir = GameObjectTool.LogicToWorld(character.direction);

            //update the data stored in Character
            Quaternion rotation = new Quaternion();
            rotation.SetFromToRotation(dir, this.transform.forward);

            //if offset is too small, do not update
            if (rotation.eulerAngles.y > this.mTurnAngle && rotation.eulerAngles.y < (360 - mTurnAngle))
            {
                character.SetDirection(GameObjectTool.WorldToLogic(this.transform.forward));
                mRigidbody.transform.forward = this.transform.forward;
                SendEntityEvent(EntityEvent.None);
            }
        }
    }
Ejemplo n.º 17
0
    void FixedUpdate()
    {
        if (character == null)
        {
            return;
        }


        float v = Input.GetAxis("Vertical");

        if (v > 0.01)
        {
            if (state != SkillBridge.Message.CharacterState.Move)
            {
                state = SkillBridge.Message.CharacterState.Move;
                this.character.MoveForward();
                this.SendEntityEvent(EntityEvent.MoveFwd);
            }
            this.rb.velocity = this.rb.velocity.y * Vector3.up + GameObjectTool.LogicToWorld(character.direction) * (this.character.speed + 9.81f) / 100f;
        }
        else if (v < -0.01)
        {
            if (state != SkillBridge.Message.CharacterState.Move)
            {
                state = SkillBridge.Message.CharacterState.Move;
                this.character.MoveBack();
                this.SendEntityEvent(EntityEvent.MoveBack);
            }
            this.rb.velocity = this.rb.velocity.y * Vector3.up + GameObjectTool.LogicToWorld(character.direction) * (this.character.speed + 9.81f) / 100f;
        }
        else
        {
            if (state != SkillBridge.Message.CharacterState.Idle)
            {
                state            = SkillBridge.Message.CharacterState.Idle;
                this.rb.velocity = Vector3.zero;
                this.character.Stop();
                this.SendEntityEvent(EntityEvent.Idle);
            }
        }

        if (Input.GetButtonDown("Jump"))
        {
            this.SendEntityEvent(EntityEvent.Jump);
        }

        float h = Input.GetAxis("Horizontal");

        if (h < -0.1 || h > 0.1)
        {
            this.transform.Rotate(0, h * rotateSpeed, 0);
            Vector3    dir = GameObjectTool.LogicToWorld(character.direction);
            Quaternion rot = new Quaternion();
            rot.SetFromToRotation(dir, this.transform.forward);

            if (rot.eulerAngles.y > this.turnAngle && rot.eulerAngles.y < (360 - this.turnAngle))
            {
                character.SetDirection(GameObjectTool.WorldToLogic(this.transform.forward));
                rb.transform.forward = this.transform.forward;
                this.SendEntityEvent(EntityEvent.None);
            }
        }
        //Debug.LogFormat("velocity {0}", this.rb.velocity.magnitude);
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        if (character == null)
        {
            return;
        }
        if (!isPlayer)
        {
            return;
        }
        //if (InputManager)
        //{

        //}
        float v = Input.GetAxis("Vertical");

        if (v > 0.01f)
        {
            if (state != CharacterState.Move)
            {
                state = CharacterState.Move;
                this.character.MoveForward();                                                                                               //改变消息速度
                SendEntityEvent(EntityEvent.MoveFwd);                                                                                       //动画状态改变并同步
            }
            rb.velocity = rb.velocity.y * Vector3.up + GameObjectTool.LogicToWorld(character.direction) * (character.speed + 9.81f) / 100f; //9.81为了移动更平滑
            //Debug.Log(rb.velocity);
            //Debug.Log(character.speed);
        }
        else if (v < -0.01f)
        {
            if (state != CharacterState.Move)
            {
                state = CharacterState.Move;
                this.character.MoveBack();
                SendEntityEvent(EntityEvent.MoveBack);//动画状态改变并同步
            }

            rb.velocity = rb.velocity.y * Vector3.up + GameObjectTool.LogicToWorld(character.direction) * (character.speed + 9.81f) / 100f;
        }
        else
        {
            if (state != CharacterState.Idle)
            {
                state            = CharacterState.Idle;
                this.rb.velocity = Vector3.zero;
                character.Stop();
                SendEntityEvent(EntityEvent.Idle);
            }
        }
        if (Input.GetButtonDown("Jump"))
        {
            this.SendEntityEvent(EntityEvent.Jump);
        }

        float h = Input.GetAxis("Horizontal");

        if (h < -0.1 || h > 0.1)
        {
            this.transform.Rotate(0, h * rotalSpeed, 0);//绕y轴旋转
            Vector3    dir    = GameObjectTool.LogicToWorld(character.direction);
            Quaternion rotate = new Quaternion();
            rotate.SetFromToRotation(dir, this.transform.forward);                               //从第一个参数旋转到第二个参数
            if (rotate.eulerAngles.y > this.turnAgle && rotate.eulerAngles.y < (360 - turnAgle)) //10度以内忽略不计
            {
                character.SetDirection(GameObjectTool.WorldToLogic(this.transform.forward));

                this.SendEntityEvent(EntityEvent.None);
            }
            //rb.transform.forward = this.transform.forward;
        }
    }
Ejemplo n.º 19
0
 void UpdateAnmi()
 {
     speed = GameObjectTool.LogicToWorld(entity.speed);
     anim.SetFloat("Speed", speed);
 }
Ejemplo n.º 20
0
 public void UpdateDirection()//------
 {
     this.direction         = GameObjectTool.LogicToWorld(entity.direction);
     this.transform.forward = this.direction;
     this.lastRotation      = this.rotation;
 }