Ejemplo n.º 1
0
        public void Add(UR_ICommand p_cmd, bool p_isAlreadyExecuted)
        {
            if (p_cmd != null)
            {
                if (!p_isAlreadyExecuted)
                {
                    p_cmd.Execute();
                }

                if (m_undoCommands.Count > 0)
                {
                    UR_ICommand lastCmd      = m_undoCommands[m_undoCommands.Count - 1];
                    long        lastCmdBytes = lastCmd.GetStoredBytes();
                    if (lastCmd.CombineWithNext(p_cmd))
                    {
                        ClearRedoCommands();
                        m_commandsStoredBytes += lastCmd.GetStoredBytes() - lastCmdBytes;
                        LimitMemoryUsage();
                        return;                         // commands are combined now
                    }
                }
                m_undoCommands.Add(p_cmd);
                ClearRedoCommands();
                m_commandsStoredBytes += p_cmd.GetStoredBytes();
                LimitMemoryUsage();
            }
            else
            {
                Debug.LogError("UR_CommandMgr: Add: p_cmd is null!");
            }
        }
Ejemplo n.º 2
0
 private void LimitMemoryUsage()
 {
     while (m_commandsStoredBytes > m_commandsStoredBytesLimit && m_undoCommands.Count > 0)
     {
         // remove oldest command
         UR_ICommand oldestCmd = m_undoCommands[0];
         m_undoCommands.RemoveAt(0);
         m_commandsStoredBytes -= oldestCmd.GetStoredBytes();
     }
     // in theory the redo list could use a lot storage space, but since the redo list is cleared after every new command, we do not check it here
     // => this means, that reducing the StoredBytesLimit on runtime will not delete the redo stack, it will be deleted when a new command is executed
 }
Ejemplo n.º 3
0
 public bool Undo()
 {
     if (IsUndoable)
     {
         UR_ICommand cmd = m_undoCommands[m_undoCommands.Count - 1];
         m_undoCommands.RemoveAt(m_undoCommands.Count - 1);
         m_commandsStoredBytes -= cmd.GetStoredBytes();
         cmd.Rollback();
         m_commandsStoredBytes += cmd.GetStoredBytes();
         m_redoCommands.Add(cmd);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
        public override bool CombineWithNext(UR_ICommand p_nextCmd)
        {
            if (p_nextCmd is LE_CmdChangeObjectColor)
            {
                LE_CmdChangeObjectColor nextCmd = (LE_CmdChangeObjectColor)p_nextCmd;
                if (nextCmd.RealTime - RealTime < 1.25f &&
                    (m_deltaColor.r != 0 || nextCmd.m_deltaColor.r == 0) &&
                    (m_deltaColor.g != 0 || nextCmd.m_deltaColor.g == 0) &&
                    (m_deltaColor.b != 0 || nextCmd.m_deltaColor.b == 0) &&
                    (m_deltaColor.a != 0 || nextCmd.m_deltaColor.a == 0))
                {
                    m_deltaColor += nextCmd.m_deltaColor;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
 public abstract bool CombineWithNext(UR_ICommand p_nextCmd);
Ejemplo n.º 6
0
        public override void SetIsCursorAction(bool p_isCursorAction)
        {
            if (m_isTerrainPaintHeightReadInFrame != -1 && !p_isCursorAction && m_isTerrainPaintHeightReadInFrame + 1 < Time.frameCount)
            {
                m_isReadingTerrainPaintHeight     = false;
                m_isTerrainPaintHeightReadInFrame = -1;
            }
            if (IsCursorOverSomething && IsInteractable && p_isCursorAction && m_lastCursorActiveScreenCoords != m_cursorScreenCoords)
            {
                m_lastCursorActiveScreenCoords = m_cursorScreenCoords;
                if (m_cursorHitInfo.transform.gameObject.GetComponent <Terrain>() != null)
                {
                    if (m_isReadingTerrainPaintHeight)
                    {
                        Terrain terrain     = m_cursorHitInfo.transform.gameObject.GetComponent <Terrain>();
                        float   heightWorld = terrain.SampleHeight(m_cursorHitInfo.point);
                        m_targetRelativeValue             = Mathf.Clamp01(heightWorld / terrain.terrainData.size.y);
                        m_isTerrainPaintHeightReadInFrame = Time.frameCount;
                    }
                    else
                    {
                        if (m_genCmdTerrain == null)
                        {
                            LE_GenCmdTerrain.Mode cmdMode = m_editMode == LE_ETerrainEditMode.DRAW_TEXTURE ? LE_GenCmdTerrain.Mode.ALPHAMAPS_CMD : LE_GenCmdTerrain.Mode.HEIGHTS_CMD;
                            m_genCmdTerrain = new LE_GenCmdTerrain(this, m_terrainMgr, cmdMode);
                        }
                        switch (m_editMode)
                        {
                        case LE_ETerrainEditMode.CHANGE_HEIGHT:
                            m_genCmdTerrain.ChangeHeight(Mathf.Sign(Amount) * Mathf.Max(0.002f, Amount * Amount) * Time.deltaTime * 2f, BrushAlphaTexture, Size, GetRelativeLocalLocation(m_cursorHitInfo));
                            break;

                        case LE_ETerrainEditMode.CHANGE_HEIGHT_TO_TARGET_VALUE:
                            m_genCmdTerrain.ChangeHeight(Mathf.Max(0.002f, Amount * Amount) * Time.deltaTime * 2f, TargetRelativeValue, BrushAlphaTexture, Size, GetRelativeLocalLocation(m_cursorHitInfo));
                            break;

                        case LE_ETerrainEditMode.SMOOTH_HEIGHT:
                            int neighbourCount = 3 + 2 * Mathf.RoundToInt((Mathf.Abs(Amount) * 3f));
                            m_genCmdTerrain.SmoothHeight(Time.deltaTime * 2f, neighbourCount, BrushAlphaTexture, Size, GetRelativeLocalLocation(m_cursorHitInfo), m_isDirectedSmooth, m_directedSmoothAngle);
                            break;

                        case LE_ETerrainEditMode.DRAW_TEXTURE:
                            m_genCmdTerrain.PaintTexture(SelectedSplatPrototype, Mathf.Abs(Amount) * Time.deltaTime * 8f, TargetRelativeValue, BrushAlphaTexture, Size, GetRelativeLocalLocation(m_cursorHitInfo));
                            break;

                        default:
                            Debug.LogError("LE_GUI3dTerrain: unknown EditMode!");
                            break;
                        }
                    }
                }
            }
            else
            {
                m_lastCursorActiveScreenCoords = -1 * Vector3.one;
            }

            if (m_genCmdTerrain != null && m_genCmdTerrain.LastEditedFrame + 1 < Time.frameCount)
            {
                UR_ICommand cmd = m_genCmdTerrain.GetCmd();
                if (cmd != null)
                {
                    UR_CommandMgr.Instance.Add(cmd, true);
                }
                m_genCmdTerrain = null;
            }
        }
Ejemplo n.º 7
0
 public void Execute(UR_ICommand p_cmd)
 {
     Add(p_cmd, false);
 }
Ejemplo n.º 8
0
 public override bool CombineWithNext(UR_ICommand p_nextCmd)
 {
     return(false);
 }