// 移动
    private void Moving()
    {
        if (moving)
        {
            if (player != null)
            {
                float x = -movintSpeed *Mathf.Sin(orientAngle),
                      y = movintSpeed * Mathf.Cos(orientAngle);

                // 动画、行走 方向相反
                if ((x < 0 && !orientLeft) || (x > 0 && orientLeft))
                {
                    Vector3 playerScale = player.transform.localScale;
                    player.transform.localScale = new Vector3(-playerScale.x, playerScale.y, playerScale.z);

                    orientLeft = x < 0 ? true : false;
                }

                player.GetComponent <Rigidbody>().velocity = new Vector3(x, 0.1f, y);
            }
            GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_PlayerMoveEvent(player.transform.position);
        }
        else
        {
            player.GetComponent <Rigidbody>().velocity = Vector3.zero;
        }
    }
示例#2
0
    /// <summary>
    /// 读取某关卡的怪物信息数据
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public List <Monster> loadMonterDataForStage(string path)
    {
        List <Monster> list = PlayerManager.instance.xmlToObject <List <Monster> >(path);

        monstersDependOnPosition = new List <Monster>();

        //StartCoroutine(WaitForCreateMonster(list[0]));
        foreach (Monster monster in list)
        {
            if (monster.DependOnTime)
            {
                StartCoroutine(WaitForCreateMonster(monster));
            }
            else if (monster.DependOnPosition)
            {
                monstersDependOnPosition.Add(monster);
            }
        }
        if (monstersDependOnPosition.Count > 0)
        {
            GameRoot_InBattle.getSingleton <MessageManager_InBattle>().playerMoveEvent
                += new MessageManager_InBattle.PlayerMoveDelegrate(checkPlayerPositionForMonsterCreate);
        }

        return(list);
    }
示例#3
0
    public void OnPress(bool press)
    {
        if (press)
        {
            pressed = true;
            //print("Press");

            if (!CDOver)
            {
                return;
            }

            if (hasShoot && !weapon.ContinueShoot)
            {
                return;
            }

            gameObject.GetComponent <UISprite>().spriteName = "WeaponContainer_2";
            shoot();
        }
        else
        {
            pressed = false;
            //print("UnPress");

            hasShoot = false;

            gameObject.GetComponent <UISprite>().spriteName = "WeaponContainer_1";
            GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_ShotItemReleaseEvent(index, weapon);
        }
    }
示例#4
0
 public void OnTriggerEnter(Collider collider)
 {
     //Debug.Log("Bullet OnTriggerEnter");
     if ((sender == Sender.Player || collider.tag == "Player") && (gameObject.tag != collider.tag))
     {
         GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_BulletCollisionEvent(this, collider.gameObject, collider.GetComponent <CharacterData>());
     }
 }
    // 反注册事件
    private void UnRegisterEvent()
    {
        GameRoot_InBattle.getSingleton <MessageManager_InBattle>().rockerEvent
            -= new MessageManager_InBattle.RockedDelegrate(RockerEvent);

        GameRoot_InBattle.getSingleton <MessageManager_InBattle>().shotItemPressEvent
            -= new MessageManager_InBattle.ShotItemDelegrate(PressWeapon);
    }
示例#6
0
    public static T getSingleton <T>() where T : Singleton <T>
    {
        if (instance == null)
        {
            instance = new GameRoot_InBattle();
        }

        return(instance.rootObj.GetComponent <T>());
    }
示例#7
0
    // Use this for initialization
    void Start()
    {
        pressed  = false;
        CDOver   = true;
        hasShoot = false;

        GameRoot_InBattle.getSingleton <MessageManager_InBattle>().shotSuccessfulEvent
            += new MessageManager_InBattle.ShotItemDelegrate(ShotSuccessful);
    }
