Beispiel #1
0
        public static void OnBeginPlay()
        {
            Debug.AddOnScreenMessage(-1, 3.0f, Color.LightGreen, MethodBase.GetCurrentMethod().DeclaringType + " system started!");

            World.GetFirstPlayerController().SetViewTarget(World.GetActor <Camera>("MainCamera"));
            World.SetOnActorBeginOverlapCallback(OnActorBeginOverlap);
            World.SetOnActorEndOverlapCallback(OnActorEndOverlap);
            World.SetOnActorHitCallback(OnActorHit);
            World.SetOnComponentBeginOverlapCallback(OnComponentBeginOverlap);
            World.SetOnComponentEndOverlapCallback(OnComponentEndOverlap);
            World.SetOnComponentHitCallback(OnComponentHit);

            const float linesThickness = 3.0f;

            TriggerBox   triggerBox         = new TriggerBox();
            BoxComponent collisionComponent = triggerBox.GetComponent <BoxComponent>();
            Vector3      collisionLocation  = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3      collisionShape     = new Vector3(200.0f, 200.0f, 200.0f);

            collisionComponent.GetLocation(ref collisionLocation);
            collisionComponent.SetBoxExtent(collisionShape);

            Debug.DrawBox(collisionLocation, collisionShape, Quaternion.Identity, Color.Aqua, true, thickness: linesThickness);

            leftActor.RegisterEvent(ActorEventType.OnActorBeginOverlap);
            leftActor.RegisterEvent(ActorEventType.OnActorEndOverlap);
            leftActor.RegisterEvent(ActorEventType.OnActorHit);

            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentBeginOverlap);
            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentEndOverlap);
            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentHit);
            leftStaticMeshComponent.SetGenerateOverlapEvents(true);
            leftStaticMeshComponent.SetGenerateHitEvents(true);

            leftStaticMeshComponent.SetStaticMesh(StaticMesh.Cube);
            leftStaticMeshComponent.SetMaterial(0, material);
            leftStaticMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetVectorParameterValue("Color", LinearColor.Green);
            leftStaticMeshComponent.SetWorldLocation(new Vector3(0.0f, -startY, 0.0f));
            leftStaticMeshComponent.SetEnableGravity(false);
            leftStaticMeshComponent.SetSimulatePhysics(true);

            rightActor.RegisterEvent(ActorEventType.OnActorBeginOverlap);
            rightActor.RegisterEvent(ActorEventType.OnActorEndOverlap);
            rightActor.RegisterEvent(ActorEventType.OnActorHit);

            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentBeginOverlap);
            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentEndOverlap);
            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentHit);
            rightStaticMeshComponent.SetGenerateOverlapEvents(true);
            rightStaticMeshComponent.SetGenerateHitEvents(true);

            rightStaticMeshComponent.SetStaticMesh(StaticMesh.Cube);
            rightStaticMeshComponent.SetMaterial(0, material);
            rightStaticMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetVectorParameterValue("Color", LinearColor.Yellow);
            rightStaticMeshComponent.SetWorldLocation(new Vector3(0.0f, startY, 0.0f));
            rightStaticMeshComponent.SetEnableGravity(false);
            rightStaticMeshComponent.SetSimulatePhysics(true);
        }
        public void OnBeginPlay()
        {
            World.GetFirstPlayerController().SetViewTarget(World.GetActor <Camera>("MainCamera"));

            Actor actor = new Actor();
            StaticMeshComponent staticMeshComponent = new StaticMeshComponent(actor, setAsRoot: true);
            Texture2D           texture             = Texture2D.Load("/Game/Tests/BasicTexture");

            staticMeshComponent.SetStaticMesh(StaticMesh.Plane);
            staticMeshComponent.SetMaterial(0, Material.Load("/Game/Tests/TextureMaterial"));
            staticMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetTextureParameterValue("Texture", texture);
            staticMeshComponent.SetWorldLocation(new Vector3(-800.0f, 0.0f, 0.0f));
            staticMeshComponent.SetWorldRotation(Maths.Euler(90.0f, 0.0f, 90.0f));

            Debug.AddOnScreenMessage(-1, 5.0f, Color.PowderBlue, "Texture size: " + texture.GetSize());
            Debug.AddOnScreenMessage(-1, 5.0f, Color.PowderBlue, "Pixel format: " + texture.GetPixelFormat());
        }
