Exemple #1
0
    //called when a tower building is initated in DragNDrop, instantiate the tower and set it in DragNDrop mode
    public static string BuildTowerDragNDrop(UnitTower tower)
    {
        if(tower.type==_TowerType.ResourceTower && GameControl.gameState==_GameState.Idle){
            //GameMessage.DisplayMessage("Cant Build Tower before spawn start");
            return "Cant Build Tower before spawn start";
        }

        if(GameControl.HaveSufficientResource(tower.GetCost())){
            //~ Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //~ Vector3 pos=ray.GetPoint(10000);

            //~ GameObject towerObj=(GameObject)Instantiate(tower.thisObj, pos, Quaternion.identity);
            //~ UnitTower towerCom=towerObj.GetComponent<UnitTower>();

            //~ towerCom.StartCoroutine(towerCom.DragNDropRoutine(buildManager.dragNDropStatusFlicker));

            int ID=0;
            for(int i=0; i<buildManager.towers.Length; i++){
                if(buildManager.towers[i]==tower){
                    ID=i;
                    break;
                }
            }
            buildManager.sampleTower[ID].thisObj.SetActiveRecursively(true);
            GameControl.ShowIndicator(buildManager.sampleTower[ID]);
            UnitTower towerCom=buildManager.sampleTower[ID];
            towerCom.StartCoroutine(towerCom.DragNDropRoutine(!buildManager.retainPrefabShaderForSamples));

            return "";
        }

        //GameMessage.DisplayMessage("Insufficient Resource");
        return "Insufficient Resource";
    }
Exemple #2
0
 public static void DragNDropIndicator(UnitTower tower)
 {
     if(tower.type!=_TowerType.ResourceTower){
         gameControl._ShowIndicator(tower);
         gameControl.StartCoroutine(gameControl._DragNDropIndicator(tower));
     }
 }
Exemple #3
0
    public static void Unbuilding(UnitTower unit)
    {
        if(overlayManager==null) Init();

        int num=GetUnuseFlag();
        inUseFlags[num]=true;

        overlayManager.StartCoroutine(overlayManager.Unbuilding(num, unit));
    }
    //called when a tower building is initated in DragNDrop, instantiate the tower and set it in DragNDrop mode
    public static bool BuildTowerDragNDrop(UnitTower tower)
    {
        if(tower.type==_TowerType.ResourceTower && GameControl.gameState==_GameState.Idle){
            GameMessage.DisplayMessage("Cant Build Tower before spawn start");
            return false;
        }

        if(GameControl.HaveSufficientResource(tower.GetCost())){
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Vector3 pos=ray.GetPoint(10000);

            GameObject towerObj=(GameObject)Instantiate(tower.thisObj, pos, Quaternion.identity);
            UnitTower towerCom=towerObj.GetComponent<UnitTower>();

            towerCom.StartCoroutine(towerCom.DragNDropRoutine());

            return true;
        }

        GameMessage.DisplayMessage("Insufficient Resource");
        return false;
    }
Exemple #5
0
 //Call by inherited class UnitTower, caching inherited UnitTower instance to this instance
 public void SetSubClassInt(UnitTower unit)
 {
     unitT=unit;
     subClass=_UnitSubClass.Tower;
 }
 public static void ClearSelection()
 {
     selectedTower=null;
     gameControl._ClearIndicator();
 }
 void OnTowerDestroy(UnitTower tower)
 {
     if(selectedTower==tower || selectedTower==null || !selectedTower.thisObj.active){
         ClearSelection();
     }
 }
Exemple #8
0
    IEnumerator _DragNDropIndicator(UnitTower tower)
    {
        if(tower.type==_TowerType.Block){
            ClearIndicator();
            yield break;
        }

        dragNDrop=true;

        while(dragNDrop){
            if(tower.type==_TowerType.SupportTower){
                if(rangeIndicatorF!=null) rangeIndicatorF.position=tower.thisT.position;
            }
            else{
                if(tower.targetingArea==_TargetingArea.AllAround){
                    if(rangeIndicatorH!=null) rangeIndicatorH.position=tower.thisT.position;
                }
                else{
                    if(rangeIndicatorConeH!=null) rangeIndicatorConeH.position=tower.thisT.position;
                }
            }

            yield return null;
        }
        ClearIndicator();
    }
