Exemple #1
0
 public virtual void Load()
 {
     // GetState();
     base_state temp = (base_state)_state;
     manager_state.Instance.Load(gameObject.name, out temp, TypeState.MOB);
     _state = (state_data)temp;
     // * testing
     // _healthInst = _state.Health;
     HealthRestore();
     HealthDrain(_health - _state.Health);
     _resurrect = _state.Resurrect;
     // _hostiles = _state.Hostiles;
     _hostiles.Clear();
     if (gameObject.layer == game_variables.Instance.LayerMob)
         _hostiles.Add(controller_player.Instance.Motor.transform);
     // Clear();
     // _target = _state.Target;
     // _target = null;
     // _flag = _state.Flag;
     // if (_collider)
     //     _collider.radius = _state.Radius;
     // * testing feedback action
     if (_action)
         _action.Disable();
     // _inventory = _state.Inventory;
     _timerIframes = 0f;
 }
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
     DontDestroyOnLoad(this);
     // // * testing
     // _isSave = false;
     _state       = new base_state();
     _isDeveloper = false;
 }
    // void Start()
    // {
    //     // game_variables.Instance.IsSave;
    //     // _isSave = PlayerPrefs.GetInt("save", 0) == 0 ? false : true;
    // }
    public void Save(string id, base_state state, TypeState type)
    {
        //
        FileStream file = new FileStream(Application.persistentDataPath + "/" + type.ToString() + "/" + id + ".dot", FileMode.OpenOrCreate);

        try
        {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(file, state);
        }
        catch (SerializationException e)
        {
            feedback_toaster.Instance.RegisterMessage(gameObject.name + " : " + e.Message, game_variables.Instance.ColorDefault);
        }
        finally
        {
            file.Close();
            game_variables.Instance.Save();
        }
    }