Advertisement
Guest User

History

a guest
Dec 6th, 2013
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class History : MonoBehaviour {
  6.  
  7.     //Скрипт отвечающий за откат и повторение действий. Undo и Redo. Думаю в объяснениях не нуждается
  8.  
  9.     List<List<HistoryItem>> undoItems = new List<List<HistoryItem>>();
  10.     List<List<HistoryItem>> redoItems = new List<List<HistoryItem>>();
  11.  
  12.     public void AddToHistory(List<GameObject> items,string action) {
  13.         List<HistoryItem> list = new List<HistoryItem> ();
  14.         for(int i = 0;i < items.Count;i++) {
  15.             HistoryItem newInstance = new HistoryItem ();
  16.             newInstance.gameobject = items[i];
  17.             newInstance.action = action;
  18.             list.Add(newInstance);
  19.         }
  20.         undoItems.Add(list);
  21.     }
  22.  
  23.     public void Undo () {
  24.         if(undoItems.Count > 0) {
  25.             int lastIndex = undoItems.Count - 1;
  26.             string action = undoItems[lastIndex][0].action;
  27.             if(action == "Instance") {
  28.                 for(int i = 0;i < undoItems[lastIndex].Count;i++) {
  29.                     GameObject go = undoItems[lastIndex][i].gameobject;
  30.                     DestroyImmediate(undoItems[lastIndex][i].gameobject,true);
  31.                 }
  32.             }
  33.             undoItems.RemoveAt(lastIndex);
  34.         }
  35.     }
  36.  
  37.     public void Redo () {
  38.  
  39.     }
  40. }
  41. public class HistoryItem {
  42.     public GameObject gameobject;
  43.     public string action;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement