void ShowEffect(VisitorEffect effect) { //AudioClip clip; int index = ((int)this.visitorAttri.visitorType - 1) * 3; //AudioClip clip = audioEffect[(int)this.visitorAttri.visitorType] switch (effect) { case VisitorEffect.em_GoodEffect: /* * childLove.renderer.enabled = true; * childDislike.renderer.enabled = false;*/ childLove.GetComponent <SpriteRenderer>().color = Color.white; childDislike.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f); if (effectChanges && audioEffect[index] != null) { AudioManager.PlaySound(audioEffect[index], false); } break; case VisitorEffect.em_BadEffect: childDislike.GetComponent <SpriteRenderer>().color = Color.white; childLove.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f); if (effectChanges && audioEffect[index + 1] != null) { AudioManager.PlaySound(audioEffect[index + 1], false); } break; case VisitorEffect.None: childLove.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f); childDislike.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.0f); break; } }
/* * 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); }