jjzjj

UEC++常用代码

无情的阅读机器 2023-04-10 原文

1.组件

1)静态网格体

UPROPERTY() 
class UStaticMeshComponent* Mesh;
//源文件
#include "Components/StaticMeshComponent.h"
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));

2)粒子组件

UPROPERTY()
class UParticleSystemComponent* MyParticle;
//源文件
#include "Particles/ParticleSystemComponent.h"
MyParticle = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MyParticle"));

3)音频组件

UPROPERTY()
class UAudioComponent* MyAudio;
//源文件
#include "Components/AudioComponent.h"
MyAudio = CreateDefaultSubobject<UAudioComponent>(TEXT("MyAudio"));

 4)碰撞盒子组件

UPROPERTY()
class UBoxComponent* MyBox;
//源文件
#include "Components/BoxComponent.h"
MyBox = CreateDefaultSubobject<UBoxComponent>(TEXT("MyBox"));
MyBox->SetBoxExtent(FVector(1000.0f, 1000.0f, 100.0f));

5)球形碰撞

UPROPERTY()
USphereComponent* CollisionComponent;
//源文件
#include "Components/SphereComponent.h"
// 用球体进行简单的碰撞展示。
CollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
// 设置球体的碰撞半径。
CollisionComponent->InitSphereRadius(15.0f);

 6)发射物移动组件

// 发射物移动组件。
UPROPERTY(VisibleAnywhere, Category = Movement)
UProjectileMovementComponent* ProjectileMovementComponent;
//源文件
#include "GameFramework/ProjectileMovementComponent.h"
 // 使用此组件驱动发射物的移动。
    ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
    //更新组件(参数)的位置,通常是更新actor根组件的位置
    ProjectileMovementComponent->SetUpdatedComponent(CollisionComponent);
    //发射物初始速度
    ProjectileMovementComponent->InitialSpeed = 3000.0f;
    //发射物最高速度
    ProjectileMovementComponent->MaxSpeed = 3000.0f;
    //发射物的选择在每一帧进行更新
    ProjectileMovementComponent->bRotationFollowsVelocity = true;
    //设置反弹
    ProjectileMovementComponent->bShouldBounce = true;
    //反弹系数
    ProjectileMovementComponent->Bounciness = 0.3f;
    //发射物重量
    ProjectileMovementComponent->ProjectileGravityScale = 0.0f;

7)弹簧臂

UPROPERTY()
class USpringArmComponent* SpringArmComp;
//源文件
#include "GameFramework/SpringArmComponent.h"
SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));


//为SpringArm类的变量赋值。
SpringArmComp->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, 50.0f), FRotator(-60.0f, 0.0f, 0.0f));
SpringArmComp->TargetArmLength = 400.f;
SpringArmComp->bEnableCameraLag = true;
SpringArmComp->CameraLagSpeed = 3.0f

8)1.相机组件

UPROPERTY()
class UCameraComponent* CameraComp;
//源文件
 #include "Camera/CameraComponent.h"
CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
CameraComp->SetupAttachment(SpringArmComp,USpringArmComponent::SocketName);

2.修改相机视野大小

// Called every frame
void ASCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	//目标视角面积
	float TargetFov = bWantToZoom ? ZoomedFOV : DefaultsFOV;
	//当前视野面积:当前视野,目标视野,帧数,速度
	float NewFOV = FMath::FInterpTo(CameraComp->FieldOfView, TargetFov, DeltaTime, ZoomInterpSpeed);
	//设置摄像机当前的视角面积
	CameraComp->SetFieldOfView(NewFOV);

}

 9) 推力组件

UPROPERTY()
class UPhysicsThrusterComponent* UpThruster;
//源文件
#include "PhysicsEngine/PhysicsThrusterComponent.h"
#include "Kismet/KismetMathLibrary.h"
UpThruster = CreateDefaultSubobject<UPhysicsThrusterComponent>(TEXT("UpThruster"));
	UpThruster->SetupAttachment(RootComponent);
	UpThruster->ThrustStrength =  980.0f;
	UpThruster->SetAutoActivate(true);
	//x轴指向无人机下方
	UpThruster->SetWorldRotation(UKismetMathLibrary::MakeRotFromX(-this->GetActorUpVector()))

 10)根组件的设置

RootComponent = Mesh

11)绑定根组件和插槽

Paddle1->SetupAttachment(Mesh)

Paddle1->SetupAttachment(Mesh, TEXT("Paddle1"));

12)得到胶囊体

#include "Components/CapsuleComponent.h"
GetCapsuleComponent()

13)移动组件

#include "GameFrameWork/CharacterMovementComponent.h"

//设置最大行走速度
GetCharacterMovement()->MaxWalkSpeed = 300;

14)骨骼网格组件

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
class USkeletalMeshComponent * MeshComponent;

#include "Components/SkeletalMeshComponent.h"

MeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("MeshComponent"));

15)辐射力组件

//辐射力组件
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
	class URadialForceComponent * RadialForceComp;

#include "PhysicsEngine/RadialForceComponent.h"
//构造函数
RadialForceComp = CreateDefaultSubobject<URadialForceComponent>(TEXT("RadialForceComp"));
RadialForceComp->bImpulseVelChange = true;
RadialForceComp->bIgnoreOwningActor = true;
RadialForceComp->bAutoActivate = false;
RadialForceComp->SetupAttachment(RootComponent);


//其他函数里面

//范围力起作用
RadialForceComp->FireImpulse();

2.特效

1)在某个位置生成粒子特效

UPROPERTY()
UParticleSystem * Emitter_Projectile;
//源文件
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), Emitter_Projectile, this->GetTransform());


//项目中又遇到了一次
//生成特效在命中点
//ImpactEffect:特效 ImpactPoint:打击点 Rotation():打击方向
if (ImpactEffect)
{
   UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactEffect, Hit.ImpactPoint, Hit.ImpactNormal.Rotation());
}

 2-1)生成声音base

//发射声音
UPROPERTY(EditAnywhere)
class USoundBase * FireSound;
//源文件
#include "Kismet/GamePlayStatics.h"
UGameplayStatics::PlaySoundAtLocation(this, FireSound, this->GetActorLocation(), 2.0f);

 2-2)生成声音 cue

	//自爆警告声音特效
	UPROPERTY(EditDefaultsOnly, Category = "TracerBot")
	class USoundCue * SelfDestructSound;

	//爆炸特效
	UPROPERTY(EditDefaultsOnly, Category = "TracerBot")
	class USoundCue * ExploedSound;


    #include "Sound/SoundCue.h"

	//发生爆炸声,在actor的位置
	UGameplayStatics::PlaySoundAtLocation(this, ExploedSound, GetActorLocation());

	//将自爆警告声音绑定到根组件
	UGameplayStatics::SpawnSoundAttached(SelfDestructSound, RootComponent);

3)在组件槽点生成粒子特效

if (MuzzleEffect)
{
  //粒子特效,组件,组件的socket
  UGameplayStatics::SpawnEmitterAttached(MuzzleEffect, MeshComponent, MuzzleSocketName);
}

 

3.输入

1)限制组件类型

UPROPERTY()
TSubclassOf<AFloatingActor> floatingActor;//AFloatingActor是一个类型,这是一个例子

2)character前后左右移动 

void MoveX(float value);
void MoveY(float value);

//定义
void APacdotPlayer::MoveX(float value)
{
    //Vlocity是FVector类型
	Vlocity.X = value;
	Vlocity.Y = 0;

	//character自带的函数,我们把向量喂给他就可以了
	AddMovementInput(Vlocity);
}

void APacdotPlayer::MoveY(float value)
{
	Vlocity.X = 0;
	Vlocity.Y = value;
	AddMovementInput(Vlocity);
}

//绑定函数
void APacdotPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
	PlayerInputComponent->BindAxis("MoveX", this, &APacdotPlayer::MoveX);
	PlayerInputComponent->BindAxis("MoveY", this, &APacdotPlayer::MoveY);
}

4.输出

1)float转string并打印


#include "Kismet/KismetSystemLibrary.h"
FString::SanitizeFloat(UpThruster->ThrustStrength);
UKismetSystemLibrary::PrintString(this,FString::SanitizeFloat(UpThruster->ThrustStrength));

2)生成Actor

//发射物种类
UPROPERTY(EditAnywhere)
TSubclassOf<class AMissle> Bullet;
//源文件
FTransform firepoint = Mesh->GetSocketTransform(TEXT("Fire"));
GetWorld()->SpawnActor<AMissle>(Bullet, firepoint);



//另一个项目
//生成参数
FActorSpawnParameters SpawnParams;
//参数设置
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
//抛射物对象,生成位置,方向,生成参数
GetWorld()->SpawnActor<AActor>(ProjectileClass, MuzzleLocation, EyeRotator, SpawnParams);

生成actor并绑定到骨骼组件的插槽上

#include "Engine/World.h"
#include "SWeapen.h"
#include "Components/SkeletalMeshComponent.h"	
//设置生成参数,当生成的actor碰到了其他物体,也要生成
	FActorSpawnParameters Parameters;
	Parameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
	//生成武器actor(类型、位置、方向、参数),并且其地址赋予到指针上
	CurrentWeapen = GetWorld()->SpawnActor<ASWeapen>(StartWeapen, FVector::ZeroVector, FRotator::ZeroRotator, Parameters);
	//设置武器的位置与骨骼的插槽中,并设置主人
	if (CurrentWeapen)
	{
		CurrentWeapen->SetOwner(this);
		CurrentWeapen->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale,WeaponAttachSoketName);
	}

5.工具

1)timer定时器

//添加一个句柄
FTimerHandle SpwanTimerHandle;

#include "Engine/public/TimerManager.h"
 
//要调用的函数
UFUNCTION()
void SpwanHandler();
//源文件
void AEnemySpawner::BeginPlay()
{
	Super::BeginPlay();
	GetWorld()->GetTimerManager().SetTimer(SpwanTimerHandle,this,&AEnemySpawner::SpwanHandler,2.0f,true);
	
}
//还有一种写法
GetWorldTimerManager().SetTimer(VulnerableTimerHandle, this, &APacdotEnermy::SetNormal, Time ,false);
//根据句柄得到对应计时器剩余时间
GetWorldTimerManager().GetTimerRemaining((*Iter)->VulnerableTimerHandle);
//清除对应计时器
GetWorldTimerManager().ClearTimer(VulnerableTimerHandle);

2)添加日志消息


#include "Engine/Engine.h"
check(GEngine != nullptr);
 
  // 显示调试消息五秒。 
  // 参数中的-1"键"值类型参数能防止该消息被更新或刷新。
//游戏启动时,StartPlay()将在屏幕上打印一条新的调试消息
//("Hello World, this is FPSGameModeBase!"),采用黄色文本,显示五秒钟。
  GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Hello World, this is FPSGameMode!"));

3)向量

private:
	FVector Vlocity;

//构造函数里这个向量一定是要初始化的

Vlocity = FVector(0, 0, 0);

4)重启关卡

GetWorld()->GetFirstLocalPlayerFromController()->ConsoleCommand(TEXT("RestartLevel"));

5)弹道,碰到物体会返回对应的actor

        #include "Engine/World.h"

        //位置
		FVector EyeLocation;
		//方向
		FRotator EyeRotator;
		//得到眼睛的位置和角度
		MyOwner->GetActorEyesViewPoint(EyeLocation,EyeRotator);
		//弹道的终点就是起点+方向*10000
		FVector TraceEnd = EyeLocation + (EyeRotator.Vector() * 1000);
		//设置碰撞通道为可见性通道
		FCollisionQueryParams  QueryParams;
		//让射线忽略玩家和枪
		QueryParams.AddIgnoredActor(MyOwner);
		QueryParams.AddIgnoredActor(this);
		//符合追踪设为true,可以让射击更加精准
		QueryParams.bTraceComplex = true;
        //LineTraceSingleByChannel击中物体返回true
        GetWorld()->LineTraceSingleByChannel(Hit, EyeLocation, TraceEnd, ECC_Visibility, QueryParams)

6)debug弹道画线

#include "DrawDebugHelpers.h"

//方便debug
DrawDebugLine(GetWorld(), EyeLocation, TraceEnd, FColor::Red, false, 1, 0, 1);

7)造成点伤害

            //命中对象
			AActor * HitActor = Hit.GetActor();
			//造成点伤害ApplyPointDamage
			//参数分别为命中对象、基础伤害、射击方向、命中信息(命中句柄)、MyOwner->GetInstigatorController(暂时不了解)
			//this(射击者) 和伤害类型 
			UGameplayStatics::ApplyPointDamage(HitActor, 20, EyeRotator.Vector(), Hit,MyOwner->GetInstigatorController(),this, DamageType);

8)控制台变量

static int32 DebugWeaponDrawing = 0;
FAutoConsoleVariableRef CVARDebugWeaponDrawing(
	TEXT("COOP.DebugWeapons"),
	DebugWeaponDrawing,
	TEXT("Draw Debug Line For Weapons"),
	ECVF_Cheat

);

6.事件

1)重叠事件及其绑定

//OverlappedComponent:自身的重叠组件   OtherActor:重叠的对方  OtherComp:对方的组件
	UFUNCTION()
	void OverlapHanler(UPrimitiveComponent*  OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &  SweepResult);
//源文件
//启动overlap事件
Mesh->SetGenerateOverlapEvents(true);
//重叠事件与函数的绑定,this是自身,后面的是要绑定的函数
Mesh->OnComponentBeginOverlap.AddDynamic(this,&AMissle::OverlapHanler);

2)组件的函数绑定在owner的伤害事件 

void HandleTakeAnyDamage(AActor* DamagedActor, float Damage, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser);

//源文件
void USHealthComponent::HandleTakeAnyDamage(AActor * DamagedActor, float Damage, const UDamageType * DamageType, AController * InstigatedBy, AActor * DamageCauser)
{
	//当前生命值<=0,就不做任何处理
	if (Health <= 0)
	{
		return;
	}
	//承受伤害
	Health = FMath::Clamp(Health - Damage, 0.0f, DefaultHealth);
	
}

// Called when the game starts
void USHealthComponent::BeginPlay()
{
	Super::BeginPlay();

	Health = DefaultHealth;
	
	AActor * Owner = GetOwner();
	//将该函数绑定在角色的受伤事件上
	if (Owner)
	{
		Owner->OnTakeAnyDamage.AddDynamic(this, &USHealthComponent::HandleTakeAnyDamage);
	}
}

3)自定义扣血事件

DECLARE_DYNAMIC_MULTICAST_DELEGATE_SixParams(FOnHealthChangedSignature, USHealthComponent*, HealthComp, float, Health, float, HealthDelta, const class UDamageType*, DamageType, class AController*, InstigatedBy, AActor*, DamageCauser);

//自定义事件的变量
UPROPERTY( BlueprintAssignable, Category = "HealthComponent")
FOnHealthChangedSignature OnHealthChanged;

//源文件
void USHealthComponent::HandleTakeAnyDamage(AActor * DamagedActor, float Damage, const UDamageType * DamageType, AController * InstigatedBy, AActor * DamageCauser)
{
	//当前生命值<=0,就不做任何处理
	if (Health <= 0)
	{
		return;
	}
	//承受伤害
	Health = FMath::Clamp(Health - Damage, 0.0f, DefaultHealth);
	UE_LOG(LogTemp, Log, TEXT("Health :%s"), *FString::SanitizeFloat(Health));
	//自定义事件
	OnHealthChanged.Broadcast(this, Health, Damage, DamageType, InstigatedBy, DamageCauser);
}

4)脱离玩家控制

//让玩家控制器与玩家角色分离,并让角色消失(3s)
		DetachFromControllerPendingDestroy();
		SetLifeSpan(3.0f);

7.UPROPERTY

1.EditAnywhere

2.VisibleAnywhere

3.Category

4.BlueprintReadWrite

5.VisibleAnywhere

8.UFUNCTION

1.BlueprintCallable 

2.BlueprintImplementableEvent 

3.BlueprintNativeEvent 

9.迭代器

1.模板迭代器

	//利用迭代,查找场景中有多少食物
    //TActorIterator<APacdot>是类型,PacItr是对象名,(GetWorld())构造函数参数表
    //上述就是简单的创建一个对象的过程
    //我认为PacItr是指向指针的指针,指向APacdot类型的指针
	for (TActorIterator<APacdot> PacItr(GetWorld()); PacItr; ++PacItr)
	{
		PacdotNum++;
	}
	//利用迭代,找到所有敌人
	for (TActorIterator<APacdotEnermy> EneItr(GetWorld()); EneItr; ++EneItr)
	{
		Enermis.Add(Cast<APacdotEnermy>(*EneItr));
	}

2.Iter迭代器

//auto 自动声明对象类型
for (auto Iter(Enermis.CreateIterator()); Iter; ++Iter)
  {
	Cast<AEnermyController>((*Iter)->GetController())->GoToNewDestination();
  }

10.得到游戏模式

//	APacmanGameModeBase 是游戏模式类的子类
class APacmanGameModeBase * ModeBaseRef;


#include "PacmanGameModeBase.h"
ModeBaseRef = Cast< APacmanGameModeBase>(UGameplayStatics::GetGameMode(this));

11.网络

1)复制成员变量

	//目前玩家手中的武器
	UPROPERTY(Replicated)
	class ASWeapen * CurrentWeapen1;


	//用于网络同步的函数
	void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

void ASCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	//同步给所有的客户端和服务器
	DOREPLIFETIME(ASCharacter, CurrentWeapen1);
}

2)客户端向服务器端复制成员函数的执行内容

//让服务器端也执行开火
//Server服务器 Reliable一直连接 WithValidation 验证
UFUNCTION(Server, Reliable, WithValidation)
		void ServerFire();

//函数的实现
void ASWeapen::ServerFire_Implementation()
{
	Fire();
}

bool ASWeapen::ServerFire_Validate()
{
	return true;
}

//在其他函数中调用
//如果不是服务器,就执行ServerFire(),服务器端就有响应
void ASWeapen::Fire()
{
	if (Role < ROLE_Authority)
	{
		ServerFire();
		
	}
    .........

3)服务器端向客户端复制成员函数的执行内容

//要共享的内容
USTRUCT()
struct FHitScanTrace
{
	GENERATED_BODY()
public:
	//弹道的目的坐标
	UPROPERTY()
	FVector_NetQuantize TraceTo;
	//子弹数目:为了让该结构体内容发生变化,结构体才被不断得被网络复制
	UPROPERTY()
	uint8 BrustCounter;

};

	//网络射击信息 (当HitScanTrace发生改变,就会激活OnRep_HitScanTrace)
	UPROPERTY(ReplicatedUsing = OnRep_HitScanTrace)
	FHitScanTrace HitScanTrace;

	//网络复制函数
	UFUNCTION()
	void OnRep_HitScanTrace();

	//复制网络射击信息
	void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

//让客户端要做的事情
void ASWeapen::OnRep_HitScanTrace()
{
	//调用射击特效
	PlayFireEffects(HitScanTrace.TraceTo);
}

void ASWeapen::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	//同步给所有的客户端和服务器(DOREPLIFETIME_CONDITION不用同步给自己)
	DOREPLIFETIME_CONDITION(ASWeapen, HitScanTrace,COND_SkipOwner);
}

有关UEC++常用代码的更多相关文章

  1. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  2. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  3. ruby-on-rails - Rails 源代码 : initialize hash in a weird way? - 2

    在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has

  4. ruby-on-rails - 浏览 Ruby 源代码 - 2

    我的主要目标是能够完全理解我正在使用的库/gem。我尝试在Github上从头到尾阅读源代码,但这真的很难。我认为更有趣、更温和的踏脚石就是在使用时阅读每个库/gem方法的源代码。例如,我想知道RubyonRails中的redirect_to方法是如何工作的:如何查找redirect_to方法的源代码?我知道在pry中我可以执行类似show-methodmethod的操作,但我如何才能对Rails框架中的方法执行此操作?您对我如何更好地理解Gem及其API有什么建议吗?仅仅阅读源代码似乎真的很难,尤其是对于框架。谢谢! 最佳答案 Ru

  5. ruby - 模块嵌套代码风格偏好 - 2

    我的假设是moduleAmoduleBendend和moduleA::Bend是一样的。我能够从thisblog找到解决方案,thisSOthread和andthisSOthread.为什么以及什么时候应该更喜欢紧凑语法A::B而不是另一个,因为它显然有一个缺点?我有一种直觉,它可能与性能有关,因为在更多命名空间中查找常量需要更多计算。但是我无法通过对普通类进行基准测试来验证这一点。 最佳答案 这两种写作方法经常被混淆。首先要说的是,据我所知,没有可衡量的性能差异。(在下面的书面示例中不断查找)最明显的区别,可能也是最著名的,是你的

  6. ruby - 寻找通过阅读代码确定编程语言的ruby gem? - 2

    几个月前,我读了一篇关于ruby​​gem的博客文章,它可以通过阅读代码本身来确定编程语言。对于我的生活,我不记得博客或gem的名称。谷歌搜索“ruby编程语言猜测”及其变体也无济于事。有人碰巧知道相关gem的名称吗? 最佳答案 是这个吗:http://github.com/chrislo/sourceclassifier/tree/master 关于ruby-寻找通过阅读代码确定编程语言的rubygem?,我们在StackOverflow上找到一个类似的问题:

  7. ruby - Net::HTTP 获取源代码和状态 - 2

    我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur

  8. 程序员如何提高代码能力? - 2

    前言作为一名程序员,自己的本质工作就是做程序开发,那么程序开发的时候最直接的体现就是代码,检验一个程序员技术水平的一个核心环节就是开发时候的代码能力。众所周知,程序开发的水平提升是一个循序渐进的过程,每一位程序员都是从“菜鸟”变成“大神”的,所以程序员在程序开发过程中的代码能力也是根据平时开发中的业务实践来积累和提升的。提高代码能力核心要素程序员要想提高自身代码能力,尤其是新晋程序员的代码能力有很大的提升空间的时候,需要针对性的去提高自己的代码能力。提高代码能力其实有几个比较关键的点,只要把握住这些方面,就能很好的、快速的提高自己的一部分代码能力。1、多去阅读开源项目,如有机会可以亲自参与开源

  9. 7个大一C语言必学的程序 / C语言经典代码大全 - 2

    嗨~大家好,这里是可莉!今天给大家带来的是7个C语言的经典基础代码~那一起往下看下去把【程序一】打印100到200之间的素数#includeintmain(){ inti; for(i=100;i 【程序二】输出乘法口诀表#includeintmain(){inti;for(i=1;i 【程序三】判断1000年---2000年之间的闰年#includeintmain(){intyear;for(year=1000;year 【程序四】给定两个整形变量的值,将两个值的内容进行交换。这里提供两种方法来进行交换,第一种为创建临时变量来进行交换,第二种是不创建临时变量而直接进行交换。1.创建临时变量来

  10. git使用常见问题(提交代码,合并冲突) - 2

    文章目录git常用命令(简介,详细参数往下看)Git提交代码步骤gitpullgitstatusgitaddgitcommitgitpushgit代码冲突合并问题方法一:放弃本地代码方法二:合并代码常用命令以及详细参数gitadd将文件添加到仓库:gitdiff比较文件异同gitlog查看历史记录gitreset代码回滚版本库相关操作远程仓库相关操作分支相关操作创建分支查看分支:gitbranch合并分支:gitmerge删除分支:gitbranch-ddev查看分支合并图:gitlog–graph–pretty=oneline–abbrev-commit撤消某次提交git用户名密码相关配置g

随机推荐