Example #1
0
 /// <summary>
 /// Execute the given action
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public IAction ExecuteAction(IAction action, object context      = null,
                              bool performPostExecutionOperations = true, bool promptForInputs = true,
                              bool chain = false)
 {
     if (action != null)
     {
         CurrentAction = action;
         string commandName = action.GetCommandName();
         try
         {
             if (action is IContextualAction)
             {
                 ((IContextualAction)action).PopulateInputsFromContext(context);
             }
             if (PreviousActions.ContainsKey(commandName))
             {
                 action.CopyPersistentValuesFrom(PreviousActions[commandName]);
             }
             if (!promptForInputs || action.PromptUserForInputs(chain))
             {
                 if (action.PreExecutionOperations())
                 {
                     //Core.Instance.Undo.BeginStage();
                     action.Execute();
                     if (performPostExecutionOperations)
                     {
                         action.PostExecutionOperations();
                     }
                     //Core.Instance.Undo.EndStage();
                     Core.Instance.Host.Refresh();
                 }
             }
         }
         catch (Exception ex)
         {
             Core.PrintLine("Error: Newt action '" + commandName + "' failed to complete.");
             Core.PrintLine(ex.Message);
             Core.PrintLine(ex.StackTrace);
         }
         PreviousActions[commandName] = action;
         LastCommand   = action;
         CurrentAction = null;
     }
     return(action);
 }
Example #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);
    }