public static bool Load(ScriptReference xmlScriptReference, GameObject gameObject, out BaseScript newScript) { bool result = true; newScript = null; if (xmlScriptReference != null && xmlScriptReference.HasScriptName()) { string name = (string)xmlScriptReference.GetScriptName().Value; Type scriptType = Type.GetType(name); if (scriptType != null) { newScript = gameObject.AddComponent(scriptType) as BaseScript; for (int i = 0; i < xmlScriptReference.GetParameterCount(); i++) { ParameterType parameter = xmlScriptReference.GetParameterAt(i); if (parameter.HasName()) { string parameterName = parameter.GetName().Value; string parameterType = parameter.GetType2().Value; object target = null; if (parameterType == typeof(UnityEngine.GameObject).ToString()) { if (!Variable.ObjectFromString(parameter.GetValue().GetString2().Value, out target)) { Debug.LogError("Script " + name + " references an object (" + parameter.GetValue().GetString2().Value + ") that was not found."); } } else { target = Variable.GetValueFromConstant(parameter.GetValue()); } if (!newScript.SetFieldValue(parameterName, target)) { Debug.LogError("Script " + name + " failed to set a value for " + parameterName); } } } } else { Debug.LogError("Script (" + name + ") is referenced as a sensor or an action but was not found"); result = false; } } return result; }
public ParameterEnumerator(ScriptReference par) { parent = par; nIndex = -1; }
public ScriptNameEnumerator(ScriptReference par) { parent = par; nIndex = -1; }
public void ReplaceCallScriptAt(ScriptReference newValue, int index) { ReplaceDomElementAt("", "CallScript", index, newValue); }
public void InsertCallScriptAt(ScriptReference newValue, int index) { InsertDomElementAt("", "CallScript", index, newValue); }
public void AddCallScript(ScriptReference newValue) { AppendDomElement("", "CallScript", newValue); }
public static bool Save(BaseScript script, out ScriptReference xmlScriptReference) { xmlScriptReference = new ScriptReference(); xmlScriptReference.AddScriptName(new SchemaString(script.GetType().ToString())); foreach (FieldInfo field in script.m_Fields) { ParameterType parameter = new ParameterType(); parameter.AddName(new SchemaString(field.Name)); parameter.AddType2(new SchemaString(field.FieldType.ToString())); object value = field.GetValue(script); if (value != null) parameter.AddValue(Variable.GetConstantFromValue(value)); else Debug.LogError("Error saving value for field " + field.Name + " in script " + script.GetType().ToString()); xmlScriptReference.AddParameter(parameter); } return true; }
public void ReplaceUpdateScriptAt(ScriptReference newValue, int index) { ReplaceDomElementAt("", "UpdateScript", index, newValue); }
public void InsertUpdateScriptAt(ScriptReference newValue, int index) { InsertDomElementAt("", "UpdateScript", index, newValue); }
public void AddUpdateScript(ScriptReference newValue) { AppendDomElement("", "UpdateScript", newValue); }