Exemple #9
0
    // Use this for initialization
    void Start()
    {
        tower = GetComponentInChildren<UnitTower>();

        tower.playShootAnimation += PlayShootAnimation;

        targetIndicator = transform.Find("TargetIndicator");

        //Transform specialT = transform.Find("Special");
        //if (specialT != null)
        //{
        //    special = specialT.GetComponent<ShooterSpecial>();
        //}

        //loaded = false;

        shooterUI.Initialize(this);
        shooterUI.CollapseUI();

        NotificationCenter.DefaultCenter.AddObserver(this, "OnMaxEnergy", tower);

        ApplyLevel();
    }
Exemple #10
0
    /*
     * public void OnMouseStay()
     * {
     * }*/
    public void OnMouseUpAsButton()
    {
        if (child != null)
        {
            //child.GetComponent<SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
            this.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
            if (this.transform.name.Contains("BuildingFlag"))
            {
                GameManager.ClearUpgradeUI();
                GameManager.ClearDismantleUI();
                BuildManager.Select(this.transform);
            }
            else if (this.name.Contains("Pause"))
            {
                AudioManager.PlayButton();
                othChild = this.transform.Find("mouseDown").gameObject;
                othChild.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                //othChild = this.transform.Find("general").gameObject;
                //othChild.GetComponent<SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                child.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                Time.timeScale = (float)((int)(Time.timeScale + 1.0f) % 2);
            }
            else if (this.name.Contains("Select"))
            {
                AudioManager.PlayButton();
                //othChild = this.transform.Find("mouseDown").gameObject;
                //othChild.GetComponent<SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);

                //child.GetComponent<SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f);

                GameManager.ShowInterfaceSet();
                Time.timeScale = 0.0f;
            }
            else if (this.name.Contains("UpgradeUI"))
            {
                GameManager.ClearBaseBuildings();
                BuildManager.SelectUpgradeUI();
            }
            else if (this.name.Contains("Dismantle"))
            {
                BuildManager.SelectDismantleUI();
            }
            else if (this.name.Contains("Replay"))
            {
                AudioManager.PlayButton();
                string name = "Yotta_Level" + GameManager.gameManager.currentLevel.ToString();
                AudioManager.PlayButton();
                Application.LoadLevel(name);
            }
            else if (this.name.Contains("Next"))
            {
                //for now, the level is limited to 2;
                AudioManager.PlayButton();
                int nextlevel = GameManager.gameManager.currentLevel + 1;
                if (nextlevel > 2)
                {
                    nextlevel = 2;
                }
                string name = "Yotta_Level" + nextlevel.ToString();
                Application.LoadLevel(name);
            }
            else if (this.name.Contains("Back"))
            {
                AudioManager.PlayButton();
                //this.transform.parent.gameObject.SetActive(false);
                //Vector3 pos = this.transform.parent.position;
                //this.transform.parent.position= new Vector3(pos.x, pos.y, -2);
                GameManager.ClearInterfaceSet();
                Time.timeScale = 1.0f;
            }
            else if (this.name.Contains("LevSel"))
            {
                AudioManager.StopSound(AudioManager.audioManager.backSound);
                Application.LoadLevel("Yotta_LevelSelect");
            }
            else if (this.name.Contains("TeamMem"))
            {
                othChild.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                child.GetComponent <SpriteRenderer>().color    = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                this.GetComponent <SpriteRenderer>().color     = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                AudioManager.PlayButton();
                Vector3 pos = new Vector3(0, 0, 0);
                Instantiate(teamMem, pos, Quaternion.identity);
                GameObject.Find("TeamMem").GetComponent <BoxCollider2D>().enabled   = false;
                GameObject.Find("StartGame").GetComponent <BoxCollider2D>().enabled = false;
            }
            else if (this.name.Contains("Start"))
            {
                othChild.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                child.GetComponent <SpriteRenderer>().color    = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                this.GetComponent <SpriteRenderer>().color     = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                AudioManager.PlayButton();
                AudioManager.StopSound(AudioManager.audioManager.backSound);
                Application.LoadLevel("Yotta_Start_mov");
            }
            else if (this.name.Contains("Exit"))
            {
                othChild.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                child.GetComponent <SpriteRenderer>().color    = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                this.GetComponent <SpriteRenderer>().color     = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                Application.Quit();
            }
            else if (this.name.Contains("ReturntoMain"))
            {
                othChild.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                child.GetComponent <SpriteRenderer>().color    = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                this.GetComponent <SpriteRenderer>().color     = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                AudioManager.PlayButton();
                AudioManager.StopSound(AudioManager.audioManager.backSound);
                Application.LoadLevel("Yotta_Start0");
            }
            else if (this.name.Contains("Button_next"))
            {
                AudioManager.PlayButton();
                GameObject.Find("TeamMem").GetComponent <BoxCollider2D>().enabled   = true;
                GameObject.Find("StartGame").GetComponent <BoxCollider2D>().enabled = true;
                GameObject.Destroy(this.transform.parent.gameObject);
            }
        }
        else if (this.name.Contains("Music"))
        {
            AudioManager.PlayButton();
            othChild = this.transform.Find("mouseClick").gameObject;
            int flag = (int)GlobalVariables.soundOn;
            //Color color;//the change with color param can be done later
            if (othChild != null)
            {
                flag = (int)this.GetComponent <SpriteRenderer>().color.a;
                this.GetComponent <SpriteRenderer>().color     = new Color(1.0f, 1.0f, 1.0f, (float)((flag + 1) % 2));
                othChild.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, flag * 1.0f);
                GameObject otherObj;
                GameObject otherObjChild;
                otherObj = this.transform.parent.Find("SetOff").gameObject;
                otherObj.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, (float)((flag + 1) % 2));
                otherObjChild = otherObj.transform.Find("mouseClick").gameObject;
                if (otherObjChild != null)
                {
                    otherObjChild.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, flag * 1.0f);
                }
            }
            GlobalVariables.soundOn = (flag + 1) % 2;
        }
        else if (this.name.Contains("Off"))
        {
            AudioManager.PlayButton();
            othChild = this.transform.Find("mouseClick").gameObject;
            int flag = 0;

            //Color color;//the change with color param can be done later
            if (othChild != null)
            {
                flag = (int)this.GetComponent <SpriteRenderer>().color.r;
                this.GetComponent <SpriteRenderer>().color     = new Color(1.0f, 1.0f, 1.0f, (flag + 1) % 2 * 1.0f);
                othChild.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, flag * 1.0f);
                GameObject otherObj;
                GameObject otherObjChild;
                otherObj = this.transform.parent.Find("SetMusic").gameObject;
                otherObj.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, (flag + 1) % 2 * 1.0f);
                otherObjChild = otherObj.transform.Find("mouseClick").gameObject;
                if (otherObjChild != null)
                {
                    otherObjChild.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, flag * 1.0f);
                }
            }
            GlobalVariables.soundOn = (flag + 1) % 2;
        }
        else if (this.name.Contains("icon"))
        {
            this.GetComponent <SpriteRenderer>().color = Color.green;
            Transform  can  = this.transform.FindChild("Canvas");
            GameObject tex  = can.FindChild("Text").gameObject;
            Text       text = tex.transform.GetComponent <Text>();
            text.color = Color.green;
            GameManager.ClearBaseBuildings();
            BuildManager.Select(this.gameObject);
        }
        else if (this.name.Contains("B0"))       //building
        {
            UnitTower tower = this.GetComponent <UnitTower>();
            BuildManager.Select(tower);
        }
        else if (this.name.Contains("Esse"))
        {
            AudioManager.PlaySound(AudioManager.audioManager.essenCollectSound, false);
            ScoreControl.EssenceIncrease(increaseAmount);
            Destroy(this.transform.parent.gameObject);
            PoolManager.Unspawn(this.transform.parent.gameObject);
        }
    }
