Beispiel #1
0
 void OnDestroy()
 {
     if (destoryAudio != null)
     {
         UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, destoryAudio, 1.5f));
     }
 }
Beispiel #2
0
    public override void Attack(GuardAbs guardObj)
    {
        GoldCarrier gc = guardObj.gameObject.GetComponent <GoldCarrier>();

        if (gc == null || gos.Contains(gc.gameObject))
        {
            return;
        }

        gos.Add(gc.gameObject);
        UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, clip_1));
        if (guardObj.getGuardLevel() <= getAttackLevel())
        {
            //等级相同,摧毁对方(只有超载矿车)
            if (guardObj.DestrotyGameObj(this))
            {    //成功摧毁对方
                TryDestroy(this);
            }
        }
        else
        {
            //等级高于检查站,则扣钱
            int gold = gc.popGold();
            gc.setGoldAmounts(Mathf.FloorToInt(gold * tax));
        }
    }
Beispiel #3
0
 /// <summary>
 /// 用户点击制造单位
 /// </summary>
 public void OnClick()
 {
     if (isMineSelected == true)
     {
         UnityEventCenter.SendMessage <unitEvent>(new unitEvent(null, null, null, IDList[unitSelected]));
     }
 }
Beispiel #4
0
    protected void buildNow()
    {
        //生成游戏单位代码

        GameObject obj = GameObject.Instantiate <GameObject>(spawnUnit, transform.position, Quaternion.identity);

        obj.gameObject.GetComponent <GameobjBase>().setOwner(gBase.getOwner());//设置控制权

        if (obj.GetComponent <Stone>() != null)
        {
            obj.GetComponent <Stone>().setSpawner(gameObject.transform.parent.gameObject);
        }

        if (isCharacter)
        {
            //只对人有效,对车无效
            Roadmovable roadmovable = obj.gameObject.GetComponent <Roadmovable>();
            if (targetObj != null)
            {
                roadmovable.setDestination(targetObj);//设置跟踪目标,优先
            }
            else if (targetPoint != Vector3.zero)
            {
                roadmovable.setDestination(targetPoint);//设置目的地
            }
        }
        obj.GetComponent <Collider>().enabled = true;
        UnityEventCenter.SendMessage <SpawnEvent>(new SpawnEvent(gameObject, obj));//发送生成单位事件
        startTimer();
    }
Beispiel #5
0
 // Use this for initialization
 void Start()
 {
     if (startAudio != null)
     {
         UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, startAudio, 1.5f));
     }
 }
    /// <summary>
    /// 卸金矿
    /// 重点负责调用
    /// </summary>
    /// <returns></returns>
    public int popGold()
    {
        UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, clip));
        int g = goldAmounts;

        goldAmounts = 0;
        return(g);
    }
Beispiel #7
0
 /// <summary>
 /// 按照间隔制造矿车的协程
 /// </summary>
 /// <param name="arr"></param>
 /// <returns></returns>
 IEnumerator createTramcar(Spawner[] arr)
 {
     foreach (Spawner sp in arr)
     {
         UnityEventCenter.SendMessage <CreateUnitEvent>(new CreateUnitEvent(sp.spawnUnit.GetComponent <GameobjBase>().game_ID, Vector3.zero));
         yield return(new WaitForSeconds(createGap));
     }
 }
