예제 #1
0
        public void CloneTriggerWithLocalStateIsCopied(string triggerResRef)
        {
            Location  startLocation = NwModule.Instance.StartingLocation;
            NwTrigger?trigger       = NwTrigger.Create(triggerResRef, startLocation);

            Assert.That(trigger, Is.Not.Null, $"Trigger {triggerResRef} was null after creation.");
            Assert.That(trigger !.IsValid, Is.True, $"Trigger {triggerResRef} was invalid after creation.");

            createdTestObjects.Add(trigger);

            LocalVariableInt testVar = trigger.GetObjectVariable <LocalVariableInt>("test");

            testVar.Value = 9999;

            NwTrigger clone = trigger.Clone(startLocation);

            Assert.That(clone, Is.Not.Null, $"Trigger {triggerResRef} was null after clone.");
            Assert.That(clone.IsValid, Is.True, $"Trigger {triggerResRef} was invalid after clone.");

            createdTestObjects.Add(clone);

            LocalVariableInt cloneTestVar = clone.GetObjectVariable <LocalVariableInt>("test");

            Assert.That(cloneTestVar.HasValue, Is.True, "Local variable did not exist on the clone with copyLocalState = true.");
            Assert.That(cloneTestVar.Value, Is.EqualTo(testVar.Value), "Local variable on the cloned trigger did not match the value of the original trigger.");
        }
예제 #2
0
        public void CreateTriggerIsCreated(string triggerResRef)
        {
            Location  startLocation = NwModule.Instance.StartingLocation;
            NwTrigger?trigger       = NwTrigger.Create(triggerResRef, startLocation);

            Assert.That(trigger, Is.Not.Null, $"Trigger {triggerResRef} was null after creation.");
            Assert.That(trigger !.IsValid, Is.True, $"Trigger {triggerResRef} was invalid after creation.");

            createdTestObjects.Add(trigger);
        }
예제 #3
0
        public void CloneTriggerWithoutTagOriginalTagIsCopied(string triggerResRef)
        {
            Location  startLocation = NwModule.Instance.StartingLocation;
            NwTrigger?trigger       = NwTrigger.Create(triggerResRef, startLocation);

            Assert.That(trigger, Is.Not.Null, $"Trigger {triggerResRef} was null after creation.");
            Assert.That(trigger !.IsValid, Is.True, $"Trigger {triggerResRef} was invalid after creation.");

            createdTestObjects.Add(trigger);
            trigger.Tag = "expectedNewTag";

            NwTrigger clone = trigger.Clone(startLocation, null, false);

            Assert.That(clone, Is.Not.Null, $"Trigger {triggerResRef} was null after clone.");
            Assert.That(clone.IsValid, Is.True, $"Trigger {triggerResRef} was invalid after clone.");

            createdTestObjects.Add(clone);

            Assert.That(clone.Tag, Is.EqualTo(trigger.Tag), "Cloned trigger's tag did not match the original trigger's.");
        }
예제 #4
0
        public void CloneTriggerCustomTagIsApplied(string triggerResRef)
        {
            Location  startLocation = NwModule.Instance.StartingLocation;
            NwTrigger?trigger       = NwTrigger.Create(triggerResRef, startLocation);

            Assert.That(trigger, Is.Not.Null, $"Trigger {triggerResRef} was null after creation.");
            Assert.That(trigger !.IsValid, Is.True, $"Trigger {triggerResRef} was invalid after creation.");

            createdTestObjects.Add(trigger);

            string    expectedNewTag = "expectedNewTag";
            NwTrigger clone          = trigger.Clone(startLocation, expectedNewTag, false);

            Assert.That(clone, Is.Not.Null, $"Trigger {triggerResRef} was null after clone.");
            Assert.That(clone.IsValid, Is.True, $"Trigger {triggerResRef} was invalid after clone.");

            createdTestObjects.Add(clone);

            Assert.That(clone.Tag, Is.EqualTo(expectedNewTag), "Tag defined in clone method was not applied to the cloned trigger.");
        }
예제 #5
0
        public void SerializeTriggerCreatesValidData(string triggerResRef)
        {
            Location  startLocation = NwModule.Instance.StartingLocation;
            NwTrigger?trigger       = NwTrigger.Create(triggerResRef, startLocation);

            Assert.That(trigger, Is.Not.Null, $"Trigger {triggerResRef} was null after creation.");
            Assert.That(trigger !.IsValid, Is.True, $"Trigger {triggerResRef} was invalid after creation.");

            createdTestObjects.Add(trigger);

            byte[]? triggerData = trigger.Serialize();

            Assert.That(triggerData, Is.Not.Null);
            Assert.That(triggerData, Has.Length.GreaterThan(0));

            NwTrigger?trigger2 = NwTrigger.Deserialize(triggerData !);

            Assert.That(trigger2, Is.Not.Null);
            Assert.That(trigger2 !.IsValid, Is.True);

            createdTestObjects.Add(trigger2);

            Assert.That(trigger2.Area, Is.Null);
        }
            public static void Signal(NwTrigger trigger, int eventId)
            {
                Event nwEvent = NWScript.EventUserDefined(eventId) !;

                NWScript.SignalEvent(trigger, nwEvent);
            }
예제 #7
0
    public TriggerHandlerService(NativeEventService eventService)
    {
        NwTrigger trigger = NwObject.FindObjectsWithTag <NwTrigger>("mytrigger").FirstOrDefault();

        eventService.Subscribe <NwTrigger, TriggerEvents.OnEnter>(trigger, OnTriggerEnter);
    }