Exemple #11
0
 public static void Select(UnitTower tower)       //选中当前的塔
 {
     buildManager._Select(tower);
 }
Exemple #12
0
 static public void ClearSelection()
 {
     selectedTower = null;
     gameControl._ClearIndicator();
 }
Exemple #13
0
 public static void DragNDropIndicator(UnitTower tower)
 {
     gameControl._ShowIndicator(tower);
     gameControl.StartCoroutine(gameControl._DragNDropIndicator(tower));
 }
Exemple #14
0
 public static void ShowIndicator(UnitTower tower)
 {
     gameControl._ShowIndicator(tower);
 }
Exemple #15
0
    public override void OnInspectorGUI()
    {
        Undo.SetSnapshotTarget(bm, "BuildManager");

        GUI.changed = false;

        EditorGUILayout.Space();

        DrawDefaultInspector();
        EditorGUILayout.Space();

        showTowerList = GUILayout.Toggle(showTowerList, "Show Tower List");

        if (showTowerList)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("EnableAll"))
            {
                for (int i = 0; i < bm.towerAvaiList.Count; i++)
                {
                    bm.towerAvaiList[i].enabledInLvl = true;
                }
            }
            if (GUILayout.Button("DisableAll"))
            {
                for (int i = 0; i < bm.towerAvaiList.Count; i++)
                {
                    bm.towerAvaiList[i].enabledInLvl = false;
                }
            }
            EditorGUILayout.EndHorizontal();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            for (int i = 0; i < bm.towerAvaiList.Count; i++)
            {
                //~ Perk perk=bm.allPerkList[i];
                UnitTower tower = towerList[i];

                GUILayout.BeginHorizontal();

                GUIContent cont = new GUIContent(tower.icon, tower.description);
                GUILayout.Box(cont, GUILayout.Width(30), GUILayout.Height(30));

                GUILayout.BeginVertical();
                //~ GUILayout.Space (5);
                GUILayout.Label(tower.name, GUILayout.ExpandWidth(false));
                bm.towerAvaiList[i].enabledInLvl = EditorGUILayout.Toggle("enabled:", bm.towerAvaiList[i].enabledInLvl);
                //~ if(perk.enableInlvl){
                //~ perk.unlocked=EditorGUILayout.Toggle("unlocked at start:", perk.unlocked);
                //~ }
                GUILayout.EndVertical();

                GUILayout.EndHorizontal();

                //~ EditorGUILayout.Space();
            }

            GUILayout.EndScrollView();
        }

        EditorGUILayout.Space();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(bm);
            Undo.CreateSnapshot();
            Undo.RegisterSnapshot();
        }
        Undo.ClearSnapshotTarget();
    }