Beispiel #8
0
 public override void Attack(GuardAbs guardObj)
 {
     if (guardObj.getGuardLevel() <= getAttackLevel() && guardObj.gameObject.layer == Layers.VEHICLE)
     {
         if (guardObj.DestrotyGameObj(this))
         {
             UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, clip));
             TryDestroy(this);
         }
     }
 }
 protected override void OnPress(bool isPressed)
 {
     base.OnPress(isPressed);
     if (isPressed)
     {
         UnityEventCenter.SendMessage <ViewMoveEvent>(new ViewMoveEvent(false));
     }
     else
     {
         UnityEventCenter.SendMessage <ViewMoveEvent>(new ViewMoveEvent(true));
     }
 }
    protected override void OnDragDropRelease(GameObject surface)
    {
        base.OnDragDropRelease(surface);
        Ray ray   = new Ray();
        Ray uiRay = new Ray();

        if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
        {
            ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
            uiRay = UICamera.mainCamera.ScreenPointToRay(Input.mousePosition);
        }
        else
        {
            ray   = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
            uiRay = UICamera.mainCamera.ScreenPointToRay(Input.GetTouch(0).position);
        }



        RaycastHit hit = new RaycastHit();

        //if (Layers.CHARACTER == IDs.getLayerByID(sp.spawnUnit.GetComponent<GameobjBase>().game_ID))
        if (sp.spawnUnit.GetComponent <GameobjBase>().game_ID == IDs.getIDByName(Tags.Character.GATEWORKER))
        {//如果是人的话,检测到是搬道闸才能发送信息建造
            Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << Layers.BUILDING | 1 << Layers.RAILWAY);
            if (hit.collider == null || hit.collider.gameObject.tag != Tags.GATE)
            {
                return;
            }
        }
        else
        {
            //这里是车辆被拖动的内容,只能够拖动到待建造面板中

            //广播调用面板对应函数
            surface.BroadcastMessage("onDragCrad", gameObject, SendMessageOptions.DontRequireReceiver);

            //Physics.Raycast(uiRay, out hit,Mathf.Infinity,1<<Layers.UI);
            //if(hit.transform.gameObject.tag==Tags.CAR_SELECTOR)
            //{
            //    int id = sp.spawnUnit.GetComponent<GameobjBase>().game_ID;
            //    string name= sp.spawnUnit.GetComponent<GameobjBase>().game_name;
            //    UnityEventCenter.SendMessage<setVehicleEvent>(new setVehicleEvent(null, hit.transform.gameObject, id,name));
            //}
        }



        if (hit.collider != null)
        {//建造信息
            UnityEventCenter.SendMessage <CreateUnitEvent>(new CreateUnitEvent(sp.spawnUnit.GetComponent <GameobjBase>().game_ID, hit.point));
        }
    }
Beispiel #11
0
 public bool DestrotyGameObj(AttackAbs attackObj)
 {
     if (TryDestroy(attackObj))
     {
         UnityEventCenter.SendMessage <DestroyEvent>(new DestroyEvent(gameObject, gameObject));
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #12
0
    /// <summary>
    /// 加分
    /// </summary>
    /// <param name="player">加分的玩家</param>
    /// <param name="score">分</param>
    private void addScore(int player, int score)
    {
        if (scores.ContainsKey(player))
        {
            scores[player] = System.Convert.ToInt32(scores[player]) + score;
        }
        else
        {
            throw new System.Exception("- -你难道用了外挂不成,明明没有这个玩家,不不不,其实我知道的,你忘了初始化计分板了吧");
        }

        UnityEventCenter.SendMessage <ScoreEvent>(new ScoreEvent(this, player, System.Convert.ToInt32(scores[player])));//发送玩家分数更新信息
    }
    private void tryCancelMine()
    {
        if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (Physics.Raycast(UICamera.mainCamera.ScreenPointToRay(Input.mousePosition), 20))//检测是否点击到NGUI
                {
                    return;
                }
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit rh;
                Physics.Raycast(ray, out rh);
                if (rh.collider == null)
                {
                    return;
                }
                MineMountain mine = rh.collider.gameObject.GetComponent <MineMountain>();
                if (mine == null)
                {//没点击到矿山
                    mineSelected = null;
                    UnityEventCenter.SendMessage <cancelMountainEvent>(new cancelMountainEvent(null, null));
                }
            }
        }
        else
        {
            if (Input.touchCount <= 0)
            {
                return;
            }
            Touch touch = Input.GetTouch(0);

            if (touch.phase == TouchPhase.Began && touch.tapCount >= 2)
            {
                Ray        ray = Camera.main.ScreenPointToRay(touch.position);
                RaycastHit rh;
                Physics.Raycast(ray, out rh);
                if (rh.collider == null)
                {
                    return;
                }
                MineMountain mine = rh.collider.gameObject.GetComponent <MineMountain>();
                if (mine == null)
                {//没点击到矿山
                    mineSelected = null;
                    UnityEventCenter.SendMessage <cancelMountainEvent>(new cancelMountainEvent(null, null));
                }
            }
        }
    }
    void OnTriggerEnter(Collider other)
    {
        //这里要处理所有玩家的单位,所以不去继承之前写的那个基类
        GameobjBase gBase   = other.GetComponent <GameobjBase>();
        GoldCarrier carrier = other.GetComponent <GoldCarrier>();

        if (gBase == null || carrier == null)
        {
            return;
        }
        UnityEventCenter.SendMessage <ScoreAddEvent>(new ScoreAddEvent(gameObject, gBase.getOwner(), carrier.popGold()));//发送分数增加事件
        other.gameObject.SendMessage(GameobjBase.TryDestroyFUNC);
        //Destroy(other.gameObject);
    }
    public override void Attack(GuardAbs guardObj)
    {
        enemyAbs = guardObj.gameObject.GetComponent <GuardAbs>();
        if (guardObj.gameObject.layer == Layers.CHARACTER && enemyAbs != null)
        {
            if (enemyAbs.getGuardLevel() <= ATTACKLEVEL)
            {
                gunnerEnemy = guardObj.gameObject.GetComponent <GunnerAttack>();
                if (gunnerEnemy != null)
                {
                    try
                    {
                        enemyAbs.TryDestroy(myAbs);
                        myAbs.TryDestroy(myAbs);
                        UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, clip));
                    }
                    catch
                    {
                        guardObj.SendMessage(GameobjBase.TryDestroyFUNC);
                        gameObject.SendMessage(GameobjBase.TryDestroyFUNC);

                        //Destroy(guardObj.gameObject);
                        //Destroy(this.gameObject);
                    }
                }
                else
                {
                    try
                    {
                        enemyAbs.TryDestroy(myAbs);
                        UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, clip));
                    }
                    catch
                    {
                        guardObj.gameObject.SendMessage(GameobjBase.TryDestroyFUNC);

                        //Destroy(guardObj.gameObject);
                    }
                    finally
                    {
                        bulletCount--;
                        if (bulletCount == 0)
                        {
                            myAbs.TryDestroy(myAbs);
                        }
                    }
                }
            }
        }
    }
    /// <summary>
    /// 游戏结束判定,返回1为胜利,0为未结束,-1为失败
    /// </summary>
    /// <param name="score"></param>
    /// <returns></returns>
    public int isWin(playerInformation player)
    {
        switch (gameType)
        {
        case ARRIVAL_VERSUS:
        {
            if (player.score >= missionScore)
            {
                //发送游戏结束消息
                UnityEventCenter.SendMessage <GameOverEvent>(new GameOverEvent(player.playerNum, ScoreBoard.getInstance().getScoreData()));
            }
            return(0);
        }

        default: return(-1000);
        }
    }
Beispiel #17
0
    public override void OnWorldUnitCollisionStart(Collider obj)
    {
        if (obj.gameObject != targetGate)
        {
            return;
        }


        if (obj.tag == Tags.GATE)
        {
            targetGate.GetComponent <MetroGate>().GateChange(transform.position);
            if (targetGate.GetComponent <MetroGate>().getCanChange())
            {
                UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, clip));
            }
        }
    }
Beispiel #18
0
 public override void Arrive()
 {
     SendMessage(Builder.BUILDFUNC);
     UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, clip));
     base.Arrive();
 }
Beispiel #19
0
 public virtual void OnMouseDown()
 {
     UnityEventCenter.SendMessage <GameObjSeletEvent>(new GameObjSeletEvent(gameObject));//游戏物体被选择
 }
Beispiel #20
0
 /// <summary>
 /// 延迟占领
 /// </summary>
 /// <param name="b"></param>
 private void HoldMineDelay()
 {
     Invoke("HoldMine", reqTime);
     UnityEventCenter.SendMessage <AudioEvent>(new AudioEvent(gameObject, clip));
     GetComponent <RailwayMovable>().enabled = false;
 }
Beispiel #21
0
 void Start()
 {
     UnityEventCenter.SendMessage <MineMoutainSpawnerEvent>(new MineMoutainSpawnerEvent(this));
     InvokeRepeating("increaseMine", 0.0f, increaseFlashTime);
 }
Beispiel #22
0
 void OnMouseDown()
 {
     UnityEventCenter.SendMessage <MineSelectEvent>(new MineSelectEvent(gameObject));//矿山被选择事件
 }
Beispiel #23
0
 void increaseMine()
 {
     UnityEventCenter.SendMessage <MineStateChangeEvent>(new MineStateChangeEvent(this));//发送矿山状态改变事件
     totalMine += (int)(increaseRate * increaseFlashTime);
 }
 // Use this for initialization
 void Start()
 {
     UnityEventCenter.SendMessage <ScoreBuildingSpawnEvent>(new ScoreBuildingSpawnEvent(gameObject));
 }