public override void Update(float dt) { if (!showingGatherIcon && nextShowIconTime < ServerTime.Instance.Now()) { showingGatherIcon = true; //显示icon if (!gatherIcon) { gatherIcon = (GameObject)ResourceManager.Instance.LoadAndCreate("Homeland/BuilderUI/CollectResIcon"); IsoHelper.FaceToWorldCamera(gatherIcon.transform); CollectResIconUI view = gatherIcon.GetComponent <CollectResIconUI>(); view.OnClickEvent += GatherResource; view.SpriteName = Entity.model.resourceType.ToString(); Entity.view.AddSubView(gatherIcon, new Vector3(0, Constants.COLLECTABLE_ICON_VERTICAL_HEIGHT, 0)); //装满了 if (DataCenter.Instance.GetResource(Entity.model.resourceType) >= DataCenter.Instance.GetMaxResourceStorage(Entity.model.resourceType)) { gatherIcon.GetComponentInChildren <UISprite>().color = Color.black; } } gatherIcon.SetActive(true); } }
public void Init(int size) { var offset = 2f; var height = size + 1; left.transform.localPosition = new Vector3(0, height, offset); right.transform.localPosition = new Vector3(offset, height, 0); IsoHelper.FaceToWorldCamera(left.transform); IsoHelper.FaceToWorldCamera(right.transform); }
public void SetHpBarPercent(float percent) { if (hpBar == null) { hpBar = ((GameObject)ResourceManager.Instance.LoadAndCreate("Misc/HPBar")).GetComponent <tk2dUIProgressBar>(); AddSubView(hpBar.gameObject, new Vector3(0, Constants.HPBAR_VERTICAL_HEIGHT, 0)); IsoHelper.FaceToWorldCamera(hpBar.transform); } hpBar.Value = percent; }
public GameEffect(int effectId, string effectName, Vector3 pos, bool loop) { this.effectId = effectId; var prefab = (GameObject)ResourceManager.Instance.Load("Effects/" + effectName); if (prefab != null) { m_view = PoolManager.Instance.Spawn(prefab); } if (m_view != null) { m_view.transform.position = pos; IsoHelper.MoveAlongCamera(m_view.transform, Constants.EFFECT_Z_ORDER); IsoHelper.FaceToWorldCamera(m_view.transform); // REMARK:循环效果应该手动释放 if (!loop) { var trigger = m_view.GetComponent <EffectTrigger>(); if (trigger != null) { trigger.CompleteEvent += trigger_CompleteEvent; } else { //TODO 临时方案 m_animator = m_view.GetComponentInChildren <tk2dSpriteAnimator>(); if (m_animator != null) { m_animator.AnimationCompleted = OnAnimationCompleted; m_animator.DefaultClip.wrapMode = (loop ? tk2dSpriteAnimationClip.WrapMode.Loop : tk2dSpriteAnimationClip.WrapMode.Once); if (!m_animator.playAutomatically) { m_animator.Play(m_animator.DefaultClip); } } else { Debug.LogWarning(string.Format("effect {0} miss animator...", effectName)); } } } } }
public void Init(int size) { // tl.transform.localPosition = new Vector3(-IsoHelper.TILE_HALF_WIDTH + IsoHelper.TILE_HALF_WIDTH * 0.5f * (size-1),IsoHelper.TILE_HALF_HEIGHT + IsoHelper.TILE_HALF_HEIGHT * 0.5f * (size-1)); // bl.transform.localPosition = new Vector3(-IsoHelper.TILE_HALF_WIDTH + IsoHelper.TILE_HALF_WIDTH * 0.5f * (size-1),-IsoHelper.TILE_HALF_HEIGHT - IsoHelper.TILE_HALF_HEIGHT * 0.5f * (size-1)); // tr.transform.localPosition = new Vector3(IsoHelper.TILE_HALF_WIDTH + IsoHelper.TILE_HALF_WIDTH * (size - 1) + IsoHelper.TILE_HALF_WIDTH * 0.5f * (size-1), IsoHelper.TILE_HALF_HEIGHT + IsoHelper.TILE_HALF_HEIGHT * (size - 1) - IsoHelper.TILE_HALF_HEIGHT * 0.5f * (size-1)); // br.transform.localPosition = new Vector3(IsoHelper.TILE_HALF_WIDTH + IsoHelper.TILE_HALF_WIDTH * (size - 1) + IsoHelper.TILE_HALF_WIDTH * 0.5f * (size-1), -IsoHelper.TILE_HALF_HEIGHT - IsoHelper.TILE_HALF_HEIGHT * (size - 1) + IsoHelper.TILE_HALF_HEIGHT * 0.5f * (size-1)); var center = size * 0.5f - 0.5f; var dist = size * 0.5f + 0.5f; tl.transform.localPosition = new Vector3(center, 0, center + dist); tr.transform.localPosition = new Vector3(center + dist, 0, center); bl.transform.localPosition = new Vector3(center - dist, 0, center); br.transform.localPosition = new Vector3(center, 0, center - dist); IsoHelper.FaceToWorldCamera(tl.transform); IsoHelper.FaceToWorldCamera(bl.transform); IsoHelper.FaceToWorldCamera(tr.transform); IsoHelper.FaceToWorldCamera(br.transform); }
private void UpdateDestroy(float dt) { // 死亡了 但尚未置于死亡状态(则释放) if (currentHp <= 0 && this.State != EntityStateType.Dead) { this.State = EntityStateType.Dead; if (GameWorld.Instance.worldType == WorldType.Battle || GameWorld.Instance.worldType == WorldType.Replay) { BattleManager.Instance.OnEntityDestroy(this); } //创建战斗时被销毁的残渣 if (EntityTypeUtil.IsAnyBuilding(entityType)) { GameObject.Destroy(view.body.gameObject); GameObject.Destroy(view.hpBar.gameObject); if (view.shadow != null) { GameObject.Destroy(view.shadow.gameObject); } GameEffectManager.Instance.AddEffect("Phouse_die", GetRenderPosition());//TODO var destroyView = (GameObject)ResourceManager.Instance.LoadAndCreate("Misc/DestroyedBuildingView"); view.AddSubView(destroyView, Vector3.zero); IsoHelper.FaceToWorldCamera(destroyView.transform); IsoHelper.MoveAlongCamera(destroyView.transform, 19); Destroy(false); IsoMap.Instance.RemoveBuildingMapData(this);//移除占地数据,对象还是在IsoMap中 } else if (EntityTypeUtil.IsAnyActor(entityType)) { GameEffectManager.Instance.AddEffect("Psoldier_die", GetRenderPosition()); IsoMap.Instance.DelayRemoveEntity(this); Destroy(); } else { IsoMap.Instance.DelayRemoveEntity(this); Destroy(); } } }
public void Init(int size) { foreach (Transform child in transform) { Destroy(child.gameObject); } for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { var tile = Instantiate(smallTilePrefab, IsoHelper.GridToPosition(i, j), Quaternion.identity) as GameObject; tile.transform.position = IsoHelper.GridToPosition(i, j); var localPos = tile.transform.localPosition; tile.transform.parent = transform; tile.transform.localPosition = localPos; IsoHelper.FaceToWorldCamera(tile.transform); } } }
public void Init(int size) { //left fence for (int i = 0; i < size; i++) { var go = new GameObject("fence"); var sprite = go.AddComponent <tk2dSprite>(); sprite.SetSprite(spriteCollection.spriteCollection, "buildFence"); sprite.transform.parent = transform; sprite.transform.localPosition = new Vector3(i * 2, 0, 0); IsoHelper.FaceToWorldCamera(sprite.transform); } //right fence for (int i = 1; i < size; i++) { var go = new GameObject("fence"); var sprite = go.AddComponent <tk2dSprite>(); sprite.SetSprite(spriteCollection.spriteCollection, "buildFence"); sprite.transform.parent = transform; sprite.transform.localPosition = new Vector3(0, 0, i * 2); IsoHelper.FaceToWorldCamera(sprite.transform); } //lines for (int i = 0; i < size - 1; i++) { var go = new GameObject("fenceLineLeft"); var sprite = go.AddComponent <tk2dSprite>(); sprite.SetSprite(spriteCollection.spriteCollection, "buildFenceLeft"); sprite.transform.parent = transform; sprite.transform.localPosition = new Vector3(0, 0, i * 2); IsoHelper.FaceToWorldCamera(sprite.transform); var goRight = new GameObject("fenceLineRight"); var spriteRight = goRight.AddComponent <tk2dSprite>(); spriteRight.SetSprite(spriteCollection.spriteCollection, "buildFenceRight"); spriteRight.transform.parent = transform; spriteRight.transform.localPosition = new Vector3(i * 2, 0, 0); IsoHelper.FaceToWorldCamera(sprite.transform); } }
virtual public void Init(bool faceToMainCamera = true) { _animationFinishCallbacks = null; if (faceToMainCamera) { foreach (Transform child in transform) { if (child.GetComponent <tk2dSprite>() != null) { IsoHelper.FaceToWorldCamera(child); if (child.name.IndexOf("Shadow") != -1) { shadow = child; IsoHelper.MoveAlongCamera(child, Constants.SHADOW_Z_ORDER); } } } } body = transform.FindChild("body"); if (body == null)//多状态的 { SwitchBody(1); } else { animator = body.GetComponentInChildren <tk2dSpriteAnimator>(); //attachPoint = body.GetComponentInChildren<tk2dSpriteAttachPoint>(); this.effAttachPoint = body.GetComponentInChildren <tk2dSpriteAttachPoint>(); //RegisterSpriteChangeEvent(); } if (animator != null) { animator.AnimationCompleted = ontk2dSpriteAnimatorCallback_Completed; animator.AnimationEventTriggered = OnAnimationEventTriggered; animator.enabled = false; // REMARK:禁用掉然后手动更新 } }
public static TileEntity Create(OwnerType owner, EntityModel model, bool isFriendly = false) { var entityObj = LoadAndCreate(model); var tileEntity = new TileEntity(); tileEntity.owner = owner; tileEntity.model = model; tileEntity.State = EntityStateType.Idle; tileEntity.aiType = (EntityAiType)model.targetType; tileEntity.entityType = model.entityType; tileEntity.Friendly = isFriendly; if (model.tileSize > 0) { tileEntity.width = tileEntity.height = model.tileSize * 2; // REMARK:建筑实际占用格子扩大2倍 } else { tileEntity.width = tileEntity.height = 1; } tileEntity.currentHp = tileEntity.maxHp = Mathf.Max(model.hp, 1); // REMARK:这里设置最大hp的最小值为1,不然对于工人等直接就是dead状态。 tileEntity.animationNamePrefix = model.nameForResource + "_"; // REMARK:建筑按照格子建造、士兵按照边行走(所以士兵位置比建筑偏移(0.5,0.5)) if (EntityTypeUtil.IsAnyActor(model.entityType)) { tileEntity.renderTileSizeOffset = new Vector2((tileEntity.width * 0.5f) - 1.0f, (tileEntity.height * 0.5f) - 1.0f); } else { tileEntity.renderTileSizeOffset = new Vector2((tileEntity.width * 0.5f) - 0.5f, (tileEntity.height * 0.5f) - 0.5f); } tileEntity.view = entityObj.GetComponent <EntityViewComponent>(); if (tileEntity.view == null) { if (EntityTypeUtil.IsAnyActor(tileEntity.entityType)) { tileEntity.view = entityObj.AddComponent <ActorView>(); } else if (EntityTypeUtil.IsAnyTower(tileEntity.entityType)) { tileEntity.view = entityObj.AddComponent <TowerView>(); } else { tileEntity.view = entityObj.AddComponent <EntityViewComponent>(); } } if (EntityTypeUtil.IsAnyBuilding(tileEntity.entityType))//[建筑类] { //1格以上建筑有地皮 if (model.tileSize > 2) { var floorBase = (GameObject)ResourceManager.Instance.LoadAndCreate(model.raceType + "/Entities/Misc/Floor4");//地皮 tileEntity.view.AddSubView(floorBase, Vector3.zero); IsoHelper.FaceToWorldCamera(floorBase.transform); IsoHelper.MoveAlongCamera(floorBase.transform, Constants.FLOOR_Z_ORDER); floorBase.transform.localScale = Vector3.one * model.tileSize / 4;//REMARK 现有素材占4x4个tilesize } if (EntityTypeUtil.IsBarracks(model)) { tileEntity.blockingRange = 3; } else { tileEntity.blockingRange = model.tileSize * 2 - 1; } tileEntity.AddComponent <ConstructBuildingComponent>(); if (model.entityType == EntityType.Tower) { tileEntity.AddComponent <TowerComponent>(); } else if (model.entityType == EntityType.Wall) { tileEntity.AddComponent <WallComponent>(); } else if (EntityTypeUtil.IsGatherResourceBuilding(model)) { tileEntity.AddComponent <GatherResourceBuildingComponent>(); } else if (EntityTypeUtil.IsStorageResoruceBuilding(model)) { tileEntity.AddComponent <ResourceStorageBuildingComponent>(); } else if (EntityTypeUtil.IsArmyShop(model)) { tileEntity.AddComponent <ProductSoldierBuildingComponent>(); } else if (EntityTypeUtil.IsSkillShop(model)) { tileEntity.AddComponent <ProductSkillBuildingComponent>(); } else if (EntityTypeUtil.IsWorkerHouse(model)) { tileEntity.AddComponent <WorkerHouseComponent>(); } else if (EntityTypeUtil.IsFederal(model)) { tileEntity.AddComponent <FederalComponent>(); } else if (EntityTypeUtil.IsResearch(model)) { tileEntity.AddComponent <ResearchBuildingComponent>(); } } else if (EntityTypeUtil.IsAnyActor(model.entityType)) //[角色类] { // 战斗模式 家园模式 通用组件 tileEntity.AddComponent <ActorMoveComponent>(); if (GameWorld.Instance.worldType == WorldType.Home || GameWorld.Instance.worldType == WorldType.Visit) //家园模式 或者 访问模式 { // 家园模式 // 工人(添加工人组件&添加到工人小屋中) if (EntityTypeUtil.IsWorker(model)) { tileEntity.AddComponent <WorkmanComponent>(); var houseComp = IsoMap.Instance.GetWorkerHouseComponent(); Assert.Should(houseComp != null, "worker house is not exist..."); houseComp.AddAWorkman(tileEntity); } else { tileEntity.AddComponent <ArmyComponent>(); } } else //战斗模式 { tileEntity.AddComponent <GameBufferComponent>(); // 设置士兵的监视范围(寻找目标用) REMARK:设定为4.0秒可以移动的范围 tileEntity.monitorRange = Mathf.Clamp(model.speed * 4.0f, 5.0f, 20.0f); if (EntityTypeUtil.IsBombMan(model)) { tileEntity.monitorRange = 0.0f; // 暂时不限制炸弹人 tileEntity.AddComponent <BombManComponent>(); } else if (EntityTypeUtil.IsCurer(model)) { tileEntity.AddComponent <CurerComponent>(); } else if (isFriendly) // 友军/援军 { tileEntity.AddComponent <FriendComponent>(); } else { tileEntity.AddComponent <ActorComponent>(); } // 除【友军/援军】以外添加拆墙组件(REMARK:友军/援军不可拆墙) if (!isFriendly) { tileEntity.AddComponent <ActorDestroyWallComponent>(); } } } else if (EntityTypeUtil.IsAnyTrap(model)) // [陷阱类] { tileEntity.AddComponent <TrapComponent>(); } Assert.Should((tileEntity.blockingRange == 0 || (tileEntity.blockingRange % 2) == 1), "invalid blockingRange..."); Assert.Should(tileEntity.blockingRange <= tileEntity.width - 1 && tileEntity.blockingRange <= tileEntity.height - 1, "invalid blockingRange..."); return(tileEntity); }
public void Start() { IsoHelper.FaceToWorldCamera(transform); IsoHelper.MoveAlongCamera(transform, zOrder); }