示例#8
0
    /// <summary>
    /// (被打者)处理子弹伤害
    /// </summary>
    /// <param name="bullet"></param>
    /// <param name="monster"></param>
    /// <param name="charaterData"></param>
    private void DealWithHurt(Bullets bullet, GameObject monster, CharacterData charaterData)
    {
        float hurt = bullet.weapon.Attack;

        //Debug.Log(monster.name);
        //Debug.Log(monster.GetComponent<HP_Text_Manager>() == null);
        GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_MonsterHurtEvent(bullet, monster, charaterData, hurt);
        charaterData.HP_Current -= hurt;
        //monster.GetComponent<HP_Text_Manager>().showHurt((int)hurt);
    }
示例#9
0
    // Use this for initialization
    void Start()
    {
        player = GameRoot_InBattle.getSingleton <PlayerManager_InBattle>().player.GetComponent <Player>();
        if (player != null)
        {
            moveToPlayer(player.transform.position);
        }

        registerEvent();
        closePlayer = false;
    }
示例#10
0
    public static T addSingleton <T>() where T : Singleton <T>
    {
        if (instance == null)
        {
            instance = new GameRoot_InBattle();
        }

        T t = instance.rootObj.AddComponent <T>();

        t.Init();
        return(t);
    }
示例#11
0
    // Use this for initialization
    void Awake()
    {
        if (PlayerManager.instance == null)
        {
            PlayerManager.init();
        }

        GameRoot_InBattle.addSingleton <MessageManager_InBattle>();
        GameRoot_InBattle.addSingleton <Mapcreater_2>();
        GameRoot_InBattle.addSingleton <GameManager_InBattle>();
        GameRoot_InBattle.addSingleton <PlayerManager_InBattle>();
        GameRoot_InBattle.addSingleton <MonsterManager>();
        GameRoot_InBattle.addSingleton <BulletsManager>();
    }
示例#12
0
    /// <summary>
    /// 在场上创建怪物
    /// </summary>
    /// <param name="monster"></param>
    private void createMonsterOnScene(Monster monster)
    {
        GameObject monsterGO = Pool.Instance.getObjFromPool(Pool.PoolType.Monster);
        float      x         = monster.Position.x,
                   z = monster.Position.z;

        z = z > 6.4 ? 6.4f : z;
        z = z < -3 ? -3f : z;
        monsterGO.transform.position = new Vector3(x, 4.3f, z);
        monsterGO.SendMessage("SetMonster", monster);
        monsterGO.SetActive(true);
        monsterGO.AddComponent <AI_1>();

        CharacterData data = monsterGO.GetComponent <CharacterData>();

        data.monster    = monster;
        data.HP_Current = monster.Hp;
        data.ID         = ++monsterIndex;

        GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_CreateMonsterEvent(monsterGO, monster, data);
    }
    // 按下“开枪”按键事件
    private void PressWeapon(int index, Weapon weapon)
    {
        //Debug.Log("Shot");
        if (weapon == null)
        {
            return;
        }

        GameObject bulletGO = Pool.Instance.getObjFromPool(Pool.PoolType.Bullet);
        Bullets    bullet   = bulletGO.GetComponent <Bullets>();

        // 设置子弹与武器相关的属性
        switch (weapon.Type)
        {
        case EquipmentManager.WeaponType.Rifle:
            //bullet.bulletGameObject.GetComponent<MeshRenderer>().material.mainTexture = Resources.Load("Effect/Ammo_001_mip_1") as Texture;
            // 发射者
            bullet.sender = Bullets.Sender.Player;
            // 位置
            bulletGO.transform.position = player.transform.FindChild("Point_Rifle").position;
            // 方向
            bulletGO.transform.rotation = new Quaternion(0, 0, orientLeft ? 0 : 180, 0);
            //bullet.bulletGameObject.transform.LookAt(orientLeft ? GameRoot_InBattle.getSingleton<BulletsManager>().go_Left.transform.position
            //    : GameRoot_InBattle.getSingleton<BulletsManager>().go_Right.transform.position);
            // 速度
            bulletGO.GetComponent <Rigidbody>().velocity = new Vector3(weapon.BulletSpeed * (orientLeft ? -1 : 1),
                                                                       0, Random.Range(-weapon.BulletAngle, weapon.BulletAngle));
            // 自动销毁协程
            StartCoroutine(DestroyBulletCoroutine(3, bullet));

            break;
        }
        // 子弹图片
        bulletGO.GetComponent <MeshRenderer>().material = Resources.Load(weapon.BulletPath) as Material;

        bullet.weapon = weapon;
        // 发送“子弹发射成功”消息
        GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_ShotSuccessfulEvent(index, weapon);
    }
