コード例 #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;
        }
コード例 #2
0
			public ParameterEnumerator(ScriptReference par) 
			{
				parent = par;
				nIndex = -1;
			}
コード例 #3
0
			public ScriptNameEnumerator(ScriptReference par) 
			{
				parent = par;
				nIndex = -1;
			}
コード例 #4
0
		public void ReplaceCallScriptAt(ScriptReference newValue, int index)
		{
			ReplaceDomElementAt("", "CallScript", index, newValue);
		}
コード例 #5
0
		public void InsertCallScriptAt(ScriptReference newValue, int index)
		{
			InsertDomElementAt("", "CallScript", index, newValue);
		}
コード例 #6
0
		public void AddCallScript(ScriptReference newValue)
		{
			AppendDomElement("", "CallScript", newValue);
		}
コード例 #7
0
 public ParameterEnumerator(ScriptReference par)
 {
     parent = par;
     nIndex = -1;
 }
コード例 #8
0
 public ScriptNameEnumerator(ScriptReference par)
 {
     parent = par;
     nIndex = -1;
 }
コード例 #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;
        }
コード例 #10
0
 public void ReplaceUpdateScriptAt(ScriptReference newValue, int index)
 {
     ReplaceDomElementAt("", "UpdateScript", index, newValue);
 }
コード例 #11
0
 public void InsertUpdateScriptAt(ScriptReference newValue, int index)
 {
     InsertDomElementAt("", "UpdateScript", index, newValue);
 }
コード例 #12
0
 public void AddUpdateScript(ScriptReference newValue)
 {
     AppendDomElement("", "UpdateScript", newValue);
 }
コード例 #13
0
ファイル: ActionType.cs プロジェクト: lickey10/u_Behaviors
 public void AddCallScript(ScriptReference newValue)
 {
     AppendDomElement("", "CallScript", newValue);
 }
コード例 #14
0
		public void AddUpdateScript(ScriptReference newValue)
		{
			AppendDomElement("", "UpdateScript", newValue);
		}