예제 #1
0
        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);
            }
        }
예제 #2
0
 /// <summary>
 /// Handle scoring when block is clicked
 /// </summary>
 public void AddScore()
 {
     Score++;
     using (FText text = FText.FromString("Score: " + Score))
     {
         // NOTE:
         // ScoreText.SetText() calls UActorComponent::MarkRenderStateDirty() which updates the actual render of the text.
         // If ScoreText.Text=text; was used the text may not visually change
         ScoreText.SetText(text);
     }
 }
예제 #3
0
        public void Deserialize(FArchive reader)
        {
            if (reader.Version >= UE4Version.VER_UE4_K2NODE_VAR_REFERENCEGUIDS)
            {
                reader.Read(out FString _arg);
                _argumentName = FText.FromString(_arg);
            }
            else
            {
                reader.Read(out _argumentName);
            }

            reader.Read(out _argumentValue);
        }