public static unsafe IEnumerable <EventNodeData> GetEventsFromApi(
            VisualScriptingEventSystem eventSystem,
            IReadOnlyDictionary <ulong, List <FieldDescription> > fieldDescriptions)
        {
            using (var events = new NativeList <VisualScriptingEventData>(Allocator.TempJob))
            {
                new CollectDispatchedEventsJob {
                    Events = events
                }.Schedule(eventSystem).Complete();
                var data = new List <EventNodeData>();

                foreach (var evt in events)
                {
                    var values = new List <Value>();
                    if (fieldDescriptions.TryGetValue(evt.EventTypeHash, out var descriptions))
                    {
                        foreach (var description in descriptions)
                        {
                            var fieldPtr = (byte *)evt.EventPtr.ToPointer() + description.Offset;
                            if (description.FieldValueType == ValueType.StringReference)
                            {
                                var stringRefIndex = EventDataBridge.NativeStrings128.Count;
                                EventDataBridge.NativeStrings128.Add(*(NativeString128 *)fieldPtr);
                                values.Add(new StringReference(stringRefIndex, StringReference.Storage.Unmanaged128));
                                continue;
                            }
                            values.Add(Value.FromPtr(fieldPtr, description.FieldValueType));
                        }
                    }
                    data.Add(new EventNodeData(evt.EventTypeHash, values));
                }

                return(data);
            }
        }
Beispiel #2
0
        protected override void OnCreate()
        {
            m_Contexts           = new Dictionary <Entity, GraphInstance>();
            m_UninitializedQuery = GetEntityQuery(typeof(ScriptingGraph), ComponentType.Exclude <ScriptingGraphInstance>());
            m_Query = GetEntityQuery(typeof(ScriptingGraphInstance));
            var beingDestroyedQuery = GetEntityQuery(typeof(ScriptingGraphInstance), ComponentType.Exclude <ScriptingGraphInstanceAlive>());

            m_BeingDestroyedQueryMask = EntityManager.GetEntityQueryMask(beingDestroyedQuery);
            m_OutputTriggersPerEntityGraphActivated  = new NativeMultiHashMap <Entity, uint>(100, Allocator.Persistent);
            m_OutputTriggersPerEntityGraphActivated2 = new NativeMultiHashMap <Entity, uint>(100, Allocator.Persistent);
            m_InputTriggersPerEntityGraphActivated   = new NativeHashMap <Entity, uint>(100, Allocator.Persistent);
            m_EventSystem            = World.GetOrCreateSystem <VisualScriptingEventSystem>();
            m_EventFieldDescriptions = new Dictionary <ulong, List <FieldDescription> >();

#if VS_DOTS_PHYSICS_EXISTS
            // TODO A FULL HUNDRED
            m_TriggerData   = new NativeMultiHashMap <Entity, VisualScriptingPhysics.CollisionTriggerData>(100, Allocator.Persistent);
            m_CollisionData = new NativeMultiHashMap <Entity, VisualScriptingPhysics.CollisionTriggerData>(100, Allocator.Persistent);
#endif
        }
Beispiel #3
0
        internal static unsafe JobHandle Schedule <T>(
            this T job,
            VisualScriptingEventSystem eventSystem,
            JobHandle inputDeps = default)
            where T : struct, IVisualScriptingEventPtrReceiverJob
        {
            var data = new EventPtrReceiverJobData <T>
            {
                UserJob   = job,
                EventData = eventSystem.Events
            };

            var handle     = eventSystem.AddJobHandleForProducer(inputDeps);
            var parameters = new JobsUtility.JobScheduleParameters(
                UnsafeUtility.AddressOf(ref data),
                ExecuteUserEventPtrReceiverJobs <T> .Initialize(),
                handle,
                ScheduleMode.Batched);

            return(JobsUtility.Schedule(ref parameters));
        }