Beispiel #3
0
        public static void OnBeginPlay()
        {
            Debug.AddOnScreenMessage(-1, 3.0f, Color.LightGreen, MethodBase.GetCurrentMethod().DeclaringType + " system started!");

            World.GetFirstPlayerController().SetViewTarget(World.GetActor <Camera>("MainCamera"));

            Actor actor = new Actor();
            StaticMeshComponent staticMeshComponent = new StaticMeshComponent(actor, setAsRoot: true);
            Texture2D           texture             = Texture2D.Load("/Game/Tests/BasicTexture");

            staticMeshComponent.SetStaticMesh(StaticMesh.Plane);
            staticMeshComponent.SetMaterial(0, Material.Load("/Game/Tests/TextureMaterial"));
            staticMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetTextureParameterValue("Texture", texture);
            staticMeshComponent.SetWorldLocation(new Vector3(-800.0f, 0.0f, 0.0f));
            staticMeshComponent.SetWorldRotation(Maths.Euler(90.0f, 0.0f, 90.0f));

            Vector2 textureSize = default(Vector2);

            texture.GetSize(ref textureSize);

            Debug.AddOnScreenMessage(-1, 5.0f, Color.PowderBlue, "Texture size: " + textureSize);
        }
        public void OnBeginPlay()
        {
            playerController.ShowMouseCursor       = true;
            playerController.EnableClickEvents     = true;
            playerController.EnableMouseOverEvents = true;
            playerController.SetViewTarget(World.GetActor <Camera>("MainCamera"));

            World.SetOnActorBeginOverlapCallback(OnActorBeginOverlap);
            World.SetOnActorEndOverlapCallback(OnActorEndOverlap);
            World.SetOnActorHitCallback(OnActorHit);
            World.SetOnActorBeginCursorOverCallback(OnActorBeginCursorOver);
            World.SetOnActorEndCursorOverCallback(OnActorEndCursorOver);
            World.SetOnActorClickedCallback(OnActorClicked);
            World.SetOnActorReleasedCallback(OnActorReleased);
            World.SetOnComponentBeginOverlapCallback(OnComponentBeginOverlap);
            World.SetOnComponentEndOverlapCallback(OnComponentEndOverlap);
            World.SetOnComponentHitCallback(OnComponentHit);
            World.SetOnComponentBeginCursorOverCallback(OnComponentBeginCursorOver);
            World.SetOnComponentEndCursorOverCallback(OnComponentEndCursorOver);
            World.SetOnComponentClickedCallback(OnComponentClicked);
            World.SetOnComponentReleasedCallback(OnComponentReleased);

            const float linesThickness = 3.0f;

            Vector3 collisionShape = new(200.0f, 200.0f, 200.0f);

            triggerCollisionComponent.SetBoxExtent(collisionShape);

            Debug.DrawBox(triggerCollisionComponent.GetLocation(), collisionShape, Quaternion.Identity, Color.Aqua, true, thickness: linesThickness);

            leftActor.RegisterEvent(ActorEventType.OnActorBeginOverlap);
            leftActor.RegisterEvent(ActorEventType.OnActorEndOverlap);
            leftActor.RegisterEvent(ActorEventType.OnActorHit);
            leftActor.RegisterEvent(ActorEventType.OnActorBeginCursorOver);
            leftActor.RegisterEvent(ActorEventType.OnActorEndCursorOver);
            leftActor.RegisterEvent(ActorEventType.OnActorClicked);
            leftActor.RegisterEvent(ActorEventType.OnActorReleased);

            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentBeginOverlap);
            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentEndOverlap);
            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentHit);
            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentBeginCursorOver);
            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentEndCursorOver);
            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentClicked);
            leftStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentReleased);
            leftStaticMeshComponent.SetGenerateOverlapEvents(true);
            leftStaticMeshComponent.SetGenerateHitEvents(true);

            leftStaticMeshComponent.SetStaticMesh(StaticMesh.Cube);
            leftStaticMeshComponent.SetMaterial(0, material);
            leftStaticMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetVectorParameterValue("Color", LinearColor.Green);
            leftStaticMeshComponent.SetWorldLocation(new(0.0f, -startY, 0.0f));
            leftStaticMeshComponent.UpdateToWorld(TeleportType.ResetPhysics);
            leftStaticMeshComponent.SetEnableGravity(false);
            leftStaticMeshComponent.SetSimulatePhysics(true);

            Assert.IsNotNull(leftStaticMeshComponent.GetMaterial(0));

            rightActor.RegisterEvent(ActorEventType.OnActorBeginOverlap);
            rightActor.RegisterEvent(ActorEventType.OnActorEndOverlap);
            rightActor.RegisterEvent(ActorEventType.OnActorHit);
            rightActor.RegisterEvent(ActorEventType.OnActorBeginCursorOver);
            rightActor.RegisterEvent(ActorEventType.OnActorEndCursorOver);
            rightActor.RegisterEvent(ActorEventType.OnActorClicked);
            rightActor.RegisterEvent(ActorEventType.OnActorReleased);

            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentBeginOverlap);
            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentEndOverlap);
            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentHit);
            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentBeginCursorOver);
            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentEndCursorOver);
            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentClicked);
            rightStaticMeshComponent.RegisterEvent(ComponentEventType.OnComponentReleased);
            rightStaticMeshComponent.SetGenerateOverlapEvents(true);
            rightStaticMeshComponent.SetGenerateHitEvents(true);

            rightStaticMeshComponent.SetStaticMesh(StaticMesh.Cube);
            rightStaticMeshComponent.SetMaterial(0, material);
            rightStaticMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetVectorParameterValue("Color", LinearColor.Yellow);
            rightStaticMeshComponent.SetWorldLocation(new(0.0f, startY, 0.0f));
            rightStaticMeshComponent.UpdateToWorld(TeleportType.ResetPhysics);
            rightStaticMeshComponent.SetEnableGravity(false);
            rightStaticMeshComponent.SetSimulatePhysics(true);

            Assert.IsNotNull(rightStaticMeshComponent.GetMaterial(0));
        }
        public static void OnBeginPlay()
        {
            Debug.AddOnScreenMessage(-1, 3.0f, Color.LightGreen, MethodBase.GetCurrentMethod().DeclaringType + " system started!");

            World.GetFirstPlayerController().SetViewTarget(World.GetActor <Camera>("MainCamera"));

            const float  linesThickness   = 3.0f;
            const string collisionProfile = "TestCollisionProfile";

            Actor box = new Actor("Box");
            StaticMeshComponent staticMeshComponent = new StaticMeshComponent(box, setAsRoot: true);
            Vector3             boxLocation         = new Vector3(0.0f, 500.0f, 0.0f);
            Vector3             boxScale            = new Vector3(1.0f, 1.0f, 1.0f);

            staticMeshComponent.SetWorldLocation(boxLocation);
            staticMeshComponent.SetWorldScale(boxScale);
            staticMeshComponent.SetStaticMesh(StaticMesh.Cube);
            staticMeshComponent.SetMaterial(0, Material.Load("/Game/Tests/BasicMaterial"));
            staticMeshComponent.CreateAndSetMaterialInstanceDynamic(0).SetVectorParameterValue("Color", new LinearColor(0.18f, 0.0f, 0.9f));
            staticMeshComponent.SetCollisionChannel(CollisionChannel.WorldStatic);
            staticMeshComponent.SetCollisionProfileName(collisionProfile);

            Debug.DrawBox(boxLocation, boxScale * 50.0f, Quaternion.Identity, Color.SlateBlue, true, thickness: linesThickness);

            Hit     hit            = default(Hit);
            Vector3 lineTraceStart = new Vector3(0.0f, 0.0f, 0.0f);

            bool hitTraceByChannel = World.LineTraceSingleByChannel(lineTraceStart, boxLocation, CollisionChannel.WorldStatic, ref hit);

            Assert.IsTrue(hitTraceByChannel);
            Assert.IsTrue(hit.BlockingHit);
            Assert.IsTrue(box.Equals(hit.GetActor()));

            if (hitTraceByChannel)
            {
                Debug.AddOnScreenMessage(-1, 15.0f, Color.DeepPink, "Box trace hit by channel!");
                Debug.DrawPoint(hit.TraceStart, 8.0f, Color.DeepPink, true, depthPriority: 3);
                Debug.DrawPoint(hit.TraceEnd, 8.0f, Color.DeepPink, true, depthPriority: 3);
                Debug.DrawLine(hit.TraceStart, hit.TraceEnd, Color.DeepPink, true, depthPriority: 3, thickness: linesThickness);
            }

            bool hitTraceByProfile = World.LineTraceSingleByProfile(lineTraceStart, boxLocation, collisionProfile, ref hit);

            Assert.IsTrue(hitTraceByProfile);
            Assert.IsTrue(hit.BlockingHit);

            if (hitTraceByProfile)
            {
                Debug.AddOnScreenMessage(-1, 15.0f, Color.DeepPink, "Box trace hit by profile!");
            }

            const float sphereRadius = 50.0f;

            CollisionShape sphereShape = CollisionShape.CreateSphere(sphereRadius);

            bool hitSweepByChannel = World.SweepSingleByChannel(lineTraceStart, boxLocation, Quaternion.Identity, CollisionChannel.WorldStatic, sphereShape, ref hit);

            Assert.IsTrue(hitSweepByChannel);
            Assert.IsTrue(hit.BlockingHit);

            if (hitSweepByChannel)
            {
                Debug.AddOnScreenMessage(-1, 15.0f, Color.Yellow, "Sphere sweep hit by channel!");
                Debug.DrawSphere(hit.Location, sphereRadius, 16, Color.Yellow, true, depthPriority: 2, thickness: linesThickness);
            }

            bool hitSweepByProfile = World.SweepSingleByProfile(lineTraceStart, boxLocation, Quaternion.Identity, collisionProfile, sphereShape, ref hit);

            Assert.IsTrue(hitSweepByProfile);
            Assert.IsTrue(hit.BlockingHit);

            if (hitSweepByProfile)
            {
                Debug.AddOnScreenMessage(-1, 15.0f, Color.Yellow, "Sphere sweep hit by profile!");
            }

            Vector3        overlapLocation = boxLocation - new Vector3(0.0f, 100.0f, 0.0f);
            Vector3        boxExtent       = boxScale * 60.0f;
            CollisionShape boxShape        = CollisionShape.CreateBox(boxExtent);

            bool overlapByChannel = World.OverlapAnyTestByChannel(overlapLocation, Quaternion.Identity, CollisionChannel.WorldStatic, boxShape);

            Assert.IsTrue(hitSweepByProfile);

            if (overlapByChannel)
            {
                Debug.AddOnScreenMessage(-1, 15.0f, Color.MediumTurquoise, "Box overlap by channel!");
                Debug.DrawBox(overlapLocation, boxExtent, Quaternion.Identity, Color.MediumTurquoise, true, thickness: linesThickness);
            }

            bool overlapByProfile = World.OverlapAnyTestByProfile(overlapLocation, Quaternion.Identity, collisionProfile, boxShape);

            Assert.IsTrue(hitSweepByProfile);

            if (overlapByProfile)
            {
                Debug.AddOnScreenMessage(-1, 15.0f, Color.MediumTurquoise, "Box overlap by profile!");
            }
        }