Exemple #16
0
 public void Shoot(Unit tgt, UnitTower src)
 {
     Shoot(tgt, src, null);
 }
Exemple #17
0
    //called when a build button is pressed, the button object which is pressed is passed
    void OnTowerBuild(GameObject obj)
    {
        //check which button has been pressed exactly
        //we can know from comparing to the buildButton list
        //from the position of the button in the list, we can know which towers is associated with the button
        int towerID=-1;
        for(int i=0; i<buildButtons.Length; i++){
            if(obj==buildButtons[i]){
                towerID=i;
                break;
            }
        }

        if(towerID==-1){
            return;
        }
        //if there's a matching button
        else{

            //get the tower
            UnitTower[] towerList=BuildManager.GetTowerList();
            UnitTower tower=towerList[towerID];

            //for PointNBuild mode
            if(buildMode==_BuildMode.PointNBuild){
                //call the function to build a tower, an empty string will be returned if building is sucessful
                string result=BuildManager.BuildTowerPointNBuild(tower);
                //if a tower is built
                if(result==""){
                    //hide the build menu and clear the tooltip
                    if(buildMenu && !alwaysShowBuildButton){
                        buildMenu=false;
                        DisableBuildButtons();
                        BuildManager.ClearBuildPoint();
                        OnTowerClearTooltip();
                    }
                }
                //else just display why the building operation failed
                else{
                    DisplayMessage(result);
                }
            }
            //for drag and drop mode
            else if(buildMode==_BuildMode.DragNDrop){
                //call the function to build a tower, an empty string will be returned if building is sucessful
                string result=BuildManager.BuildTowerDragNDrop(tower);
                //display why the building operation failed
                if(result!=""){
                    DisplayMessage(result);
                }
            }
        }

        //if there's a tower being selected, clear it
        if(currentSelectedTower!=null){
            currentSelectedTower=null;
            OnTowerSelect();
        }
    }
