Advertisement
Alynie

SaveObject.cs

Sep 16th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. //[AddComponentMenu(typeof(UniqueId))]
  6. //[RequireComponent(typeof(UniqueId))]
  7. public class SaveObject : MonoBehaviour {
  8.  
  9.     [DisplayWithoutEdit(), UniqueIdentifier]
  10.     public string id;
  11.      bool resetId;
  12.     //[DisplayWithoutEdit()]
  13.     //public string previewId;
  14.     //public bool Refresh;
  15.  
  16.     void Awake () {
  17.         //PlayerPrefs.SetInt("_" + id, PlayerPrefs.GetInt(id) + 1);
  18. //      if(id == 0){
  19. //          id = new System.Random().Next(1000000, 9999999);
  20. //      }
  21.         //id = GetComponent<UniqueId>().uniqueId;
  22.         //gameObject.name = id.ToString();
  23.         //var i = "_" + name;
  24.         //int p = PlayerPrefs.GetInt(i);
  25.         //PlayerPrefs.SetInt(i, p + 1);
  26.         //devSettings = Resources.Load("DevSettings") as DevSettings;
  27.         //if(devSettings.useSaveSystem){
  28.         //id = GetComponent<GameObjectGUID>().gameObjectID;
  29. //      if(id == System.Guid.Empty){
  30. //          id = System.Guid.NewGuid();
  31. //      }
  32.             //NS.Base.Debug(gameObject + "  " + id);
  33.         //print(gameObject.GetInstanceID());
  34.         //name = GetHashCode();
  35.         if(PlayerPrefs.HasKey(id.ToString())){
  36.             gameObject.SetActive(NS.SaveSystem.Check(id));
  37.         }else{
  38.             NS.SaveSystem.SaveObject(id, true);
  39.             gameObject.SetActive(NS.SaveSystem.Check(id));
  40.         }
  41.         //previewId = id.ToString();
  42.         //InvokeRepeating("CustomUpdate", 1, 1);
  43.         //}
  44.     }
  45.  
  46.     void OnEnable(){
  47.     }
  48.    
  49. //  void CustomUpdate () {
  50. //      if(id == ""){
  51. //          NS.Base.Debug(gameObject);
  52. //      }
  53. //      //print(id);
  54. //      //gameObject.SetActive(NS.SaveSystem.Check(GetComponent<GameObjectGUID>().gameObjectID));
  55. //      //previewId = id.ToString();
  56. //  }
  57.  
  58.     void OnValidate(){
  59. //      if(id == 0){
  60. //          id = new System.Random().Next(1000000, 9999999);
  61. //      }
  62.         //if(GetComponent<UniqueId>()) id = GetComponent<UniqueId>().uniqueId;
  63.         if(resetId){
  64. //          id = 0;
  65.             resetId = false;
  66.         }
  67.  
  68.     }
  69.  
  70.     public void Save(){
  71.         NS.PlayerPrefs.SetBool(id, false);
  72.     }
  73.  
  74.  
  75.     public void Setup(){
  76.         id = System.Guid.NewGuid().ToString();
  77.     }
  78.        
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement