Vector3 m_Position; // 出現位置 // 訓練 public TrainSoldierCommand( ENUM_Soldier emSoldier, ENUM_Weapon emWeapon, int Lv, Vector3 Position) { m_emSoldier = emSoldier; m_emWeapon = emWeapon; m_Lv = Lv; m_Position = Position; }
// 建立武器 public override IWeapon CreateWeapon(ENUM_Weapon emWeapon) { IWeapon pWeapon = null; string AssetName = ""; int AttrID = 0; //根据武器类型建立 switch (emWeapon) { case ENUM_Weapon.Knife: pWeapon = new WeaponKnife(); AssetName = "5"; AttrID = 1; break; default: Debug.LogWarning("创建[" + emWeapon + "]失败!!!"); return(null); } // 加载武器资源 IAssetFactory AssetFactory = GameFactory.GetAssetFactory(); Sprite WeaponGameObjet = AssetFactory.LoadWeapon(AssetName); pWeapon.SetIWeapon(WeaponGameObjet); // 设置武器的威力 IAttrFactory theAttrFactory = GameFactory.GetAttrFactory(); WeaponAttr theWeaponAttr = theAttrFactory.GetWeaponAttr(AttrID); pWeapon.SetWeaponAttr(theWeaponAttr); return(pWeapon); }
// 建立Soldier public override ISoldier CreateSoldier(ENUM_Soldier emSoldier, ENUM_Weapon emWeapon, int Lv, Vector3 SpawnPosition) { // 產生對應的Character ICharacter theSoldier = null; switch (emSoldier) { case ENUM_Soldier.Rookie: theSoldier = new SoldierRookie(); break; case ENUM_Soldier.Sergeant: theSoldier = new SoldierSergeant(); break; case ENUM_Soldier.Captain: theSoldier = new SoldierCaptain(); break; default: Debug.LogWarning("CreateSoldier:無法建立[" + emSoldier + "]"); return(null); } // 增加角色功能 AddCharacterFuncs(theSoldier, emWeapon, Lv); // 加入管理器 //PBaseDefenseGame.Instance.AddSoldier( theSoldier as ISoldier); return(theSoldier as ISoldier); }
// 加入Troll單位 public IEnemy AddTroll(ENUM_Weapon emWeapon) { // 產生物件 EnemyTroll theEnmey = new EnemyTroll(); // 設定模型 GameObject tmpGameObject = CreateGameObject("TrollGameObjectName"); tmpGameObject.gameObject.name = "EnemyTroll"; theEnmey.SetGameObject(tmpGameObject); // 加入武器 IWeapon Weapon = CreateWeapon(emWeapon); theEnmey.SetWeapon(Weapon); // 取得Soldier的數值,設定給角色 EnemyAttr theEnemyAttr = CreateEnemyAttr(3); theEnmey.SetCharacterAttr(theEnemyAttr); // 加入AI EnemyAI theAI = CreateEnemyAI(); theEnmey.SetAI(theAI); // 加入管理器 //PBaseDefenseGame.Instance.AddEnemy( theEnmey as IEnemy ); return(theEnmey as IEnemy); }
// 建立Enemy public override IEnemy CreateEnemy(ENUM_Enemy emEnemy, ENUM_Weapon emWeapon, Vector3 SpawnPosition, Vector3 AttackPosition) { // 產生對應的Character ICharacter theEnemy = null; switch (emEnemy) { case ENUM_Enemy.Elf: theEnemy = new EnemyElf(); break; case ENUM_Enemy.Troll: theEnemy = new EnemyTroll(); break; case ENUM_Enemy.Ogre: theEnemy = new EnemyOgre(); break; default: Debug.LogWarning("無法建立[" + emEnemy + "]"); return(null); } // 增加角色功能 AddCharacterFuncs(theEnemy, emWeapon, 0); // 加入管理器 //PBaseDefenseGame.Instance.AddEnemy( theEnemy as IEnemy); return(theEnemy as IEnemy); }
// ------------------------------------------------------------------ static public Vector3 GetWeaponIconScale(ENUM_Weapon pWeapon) { if (pWeapon == ENUM_Weapon.Knife) { return(new Vector3(0.7f, 0.8f, 1)); } else if (pWeapon == ENUM_Weapon.Pistol) { return(new Vector3(0.75f, 0.85f, 1)); } else if (pWeapon == ENUM_Weapon.Revolver) { return(new Vector3(0.7f, 0.8f, 1)); } else if (pWeapon == ENUM_Weapon.Eagle) { return(new Vector3(0.65f, 0.8f, 1)); } else if (pWeapon == ENUM_Weapon.SUB) { return(new Vector3(0.6f, 0.7f, 1)); } else if (pWeapon == ENUM_Weapon.Rifle) { return(new Vector3(0.43f, 0.6f, 1)); } else if (pWeapon == ENUM_Weapon.LMG) { return(new Vector3(0.5f, 0.7f, 1)); } else { return(new Vector3(1.2f, 1.2f, 1)); } }
// 訓練Rookie單位 public ISoldier TrainRookie(ENUM_Weapon emWeapon, int Lv) { // 產生物件 SoldierRookie theSoldier = new SoldierRookie(); // 設定模型 GameObject tmpGameObject = CreateGameObject("RookieGameObjectName"); tmpGameObject.gameObject.name = "SoldierRookie"; theSoldier.SetGameObject(tmpGameObject); // 加入武器 IWeapon Weapon = CreateWeapon(emWeapon); theSoldier.SetWeapon(Weapon); // 取得Soldier的數值,設定給角色 SoldierAttr theSoldierAttr = CreateSoliderAttr(1); theSoldierAttr.SetSoldierLv(Lv); theSoldier.SetCharacterAttr(theSoldierAttr); // 加入AI SoldierAI theAI = CreateSoldierAI(); theSoldier.SetAI(theAI); // 加入管理器 //PBaseDefenseGame.Instance.AddSoldier( theSoldier as ISoldier ); return(theSoldier as ISoldier); }
// 建立Enemy(Generice版) public IEnemy CreateEnemy <T>(ENUM_Weapon emWeapon, Vector3 SpawnPosition, Vector3 AttackPosition) where T : IEnemy, new() { // 产生Enemy的参数 EnemyBuildParam EnemyParam = new EnemyBuildParam(); // 产生对应的Character EnemyParam.NewCharacter = new T(); if (EnemyParam.NewCharacter == null) { return(null); } // 设定共用参数 EnemyParam.emWeapon = emWeapon; EnemyParam.SpawnPosition = SpawnPosition; EnemyParam.AttackPosition = AttackPosition; // 产生对应的Builder及设定参数 EnemyBuilder theEnemyBuilder = new EnemyBuilder(); theEnemyBuilder.SetBuildParam(EnemyParam); // 产生 m_BuilderDirector.Construct(theEnemyBuilder); return(EnemyParam.NewCharacter as IEnemy); }
public override IEnemy createEnemy(ENUM_Enemy emEnemy, ENUM_Weapon emWeapon, Vector3 spawnPosition) { //建造参数 EnemyBuildParam buildParam = new EnemyBuildParam(); switch (emEnemy) { case ENUM_Enemy.Zombie: buildParam.character = new EnemyZombie(); break; default: Debug.Log("不存在该Enemy类型"); return(null); } buildParam.weapon = emWeapon; buildParam.spawnPosition = spawnPosition; EnemyBuilder enemyBuilder = new EnemyBuilder(); enemyBuilder.setBuildParam(buildParam); m_characterBuilderSystem.construct(enemyBuilder); return(buildParam.character as IEnemy); }
// 建立Soldier(Generice版) public ISoldier CreateSoldier <T>(ENUM_Weapon emWeapon, int Lv, Vector3 SpawnPosition) where T : ISoldier, new() { // 产生Soldier的参数 SoldierBuildParam SoldierParam = new SoldierBuildParam(); // 产生对应的T类别 SoldierParam.NewCharacter = new T(); if (SoldierParam.NewCharacter == null) { return(null); } // 设定共用参数 SoldierParam.emWeapon = emWeapon; SoldierParam.SpawnPosition = SpawnPosition; SoldierParam.Lv = Lv; // 产生对应的Builder及设定参数 SoldierBuilder theSoldierBuilder = new SoldierBuilder(); theSoldierBuilder.SetBuildParam(SoldierParam); // 产生 m_BuilderDirector.Construct(theSoldierBuilder); return(SoldierParam.NewCharacter as ISoldier); }
// 训练Caption单位 public ISoldier TrainCaption(ENUM_Weapon emWeapon, int Lv) { // 产生物件 SoldierCaptain theSoldier = new SoldierCaptain(); // 设定模型 GameObject tmpGameObject = CreateGameObject("CaptainGameObjectName"); tmpGameObject.gameObject.name = "SoldierCaptain"; theSoldier.SetGameObject(tmpGameObject); // 加入武器 IWeapon Weapon = CreateWeapon(emWeapon); theSoldier.SetWeapon(Weapon); // 取得Soldier的数值,设定给角色 SoldierAttr theSoldierAttr = CreateSoliderAttr(3); theSoldierAttr.SetSoldierLv(Lv); theSoldier.SetCharacterAttr(theSoldierAttr); // 加入AI SoldierAI theAI = CreateSoldierAI(); theSoldier.SetAI(theAI); // 加入管理器 //PBaseDefenseGame.Instance.AddSoldier( theSoldier as ISoldier ); return(theSoldier as ISoldier); }
// 增加关卡的敌方单位 public void AddStageData(ENUM_Enemy emEnemy, ENUM_Weapon emWeapon, int Count) { for (int i = 0; i < Count; ++i) { m_StageData.Add(new StageData(emEnemy, emWeapon)); } }
// 加入武器 public override void AddWeapon(ICharacter pRole, ENUM_Weapon emWeapon) { // 加入武器 IWeapon Weapon = CreateWeapon(emWeapon); pRole.SetWeapon(Weapon); }
Vector3 m_Position; // 出現位置 // 訓練 public TrainSoldierCommand(ENUM_Soldier emSoldier, ENUM_Weapon emWeapon, int Lv, Vector3 Position) { m_emSoldier = emSoldier; m_emWeapon = emWeapon; m_Lv = Lv; m_Position = Position; }
// 新增收集 public bool Add(ENUM_Weapon Weapon, int iLevel, int iIndex) { if (Weapon == ENUM_Weapon.Null || Weapon == ENUM_Weapon.Count) { return(false); } if (iLevel <= 0 || iLevel > GameDefine.iMaxCollectionLv) { return(false); } if (iIndex <= 0 || iIndex > GameDefine.iMaxCollectionCount) { return(false); } Collection Temp = new Collection(Weapon, iLevel, iIndex); string szTemp = Temp.ToStringData(); if (Data.Any((Itor) => Itor.ToStringData() == szTemp)) { return(false); } Data.Add(new Collection(Weapon, iLevel, iIndex)); return(true); }
// 新增收集 public void Add(ENUM_Weapon Weapon, int iLevel) { for (int iIndex = 0; iIndex <= GameDefine.iMaxCollectionCount; ++iIndex) { Add(Weapon, iLevel, iIndex); } }
// 訓練Rookie單位 public ISoldier TrainRookie(ENUM_Weapon emWeapon,int Lv) { // 產生物件 SoldierRookie theSoldier = new SoldierRookie(); // 設定模型 GameObject tmpGameObject = CreateGameObject("RookieGameObjectName"); tmpGameObject.gameObject.name = "SoldierRookie"; theSoldier.SetGameObject( tmpGameObject ); // 加入武器 IWeapon Weapon = CreateWeapon(emWeapon); theSoldier.SetWeapon( Weapon ); // 取得Soldier的數值,設定給角色 SoldierAttr theSoldierAttr = CreateSoliderAttr(1); theSoldierAttr.SetSoldierLv(Lv); theSoldier.SetCharacterAttr(theSoldierAttr); // 加入AI SoldierAI theAI = CreateSoldierAI(); theSoldier.SetAI( theAI ); // 加入管理器 //PBaseDefenseGame.Instance.AddSoldier( theSoldier as ISoldier ); return theSoldier as ISoldier; }
// 加入Ogre单位 public IEnemy AddOgre(ENUM_Weapon emWeapon) { // 产生物件 EnemyOgre theEnmey = new EnemyOgre(); // 设定模型 GameObject tmpGameObject = CreateGameObject("OgreGameObjectName"); tmpGameObject.gameObject.name = "EnemyOgre"; theEnmey.SetGameObject(tmpGameObject); // 加入武器 IWeapon Weapon = CreateWeapon(emWeapon); theEnmey.SetWeapon(Weapon); // 取得Soldier的数值,设定给角色 EnemyAttr theEnemyAttr = CreateEnemyAttr(2); theEnmey.SetCharacterAttr(theEnemyAttr); // 加入AI EnemyAI theAI = CreateEnemyAI(); theEnmey.SetAI(theAI); // 加入管理器 //PBaseDefenseGame.Instance.AddEnemy( theEnmey as IEnemy ); return(theEnmey as IEnemy); }
// ------------------------------------------------------------------ // Use this for initialization void Start() { for (int i = 0; i < DataGame.pthis.iWeaponType.Length; i++) { ENUM_Weapon pType = (ENUM_Weapon)DataGame.pthis.iWeaponType[i]; // 如果沒R到物品就隱藏 if (pType == ENUM_Weapon.Null) { continue; } ObjItem[i].SetActive(true); if (ObjItem[i] && ObjItem[i].GetComponent <G_WeaponItem>()) { ObjItem[i].GetComponent <G_WeaponItem>().SetInfo(pType, WeaponTransIndex(DataGame.pthis.iWeaponIndex[i])); } } // 更動位置. if (ObjItem[0] && ObjItem[0].GetComponent <G_WeaponItem>()) { ObjItem[0].GetComponent <G_WeaponItem>().SetPos(ObjItem[1].activeSelf); } if (ObjItem[1] && ObjItem[1].GetComponent <G_WeaponItem>()) { ObjItem[1].GetComponent <G_WeaponItem>().SetPos(ObjItem[0].activeSelf); } }
// ------------------------------------------------------------------ public void Init(bool bIsIn, int iItemID, Member pMember) { // 未加入角色要被加上蜘蛛網. if (!bIsIn) { ObjCatch = UITool.pthis.CreateUI(gameObject, "Prefab/Item/G_Catch"); ObjCatch.transform.localPosition = new Vector3(0, 0, -0.01f); ObjCatch.GetComponent <Btn_SaveRole>().iItemID = iItemID; ObjCatch.GetComponent <Btn_SaveRole>().pPlayer = this; } // 有盾套盾. if (iPlayer < DataPlayer.pthis.MemberParty.Count && DataPlayer.pthis.MemberParty[iPlayer].iShield > 0) { ObjShield = UITool.pthis.CreateUI(gameObject, "Prefab/G_Shield"); } fRectTime = pMember.fReactTime; pWeapon = (ENUM_Weapon)pMember.iEquip; // 建立外觀. ObjHuman = UITool.pthis.CreateRole(gameObject, pMember.iLooks); // 建立動作播放器 pAction = ObjHuman.AddComponent <G_ChrAction>(); // 設定武器. if (ObjHuman) { ObjHuman.AddComponent <G_PLook>().SetLook(this, iPlayer, pWeapon); } // 設定武器音效 if (pWeapon != ENUM_Weapon.Null && pWeapon != ENUM_Weapon.Light) { audioClip = Resources.Load("Sound/FX/W_" + pWeapon) as AudioClip; } }
public override void OnInspectorGUI() { if (EditorApplication.isPlaying == false) { return; } // show edit area { GUILayout.BeginHorizontal("box"); if (GUILayout.Button("Set", GUILayout.Width(60.0f))) { Target.Add(Weapon, Level, Index); } if (GUILayout.Button("Set All", GUILayout.Width(60.0f))) { Target.Add(Weapon, Level); } if (GUILayout.Button("Del", GUILayout.Width(60.0f))) { Target.Del(Weapon, Level, Index); } Weapon = (ENUM_Weapon)EditorGUILayout.EnumPopup(Weapon, GUILayout.Width(150.0f)); Level = EditorGUILayout.IntField(Level, GUILayout.Width(60.0f)); Index = EditorGUILayout.IntField(Index, GUILayout.Width(60.0f)); GUILayout.EndHorizontal(); } // show content WeaponShow = (ENUM_Weapon)EditorGUILayout.EnumPopup(WeaponShow, GUILayout.Width(150.0f)); GUILayout.BeginHorizontal("box"); GUILayout.Label("Level", GUILayout.Width(100.0f)); GUILayout.Label("A", GUILayout.Width(60.0f)); GUILayout.Label("B", GUILayout.Width(60.0f)); GUILayout.Label("C", GUILayout.Width(60.0f)); GUILayout.Label("D", GUILayout.Width(60.0f)); GUILayout.Label("E", GUILayout.Width(60.0f)); GUILayout.EndHorizontal(); for (int iLv = 1; iLv <= GameDefine.iMaxCollectionLv; ++iLv) { GUILayout.BeginHorizontal("box"); GUILayout.Label(iLv.ToString(), GUILayout.Width(100.0f)); for (int iID = 1; iID <= GameDefine.iMaxCollectionCount; ++iID) { GUILayout.Label(Target.IsExist(WeaponShow, iLv, iID) ? "O" : "X", GUILayout.Width(60.0f)); } GUILayout.EndHorizontal(); } //for }
public void SetInfo(ENUM_Weapon pType, string sIndex) { pS_Weapon.spriteName = string.Format("ui_w{0:00}", (int)pType); pS_Weapon.MakePixelPerfect(); pS_Weapon.gameObject.transform.localScale = ToolKit.GetWeaponIconScale(pType); pS_Box.color = SysMain.pthis.ColorLv[Rule.GetWeaponLevel(pType) + 1]; pLb_Index.text = sIndex; }
// ------------------------------------------------------------------ // 創建子彈. public GameObject CreateBullet(GameObject Parent, ENUM_Weapon pWeapon) { if (pWeapon == ENUM_Weapon.Null) { return(null); } return(NGUITools.AddChild(Parent, ObjList[pWeapon.ToString()])); }
// 刪除收集 public void Del(ENUM_Weapon Weapon, int iLevel, int iIndex) { string szTemp = (new Collection(Weapon, iLevel, iIndex)).ToStringData(); int iPos = Data.FindIndex((Itor) => Itor.ToStringData() == szTemp); if (iPos >= 0 && iPos < Data.Count) { Data.RemoveAt(iPos); } }
// 增加角色功能 public void AddCharacterFuncs(ICharacter pRole, ENUM_Weapon emWeapon, int Lv) { // 顯示的模式 AddGameObject(pRole); // 設定武器 AddWeapon(pRole, emWeapon); // 設定角色數值 AddAttr(pRole, Lv); // 設定角色AI AddAI(pRole); }
public int iIndex = 0; // 索引編號 public Collection(string data) { string[] szTemp = data.Split(new char[] { '_' }); if (szTemp.Length >= 3) { Weapon = (ENUM_Weapon)System.Convert.ToInt32(szTemp[0]); iLevel = System.Convert.ToInt32(szTemp[1]); iIndex = System.Convert.ToInt32(szTemp[2]); } //if }
// ------------------------------------------------------------------ void OnClick() { // 水晶不足. if (DataReward.pthis.iCrystal < GameDefine.iPriceWeaponItem) { return; } if (iIndex >= DataGame.pthis.iWeaponType.Length || DataGame.pthis.iWeaponType[iIndex] == (int)ENUM_Weapon.Null) { return; } ENUM_Weapon pType = (ENUM_Weapon)DataGame.pthis.iWeaponType[iIndex]; int iLevel = Rule.GetWeaponLevel(pType) + 1; int iPos = DataGame.pthis.iWeaponIndex[iIndex]; // 如果已經有這個東西了. if (DataCollection.pthis.IsExist(pType, iLevel, iPos) && GetComponent <UIButton>()) { GetComponent <UIButton>().isEnabled = false; return; } DataReward.pthis.iCrystal -= GameDefine.iPriceWeaponItem; // 新增收集物品, 並且判斷是否完成收集 if (Rule.CollectionAdd(pType, iLevel, iPos)) { // 增加武器等級 Rule.AddWeaponLevel(pType); // 如果完成收集, 要顯示通知 GameObject pObj = SysUI.pthis.CreatePanel("Prefab/P_WeaponLvUp"); if (pObj.GetComponent <P_WeaponLvUp>()) { pObj.GetComponent <P_WeaponLvUp>().pWeapon = pType; } } //if if (GetComponent <UIButton>()) { GetComponent <UIButton>().isEnabled = false; } DataGame.pthis.iWeaponType[iIndex] = (int)ENUM_Weapon.Null; DataReward.pthis.Save(); DataCollection.pthis.Save(); DataGame.pthis.Save(); }
// 建立武器 public override IWeapon CreateWeapon(ENUM_Weapon emWeapon) { IWeapon pWeapon = null; string AssetName = ""; // Unity模型名称 int AttrID = 0; // 武器的能力值 // 依武器 switch (emWeapon) { case ENUM_Weapon.Gun: pWeapon = new WeaponGun(); AssetName = "WeaponGun"; AttrID = 1; break; case ENUM_Weapon.Rifle: pWeapon = new WeaponRifle(); AssetName = "WeaponRifle"; AttrID = 2; break; case ENUM_Weapon.Rocket: pWeapon = new WeaponRocket(); AssetName = "WeaponRocket"; AttrID = 3; break; default: Debug.LogWarning("CreateWeapon:无法建立[" + emWeapon + "]"); return(null); } // 产生Asset IAssetFactory AssetFactory = PBDFactory.GetAssetFactory(); GameObject WeaponGameObjet = AssetFactory.LoadWeapon(AssetName); pWeapon.SetGameObject(WeaponGameObjet); // 取得武器的威力 IAttrFactory theAttrFactory = PBDFactory.GetAttrFactory(); WeaponAttr theWeaponAttr = theAttrFactory.GetWeaponAttr(AttrID); // 设定武器的威力 pWeapon.SetWeaponAttr(theWeaponAttr); return(pWeapon); }
// 建立武器 public override IWeapon CreateWeapon(ENUM_Weapon enumWeapon) { IWeapon weapon = null; string AssetName = ""; // Unity模型名称 int AttrID = 0; // 武器能力值 switch (enumWeapon) { case ENUM_Weapon.Gun: weapon = new WeaponGun(); AssetName = "WeaponGun"; AttrID = 1; break; case ENUM_Weapon.Rifle: weapon = new WeaponRifle(); AssetName = "WeaponRifle"; AttrID = 2; break; case ENUM_Weapon.Rocket: weapon = new WeaponRocket(); AssetName = "WeaponRocket"; AttrID = 3; break; default: Debug.LogWarning("CreateWeapon无法建立[" + enumWeapon + "]"); return(null); } // 产生Asset IAssetFactory AssetFactory = RTSFactory.GetAssetFactory(); GameObject WeaponGameObject = AssetFactory.LoadWeapon(AssetName); weapon.SetGameObject(WeaponGameObject); // 获取武器威力 IAttrFactory AttrFactory = RTSFactory.GetAttrFactory(); WeaponAttr theWeaponAttr = AttrFactory.GetWeaponAttr(AttrID); // 设置属性 weapon.SetWeaponAttr(theWeaponAttr); return(weapon); }
// 建立Enemy public override IEnemy CreateEnemy(ENUM_Enemy emEnemy, ENUM_Weapon emWeapon, Vector3 SpawnPosition, Vector3 AttackPosition) { // 產生Enemy的參數 EnemyBuildParam EnemyParam = new EnemyBuildParam(); // 產生對應的Character switch (emEnemy) { case ENUM_Enemy.Elf: EnemyParam.NewCharacter = new EnemyElf(); break; case ENUM_Enemy.Troll: EnemyParam.NewCharacter = new EnemyTroll(); break; case ENUM_Enemy.Ogre: EnemyParam.NewCharacter = new EnemyOgre(); break; default: Debug.LogWarning("無法建立[" + emEnemy + "]"); return(null); } if (EnemyParam.NewCharacter == null) { return(null); } // 設定共用參數 EnemyParam.emWeapon = emWeapon; EnemyParam.SpawnPosition = SpawnPosition; EnemyParam.AttackPosition = AttackPosition; // 產生對應的Builder及設定參數 EnemyBuilder theEnemyBuilder = new EnemyBuilder(); theEnemyBuilder.SetBuildParam(EnemyParam); // 產生 m_BuilderDirector.Construct(theEnemyBuilder); return(EnemyParam.NewCharacter as IEnemy); }
public override int GetTrainCost(ENUM_Soldier emSoldier, int CampLv, ENUM_Weapon emWeapon) { int Cost = 0; // 依兵種 switch (emSoldier) { case ENUM_Soldier.Rookie: Cost = 5; break; case ENUM_Soldier.Sergeant: Cost = 7; break; case ENUM_Soldier.Captain: Cost = 10; break; default: Debug.LogWarning("沒有定義[" + emSoldier + "]的訓練花費"); break; } // 依武器 switch (emWeapon) { case ENUM_Weapon.Gun: Cost += 5; break; case ENUM_Weapon.Rifle: Cost += 7; break; case ENUM_Weapon.Rocket: Cost += 10; break; } // 加等級 Cost += (CampLv - 1) * 2; return(Cost); }
// 建立Soldier public override ISoldier CreateSoldier(ENUM_Soldier emSoldier, ENUM_Weapon emWeapon, int Lv, Vector3 SpawnPosition) { // 產生Soldier的參數 SoldierBuildParam SoldierParam = new SoldierBuildParam(); // 產生對應的Character switch (emSoldier) { case ENUM_Soldier.Rookie: SoldierParam.NewCharacter = new SoldierRookie(); break; case ENUM_Soldier.Sergeant: SoldierParam.NewCharacter = new SoldierSergeant(); break; case ENUM_Soldier.Captain: SoldierParam.NewCharacter = new SoldierCaptain(); break; default: Debug.LogWarning("CreateSoldier:無法建立[" + emSoldier + "]"); return(null); } if (SoldierParam.NewCharacter == null) { return(null); } // 設定共用參數 SoldierParam.emWeapon = emWeapon; SoldierParam.SpawnPosition = SpawnPosition; SoldierParam.Lv = Lv; // 產生對應的Builder及設定參數 SoldierBuilder theSoldierBuilder = new SoldierBuilder(); theSoldierBuilder.SetBuildParam(SoldierParam); // 產生 m_BuilderDirector.Construct(theSoldierBuilder); return(SoldierParam.NewCharacter as ISoldier); }
// 建立武器 public override IWeapon CreateWeapon( ENUM_Weapon emWeapon) { IWeapon pWeapon = null; string AssetName = ""; // Unity模型名稱 int AttrID = 0; // 武器的能力值 // 依武器 switch( emWeapon ) { case ENUM_Weapon.Gun: pWeapon = new WeaponGun(); AssetName = "WeaponGun"; AttrID = 1; break; case ENUM_Weapon.Rifle: pWeapon = new WeaponRifle(); AssetName = "WeaponRifle"; AttrID = 2; break; case ENUM_Weapon.Rocket: pWeapon = new WeaponRocket(); AssetName = "WeaponRocket"; AttrID = 3; break; default: Debug.LogWarning("CreateWeapon:無法建立["+emWeapon+"]"); return null; } // 產生Asset IAssetFactory AssetFactory = PBDFactory.GetAssetFactory(); GameObject WeaponGameObjet = AssetFactory.LoadWeapon( AssetName ); pWeapon.SetGameObject( WeaponGameObjet ); // 取得武器的威力 IAttrFactory theAttrFactory = PBDFactory.GetAttrFactory(); WeaponAttr theWeaponAttr = theAttrFactory.GetWeaponAttr( AttrID ); // 設定武器的威力 pWeapon.SetWeaponAttr( theWeaponAttr ); return pWeapon; }
public override int GetTrainCost( ENUM_Soldier emSoldier,int CampLv, ENUM_Weapon emWeapon) { int Cost = 0; // 依兵種 switch( emSoldier ) { case ENUM_Soldier.Rookie: Cost = 5; break; case ENUM_Soldier.Sergeant: Cost = 7; break; case ENUM_Soldier.Captain: Cost = 10; break; default: Debug.LogWarning("沒有定義["+emSoldier+"]的訓練花費"); break; } // 依武器 switch( emWeapon) { case ENUM_Weapon.Gun: Cost += 5; break; case ENUM_Weapon.Rifle: Cost += 7; break; case ENUM_Weapon.Rocket: Cost += 10; break; } // 加等級 Cost += (CampLv-1)*2; return Cost; }
// 建立Soldier public override ISoldier CreateSoldier( ENUM_Soldier emSoldier, ENUM_Weapon emWeapon, int Lv, Vector3 SpawnPosition) { // 產生Soldier的參數 SoldierBuildParam SoldierParam = new SoldierBuildParam(); // 產生對應的Character switch( emSoldier) { case ENUM_Soldier.Rookie: SoldierParam.NewCharacter = new SoldierRookie(); break; case ENUM_Soldier.Sergeant: SoldierParam.NewCharacter = new SoldierSergeant(); break; case ENUM_Soldier.Captain: SoldierParam.NewCharacter = new SoldierCaptain(); break; default: Debug.LogWarning("CreateSoldier:無法建立[" + emSoldier + "]"); return null; } if( SoldierParam.NewCharacter == null) return null; // 設定共用參數 SoldierParam.emWeapon = emWeapon; SoldierParam.SpawnPosition = SpawnPosition; SoldierParam.Lv = Lv; // 產生對應的Builder及設定參數 SoldierBuilder theSoldierBuilder = new SoldierBuilder(); theSoldierBuilder.SetBuildParam( SoldierParam ); // 產生 m_BuilderDirector.Construct( theSoldierBuilder ); return SoldierParam.NewCharacter as ISoldier; }
// 建立Enemy public override IEnemy CreateEnemy( ENUM_Enemy emEnemy, ENUM_Weapon emWeapon, Vector3 SpawnPosition, Vector3 AttackPosition) { // 產生Enemy的參數 EnemyBuildParam EnemyParam = new EnemyBuildParam(); // 產生對應的Character switch( emEnemy) { case ENUM_Enemy.Elf: EnemyParam.NewCharacter = new EnemyElf(); break; case ENUM_Enemy.Troll: EnemyParam.NewCharacter = new EnemyTroll(); break; case ENUM_Enemy.Ogre: EnemyParam.NewCharacter = new EnemyOgre(); break; default: Debug.LogWarning("無法建立["+emEnemy+"]"); return null; } if( EnemyParam.NewCharacter == null) return null; // 設定共用參數 EnemyParam.emWeapon = emWeapon; EnemyParam.SpawnPosition = SpawnPosition; EnemyParam.AttackPosition = AttackPosition; // 產生對應的Builder及設定參數 EnemyBuilder theEnemyBuilder = new EnemyBuilder(); theEnemyBuilder.SetBuildParam( EnemyParam ); // 產生 m_BuilderDirector.Construct( theEnemyBuilder ); return EnemyParam.NewCharacter as IEnemy; }
// 建立Soldier public abstract ISoldier CreateSoldier( ENUM_Soldier emSoldier, ENUM_Weapon emWeapon, int Lv,Vector3 SpawnPosition);
protected int m_AtkPlusValue = 0; // 額外加乘值 public Weapon(ENUM_Weapon Type,int AtkValue, int AtkRange) { m_emWeapon = Type; m_AtkValue = AtkValue; m_AtkRange = AtkRange; }
public abstract int GetTrainCost( ENUM_Soldier emSoldier,int CampLv, ENUM_Weapon emWeapon);
// 建立Enemy public override IEnemy CreateEnemy( ENUM_Enemy emEnemy, ENUM_Weapon emWeapon, Vector3 SpawnPosition, Vector3 AttackPosition) { // 產生對應的Character ICharacter theEnemy =null; switch( emEnemy) { case ENUM_Enemy.Elf: theEnemy = new EnemyElf(); break; case ENUM_Enemy.Troll: theEnemy = new EnemyTroll(); break; case ENUM_Enemy.Ogre: theEnemy = new EnemyOgre(); break; default: Debug.LogWarning("無法建立["+emEnemy+"]"); return null; } // 增加角色功能 AddCharacterFuncs( theEnemy, emWeapon, 0); // 加入管理器 //PBaseDefenseGame.Instance.AddEnemy( theEnemy as IEnemy); return theEnemy as IEnemy; }
// 增加角色功能 public void AddCharacterFuncs( ICharacter pRole ,ENUM_Weapon emWeapon,int Lv) { // 顯示的模式 AddGameObject (pRole); // 設定武器 AddWeapon(pRole, emWeapon); // 設定角色數值 AddAttr(pRole,Lv); // 設定角色AI AddAI(pRole); }
public abstract void AddWeapon(ICharacter pRole, ENUM_Weapon emWeapon);
// 增加關卡的敵方單位 public void AddStageData( ENUM_Enemy emEnemy, ENUM_Weapon emWeapon,int Count) { for(int i=0;i<Count;++i) m_StageData.Add ( new StageData(emEnemy, emWeapon)); }
public override IEnemy CreateEnemy( ENUM_Enemy emEnemy, ENUM_Weapon emWeapon, Vector3 SpawnPosition, Vector3 AttackPosition) { // 重宣告為空,防此錯誤呼 Debug.LogWarning("SoldierFactory不應該產生IEnemy物件"); return null; }
// 建立Enemy public abstract IEnemy CreateEnemy( ENUM_Enemy emEnemy, ENUM_Weapon emWeapon, Vector3 SpawnPosition, Vector3 AttackPosition);
public IWeapon CreateWeapon( ENUM_Weapon emType ){return null;}
// 建立Soldier public override ISoldier CreateSoldier( ENUM_Soldier emSoldier, ENUM_Weapon emWeapon, int Lv,Vector3 SpawnPosition) { // 重宣告為空,防此錯誤呼 Debug.LogWarning("EnemyFactory不應該產生ISoldier物件"); return null; }
// 加入武器 public override void AddWeapon(ICharacter pRole, ENUM_Weapon emWeapon) { // 加入武器 IWeapon Weapon = CreateWeapon(emWeapon); pRole.SetWeapon( Weapon ); }
// 建立Soldier public override ISoldier CreateSoldier( ENUM_Soldier emSoldier, ENUM_Weapon emWeapon, int Lv,Vector3 SpawnPosition) { // 產生對應的Character ICharacter theSoldier = null; switch( emSoldier) { case ENUM_Soldier.Rookie: theSoldier = new SoldierRookie(); break; case ENUM_Soldier.Sergeant: theSoldier = new SoldierSergeant(); break; case ENUM_Soldier.Captain: theSoldier = new SoldierCaptain(); break; default: Debug.LogWarning("CreateSoldier:無法建立[" + emSoldier + "]"); return null; } // 增加角色功能 AddCharacterFuncs( theSoldier, emWeapon, Lv); // 加入管理器 //PBaseDefenseGame.Instance.AddSoldier( theSoldier as ISoldier); return theSoldier as ISoldier; }
// 加入Troll單位 public IEnemy AddTroll(ENUM_Weapon emWeapon) { // 產生物件 EnemyTroll theEnmey = new EnemyTroll(); // 設定模型 GameObject tmpGameObject = CreateGameObject("TrollGameObjectName"); tmpGameObject.gameObject.name = "EnemyTroll"; theEnmey.SetGameObject( tmpGameObject ); // 加入武器 IWeapon Weapon = CreateWeapon(emWeapon); theEnmey.SetWeapon( Weapon ); // 取得Soldier的數值,設定給角色 EnemyAttr theEnemyAttr = CreateEnemyAttr(3); theEnmey.SetCharacterAttr(theEnemyAttr); // 加入AI EnemyAI theAI = CreateEnemyAI(); theEnmey.SetAI( theAI ); // 加入管理器 //PBaseDefenseGame.Instance.AddEnemy( theEnmey as IEnemy ); return theEnmey as IEnemy; }
// 建立武器 public abstract IWeapon CreateWeapon( ENUM_Weapon emWeapon);
public StageData( ENUM_Enemy emEnemy, ENUM_Weapon emWeapon ) { this.emEnemy = emEnemy; this.emWeapon= emWeapon; }