Exemple #18
0
 void OnTowerDestroyed(UnitTower tower)
 {
     if(currentSelectedTower==tower){
         currentSelectedTower=null;
         OnTowerSelect();
     }
 }
Exemple #19
0
    public static string DragNDropBuilt(UnitTower tower)
    {
        //~ if(currentBuildInfo.platform!=null){
            //~ tower.SetTowerID(towerCount+=1);
            //~ if(tower.type!=_TowerType.Mine)
                //~ currentBuildInfo.platform.Build(currentBuildInfo.position, tower);
            //~ ClearBuildPoint();
            //~ return "";
        //~ }

            int ID=0;
            for(int i=0; i<buildManager.towers.Length; i++){
                if(buildManager.sampleTower[i]==tower){
                    ID=i;
                    break;
                }
            }

            BuildManager.ClearSampleTower();

            return BuildTowerPointNBuild(buildManager.towers[ID]);

        //~ return "Invalid Build Point";
    }
Exemple #20
0
    // Update is called once per frame
    void Update()
    {
        #if !UNITY_IPHONE && !UNITY_ANDROID
            if(buildMode==_BuildMode.PointNBuild)
                BuildManager.SetIndicator(Input.mousePosition);
        #endif

        if(Input.GetMouseButtonUp(0) && !IsCursorOnUI(Input.mousePosition) && !paused){

            //check if user click on towers
            UnitTower tower=GameControl.Select(Input.mousePosition);

            //if user click on tower, select the tower
            if(tower!=null){
                currentSelectedTower=tower;

                //if build mode is active, disable buildmode
                if(buildMenu){
                    buildMenu=false;
                    BuildManager.ClearBuildPoint();
                    ClearBuildListRect();
                }
            }
            //no tower is selected
            else{
                //if a tower is selected previously, clear the selection
                if(currentSelectedTower!=null){
                    GameControl.ClearSelection();
                    currentSelectedTower=null;
                    towerUIRect=new Rect(0, 0, 0, 0);
                    //UIRect.RemoveRect(towerUIRect);
                }

                //if we are in PointNBuild Mode
                if(buildMode==_BuildMode.PointNBuild){

                    //check for build point, if true initiate build menu
                    if(BuildManager.CheckBuildPoint(Input.mousePosition)){
                        UpdateBuildList();
                        InitBuildListRect();
                        buildMenu=true;
                    }
                    //if there are no valid build point but we are in build mode, disable it
                    else{
                        if(buildMenu){
                            buildMenu=false;
                            BuildManager.ClearBuildPoint();
                            ClearBuildListRect();
                        }
                    }

                }
            }

        }
        //if right click,
        else if(Input.GetMouseButtonUp(1)){
            //clear the menu
            if(buildMenu){
                buildMenu=false;
                BuildManager.ClearBuildPoint();
                ClearBuildListRect();
            }

            //if there are tower currently being selected
            if(currentSelectedTower!=null){
                CheckForTarget();
            }
        }

        //if escape key is pressed, toggle pause
        if(Input.GetKeyUp(KeyCode.Escape)){
            TogglePause();
        }
    }
Exemple #21
0
    public static UnitTower Select(Vector3 pointer)
    {
        //change this
        int layer=LayerManager.LayerTower();

        LayerMask mask=1<<layer;
        Ray ray = Camera.main.ScreenPointToRay(pointer);
        RaycastHit hit;
        if(!Physics.Raycast(ray, out hit, Mathf.Infinity, mask)){
            return null;
        }

        selectedTower=hit.transform.gameObject.GetComponent<UnitTower>();
        //selectedTower.Select();

        gameControl._ShowIndicator(selectedTower);

        return selectedTower;
    }
