Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class History : MonoBehaviour {
- //Скрипт отвечающий за откат и повторение действий. Undo и Redo. Думаю в объяснениях не нуждается
- List<List<HistoryItem>> undoItems = new List<List<HistoryItem>>();
- List<List<HistoryItem>> redoItems = new List<List<HistoryItem>>();
- public void AddToHistory(List<GameObject> items,string action) {
- List<HistoryItem> list = new List<HistoryItem> ();
- for(int i = 0;i < items.Count;i++) {
- HistoryItem newInstance = new HistoryItem ();
- newInstance.gameobject = items[i];
- newInstance.action = action;
- list.Add(newInstance);
- }
- undoItems.Add(list);
- }
- public void Undo () {
- if(undoItems.Count > 0) {
- int lastIndex = undoItems.Count - 1;
- string action = undoItems[lastIndex][0].action;
- if(action == "Instance") {
- for(int i = 0;i < undoItems[lastIndex].Count;i++) {
- GameObject go = undoItems[lastIndex][i].gameobject;
- DestroyImmediate(undoItems[lastIndex][i].gameobject,true);
- }
- }
- undoItems.RemoveAt(lastIndex);
- }
- }
- public void Redo () {
- }
- }
- public class HistoryItem {
- public GameObject gameobject;
- public string action;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement