Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
			public ParameterEnumerator(ScriptReference par) 
			{
				parent = par;
				nIndex = -1;
			}
Exemplo n.º 3
0
			public ScriptNameEnumerator(ScriptReference par) 
			{
				parent = par;
				nIndex = -1;
			}
Exemplo n.º 4
0
		public void ReplaceCallScriptAt(ScriptReference newValue, int index)
		{
			ReplaceDomElementAt("", "CallScript", index, newValue);
		}
Exemplo n.º 5
0
		public void InsertCallScriptAt(ScriptReference newValue, int index)
		{
			InsertDomElementAt("", "CallScript", index, newValue);
		}
Exemplo n.º 6
0
		public void AddCallScript(ScriptReference newValue)
		{
			AppendDomElement("", "CallScript", newValue);
		}
Exemplo n.º 7
0
 public ParameterEnumerator(ScriptReference par)
 {
     parent = par;
     nIndex = -1;
 }
Exemplo n.º 8
0
 public ScriptNameEnumerator(ScriptReference par)
 {
     parent = par;
     nIndex = -1;
 }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
 public void ReplaceUpdateScriptAt(ScriptReference newValue, int index)
 {
     ReplaceDomElementAt("", "UpdateScript", index, newValue);
 }
Exemplo n.º 11
0
 public void InsertUpdateScriptAt(ScriptReference newValue, int index)
 {
     InsertDomElementAt("", "UpdateScript", index, newValue);
 }
Exemplo n.º 12
0
 public void AddUpdateScript(ScriptReference newValue)
 {
     AppendDomElement("", "UpdateScript", newValue);
 }
Exemplo n.º 13
0
 public void AddCallScript(ScriptReference newValue)
 {
     AppendDomElement("", "CallScript", newValue);
 }
Exemplo n.º 14
0
		public void AddUpdateScript(ScriptReference newValue)
		{
			AppendDomElement("", "UpdateScript", newValue);
		}