private void InitCamp(EnemyType enemyType) { GameObject gameObject = null; string gameObjectName = null; string name = null; string icon = null; Vector3 position = Vector3.zero; float trainTime = 0; switch (enemyType) { case EnemyType.Elf: gameObjectName = "CaptiveCamp_Elf"; name = "俘兵营"; icon = "CaptiveCamp"; trainTime = 3; break; default: Debug.Log("CampSystem InitCamp() " + enemyType + "can't solve"); break; } gameObjectName = "Camp/" + gameObjectName; gameObject = GameObject.Find(gameObjectName); position = UnityTool.FindChild(gameObject, "TrainPoint").transform.position; CaptiveCamp camp = new CaptiveCamp(gameObject, name, icon, enemyType, position, trainTime); gameObject.AddComponent <CampMono>().OnInit(camp); captiveCamps.Add(enemyType, camp); }
//初始化俘兵营 private void InitCamp(EnemyType enemyType) { GameObject gameObject = null; string gameObjectName = null; string name = null; string iconSprite = null; Vector3 position = Vector3.zero; float trainTime = 0; switch (enemyType) { case EnemyType.Elf: gameObjectName = "CaptiveCamp_Elf"; name = "俘兵营"; iconSprite = "CaptiveCamp"; trainTime = 3; break; default: Debug.LogError("无法根据俘兵类型" + enemyType + "初始化兵营"); break; } gameObject = GameObject.Find(gameObjectName); position = UnityTool.FindChild(gameObject, "TrainPoint").transform.position; CaptiveCamp camp = new CaptiveCamp(gameObject, name, iconSprite, enemyType, position, trainTime); //添加监听点击脚本 CampOnClick campOnClick = gameObject.AddComponent <CampOnClick>(); campOnClick.Camp = camp; mCaptiveCamps.Add(enemyType, camp); }
private void InitCamp(EnemyType enemyType) { string gameObjectName = null; string name = ""; string icon = ""; float trainTime = 0f; switch (enemyType) { case EnemyType.Elf: gameObjectName = "CaptiveCamp_Elf"; name = "伏兵营"; icon = "CaptiveCamp"; trainTime = 3f; break; default: Debug.LogError("无法根据战士类型" + enemyType + "初始化兵营"); break; } GameObject gameObject = gameObject = GameObject.Find(gameObjectName); Vector3 position = UnityTool.FindChild(gameObject, "TrainPoint").transform.position; CaptiveCamp camp = new CaptiveCamp(gameObject, name, icon, enemyType, position, trainTime); CampOnClick campOnClick = gameObject.AddComponent <CampOnClick>(); campOnClick.camp = camp; mCamptiveCamp.Add(enemyType, camp); }
private void InitCamp(EnemyType enemyType) { GameObject gameObject = null; string gameObjectName = null; string name = null; string icon = null; Vector3 position = Vector3.zero; float trainTime = 0f; //aSong:这个switch可以用文档加载的方式解决.将EnemyType转换为string类型,部分匹配字段 switch (enemyType) { case EnemyType.Elf: gameObjectName = "CaptiveCamp_Elf"; name = "俘兵营"; icon = "CaptiveCamp"; trainTime = 3f; break; default: Debug.LogError("无法匹配到指定敌人类型 [" + enemyType + "]初始化兵营"); break; } Debug.Log("gameObjectName = " + gameObjectName); gameObject = GameObject.Find(gameObjectName); position = gameObject.FindChildTraversing("TrainPoint").transform.position; CaptiveCamp camp = new CaptiveCamp(gameObject, name, icon, enemyType, position, trainTime); gameObject.AddComponent <CampOnClick>().Camp = camp; mDic_CaptiveCamps.Add(enemyType, camp); }
private void InitCamp(EnemyType enemyType) { GameObject gameObject = null; string gameObjectName = null; string name = ""; string icon = ""; Vector3 position = Vector3.zero; float trainTime = 0; switch (enemyType) { case EnemyType.Elf: gameObjectName = "CaptiveCamp_Elf"; name = "俘兵营"; icon = "CaptiveCamp"; trainTime = 3; break; default: Debug.LogError("无法根据敌人类型:" + enemyType + "初始化兵营"); break; } gameObject = GameObject.Find(gameObjectName); GameObject gameObjectPos = UnityTool.FindChild(gameObject, "TrainPoint"); if (gameObjectPos != null) { position = gameObjectPos.transform.position; gameObjectPos.SetActive(false); } CaptiveCamp camp = new CaptiveCamp(gameObject, name, icon, enemyType, position, trainTime); camp.IsCaptiveCamp = true; gameObject.AddComponent<CampOnClick>().Camp = camp;//添加点击组件 mCaptiveCamps.Add(enemyType, camp); }
private void IniCaptiveCamp(Type enemyType, string iconName, float trainTime) { var go = GameObject.Find("Camps").transform.Find(enemyType.ToString()).gameObject; var spawnPos = go.transform.Find("Camp/TrainPoint").position; BaseCamp camp = new CaptiveCamp(iconName, enemyType, spawnPos, trainTime); go.AddComponent <CampOnClick>().Camp = camp; //添加点击事件监测脚本 captiveCamps.Add(enemyType, camp); }
void UnitTest_Camp() { theSoldierCamp = new SoldierCamp(null, ENUM_Soldier.Rookie, "測試", "", 2, Vector3.zero); theCaptiveCamp = new CaptiveCamp(null, ENUM_Enemy.Elf, "測試", "", 3, Vector3.zero); // 執行訓練 theSoldierCamp.Train(); theSoldierCamp.Train(); theSoldierCamp.Train(); theCaptiveCamp.Train(); theCaptiveCamp.Train(); theCaptiveCamp.Train(); }
private void InitCamp(EnemyType type) { GameObject gameObject = null; string gameObejctName = ""; string name = ""; string icon = ""; Vector3 pos = Vector3.zero; float trainTime = 0; switch (type) { case EnemyType.Elf: gameObejctName = "CaptiveCamp_Elf"; name = "俘兵营"; icon = "CaptiveCamp"; trainTime = 3; break; //case EnemyType.Ogre: // gameObejctName = "SoldierCamp_Sergeant"; // name = "中士"; // icon = "SergeantCamp"; // trainTime = 4; // break; //case EnemyType.Troll: // gameObejctName = "SoldierCamp_Captain"; // name = "上尉"; // icon = "CaptainCamp"; // trainTime = 5; // break; default: break; } gameObject = GameObject.Find(gameObejctName); pos = UnityTool.FindChild(gameObject, "TrainPoint").transform.position; CaptiveCamp camp = new CaptiveCamp(gameObject, name, icon, type, pos, trainTime); gameObject.AddComponent <CampClick>().Camp = camp; mCaptiveCamps.Add(type, camp); }
// 取得场景中的俘兵营 private CaptiveCamp CaptiveCampFactory(ENUM_Enemy emEnemy) { string GameObjectName = "CaptiveCamp_"; float CoolDown = 0; string CampName = ""; string IconSprite = ""; switch (emEnemy) { case ENUM_Enemy.Elf: GameObjectName += "Elf"; CoolDown = 3; CampName = "精灵俘兵营"; IconSprite = "CaptiveCamp"; break; default: Debug.Log("沒有指定[" + emEnemy + "]要取得的场景物件名称"); break; } // 取得物件 GameObject theGameObject = UnityTool.FindGameObject(GameObjectName); // 取得集合点 Vector3 TrainPoint = GetTrainPoint(GameObjectName); // 产生兵营 CaptiveCamp NewCamp = new CaptiveCamp(theGameObject, emEnemy, CampName, IconSprite, CoolDown, TrainPoint); NewCamp.SetPBaseDefenseGame(m_PBDGame); // 设定兵营使用的Script AddCampScript(theGameObject, NewCamp); // 先隱藏 NewCamp.SetVisible(false); // 回传 return(NewCamp); }
private void InitCamp(EnemyType enemyType) { GameObject GO; string GOName = ""; string name = ""; string icon = ""; Vector3 position = Vector3.zero; float trainTime = 5; switch (enemyType) { case EnemyType.Elf: GOName = "CaptiveCamp_Elf"; name = "小精灵俘兵营"; icon = "CaptiveCamp"; trainTime = 3; break; default: Debug.LogError("无法根据敌人类型:" + enemyType + "初始化兵营。"); break; } GO = GameObject.Find(GOName); position = UnityTool.FindChild(GO, "TrainPoint").transform.position; //SoldierCamp soldierCamp = new SoldierCamp(GO, name, icon, soldierType, position, trainTime); CaptiveCamp camp = new CaptiveCamp(GO, name, icon, enemyType, position, trainTime); //CampOnClick campOnclick = GO.AddComponent<CampOnClick>(); //campOnclick.camp = soldierCamp; GO.AddComponent <CampOnClick>().camp = camp; //mSoldierCamps.Add(soldierType, soldierCamp); mCaptiveCamps.Add(enemyType, camp); }
// 取得場景中的俘兵營 private CaptiveCamp CaptiveCampFactory( ENUM_Enemy emEnemy ) { string GameObjectName = "CaptiveCamp_"; float CoolDown = 0; string CampName = ""; string IconSprite = ""; switch( emEnemy ) { case ENUM_Enemy.Elf : GameObjectName += "Elf"; CoolDown = 3; CampName = "精靈俘兵營"; IconSprite = "CaptiveCamp"; break; default: Debug.Log("沒有指定["+emEnemy+"]要取得的場景物件名稱"); break; } // 取得物件 GameObject theGameObject = UnityTool.FindGameObject( GameObjectName ); // 取得集合點 Vector3 TrainPoint = GetTrainPoint( GameObjectName ); // 產生兵營 CaptiveCamp NewCamp = new CaptiveCamp(theGameObject, emEnemy, CampName, IconSprite, CoolDown, TrainPoint); NewCamp.SetPBaseDefenseGame( m_PBDGame ); // 設定兵營使用的Script AddCampScript( theGameObject, NewCamp); // 先隱藏 NewCamp.SetVisible(false); // 回傳 return NewCamp; }