Ejemplo n.º 1
0
    public void EntityEnter(uint id, Entity.Type type, uint subType, Vector3 position, float direction)
    {
        Entity entity = null;

        switch (type)
        {
        case Entity.Type.Player:
        case Entity.Type.NPC:
        {
            RoleInfo   info = Core.Database.GetRoleInfo(subType);
            GameObject go   = Core.Database.LoadResource("Roles/" + info.res);
            go.transform.localScale = Vector3.one * info.scale;
            Role role = go.AddComponent <Role>();

            go.AddComponent <RoleAnimator>();
            RoleAgent agent = go.AddComponent <RoleAgent>();
            agent.RoleId = id;

            CapsuleCollider collider = go.AddComponent <CapsuleCollider>();
            collider.radius = 0.5f;
            collider.height = 2;
            collider.center = new Vector3(0, 1.1f, 0);

            if (Core.Account.role == null)
            {
                Core.Account.role = role;
                m_camera.GetComponent <CameraController>().target = go.transform;
                go.AddComponent <RoleController>();
                Rigidbody rigidbody = go.AddComponent <Rigidbody>();
                rigidbody.freezeRotation = true;
                rigidbody.useGravity     = false;
            }

            entity = role;
        }
        break;

        case Entity.Type.Teleporter:
        {
            GameObject go = Core.Database.LoadResource("Entities/Teleporter");
            entity = go.AddComponent <Teleporter>();
        }
        break;

        case Entity.Type.Item:
        {
            GameObject go = Core.Database.LoadResource("Entities/Bottle");
            entity = go.AddComponent <DropItem>();
        }
        break;

        default:
            break;
        }

        if (entity != null)
        {
            entity.SetInfo(id, type, subType);
            entity.SetPosition(position);
            entity.SetDirection(direction);
            AddEntity(entity);
        }
    }
Ejemplo n.º 2
0
 protected override void OnStart()
 {
     m_roleAgent        = gameObject.GetComponent <RoleAgent>();
     m_headBoard        = Core.Game.overlay.RequireHeadBoard();
     m_headBoard.enable = true;
 }
Ejemplo n.º 3
0
    void Update()
    {
        m_elapsedTime += Time.deltaTime;

        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100))
            {
                Entity entity = hit.collider.GetComponent <Entity>();
                if (entity)
                {
                    switch (entity.type)
                    {
                    case Entity.Type.NPC:
                    {
                        RoleAgent agent = hit.collider.gameObject.GetComponent <RoleAgent>();
                        if (agent != null)
                        {
                            m_target = agent.RoleId;
                        }
                    }
                    break;

                    case Entity.Type.Item:
                    {
                        SendPickup(entity.id);
                    }
                    break;

                    default:
                        break;
                    }
                }
                else
                {
                    m_target = 0;
                    if (!m_animator.IsInAction())
                    {
                        SendMove(hit.point);
                    }
                }
            }
        }

        if (m_elapsedTime > AttackInterval && m_target > 0)
        {
            m_elapsedTime = 0;

            Role role = Core.Game.GetEntity(m_target) as Role;
            if (role != null)
            {
                float distance = Vector3.Distance(role.transform.position, transform.position);
                if (distance < AttackRange)
                {
                    SendAttack(role);
                }
                else
                {
                    SendMove(role.transform.position);
                }
            }
            else
            {
                m_target = 0;
            }
        }
    }