public void RegisterAgent(ISaveAndLoadAgent agent)
 {
     if (agent == null) CDebug.LogError(CDebug.eMessageTemplate.NullRefrences);
     if (_agents.Contains(agent) == false)//We dont want to have multiple of same instance of agent.
         _agents.Add(agent);
 }
 public bool RemoveAgent(ISaveAndLoadAgent agent)
 {
     if(agent == null){
         CDebug.LogError(CDebug.eMessageTemplate.NullRefrences);
         return false;
     }
     return _agents.Remove(agent);
 }
    /// <summary>
    /// Load just one agent and its clients in specefice save file.
    /// </summary>
    /// <param name='path'>
    /// Save file path.
    /// </param>
    /// <param name='agent'>
    /// Agent for retriving data from save file.
    /// </param>
    public bool Load(string path,ISaveAndLoadAgent agent)
    {
        string fileName        = Path.GetFileName(path);
        string pathWithoutFile = Path.GetDirectoryName(path);

        if (agent == null){
            CDebug.LogError(CDebug.eMessageTemplate.NullParameter);
            return false;
        }

        //Check path to isure is not NULL or EMPTY.
        if (string.IsNullOrEmpty(path) == true) {
            CDebug.LogError(CDebug.eMessageTemplate.NullRefrences);
            return false;
        }
        //Check file name of given path to insure is not invalide.
        if (fileName.IndexOfAny(_invalideFileNameChars) != -1){
            CDebug.LogError(CDebug.eMessageTemplate.InvalideFileName);
            return false;
        }
        //Check path without file name to insure is not invalide.
        if(pathWithoutFile.IndexOfAny(_invalidePathChars) != -1){
            CDebug.LogError(CDebug.eMessageTemplate.InvalidePathAddress);
            return false;
        }

        Directory.CreateDirectory(pathWithoutFile);//First create directories cuz File.Open Can not create directories
        _fileStream = File.Open(path,FileMode.Open);//Open a file stream
        bool res = agent.LoadFromFile(ref _fileStream, _defualtFormatter);//call agent's LoadFromFile() function.
        if (res == false) {
            _fileStream.Close();
            return false;
        }
        for(int i = 0; i < agent.ClientsInstances.Count; i++)// call OnLoad() functions
            agent.ClientsInstances[i].OnLoad();

        _fileStream.Close();
        return true;
    }