public void Update(int filterIndex, Selection selection, float deltaTime) { switch (filterIndex) { case 0: isNewFrame = selection.First().GetComp <C_FrameIndex>().newFrame; break; case 1: if (!isNewFrame) { return; } guiActions.Clear(); foreach (var e in selection) { C_MonsterHp hp = e.GetComp <C_MonsterHp>(); Vector2 screen = IMGUIDrawer.Instance.GetUnitScreenPosForIMGUI(e); Rect rect = new Rect(screen, new Vector2(400, 400)); string text = $"{hp.rest}/{hp.max}"; guiActions.Add(() => { GUI.Label(rect, text, new GUIStyle(GUI.skin.label) { fontSize = 20 }); }); } break; } }
private void OnDamage(Entity target, int damage, C_MonsterHp hp, Context context) { hp.rest -= damage; if (hp.rest == 0) { C_MonsterBonus bonus = target.GetComp <C_MonsterBonus>(); int value = bonus != null ? bonus.value : 0; if (context.Remove(target.id)) { var player = context.SelectOne <C_PlayerProperties>().GetComp <C_PlayerProperties>(); player.coins += value; } } }
public void Update(int filterIndex, Selection selection, float deltaTime) { foreach (var s in selection) { Entity target = s.GetComp <C_Target>().TargetAsEntity(selection.context); if (!Entity.IsNullOrInvalid(target)) { C_MonsterHp hp = target.GetComp <C_MonsterHp>(); //Debug.LogError($" 子弹{s.id} 击中 敌人{target.id}!"); OnDamage(target, 1, hp, selection.context); } selection.context.Remove(s.id); } }
public void Setup(Entity e, Context context) { e.AddComp <C_IdentifyMonster>(); C_Position position = e.AddComp <C_Position>(); Entity e1 = context.SelectOne <C_LevelData>(); LinkedListNode <LevelEntry.TileData> first = e1.GetComp <C_LevelData>().paths.First; position.position = first.Value.position; e.AddComp <C_Rotation>(); MonsterEntry monsterEntry = e.GetComp <C_MonsterConfig>().cfg; C_MonsterFindPath monsterFindPath = e.AddComp <C_MonsterFindPath>(); monsterFindPath.target = first; monsterFindPath.rotating = 0; e.AddComp <C_TargetPos>(); e.AddComp <C_MoveToPos>().speed = monsterEntry.speed / 100f; e.AddComp <C_MoveStart>(); C_MonsterHp hp = e.AddComp <C_MonsterHp>(); int h = monsterEntry.hp / 100; hp.max = h; hp.rest = h; C_Asset asset = e.AddComp <C_Asset>(); asset.mesh = "Mesh/MonsterTest"; // monsterEntry.asset; asset.material = "Materials/Red"; e.AddComp <C_Renderer>(); }