public override void Initialize(FObjectInitializer initializer) { base.Initialize(initializer); RootComponent = initializer.CreateDefaultSubobject <USceneComponent>(this, new FName("DummyRoot")); ScoreText = initializer.CreateDefaultSubobject <UTextRenderComponent>(this, new FName("ScoreText")); ScoreText.RelativeLocation = new FVector(320, 60, 0); ScoreText.RelativeRotation = new FRotator(90, 0, 0); ScoreText.RelativeScale3D = new FVector(4, 4, 4); ScoreText.AttachToComponent(RootComponent, FName.None, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, false); // Care needs to be taken when dealing with FText. In C++ FText lifetime is automatically managed via shared pointers. // Any FText which has a lifetime maintained by C# (FText.OwnsReference==true) needs to be destroyed manually. This can be // done via by calling 'Dispose()', or in a 'using' statement. If neither is used, the finalizer will do the clean up when // the C# GC runs. using (FText text = FText.FromString("Score: 0")) { ScoreText.SetText(text); // - text needs to be disposed as the lifetime is maintained by C# // - ScoreText.Text doesn't need to be disposed as the lifetime is maintained by native code Debug.Assert(text.OwnsReference && !ScoreText.Text.OwnsReference); } }
public override void Initialize(FObjectInitializer initializer) { base.Initialize(initializer); UCharacterMovementComponent characterMovement = CharacterMovement; UCapsuleComponent capsuleComponent = CapsuleComponent; // Use only Yaw from the controller and ignore the rest of the rotation. UseControllerRotationPitch = false; UseControllerRotationYaw = true; UseControllerRotationRoll = false; // Set the size of our collision capsule. capsuleComponent.SetCapsuleHalfHeight(96.0f); capsuleComponent.SetCapsuleRadius(40.0f); // Create a camera boom attached to the root (capsule) CameraBoom = initializer.CreateDefaultSubobject <USpringArmComponent>(this, (FName)"CameraBoom"); CameraBoom.SetupAttachment(RootComponent); CameraBoom.TargetArmLength = 500.0f; CameraBoom.SocketOffset = new FVector(0.0f, 0.0f, 75.0f); CameraBoom.AbsoluteRotation = true; CameraBoom.DoCollisionTest = false; CameraBoom.RelativeRotation = new FRotator(0.0f, -90.0f, 0.0f); // Create an orthographic camera (no perspective) and attach it to the boom SideViewCameraComponent = initializer.CreateDefaultSubobject <UCameraComponent>(this, (FName)"SideViewCamera"); SideViewCameraComponent.ProjectionMode = ECameraProjectionMode.Orthographic; SideViewCameraComponent.OrthoWidth = 2048.0f; SideViewCameraComponent.SetupAttachment(CameraBoom, USpringArmComponent.SocketName); // Prevent all automatic rotation behavior on the camera, character, and camera component CameraBoom.AbsoluteRotation = true; SideViewCameraComponent.UsePawnControlRotation = false; SideViewCameraComponent.AutoActivate = true; characterMovement.OrientRotationToMovement = false; // Configure character movement characterMovement.GravityScale = 2.0f; characterMovement.AirControl = 0.80f; characterMovement.JumpZVelocity = 1000.0f; characterMovement.GroundFriction = 3.0f; characterMovement.MaxWalkSpeed = 600.0f; characterMovement.MaxFlySpeed = 600.0f; // Lock character motion onto the XZ plane, so the character can't move in or out of the screen characterMovement.ConstrainToPlane = true; characterMovement.SetPlaneConstraintNormal(new FVector(0.0f, -1.0f, 0.0f)); // Behave like a traditional 2D platformer character, with a flat bottom instead of a curved capsule bottom // Note: This can cause a little floating when going up inclines; you can choose the tradeoff between better // behavior on the edge of a ledge versus inclines by setting this to true or false characterMovement.UseFlatBaseForFloorChecks = true; // Enable replication on the Sprite component so animations show up when networked Sprite.SetIsReplicated(true); Replicates = true; }
public override void Initialize(FObjectInitializer initializer) { base.Initialize(initializer); if (baseMaterial.Value == null) { baseMaterial.Value = ConstructorHelpers.FObjectFinder <UMaterialInterface> .Find("Material'/Game/Puzzle/Meshes/BaseMaterial.BaseMaterial'"); } if (blueMaterial.Value == null) { blueMaterial.Value = ConstructorHelpers.FObjectFinder <UMaterialInterface> .Find("MaterialInstanceConstant'/Game/Puzzle/Meshes/BlueMaterial.BlueMaterial'"); } if (orangeMaterial.Value == null) { orangeMaterial.Value = ConstructorHelpers.FObjectFinder <UMaterialInterface> .Find("MaterialInstanceConstant'/Game/Puzzle/Meshes/OrangeMaterial.OrangeMaterial'"); } UStaticMesh mesh = ConstructorHelpers.FObjectFinder <UStaticMesh> .Find("StaticMesh'/Game/Puzzle/Meshes/PuzzleCube.PuzzleCube'"); if (mesh != null) { BlockMesh = initializer.CreateDefaultSubobject <UStaticMeshComponent>(this, new FName("BlockMesh")); BlockMesh.SetStaticMesh(mesh); BlockMesh.RelativeLocation = new FVector(0, 0, 25); BlockMesh.RelativeScale3D = new FVector(1, 1, 0.25f); RootComponent = BlockMesh; if (blueMaterial.Value != null) { BlockMesh.SetMaterial(0, blueMaterial.Value); } } }
public override void Initialize(FObjectInitializer initializer) { base.Initialize(initializer); VrCamera = initializer.CreateDefaultSubobject <UCameraComponent>(this, new FName("VR_Camera")); VrCamera.RelativeLocation = new FVector(-100, 0, 270); VrCamera.AutoActivate = false; VrCamera.AttachToComponent(CapsuleComponent, FName.None, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, false); FpCamera = initializer.CreateDefaultSubobject <UCameraComponent>(this, new FName("FP_Camera")); FpCamera.RelativeLocation = new FVector(600, 0, 230); FpCamera.RelativeRotation = new FRotator(-89.9000015f, -1.5f, 1.5f); FpCamera.AutoActivate = false; FpCamera.AttachToComponent(CapsuleComponent, FName.None, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, EAttachmentRule.KeepRelative, false); CharacterMovement.GravityScale = 0; UseControllerRotationYaw = false; // Enable tick FTickFunction tickFunction = PrimaryActorTick; tickFunction.StartWithTickEnabled = true; tickFunction.CanEverTick = true; }