public string GetVariableName(string id) //this is called from elsewhere to get variable names. { if (!m_Variables.ContainsKey(id)) //if a variable with the given ID was NOT found in the initialdata, then create a new variable. { string name = "UNKNOWN-" + id; m_Variables["UNKNOWN-id"] = new GameVariable { name = name, id = id }; return(name); } else { return(m_Variables[id].name); } }
/// <summary> /// Add a new variable to a list with given ID and Name. /// If Name is not specified, uses ID as a Name. /// If variable with given ID and Name already exists, returns found entry. /// </summary> /// <param name="id">Variable ID</param> /// <param name="name">Variable Name</param> /// <returns>Created or found variable</returns> private GameVariable AddVariable(string id, string name = null) { name = name ?? id; if (_variables.ContainsKey(id)) { return(_variables[id].Name == name ? _variables[id] : null); } var newVariable = new GameVariable { Id = id, Name = name }; _variables[id] = newVariable; _varNames[name] = newVariable; return(newVariable); }