Exemple #22
0
    public void _ShowIndicator(UnitTower tower)
    {
        if(tower.type==_TowerType.Block) return;

        //show range indicator on the tower
        //for support tower, show friendly range indicator
        if(tower.type==_TowerType.SupportTower){
            //Debug.Log(tower.type);
            float range=tower.GetRange();
            if(rangeIndicatorF!=null){
                rangeIndicatorF.position=tower.thisT.position;
                rangeIndicatorF.localScale=new Vector3(2*range/10, 1, 2*range/10);
                rangeIndicatorF.renderer.enabled=true;
            }
            if(rangeIndicatorH!=null) rangeIndicatorH.renderer.enabled=false;
            if(rangeIndicatorConeH!=null) rangeIndicatorConeH.renderer.enabled=false;
        }
        //for support tower, show hostile range indicator
        else if(tower.type!=_TowerType.ResourceTower){
            float range=tower.GetRange();
            if(tower.targetingArea==_TargetingArea.AllAround){
                if(rangeIndicatorH!=null){
                    rangeIndicatorH.position=tower.thisT.position;
                    rangeIndicatorH.localScale=new Vector3(2*range/10, 1, 2*range/10);
                    rangeIndicatorH.renderer.enabled=true;
                }
                if(rangeIndicatorConeH!=null) rangeIndicatorConeH.renderer.enabled=false;
            }
            else{
                if(rangeIndicatorH!=null){
                    rangeIndicatorConeH.position=tower.thisT.position;
                    rangeIndicatorConeH.localScale=new Vector3(2*range/10, 1, 2*range/10);
                    rangeIndicatorConeH.rotation=Quaternion.Euler(0, (360-tower.targetingDirection)-90, 0);
                    rangeIndicatorConeH.renderer.enabled=true;
                }
                if(rangeIndicatorH!=null) rangeIndicatorH.renderer.enabled=false;
            }
            if(rangeIndicatorF!=null) rangeIndicatorF.renderer.enabled=false;
        }
    }
Exemple #23
0
 //call when a tower complete upgrade, if tower is currently selected, update the range indicator
 public static void TowerUpgradeComplete(UnitTower tower)
 {
     if(tower==selectedTower){
         gameControl._ShowIndicator(tower);
     }
 }
Exemple #24
0
 void OnSelectTower(UnitTower tower)
 {
     currentSelectedTower=tower;
     EnableSelectedTowerUI();
 }
Exemple #25
0
    /*
     * public int isPreferable(TowerType type)
     * {
     *      int dividePos = 0;
     *      for(int i=visitorAttri.preferBuilTp.Length-1; i>=0; --i)
     *      {
     *              if((int)type == (visitorAttri.preferBuilTp[i]-'0') && i>dividePos)
     *                      return 1;
     *              if(visitorAttri.preferBuilTp[i] == '0')
     *              {
     *                      dividePos = i;
     *                      continue;
     *              }
     *              if((int)type == (visitorAttri.preferBuilTp[i]-'0') && i<dividePos)
     *                      return -1;
     *
     *      }
     *      return 0;
     * }
     */
    VisitorEffect ScanForTower()
    {
        //Judge the effect
        //use the raycast method
        //repeat the number of the tower times
        //each time, 1. get the whole tower information
        //2. raycast a ray from the current position of the visitor to the tower's position
        //3. the distance is the tower's range
        //4. if hit, then add the current tower to the list of coveredTowers
        //5. check if this is the favorable tower
        //6. ShowFavorble and ClearHateful when : a. covered by a favorable tower, b. the hp is larger than the angrylimit
        //7. ShowHateful and ClearFavorable when : a. covered by no favorable tower, b. covered by a hateful tower
        //8. ClearFavorable and ClearHateful when there is no coveredTower or the coveredTower is all null
        //9. keep in mind that the range is not a circle.
        Collider2D[] towerColliders;
        //this step could be replaced by the "PoolManager.allobject" method, recheck it later
        VisitorEffect tempEffect;

        tempEffect = showEffect;
        showEffect = VisitorEffect.None;

        towerColliders = Physics2D.OverlapAreaAll(GameManager.gameManager.leftBottom, GameManager.gameManager.rightTop,
                                                  LayerMask.GetMask("Tower"));         //need to be reviewed CCat


        //---------------the things that already known
        float yratio = 2.0408163f;         // 1/(0.7^0.7)
        float range;
        int   i = 0;

        foreach (Collider2D towerColli in towerColliders)
        {
            UnitTower tower = towerColli.GetComponent <UnitTower>();
            range = tower.baseTower.range;
            Vector3 dir = towerColli.transform.position - thisT.position;
            //RaycastHit2D hit;
            //if((hit = Physics2D.Raycast(thisT.position, dir, tower.baseTower.range, LayerMask.GetMask("Tower")))!= false)
            if (dir.x * dir.x + dir.y * dir.y * yratio <= range * range)
            {
                if (i == 0)
                {
                    showEffect = VisitorEffect.em_BadEffect;
                }
                VisitorEffect visEffect = (VisitorEffect)PoolManager.GetEffect(ReadFromExcel.ExtractInt(tower.name), ReadFromExcel.ExtractInt(this.name));
                if (visEffect == VisitorEffect.em_GoodEffect)
                {
                    if (HpAttribute.m_curHp < visitorAttri.angryLimit)
                    {
                        visEffect = VisitorEffect.None;
                    }
                }
                if (visEffect != VisitorEffect.None)
                {
                    showEffect = showEffect | visEffect;
                }
                else
                {
                    showEffect = VisitorEffect.None;
                }
                //showEffect = showEffect | visEffect; //need to be checked
                ++i;
            }
        }
        if (tempEffect == showEffect)
        {
            effectChanges = false;
        }
        else
        {
            effectChanges = true;
        }
        return(showEffect);
    }