示例#14
0
    /// <summary>
    /// 玩家移动了,检查是否到了怪应该出现的位置
    /// </summary>
    /// <param name="position"></param>
    private void checkPlayerPositionForMonsterCreate(Vector3 position)
    {
        //Debug.Log("Check Position  " + position.x + "   " + monstersDependOnPosition[0].PlayerArrive);

        int     index = 0;
        Monster monster;

        while (index < monstersDependOnPosition.Count)
        {
            monster = monstersDependOnPosition[index++];
            if (position.x > monster.PlayerArrive)
            {
                Debug.Log("Create DependOn Postion");
                createMonsterOnScene(monster);
                monstersDependOnPosition.Remove(monster);
            }
        }
        if (monstersDependOnPosition.Count == 0)
        {
            GameRoot_InBattle.getSingleton <MessageManager_InBattle>().playerMoveEvent
                -= new MessageManager_InBattle.PlayerMoveDelegrate(checkPlayerPositionForMonsterCreate);
        }
    }
示例#15
0
 void OnDestroy()
 {
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().playerMoveEvent
         -= new MessageManager_InBattle.PlayerMoveDelegrate(checkPlayerPositionForMonsterCreate);
 }
示例#16
0
 // Use this for initialization
 void Start()
 {
     GameRoot_InBattle.getSingleton <Mapcreater_2>().createMap(30);
     Pool.Instance.createObjPool(Resources.Load("Prefabs/InBattle/Bullet") as GameObject, Pool.PoolType.Bullet, 20);
 }
示例#17
0
 void OnDestroy()
 {
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().monsterHurtEvent
         -= new MessageManager_InBattle.MonsterHurtDelegrate(MonsterHurted);
 }
示例#18
0
 // 开枪
 private void shoot()
 {
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_ShotItemPressEvent(index, weapon);
 }
示例#19
0
 private GameRoot_InBattle()
 {
     rootObj  = new GameObject("GameRoot");
     instance = this;
 }
示例#20
0
 private void UnRegierterEvent()
 {
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().bulletCollisionEvent
         -= new MessageManager_InBattle.BulletCollisionDelegrate(BulletCollision);
 }
示例#21
0
 // 松开摇杆
 private void ReleaseRocker()
 {
     //Debug.Log("ReleaseRocker");
     setImageSelected(false);
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_RockedEvent(angle, false);
 }
示例#22
0
 private void UnRegisterEvent()
 {
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().playerMoveEvent
         -= new MessageManager_InBattle.PlayerMoveDelegrate(moveToPlayer);
 }
示例#23
0
 void OnDestroy()
 {
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().shotSuccessfulEvent
         -= new MessageManager_InBattle.ShotItemDelegrate(ShotSuccessful);
 }
示例#24
0
 // Use this for initialization
 void Start()
 {
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().monsterHurtEvent
         += new MessageManager_InBattle.MonsterHurtDelegrate(MonsterHurted);
 }
示例#25
0
 private void UnRegisterEvent()
 {
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().createMonsterEvent
         -= new MessageManager_InBattle.CreateMonsterDelegrate(createMonsterEvent);
 }
示例#26
0
 // 移动摇杆
 private void MoveRocker()
 {
     setImageSelected(true);
     RotateImage(Input.mousePosition.x - centerX, Input.mousePosition.y - centerY);
     GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_RockedEvent(angle, true);
 }