Ejemplo n.º 1
0
        public void Tick()
        {
            // Check feelings after last action.
            // Remember last action results.

            int input = DecideWhatToDo();

            ExecuteActions.PerformAction(input, this);
        }
Ejemplo n.º 2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        EntityManager.GetAllUniqueSharedComponentData(m_UniqueTypes);

        // var a = EntityManager.GetSharedComponentOrderVersion<MoveActions> (m_UniqueTypes[0]);
        // var b = EntityManager.GetSharedComponentOrderVersion<MoveActions> (m_UniqueTypes[2]);
        foreach (var uniqueType in m_UniqueTypes)
        {
            Debug.Log(uniqueType + " ID :" + EntityManager.GetSharedComponentOrderVersion <MoveActions>(uniqueType));
        }
        Debug.Log("unique types:" + m_UniqueTypes.Count);
        //we start at one because the first one is simply the uninitialised version
        if (m_UniqueTypes.Count > 1)
        {
            for (int i = 1; i < m_UniqueTypes.Count; i++)
            {
                //  Debug.Log ("distance: " + ArrayToString( m_UniqueTypes[i].distances));
                //  Debug.Log ("rotations: " + ArrayToString(m_UniqueTypes[i].rotations));
                m_MoveActionsGroup.SetFilter(m_UniqueTypes[i]);
                int cacheIndex = i - 1;
                NativeArray <float> moveActionsDistances = new NativeArray <float>(1, Allocator.TempJob);
                NativeArray <float> moveActionsRotations = new NativeArray <float>(1, Allocator.TempJob);

                /*     if (m_UniqueTypes[i].distances.Length != m_UniqueTypes[i].rotations.Length) { Debug.LogError ("there must be a rotation for each direction given"); }
                 * if (m_UniqueTypes[i].distances.Length > 0) { moveActionsDistances = new NativeArray<float> (m_UniqueTypes[i].distances, Allocator.TempJob); }
                 * else { Debug.LogError ("movactions distance has no data, without any actions this will fail."); }
                 * if (m_UniqueTypes[i].rotations.Length > 0) { moveActionsRotations = new NativeArray<float> (m_UniqueTypes[i].rotations, Allocator.TempJob); }
                 * else { Debug.LogError ("movactions rotations has no data, without any actions this will fail."); }
                 */
                //  var tran else { Debug.LogError("movactions has no data, without any actiosn this will fail.") }slation = m_MoveActionsGroup.ToComponentDataArray<Translation> (Allocator.TempJob, out JobHandle getTranslationJobHandle);
                //    var combinedHandles = JobHandle.CombineDependencies (inputDeps, getTranslationJobHandle);
                var moveActions = m_UniqueTypes[i];

                //Essentially what this is doing is checking each time the job runs if the
                var nextActions = new PreviousActions
                {
                    MoveActionsDistances = moveActionsDistances,
                    MoveActionsRotations = moveActionsRotations
                };
                if (cacheIndex > (m_previousActions.Count - 1))
                {
                    m_previousActions.Add(nextActions);
                }
                else
                {
                    m_previousActions[cacheIndex].MoveActionsDistances.Dispose();
                    m_previousActions[cacheIndex].MoveActionsRotations.Dispose();
                }
                m_previousActions[cacheIndex] = nextActions;

                ExecuteActions executeActionsJob = new ExecuteActions
                {
                    deltaTime = Time.deltaTime,
                    // storableEntityData = m_storeableEntityData,
                    // postion = translation,
                    //moveActions = m_UniqueTypes[i],
                    rotations     = moveActionsRotations,
                    distances     = moveActionsDistances,
                    CommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer()
                };

                JobHandle executeActionsJobHandle = executeActionsJob.Schedule(this, inputDeps);
                inputDeps = executeActionsJobHandle;

                m_EntityCommandBufferSystem.AddJobHandleForProducer(inputDeps);
                m_MoveActionsGroup.AddDependency(inputDeps);
                //moveActionsRotations.Dispose();
                // moveActionsDistances.Dispose();
            }
        }
        m_UniqueTypes.Clear();

        return(inputDeps);
    }