Exemple #26
0
 public static void ShowIndicator(UnitTower tower)
 {
     gameControl._ShowIndicator(tower);
 }
Exemple #27
0
    void OnTowerBuildComplete(UnitTower tower)
    {
        if(currentSelectedTower==tower){
            if(!currentSelectedTower.IsLevelCapped())
                upgradeButton.buttonObj.enabled=true;

            UpdateSelectedTowerText();
        }
    }
Exemple #28
0
 public void _ShowIndicator(UnitTower tower)
 {
     //show range indicator on the tower
     //for support tower, show friendly range indicator
     if(tower.type==_TowerType.SupportTower){
         //Debug.Log(tower.type);
         float range=tower.GetRange();
         if(rangeIndicatorF!=null){
             rangeIndicatorF.position=tower.thisT.position;
             rangeIndicatorF.localScale=new Vector3(2*range/10, 1, 2*range/10);
             rangeIndicatorF.renderer.enabled=true;
         }
         if(rangeIndicatorH!=null) rangeIndicatorH.renderer.enabled=false;
     }
     //for support tower, show hostile range indicator
     else{
         float range=tower.GetRange();
         if(rangeIndicatorH!=null){
             rangeIndicatorH.position=tower.thisT.position;
             rangeIndicatorH.localScale=new Vector3(2*range/10, 1, 2*range/10);
             rangeIndicatorH.renderer.enabled=true;
         }
         if(rangeIndicatorF!=null) rangeIndicatorF.renderer.enabled=false;
     }
 }
Exemple #29
0
 void OnTowerDestroy(UnitTower tower)
 {
     if(currentSelectedTower==tower){
         DisableSelectedTowerUI();
     }
 }
Exemple #30
0
    IEnumerator _DragNDropIndicator(UnitTower tower)
    {
        dragNDrop=true;

        while(dragNDrop){
            if(tower.type==_TowerType.SupportTower){
                if(rangeIndicatorF!=null) rangeIndicatorF.position=tower.thisT.position;
            }
            else{
                if(rangeIndicatorH!=null) rangeIndicatorH.position=tower.thisT.position;
            }

            yield return null;
        }
        ClearIndicator();
    }
Exemple #31
0
 void OnUnselectTower()
 {
     currentSelectedTower=null;
     DisableSelectedTowerUI();
     GameControl.ClearSelection();
 }
Exemple #32
0
 public static void DragNDropIndicator(UnitTower tower)
 {
     gameControl._ShowIndicator(tower);
     gameControl.StartCoroutine(gameControl._DragNDropIndicator(tower));
 }
Exemple #33
0
 private bool BuildButtonPressed(UnitTower tower)
 {
     if(BuildManager.BuildTowerPointNBuild(tower)==""){
         //built, clear the build menu flag
         buildMenu=false;
         ClearBuildListRect();
         return true;
     }
     else{
         //Debug.Log("build failed. invalide position");
         return false;
     }
 }
