Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rhsExpr"></param>
        /// <returns></returns>
        private SteExpression BybassSingleTempVariableRhsExpr(SteExpression rhsExpr)
        {
            while (true)
            {
                //The RHS expression is not a variable name. Return the full expression
                if (rhsExpr.IsVariable == false)
                {
                    return(rhsExpr);
                }

                //The RHS expression is a variable name
                var rhsExprVarName = rhsExpr.HeadText;

                //The RHS expression is not a low-level variable name. Return the full expression
                if (LowLevelUtils.IsLowLevelVariableName(rhsExprVarName) == false)
                {
                    return(rhsExpr);
                }

                var llItem = _dataTable.GetItemByName(rhsExprVarName);

                //The RHS expression is not a temp item. Return the full expression
                if (llItem.IsTemp == false)
                {
                    return(rhsExpr);
                }

                //Iterate over the RHS of the temp low-level item whos name is given in rhsExprVarName
                rhsExpr = llItem.AssignedRhsSymbolicScalar.ToTextExpressionTree();
            }
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            GatherEvents(Allocator.TempJob, out var pointerEvents, out var keyboardEvents);
            var pointerFrameData = GatherPointerFrameData(Allocator.TempJob);

            NativeArray <Entity> roots    = m_RootGroup.ToEntityArray(Allocator.TempJob);
            var childrenFromEntity        = GetBufferFromEntity <UIChild>(true);
            var worldSpaceRectFromEntity  = GetComponentDataFromEntity <WorldSpaceRect>(true);
            var parentFromEntity          = GetComponentDataFromEntity <UIParent>(true);
            var pointerReceiverFromEntity = GetComponentDataFromEntity <PointerInputReceiver>(true);

            var stateComponentFromEntity = GetComponentDataFromEntity <InputSystemState>();
            var selectableFromEntity     = GetComponentDataFromEntity <Selectable>();
            var stateEntity = GetSingletonEntity <InputSystemState>();

            NativeArray <Entity> perCanvasHits =
                new NativeArray <Entity>(pointerFrameData.Length * roots.Length, Allocator.TempJob);
            NativeArray <Entity> globalHits = new NativeArray <Entity>(pointerFrameData.Length, Allocator.TempJob);

            LowLevelUtils.MemSet(perCanvasHits, default);
            LowLevelUtils.MemSet(globalHits, default);
            ProcessPerCanvasInput process = new ProcessPerCanvasInput()
            {
                Roots = roots,
                ChildrenFromEntity = childrenFromEntity,
                Hits = perCanvasHits,
                LocalToWorldFromEntity = worldSpaceRectFromEntity,
                PointerInputReceiver   = pointerReceiverFromEntity,
                PointersPosition       = pointerFrameData
            };

            inputDeps = process.Schedule(roots.Length, 1, inputDeps);
            var canvasLayerFromEntity = GetComponentDataFromEntity <CanvasSortLayer>();

            LowLevelUtils.MemSet(globalHits, default);
            CanvasHitsToGlobal canvasHits = new CanvasHitsToGlobal()
            {
                Roots = roots,
                CanvasLayerFromEntity = canvasLayerFromEntity,
                GlobalHits            = globalHits,
                PerCanvasHits         = perCanvasHits
            };

            inputDeps = canvasHits.Schedule(inputDeps);

            EntityCommandBuffer ecb = m_CommandBufferSystem.CreateCommandBuffer();
            UpdatePointerEvents updatePointerJob = new UpdatePointerEvents()
            {
                ButtonStates       = m_ButtonStates,
                EventArchetype     = m_PointerEventArchetype,
                StateEntity        = stateEntity,
                Hits               = globalHits,
                ReceiverFromEntity = pointerReceiverFromEntity,
                StateFromEntity    = stateComponentFromEntity,
                Manager            = ecb,
                PointerEvents      = pointerEvents,
                ParentFromEntity   = parentFromEntity,
                PointerFrameData   = pointerFrameData,
            };

            inputDeps = updatePointerJob.Schedule(inputDeps);
            inputDeps.Complete();

            if (keyboardEvents.Length > 0)
            {
                var selected = GetSingleton <InputSystemState>().SelectedEntity;
                if (selected != default)
                {
                    var eventEntity = EntityManager.CreateEntity(m_KeyboardEventArchetype);
                    var buff        = EntityManager.GetBuffer <KeyboardInputBuffer>(eventEntity);
                    EntityManager.SetComponentData(eventEntity, new KeyboardEvent()
                    {
                        Target = selected
                    });
                    for (int i = 0; i < keyboardEvents.Length; i++)
                    {
                        if (keyboardEvents[i].EventType == NativeInputEventType.KeyDown)
                        {
                            buff.Add(new KeyboardInputBuffer()
                            {
                                Character = keyboardEvents[i].Character,
                                EventType = keyboardEvents[i].KbdEvent,
                                KeyCode   = keyboardEvents[i].KeyCode
                            });
                        }
                    }
                }
            }
            keyboardEvents.Dispose();
            m_LastFrameMousePos = ((float3)UnityEngine.Input.mousePosition).xy;
            return(inputDeps);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            GatherEvents(Allocator.TempJob, out var pointerEvents, out var keyboardEvents);
            var pointerFrameData       = GatherPointerFrameData(Allocator.TempJob);
            NativeArray <Entity> roots = m_RootGroup.ToEntityArray(Allocator.TempJob, out var rootsDeps);

            inputDeps = JobHandle.CombineDependencies(inputDeps, rootsDeps);
            var profilerSample            = new ProfilerSample("PrepareBuffers");
            var childrenFromEntity        = GetBufferFromEntity <Child>(true);
            var worldSpaceRectFromEntity  = GetComponentDataFromEntity <WorldSpaceRect>(true);
            var parentFromEntity          = GetComponentDataFromEntity <Parent>(true);
            var pointerReceiverFromEntity = GetComponentDataFromEntity <PointerInputReceiver>(true);

            var stateComponentFromEntity = GetComponentDataFromEntity <InputSystemState>();
            var stateEntity = GetSingletonEntity <InputSystemState>();

            NativeArray <Entity> perCanvasHits =
                new NativeArray <Entity>(pointerFrameData.Length * roots.Length, Allocator.TempJob);
            NativeArray <Entity> globalHits = new NativeArray <Entity>(pointerFrameData.Length, Allocator.TempJob);

            LowLevelUtils.MemSet(perCanvasHits, default);
            LowLevelUtils.MemSet(globalHits, default);
            profilerSample.Dispose();

            ProcessPerCanvasInput process = new ProcessPerCanvasInput()
            {
                Roots = roots,
                ChildrenFromEntity = childrenFromEntity,
                Hits = perCanvasHits,
                LocalToWorldFromEntity = worldSpaceRectFromEntity,
                PointerInputReceiver   = pointerReceiverFromEntity,
                PointersPosition       = pointerFrameData
            };

            inputDeps = process.Schedule(roots.Length, 1, inputDeps);
            var canvasLayerFromEntity     = GetComponentDataFromEntity <CanvasSortLayer>();
            CanvasHitsToGlobal canvasHits = new CanvasHitsToGlobal()
            {
                Roots = roots,
                CanvasLayerFromEntity = canvasLayerFromEntity,
                GlobalHits            = globalHits,
                PerCanvasHits         = perCanvasHits
            };

            inputDeps = canvasHits.Schedule(inputDeps);

            EntityCommandBuffer ecb = m_CommandBufferSystem.CreateCommandBuffer();
            NativeMultiHashMap <Entity, PointerInputBuffer> targetToEvent = new NativeMultiHashMap <Entity, PointerInputBuffer>(16, Allocator.TempJob);
            UpdatePointerEvents updatePointerJob = new UpdatePointerEvents()
            {
                ButtonStates       = m_ButtonStates,
                StateEntity        = stateEntity,
                Hits               = globalHits,
                ReceiverFromEntity = pointerReceiverFromEntity,
                StateFromEntity    = stateComponentFromEntity,
                PointerEvents      = pointerEvents,
                ParentFromEntity   = parentFromEntity,
                PointerFrameData   = pointerFrameData,
                DragThreshold      = DragThreshold,
                TargetToEvent      = targetToEvent
            };

            inputDeps = updatePointerJob.Schedule(inputDeps);
            SpawnPointerEvents spawnEventsJob = new SpawnPointerEvents()
            {
                EventArchetype = m_PointerEventArchetype,
                Ecb            = ecb,
                TargetToEvent  = targetToEvent
            };

            inputDeps = spawnEventsJob.Schedule(inputDeps);
            inputDeps = targetToEvent.Dispose(inputDeps);
            UpdateKeyboardEvents updateKeyboardJob = new UpdateKeyboardEvents()
            {
                KeyboardEvents  = keyboardEvents,
                EventArchetype  = m_KeyboardEventArchetype,
                Manager         = ecb,
                StateEntity     = stateEntity,
                StateFromEntity = stateComponentFromEntity
            };

            inputDeps = updateKeyboardJob.Schedule(inputDeps);
            m_CommandBufferSystem.AddJobHandleForProducer(inputDeps);
            m_LastFrameMousePos = (Vector2)UnityEngine.Input.mousePosition;
            return(inputDeps);
        }