/// <summary> /// 加载船上楼梯 /// </summary> public static void LoadShipPutStairBuild(int ID, int DataID, BuildInfo Info) { if (Info == null) { return; } Transform parentT = GetLifeMBornNode(true); if (parentT == null) { return; } Int2 BornPos = new Int2(Info.m_cx, Info.m_cy); Vector3 local = RoomMap.GetShipBuildLocalPos(BornPos, ShipBuildType.BuildStair); Vector3 world = Local2WorldPos(local); Building buildlife = LifeFactory.CreateBuilding(Info, DataID, parentT, world, LifeEnvironment.Edit); TouchMove touch = buildlife.m_thisT.GetChild(0).gameObject.AddComponent <TouchMove>(); Vector2 size = new Vector2(Info.m_Shape.width, Info.m_Shape.height); CanvasCore Core = new CanvasCore(ShipBuildType.BuildStair, false, ID, DataID, size); touch.InitTouchMoveCore(Core, BornPos, buildlife); AddBuildingEditPlugin(touch); TouchMoveManager.JointShipBuild(touch); }
/// <summary> /// 加载防御方炮弹兵 /// </summary> public static void ProduceEmemy(int DataID) { SoldierInfo s = CmCarbon.GetSoldierInfo(LifeMCamp.DEFENSE, DataID); if (s == null) { return; } Transform t = GetLifeMBornNode(true); if (t == null) { return; } Int2 pos = new Int2(s.CX, s.CY); MapGrid mg = MapGrid.GetMG(pos); if (mg == null) { return; } //IGameRole iRole= GameRoleFactory.Create(t, s.m_modeltype, s.m_name, AnimatorState.Stand); Role r = LifeFactory.CreateRole(t, AnimatorState.Stand, s, LifeMCamp.DEFENSE, DataID, MoveState.Walk, pos, LifeEnvironment.Combat); GameObject gRole = r.RoleSkinCom.tRoot.gameObject; gRole.transform.parent = t; gRole.transform.position = mg.WorldPos; }
/// <summary> /// 创建建筑物体 /// </summary> private static void ProduceStairBulid(BuildInfo Info) { if (Info == null) { return; } Int2 Pos = new Int2(Info.m_cx, Info.m_cy); Transform t = GetLifeMBornNode(true); if (t == null) { return; } Vector3 worldPos = Vector3.zero; MapGrid mg = MapGrid.GetMG(Pos); if (mg != null) { worldPos.x = mg.WorldPos.x; //-MapGrid.m_width/2 ; worldPos.y = mg.WorldPos.y; } else { return; } Building1201 stair = LifeFactory.CreateBuilding(Info, 0, t, worldPos, LifeEnvironment.Combat) as Building1201; if (stair != null) { stair.SetMapGrid(Info.m_cx + 2, Info.m_cy); } }
/// <summary> /// 创建建筑物体 /// </summary> private static Building ProduceRoomBulid(int DataID, BuildInfo Info) { if (Info == null) { return(null); } MapGrid mg = MapGrid.GetMG(Info.m_cy, Info.m_cx); if (mg != null) { return(LifeFactory.CreateBuilding(Info, DataID, GetLifeMBornNode(true), mg.WorldPos, LifeEnvironment.Combat)); } return(null); }
/// <summary> /// 创建建筑 /// </summary> void CreateBuilding(BuildInfo roomBuild) { // 创建地形 if (roomBuild == null) { return; } GameObject dropHeroChild = new GameObject("dropHeroChild"); dropHeroChild.transform.parent = MyHead.BtnClickTrap.transform; Vector2 size = new Vector2(roomBuild.m_Shape.width, roomBuild.m_Shape.height); Vector3 pos = new Vector3(-50f * size.x, -47.6f, -600f); Vector3 scaleSize = new Vector3(35f, 35f, 35f); if (size.y >= 2) { scaleSize = new Vector3(20f, 20f, 20f); pos = new Vector3(-50f * size.x + 20f, -47.6f, -600f); } dropHeroChild.transform.localPosition = pos; dropHeroChild.transform.localScale = scaleSize; Vector3 local = Vector3.zero; Vector3 world = dropHeroChild.transform.TransformPoint(local); roomBuild.m_cx = 0; roomBuild.m_cy = 0; m_buildlife = LifeFactory.CreateBuilding(roomBuild, 0, dropHeroChild.transform, world, LifeEnvironment.View); if (m_buildlife != null) { m_buildlife.PlayViewAni(); if (roomBuild.BuildType == 1605) { ParticleEffect effect = m_buildlife.m_thisT.gameObject.AddComponent <ParticleEffect>(); effect.EnabelScale = true; } } // 创建房间外壳 if (roomBuild.m_RoomType != RoomType.DeckTrap) //非甲板房间需加壳 { GenerateShip.GenerateShipBuildingShell(dropHeroChild.transform, roomBuild.GetBuildCanvasInfo()); } GameObjectLoader.SetGameObjectLayer(dropHeroChild, gameObject.layer); }
private void Awake() { FoodController = GameObject.Find("FoodController").GetComponent <FoodController>(); DamageSystemController = GameObject.Find("DamageSystemController").GetComponent <DamageSystemController>(); LifeSystemController = GameObject.Find("LifeSystemController").GetComponent <LifeSystemController>(); SoundController = GameObject.Find("SoundController").GetComponent <SoundController>(); GameController = GameObject.Find("GameController").GetComponent <GameController>(); MenuController = GameObject.Find("MenuController").GetComponent <MenuController>(); EnemyController = GameObject.Find("EnemyController").GetComponent <EnemyController>(); foodFactory = GameObject.Find("FoodFactory").GetComponent <FoodFactory>(); lifeFactory = GameObject.Find("LifeFactory").GetComponent <LifeFactory>(); trapFactory = GameObject.Find("TrapFactory").GetComponent <TrapFactory>(); energyCapsuleFactory = GameObject.Find("EnergyCapsuleFactory").GetComponent <EnergyCapsuleFactory>(); rockFactory = GameObject.Find("RockFactory").GetComponent <RockFactory>(); }
/// <summary> /// 创建建筑 /// </summary> void CreateBuilding(BuildInfo roomBuild) { // 创建地形 if (roomBuild == null) { return; } GameObject dropHeroChild = new GameObject("dropHeroChild"); dropHeroChild.transform.parent = MyHead.DropHero; Vector2 size = new Vector2(roomBuild.m_Shape.width, roomBuild.m_Shape.height); Vector3 pos = new Vector3(-50f * size.x, 40f, -600f); Vector3 scaleSize = new Vector3(35f, 35f, 35f); dropHeroChild.transform.localPosition = pos; dropHeroChild.transform.localScale = scaleSize; Vector3 local = Vector3.zero; Vector3 world = dropHeroChild.transform.TransformPoint(local); roomBuild.m_cx = 0; roomBuild.m_cy = 0; Building buildlife = LifeFactory.CreateBuilding(roomBuild, 0, dropHeroChild.transform, world, LifeEnvironment.View); if (buildlife != null) { buildlife.PlayClickAni(); } // 创建房间外壳 if (roomBuild.m_RoomType != RoomType.DeckTrap) //非甲板房间需加壳 { GenerateShip.GenerateShipBuildingShellWithouClear(dropHeroChild.transform, roomBuild.GetBuildCanvasInfo()); } m_Tropies = dropHeroChild; SetStarsLevel(roomBuild.StarLevel); GameObjectLoader.SetGameObjectLayer(dropHeroChild, gameObject.layer); NGUIUtil.SetActive(MyHead.Building, true); string[] s = roomBuild.m_Desc.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries); if (s.Length > 1) { string text = string.Format("{0}{1}", NGUIUtil.GetStringByKey(88800039), s[0]); NGUIUtil.SetLableText(MyHead.LblBuildDesc, text); NGUIUtil.SetLableText(MyHead.LblBuildEffect, s[1]); } }
/// <summary> /// 从仓库中创建建筑。 /// </summary> public static void CreateBuildingFromWarehouse(BuildInfo infoBuild) { if (infoBuild == null) { return; } Vector2 size = new Vector2(infoBuild.m_Shape.width, infoBuild.m_Shape.height); CanvasCore Core = new CanvasCore(ShipBuildType.BuildRoom, true, ShipPutInfo.GetNewShipPutId(), infoBuild.ID, size); Int2 BornPos = new Int2(0, 0); bool isCanPut = PutCanvasM.GetBornPos(Core, ref BornPos); if (isCanPut == false) { NGUIUtil.ShowTipWndByKey("88800007", 1.0f); return; } Transform t_start = GetLifeMBornNode(true); Vector3 local = RoomMap.GetShipBuildLocalPos(BornPos, ShipBuildType.BuildRoom); Vector3 world = Local2WorldPos(local); Building buildlife = LifeFactory.CreateBuilding(infoBuild, 0, t_start, world, LifeEnvironment.Edit); if (buildlife == null) { return; } buildlife.ShowEditHp(infoBuild.m_bear); TouchMove touch = buildlife.m_thisT.GetChild(0).gameObject.AddComponent <TouchMove>(); touch.InitTouchMoveCore(Core, BornPos, buildlife); AddBuildingEditPlugin(touch); GenerateShip.m_vStart = Vector3.zero; TouchMoveManager.JointShipBuild(touch); TouchMoveManager.SetCurTouchMove(touch); touch.WareHouse2Ship(BornPos); }
static void Main(string[] args) { #region Prototype Pattern /* Use the Prototype pattern when * You want to: * • Hide concrete classes from the client. * • Add and remove new classes (via prototypes) at runtime. * • Keep the number of classes in the system to a minimum. * • Adapt to changing structures of data at runtime. * Because: * • In C# 3.0, cloning by deep copying is absolutely straightforward. * Consider using this pattern: * • With the Composite pattern, to provide archiving. * • Instead of the Factory Method pattern, when subclasses start proliferating */ Console.WriteLine(""); Console.WriteLine("=================Prototype Pattern========================="); WholeLifePremiumIllustrations illustrations = new WholeLifePremiumIllustrations(); WholeLife wl1 = illustrations.Prototypes["SFWholeLife"].Clone(); wl1.ChildRiders[0].CoverageAmount = 1000000000; WholeLife wl2 = illustrations.Prototypes["IMLWholeLife"].DeepCopy(); wl2.ChildRiders[0].CoverageAmount = 1000000000; Console.WriteLine(""); Console.WriteLine("SFWholeLife Actual Object Coverage Amount : " + illustrations.Prototypes["SFWholeLife"].ChildRiders[0].CoverageAmount); Console.WriteLine("SFWholeLife Cloned Copy Coverage Amount : " + wl1.ChildRiders[0].CoverageAmount); Console.WriteLine(""); Console.WriteLine("IMLWholeLife Actual Object Coverage Amount : " + illustrations.Prototypes["IMLWholeLife"].ChildRiders[0].CoverageAmount); Console.WriteLine("IMLWholeLife Deep Copy Object Coverage Amount : " + wl2.ChildRiders[0].CoverageAmount); Console.WriteLine(""); #endregion #region Factory Pattern /*The Factory Method pattern is a way of creating objects, but letting subclasses * decide exactly which class to instantiate. Various subclasses might implement the * interface; the Factory Method instantiates the appropriate subclass based on information * supplied by the client or extracted from the current state. * * Use the Factory Method pattern when * • Flexibility is important. * • Objects can be extended in subclasses * • There is a specific reason why one subclass would be chosen over another—this logic forms part of the Factory * Method. * • A client delegates responsibilities to subclasses in parallel hierarchies. * Consider using instead.... * • The Abstract Factory, Prototype, or Builder patterns, which are more flexible (though also more complex). * • The Prototype pattern to store a set of objects to clone from the abstract factory. */ Samples.StructuralPatterns.General.ProductRequest request = new Samples.StructuralPatterns.General.ProductRequest() { Amount = 10000, IsSmoker = false, IssueAge = 45, ProductType = StructuralPatterns.Common.ProductTypes.WholeLife }; ProductCreator creator = new ProductCreator(); IProduct product = creator.GetFactoryProduct(request); Console.WriteLine("=================Factory Pattern========================="); Console.WriteLine(""); Console.WriteLine("Whole Life Product Amount: {0} and Premium: {1} ", product.Benefit.ToString("C"), product.CalculatePremium().ToString("C")); Console.WriteLine(""); #endregion #region Singleton Pattern #endregion #region Abstract Factory /* Use the Abstract Factory pattern when * • A system should be independent of how its products are created, composed, and represented. * • A system can be configured with one of multiple families of products. * • The constraint requiring products from the same factory to be used together must be enforced. * • The emphasis is on revealing interfaces, not implementations. */ ILifeFactory factory = new LifeFactory(request); ILifeProduct lifeproduct = factory.GetLifeProduct(); ITermProduct tpProduct = factory.GetTermProduct(false); ITermProduct ropProduct = factory.GetTermProduct(true); Console.WriteLine(""); Console.WriteLine("==========================Abstract Factory=============================="); Console.WriteLine("Whole Life Product Premium : " + lifeproduct.CalculatePremium().ToString("C")); Console.WriteLine("Term Plan Product Premium : " + tpProduct.CalculatePremium().ToString("C")); Console.WriteLine("ROP Product Premium : " + ropProduct.CalculatePremium().ToString("C")); Console.WriteLine(""); IDIFactory difactory = new DIFactory(request); IPaycheckProtection diproduct = difactory.GetDIProduct(); IBusinessExpense beproduct = difactory.GetBEProduct(false); IBusinessExpense beproduct1 = difactory.GetBEProduct(true); Console.WriteLine(""); Console.WriteLine("Paycheck protection Product Premium : " + diproduct.CalculatePremium().ToString("C")); Console.WriteLine("Business Expense Product Premium : " + beproduct.CalculatePremium().ToString("C")); Console.WriteLine("Business Expense 2013 Product Premium : " + beproduct1.CalculatePremium().ToString("C")); Console.WriteLine(""); #endregion #region Builder Pattern Samples.StructuralPatterns.General.ProductRequest request11 = new StructuralPatterns.General.ProductRequest() { Amount = 100000, IsSmoker = false, IssueAge = 34, ProductType = Common.ProductTypes.WholeLife }; Samples.StructuralPatterns.General.ProductRequest berequest1 = new StructuralPatterns.General.ProductRequest() { Amount = 40000, IsSmoker = true, IssueAge = 45, ProductType = Common.ProductTypes.BusinessExpense }; IBuilder builder = new LifeBuilder(request11); IBuilder bebuilder = new DIBuilder(berequest1); Console.WriteLine(""); Console.WriteLine("==========================Builder Pattern============================="); Console.WriteLine("Created Whole Life Extended product and Calcuated Premium is : " + builder.InsuranceProduct.CalculatePremium().ToString("C")); Console.WriteLine("Created BE Extended product and Calcuated Premium is : " + bebuilder.InsuranceProduct.CalculatePremium().ToString("C")); Console.WriteLine(""); #endregion Console.ReadKey(); }
/// <summary> /// 发送炮弹兵 /// </summary> public static bool Fire(List <Vector3> lFlyPoint, int RoleID, SoldierInfo Soldier, bool IsPlayer) { if (Soldier == null || lFlyPoint == null || lFlyPoint.Count < 3) { return(false); } Role SoldierRole = null; int sceneID = CM.DataID2SceneIDInSoldier(RoleID); Life life = CM.GetLifeM(sceneID, LifeMType.SOLDIER); if (life == null) { int RoleType = Soldier.m_modeltype; if (RoleType == 102003) { RoleType = 1020032; } if (RoleType == 200009) { RoleType = 2000092; } string SoldierName = Soldier.m_name; Transform FlyNode = BattleEnvironmentM.GetLifeMBornNode(false); FlyNode.position = new Vector3(FlyNode.position.x, FlyNode.position.y, -0.5f); //IGameRole i = GameRoleFactory.Create(FlyNode, RoleType, SoldierName, AnimatorState.Fly00000); SoldierRole = LifeFactory.CreateRole(FlyNode, AnimatorState.Fly00000, Soldier, LifeMCamp.ATTACK, RoleID, MoveState.Fly, Int2.zero, LifeEnvironment.Combat); GameObject go = SoldierRole.RoleSkinCom.tRoot.gameObject; RoleColider col = SoldierRole.RoleSkinCom.tBody.gameObject.GetComponent <RoleColider>(); col.EnableColider(ColiderType.Fire, true); Vector3 dir = lFlyPoint[1] - lFlyPoint[0]; if (dir.x <= 0) { SoldierRole.RoleSkinCom.SetMirror(1, 1, 1); } else { SoldierRole.RoleSkinCom.SetMirror(-1, 1, 1); } } else { life.SetActive(true); SoldierRole = life as Role; SoldierRole.m_bReBorn = false; } if (SoldierRole != null) { if (IsPlayer) { GodSkillWnd gsw = WndManager.FindDialog <GodSkillWnd>(); if (gsw != null) { gsw.ChangeBiaoqing((int)CaptionExpress.fire); } } if (SoldierRole.MoveAI != null && SoldierRole.MoveAI is Fly) { (SoldierRole.MoveAI as Fly).SetTrailFly(lFlyPoint); PlayFlyMusic(Soldier.m_modeltype); } } return(true); }