Exemple #34
0
    public void Build(Vector3 point, UnitTower tower)
    {
        //pathfinding related code, only call if this platform is walkable;
        if(walkable){
            if(tower.type!=_TowerType.Mine){
                //if build on the node last check for block, use the cached node and path
                if(nextBuildNode!=null && Vector3.Distance(nextBuildNode.pos, point)<BuildManager.GetGridSize()/2){
                    //Debug.Log("use cached path");
                    nextBuildNode.walkable=false;
                    tower.SetPlatform(this, nextBuildNode);
                    foreach(PathOnPlatform pathObj in pathObjects){

                        int rand=pathObj.pathID;
                        while(rand==pathObj.pathID){
                            rand=Random.Range(-999999, 999999);
                        }
                        pathObj.SetPath(pathObj.altPath, rand);
                        //forceSearch doesnt smooth path so path smoothing is call
                        //smoothPath will only valid path smoothing is enable in PathFinder
                        pathObj.SmoothPath();
                    }
                }
                //if build on node that is unchecked, find the block node and initiate a new path search
                else{
                    //Debug.Log("unexpected build point, query for new path");
                    Node node=PathFinder.GetNearestNode(point, nodeGraph);
                    node.walkable=false;
                    tower.SetPlatform(this, node);
                    foreach(PathOnPlatform pathObj in pathObjects){
                        PathFinder.GetPath(pathObj.startN, pathObj.endN, nodeGraph, this.SetPath);
                    }
                }
            }
        }
    }
Exemple #35
0
 //called if a tower is unbuilt or destroyed, check to see if that tower is selected, if so, clear the selection
 void OnTowerDestroy(UnitTower tower)
 {
     if(currentSelectedTower==tower) currentSelectedTower=null;
 }
Exemple #36
0
 void OnTowerBuildComplete(UnitTower tower)
 {
     if(currentSelectedTower==tower){
         OnTowerSelect();
     }
 }
Exemple #37
0
    //call to enable/disable pause
    void TogglePause()
    {
        paused=!paused;
        if(paused){
            Time.timeScale=0;

            //close all the button, so user can interact with game when it's paused
            if(currentSelectedTower!=null){
                GameControl.ClearSelection();
                currentSelectedTower=null;
            }
            if(buildMenu){
                buildMenu=false;
                BuildManager.ClearBuildPoint();
            }
        }
        else Time.timeScale=1;
    }
Exemple #38
0
    // Update is called once per frame
    void Update()
    {
        #if !UNITY_IPHONE && !UNITY_ANDROID
            if(buildMode==_BuildMode.PointNBuild)
                BuildManager.SetIndicator(Input.mousePosition);
        #endif

        //when is pressed, make sure it's not on any of the ui element and the game is not paused
        if(Input.GetMouseButtonDown(0) && !IsCursorOnUI(Input.mousePosition) && !pause){

            //call function to see if any tower is being selected upon the click
            UnitTower tower=GameControl.Select(Input.mousePosition);

            //if a tower has been selected on the click
            if(tower!=null){
                //set the selecte tower
                currentSelectedTower=tower;
                //for PointNBuild mode, clear buildpoint if buildmenu is currently activated
                if(buildMode==_BuildMode.PointNBuild && buildMenu){
                    BuildManager.ClearBuildPoint();
                    DisableBuildButtons();
                    buildMenu=false;
                }
            }
            //if no tower has been selected
            else{
                // if a tower has been selected previous, clear the selection now
                if(currentSelectedTower!=null){
                    GameControl.ClearSelection();
                    currentSelectedTower=null;
                }

                if(buildMode==_BuildMode.PointNBuild){

                    //check for build point, if true initiate build menu
                    if(BuildManager.CheckBuildPoint(Input.mousePosition)){
                        if(!alwaysShowBuildButton){
                            buildMenu=true;
                            UpdateBuildList();
                        }
                    }
                    //if there are no valid build point but we are in build mode, disable it
                    else{
                        if(buildMenu && !alwaysShowBuildButton){
                            buildMenu=false;
                            DisableBuildButtons();
                        }
                        BuildManager.ClearBuildPoint();
                    }

                }
            }

            //call function to update the tower selection panel
            OnTowerSelect();
        }
    }
Exemple #39
0
 //Call by inherited class UnitTower, caching inherited UnitTower instance to this instance
 public void SetSubClassInt(UnitTower unit)
 {
     unitT    = unit;
     subClass = _UnitSubClass.Tower;
 }