/// <summary> /// Returns the result of execution of command found in the commandlist by ID /// </summary> /// <param name="commandId">ID of task</param> /// <returns>NULL or result</returns> public static object Execute(int commandId) { if (_commands.ContainsKey(commandId)) { return(Execute(_commands[commandId])); } ULog.Log("CommandManager:Execute:Command id " + commandId + " Not Find ", ULogType.Warning); //InvokeCommandError(commandId, CommandEventType.NotFindCommand); return(null); }
/// <summary> /// /// </summary> /// <param name="messageKey"></param> public static void Show(int messageKey) { if (Messages.ContainsKey(messageKey)) { Show(Messages[messageKey]); } else { ULog.Log("MessageManager: Messages not contains key " + messageKey); } }
/// <summary> /// /// </summary> /// <param name="plugin"></param> /// <returns></returns> public static bool PluginExists(IUlibPlugin plugin) { if (Plugins.Contains(plugin)) { return(true); } foreach (var ulibPlugin in Plugins) { ULog.Log(ulibPlugin.PluginType); } return(false); }
private static void OnGetTranslationRemote(object inData) { //Debug.Log(string.Format("OnGetTranslationRemote")); if (inData is Hashtable) //Validates load { var result = (Hashtable)inData; var translation = new Dictionary <string, string>(); if (result["result"] is string) { translation = FileManager.ParseIni(result["result"].ToString(), result["section"].ToString()); } else if (result["result"] is Dictionary <string, string> ) { //Debug.Log(string.Format("OnGetTranslationRemote result is ")); translation = (Dictionary <string, string>)result["result"]; //Debug.Log("OnGetTranslation " + translation.Count + " for " + result["lang"].ToString() + " : " + result["section"].ToString()); /*foreach (var tr in translation) * Debug.Log(tr.Key + ":" + tr.Value);*/ } /*else if (result["list"] is Dictionary<string, Dictionary<string, object>>) * { * var translations = (Dictionary<string, Dictionary<string, object>>)result["list"]; * foreach (var translate in translations) * { * var dict = translate.Value.ToDictionary(trans => trans.Key, trans => trans.Value.ToString()); * LanguageManager.AddTranslations(result["lang"].ToString(), translate.Key, dict, true); * } * LanguageManager.Change(result["lang"].ToString(), result["section"].ToString()); * _translationLoaded = true; * }*/ LanguageManager.AddTranslations(result["lang"].ToString(), result["section"].ToString(), translation, true); LanguageManager.Change(result["lang"].ToString(), result["section"].ToString()); _translationLoaded = true; } else { if (inData != null) { ULog.Log("LanguageLoader:Error on OnGetTranslation : Type " + inData.GetType() + " : as string - " + inData, ULogType.Error); } else { ULog.Log("LanguageLoader:Error on OnGetTranslation : NULL", ULogType.Error); } } }
static void OnRequestedBuy(object inData) { SendedRequest = false; if (inData is Hashtable) { var hash = (Hashtable)inData; var buyCount = (int)hash[KeyCount]; var shopItemId = (int)hash[KeyItem]; if (OnRecivedBuy != null) { OnRecivedBuy(shopItemId, buyCount, hash[KeyParameters]); } } else if (Gateway.Debug) { ULog.Log("ShopManager.OnRequestedBuy " + inData); } }
/// <summary> /// Add object to TargetList and member by name from object to MemberList. /// If target exists - previos members not removed. /// </summary> /// <param name="targetName"></param> /// <param name="targetObject"></param> /// <param name="memberName"></param> public static void AddMember(string targetName, object targetObject, string memberName) { if (Targets.ContainsKey(targetName)) { Targets[targetName] = targetObject; } else { Targets.Add(targetName, targetObject); } var member = targetObject.GetType().GetMember(memberName)[0]; if (member != null) { Members.Add(targetName + "." + memberName, member); } else { ULog.Log("Member " + memberName + " not find in " + targetName + " (" + targetObject + ")"); } }
/// <summary> /// Returns the result of the comparison /// </summary> /// <param name="compareModel"></param> /// <returns></returns> public static bool Compare(UCompare compareModel) { var result = false; if (Targets.ContainsKey(compareModel.target)) { var targetObject = Targets[compareModel.target]; if (Members.ContainsKey(compareModel.member)) { var targetMember = Members[compareModel.member]; if (targetMember is FieldInfo) { result = Comparison(((FieldInfo)targetMember).GetValue(targetObject), compareModel.value, compareModel.condition); } else if (targetMember is PropertyInfo) { result = Comparison(((PropertyInfo)targetMember).GetValue(targetObject, null), compareModel.value, compareModel.condition); } else { try { result = Comparison(((MethodInfo)targetMember).Invoke(targetObject, compareModel.parameters), compareModel.value, compareModel.condition); } catch (Exception e) { ULog.Log("CompareManager:Compare:Method. \n" + e.Message, ULogType.Error); //InvokeCompareError(compareModel,CompareEventType.Error,e.Message); //Debug.LogError("CompareManager:Compare method " + compareModel.member + " error: " + e.Message); } } } } return(result); }
/// <summary> /// Apply one options /// </summary> /// <param name="optionValue"></param> static void ApplyOptions(UValue optionValue) { if (Targets.ContainsKey(optionValue.target)) { var targetObject = Targets[optionValue.target]; if (Members.ContainsKey(optionValue.target + "." + optionValue.member)) { var targetMember = Members[optionValue.target + "." + optionValue.member]; if (targetMember is FieldInfo) { ((FieldInfo)targetMember).SetValue(targetObject, optionValue.value); } else if (targetMember is PropertyInfo) { ((PropertyInfo)targetMember).SetValue(targetObject, optionValue.value, null); } /*else * { * try * { * /*if (evt.IsPrevios && evt.parameters.Length > evt.parameters.Length - 1)//???? >0 ??? * evt.parameters[evt.parameters.Length - 1] = previosResult;*/ /*((MethodInfo)targetMember).Invoke(targetObject, optionValue.parameters); * } * catch (Exception e) * { * ULog.Log("OptionsManager:ApplyOptions error on "+optionValue.member+" \n" + e.Message, ULogType.Error); * } * }*/ } else { ULog.Log("ApplyOptions -2 " + optionValue.member + " : " + Members.Count); } } }
internal void LoadFromGateway(ResourceSource path, string key, string extension, ResourceSource resType, ResourceManager.OnGetResource callback) { if (Gateway.Debug) { ULog.Log(string.Format("LoadFromGateway ResourceSource: {0} path: {1} , key {2} , ext: {3}", Enum.GetName(typeof(ResourceSource), resType), path, key, extension)); } //Debug.Log(Enum.GetName(typeof (ResourceSource), resType)); _callback = callback; _key = key; _decode = true; if (_loader == null) { _loader = Gateway.GetSender(); } _loader.Call( ResourceManager.serverClassName, ResourceManager.resourceLoadMethod, new Hashtable { { "path", path }, { "key", _key }, { "type", resType }, { "ext", extension } }, OnGetResources); }
/*void OnGetResourceLink(object inData) * { * _decode = false; * var table = (Hashtable) inData; * StartCoroutine(WaitLoadLocalResource("http://" + table["url"].ToString().Replace("http://", "").Replace("https://", ""), (ResourceSource)table["type"], (Hashtable)table["post"])); * }*/ /*void OnGetResourceLink(object inData) * { * var table = (Hashtable) inData; * //Debug.Log("OnGetResourceLink " + table["result"]); * StartCoroutine(WaitLoadLocalResource("http://" + table["result"].ToString().Replace("http://", "").Replace("https://", ""), * _type, table,null)); * }*/ void OnGetResources(object inData) { if (Gateway.Debug) { ULog.Log("ResourceLoader.OnGetResource(key:" + _key + ") " + inData); } var table = (Hashtable)inData; if (Gateway.Debug) { foreach (DictionaryEntry entry in table) { ULog.Log("OnGetResource Hashtable: " + entry.Key + " : " + entry.Value); } } if (table.ContainsKey("url")) { _decode = (bool)table["decode"]; StartCoroutine( WaitLoadResources( Gateway.Host + Gateway.Path + Gateway.File.Replace(".php", ".ogg"), _resourceType, new Hashtable { { "r", _resourceType }, { "n", table["url"].ToString() } })); } else { var res = ResourceManager.AddResource(_key, table["result"]); if (_callback != null) { _callback(_key, res); } Destroy(gameObject); } }
private static void OnLoadListRemote(object inData) { languageList = (Dictionary <string, string>)inData; if (Gateway.Debug) { ULog.Log(string.Format("OnLoadListRemote {0} : count {1}", languageList, languageList.Count)); } var langListCount = languageList.Count; var arr = new string[langListCount]; var i = 0; foreach (var keyVal in languageList) { arr[i] = keyVal.Key; i++; } LanguageManager.AddLanguages(arr); // LanguageManager.AddLanguages(languageList.Keys.ToArray()); if (LanguageManager.Languages.Length > 0) { LanguageManager.Change(LanguageManager.Languages[0], moduleSection); } }
/// <summary> /// Load list of languages , store pair to languageList /// </summary> /// <param name="fileName">File name</param> /// <param name="parameter">parameter for send to server class, if you used not LanguageManager on server side. /// Default:null</param> public static void LoadList(string fileName, object parameter) { if (_useLocalFiles && !Application.isWebPlayer) { /*((FileObject)Gateway.GetSender()).Call(null, ResourceManager.BasePath + "/" + languagesFolder + "/" + fileName, * ResourceSource.Text, OnLoadListLocal, false);*/ var data = FileManager.LoadText(ResourceManager.BasePath + "/" + languagesFolder + "/" + fileName); if (!string.IsNullOrEmpty(data)) { OnLoadListLocal(data); } else { ULog.Log(ResourceManager.BasePath + "/" + languagesFolder + "/" + fileName + " is empty or not exist.", ULogType.Warning); } } else { //Debug.Log("LoadList remote "); Gateway.GetSender().Call(_serverClass, _listMethod, parameter, OnLoadListRemote); } }
IEnumerator WaitLoadResource(string file, ResourceSource resType, Hashtable post) { //Debug.Log("WaitLoadResource: " + file + " " + Enum.GetName(typeof(ResourceSource), resType)); WWW loader; if (_getTable != null && _getTable.Count > 0) { file += "?"; foreach (DictionaryEntry entry in _getTable) { file = file + (entry.Key + "=" + entry.Value + "&"); } file = file.Remove(file.Length - 2, 1); } if (post != null && post.Count > 0) { var form = new WWWForm(); foreach (DictionaryEntry entry in post) { form.AddField(entry.Key.ToString(), entry.Value.ToString()); } if (Gateway.Key != String.Empty) { form.AddField(Gateway.KeyName, Gateway.Key); } loader = new WWW(file, form); } else { //Debug.Log(file); loader = new WWW(file); } yield return(loader); /*while (!loader.isDone) * yield return loader;*/ if (loader.error != null) { ULog.Log(loader.error, ULogType.Error); Destroy(gameObject); } else { object val; if (_decode) { val = new Serializer().Decode(loader.bytes); } else { switch (resType) { case ResourceSource.Textures: val = loader.texture; break; case ResourceSource.Text: val = loader.text; break; case ResourceSource.AudioClips: val = loader.audioClip; break; case ResourceSource.Assets: val = loader.assetBundle; break; /*case ResourceSource.Movies: * val = loader.movie; * break;*/ default: val = loader.bytes; break; } } OnGetResources(new Hashtable { { "result", val } }); } }
Component SetUnknowComponent(byte[] inBytes, ref int startPos, ref GameObject go) { //Debug.Log("SetUnknowComponent"); var parameters = DecodeHashtable(inBytes, ref startPos); //Debug.Log("SetUnknowComponent: class " + parameters["class"]+" on "+go.name); var newComponentType = FindType(parameters["class"].ToString()); //Debug.Log("SetUnknowComponent Class: " + parameters["class"]+" Type: "+newComponentType+" Fullname: "+newComponentType.FullName); var newComponent = AddOrCreate(ref go, newComponentType); if (newComponent != null) { foreach (DictionaryEntry member in parameters) { var fi = newComponentType.GetField(member.Key.ToString()); if (fi != null) { var tp = fi.FieldType; if (tp.BaseType == typeof(Enum)) { fi.SetValue(newComponent, Enum.ToObject(tp, member.Value)); } /*else if (ResourcedTypes.Contains(tp) || ResourcedTypes.Contains(tp.BaseType)) * fi.SetValue(newComponent, _resourcePack[(int)member.Value]);*/ else { fi.SetValue(newComponent, member.Value); } } else { var pi = newComponentType.GetProperty(member.Key.ToString()); if (pi != null) { var tp = pi.PropertyType; //Debug.Log(newComponent+"("+className+")."+pi.Name+"("+tp+")"); if (tp.BaseType == typeof(Enum)) { pi.SetValue(newComponent, Enum.ToObject(tp, member.Value), null); } /*else if (ResourcedTypes.Contains(tp) || ResourcedTypes.Contains(tp.BaseType)) * pi.SetValue(newComponent, _resourcePack[(int)member.Value], null); * else if (tp == typeof(Material[])) * { * var matIndexes = (int[])member.Value; * var mats = new Material[matIndexes.Length]; * for (var i = 0; i < matIndexes.Length; i++) * mats[i] = (Material)_resourcePack[matIndexes[i]]; * pi.SetValue(newComponent, mats, null); * }*/ else { //Debug.Log("Try set property "+pi.Name+" = "+member.Value); try { pi.SetValue(newComponent, member.Value, null); } catch (Exception e) { ULog.Log("Decode:SetComponentProps: Error on set property " + pi.Name + " in " + newComponent + "\n" + e.Message); } } } } } } return(newComponent); }
/*private readonly Dictionary<string, ComponentDecoder> _componentTypeDecoders = new Dictionary<string, ComponentDecoder> * { * {"UnityEngine.Transform",SetTransform}, * {"UnityEngine.MeshFilter",SetMeshFilter}, * {"UnityEngine.MeshRenderer",SetMeshRenderer}, * {"UnityEngine.Light",SetLight}, * {"UnityEngine.Camera",SetCamera}, * {"UnityEngine.Rigidbody",SetRigidbody}, * {"UnityEngine.Projector",SetProjector}, * {"UnityEngine.ParticleEmitter",SetParticleEmitter}, * {"UnityEngine.GUITexture",DecodeGuiTexture}, * {"UnityEngine.GUIText",DecodeGuiText}, * {"UnityEngine.Terrain",DecodeTerrain}, * {"UnityEngine.Collider",SetCollider}, * {"UnityEngine.BoxCollider",SetCollider}, * {"UnityEngine.CapsuleCollider",SetCollider}, * {"UnityEngine.MeshCollider",SetCollider}, * {"UnityEngine.SphereCollider",SetCollider}, * {"UnityEngine.Skybox",DecodeSkybox} * };*/ void SetComponent(byte[] inBytes, ref int startPos, ref GameObject result) { startPos++; //passed code 251 - resource var resourceIndex = DecodeInteger(inBytes, ref startPos); //index of resource var componentBytes = _bytesList[resourceIndex]; var componentStartPos = 0; if (componentBytes[componentStartPos] != 199) { ULog.Log("SetComponent: get not component code ( " + componentBytes[componentStartPos] + " )" + BitConverter.ToString(componentBytes, componentStartPos), ULogType.Warning); } //Debug.LogWarning("SetComponent: get not component code (199) "); componentStartPos++; var componentType = DecodeString(componentBytes, ref componentStartPos); //ULog.Log("SetComponent : component type name " + componentType); Component component = null; if (ComponentDecoders.ContainsKey(componentType)) { component = ComponentDecoders[componentType](componentBytes, ref componentStartPos, ref result, this); } else { switch (componentType) { case "UnityEngine.MeshFilter": component = SetMeshFilter(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.MeshRenderer": component = SetMeshRenderer(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.Transform": component = SetTransform(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.Collider": component = SetCollider(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.Light": component = SetLight(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.Camera": component = SetCamera(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.Rigidbody": component = SetRigidbody(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.Projector": component = SetProjector(componentBytes, ref componentStartPos, ref result); break; /*case "UnityEngine.ParticleEmitter": * component = SetParticleEmitter(componentBytes, ref componentStartPos, ref result); * break;*/ case "UnityEngine.GUITexture": component = DecodeGuiTexture(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.GUIText": component = DecodeGuiText(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.Terrain": component = DecodeTerrain(componentBytes, ref componentStartPos, ref result); break; case "UnityEngine.SkinnedMeshRenderer": component = DecodeSkinnedMeshRenderer(componentBytes, ref componentStartPos, ref result); break; /*case "UnityEngine.Animation": * component = DecodeAnimation(componentBytes, ref componentStartPos, ref result); * break;*/ default: component = SetUnknowComponent(componentBytes, ref componentStartPos, ref result); break; } } if (_objectList.ContainsValue(component)) { return; } _objectList.Add(_objectListCount, component); _objectListCount++; }
object DecodeObject(byte[] inBytes, ref int startPos) { object result = null; string typeName = null; try { typeName = DecodeString(inBytes, ref startPos); ULog.Log("START decode Class " + typeName); } catch { ULog.Log("(209)DecodeObject can't decode class name. " + typeName, ULogType.Error); //Debug.LogError("DecodeObject can't decode class name. " + typeName );// + inBytes[startPos].ToString()); } if (typeName != null && typeName.Length > 1) { var tp = Type.GetType(typeName) ?? FindType(typeName); try { result = Activator.CreateInstance(tp); } catch { ULog.Log("(221)DecodeObject can't create Instance of " + typeName, ULogType.Error); } var fieldCount = DecodeInteger(inBytes, ref startPos); for (var i = 0; i < fieldCount; i++) { var field = DecodeField(inBytes, ref startPos); //Debug.Log("Decode field " + field.name + " in class " + className); var objFieldInfo = tp.GetField(field.name); var objPropertyInfo = tp.GetProperty(field.name); if (objFieldInfo != null) { //Debug.Log("Decode Field "); try { objFieldInfo.SetValue(result, field.value); } catch (Exception e) { ULog.Log("ERROR on set FieldInfo: CLASS: " + typeName + " FIELD: " + field.name + "\n" + e.Message, ULogType.Warning); //Debug.LogError("ERROR on set FieldInfo: CLASS: " + typeName + " FIELD: " + field.name);// + " VALUE: (" + field.value.GetType().ToString() + ")" + field.value.ToString() + ""); } } else if (objPropertyInfo != null) { //Debug.Log("Decode Property "); if (objPropertyInfo.CanWrite) { try { objPropertyInfo.SetValue(result, field.value, null); } catch (Exception e) { //if (field.value != null) //{ ULog.Log("ERROR on set PropertyInfo->" + objPropertyInfo.Name + ": CLASS: " + typeName + " FIELD: " + field.name + "\n" + e.Message /*+ " VALUE: (" + field.value.GetType() + ")" + field.value + ""*/, ULogType.Warning); //Debug.LogError("ERROR on set PropertyInfo->" + objPropertyInfo.Name + ": CLASS: " + typeName + " FIELD: " + field.name + " VALUE: (" + field.value.GetType() + ")" + field.value + ""); /*} * else * { * Debug.LogError("ERROR on set PropertyInfo->" + objPropertyInfo.Name + ": CLASS: " + typeName + " FIELD: " + field.name + " VALUE: NULL "); * }*/ } } } else { ULog.Log("Member " + field.name + " not find in " + typeName, ULogType.Error); //Debug.LogError("Member " + field.name + " not find in " + typeName); } } } return(result); }
object Decoding(byte[] inBytes, ref int startPos) { var code = inBytes[startPos]; //Debug.Log("Decoding "+code); startPos++; if (TypeDecoders.ContainsKey(code)) { return(TypeDecoders[code](inBytes, ref startPos, this)); } switch (code) { case 00: //null return(null); #region Primitive 01-09 case 01: //bool false return(false); case 02: //bool true return(true); case 03: //integer return(DecodeInteger(inBytes, ref startPos)); case 04: //float return(DecodeSingle(inBytes, ref startPos)); case 05: //string //Debug.Log("DecodeString pos " + startPos); return(DecodeString(inBytes, ref startPos)); case 06: //Double return(null); case 07: //reserved return(null); case 08: //Char return(null); case 09: //DateTime return(DecodeDiteTime(inBytes, ref startPos)); #endregion #region IEnumerable 10-15 case 10: //Array return(DecodeArray(inBytes, ref startPos)); case 11: //ArrayList return(DecodeArrayList(inBytes, ref startPos)); case 12: //Hashtable return(DecodeHashtable(inBytes, ref startPos)); case 13: //List return(DecodeList(inBytes, ref startPos)); case 14: //Dictionary return(DecodeDictionary(inBytes, ref startPos)); case 15: //ByteArray return(null); #endregion #region Unity 16-199 case 16: //Vector2 return(DecodeVector2(inBytes, ref startPos)); case 17: //Vector3 return(DecodeVector3(inBytes, ref startPos)); case 18: //Vector4 return(DecodeVector4(inBytes, ref startPos)); case 19: //Quaternion return(DecodeQuaternion(inBytes, ref startPos)); case 20: //Color return(DecodeColor(inBytes, ref startPos)); case 21: //Rect return(DecodeRect(inBytes, ref startPos)); case 28: //Matrix return(DecodeMatrix(inBytes, ref startPos)); case 29: //Bounds return(DecodeBounds(inBytes, ref startPos)); case 30: //BoneWeight return(DecodeBoneWeight(inBytes, ref startPos)); case 22: //Mesh return(DecodeMesh(inBytes, ref startPos)); case 23: //Texture2D return(DecodeTexture2D(inBytes, ref startPos)); case 24: //Physics return(DecodePhysicMaterial(inBytes, ref startPos)); case 25: //GameObject return(DecodeGameObject(inBytes, ref startPos)); case 26: //Material return(DecodeMaterial(inBytes, ref startPos)); case 27: //TerrainData return(DecodeTerrainData(inBytes, ref startPos)); #endregion case 200: //Object return(DecodeObject(inBytes, ref startPos)); #region ULIB Models //201-249 /*case 201://ULabelModel * return DecodeULabelModel(inBytes, ref startPos); * case 202://UModel * return DecodeUModel(inBytes, ref startPos); * case 203://UCompare * return DecodeUCompare(inBytes, ref startPos); * case 204://UCommand * return DecodeUCommand(inBytes, ref startPos); * case 205://UValue * return DecodeUValue(inBytes, ref startPos); * case 206://UMenu * return DecodeUMenu(inBytes, ref startPos);*/ #endregion #region ULIB servicecode //250-254 case 250: //Packets of bytes //InitLists(); var bytesPackCount = DecodeInteger(inBytes, ref startPos); //count of stored resources bytes for (var i = 0; i < bytesPackCount; i++) { var bytePackLenght = DecodeInteger(inBytes, ref startPos); //lenght of [i] bytes for read var bytePack = new byte[bytePackLenght]; //bytes for resource number i Buffer.BlockCopy(inBytes, startPos, bytePack, 0, bytePackLenght); _bytesList.Add(i, bytePack); startPos += bytePackLenght; } return(Decoding(inBytes, ref startPos)); case 251: //One packet of bytes var index = DecodeInteger(inBytes, ref startPos); //Object UID if (!_objectList.ContainsKey(index)) //if position not exists { var pos = 0; var obj = Decoding(_bytesList[index], ref pos); _objectList.Add(index, obj); _objectListCount++; } return(_objectList[index]); case 252: //Previos loaded resource - reserved ULog.Log("Decoding: Recived code 252 - code is reserved for previos decoded resource", ULogType.Warning); return(null); case 253: //Crypto return(Decrypt(inBytes, ref startPos)); case 254: //Compressed return(UnzipBytes(inBytes, ref startPos)); #endregion default: ULog.Log(string.Format("Recived unknow code {0} \n{1}", code, System.Text.Encoding.UTF8.GetString(inBytes, startPos, inBytes.Length)), ULogType.Warning); return(null); } }
byte[] EncodeUnknowComponent(Component component) { ULog.Log("Component " + component + " from " + component.gameObject.name + " encode as unknow."); //Debug.Log("EncodeUnknowComponent: "+component); var componentType = component.GetType(); var componentProperties = new Hashtable { { "class", componentType.FullName } }; var componentMi = componentType.GetMembers(); var ctCount = ComponentTypes.Length; var props = componentType.GetProperties(); foreach (var propertyInfo in props) { if (propertyInfo.GetCustomAttributes(typeof(SerializeRequire), true).Length > 0) { //Debug.Log("Encode property "+propertyInfo.Name); componentProperties.Add(propertyInfo.Name, propertyInfo.GetValue(component, null)); } } foreach (var memberInfo in componentMi) { //Debug.Log("EncodeUnknowComponent member : "+memberInfo.Name); if (memberInfo is FieldInfo) { var fi = (FieldInfo)memberInfo; if (!fi.IsNotSerialized)//[NonSerialized()] { var tp = fi.FieldType; for (var i = 0; i < ctCount; i++) { if (ComponentTypes[i] == tp || ComponentTypes[i] == tp.BaseType) { var val = fi.GetValue(component); if (val != null && val.ToString() != "null" && !componentProperties.ContainsKey(fi.Name)) { componentProperties.Add(fi.Name, val); } } } /*if (ComponentTypes.Contains(tp) || ComponentTypes.Contains(tp.BaseType)) * { * var val = fi.GetValue(component); * if (val != null && val.ToString() != "null") * componentProperties.Add(fi.Name, val); * }*/ } } else if (memberInfo is PropertyInfo) { var pi = (PropertyInfo)memberInfo; if (pi.CanWrite) { var tp = pi.PropertyType; for (var i = 0; i < ctCount; i++) { if (ComponentTypes[i] == tp || ComponentTypes[i] == tp.BaseType) { var obj = pi.GetValue(component, null); if (obj != null && obj.ToString() != "null" && !componentProperties.ContainsKey(pi.Name)) { componentProperties.Add(pi.Name, obj); } } } } } } /*if (Gateway.Debug) * ULog.Log("EncodeUnknowComponent END");*/ return(EncodeHashtable(componentProperties)); }
private static bool Comparison(object fieldValue, object comparedValue, string condition) { var result = false; try { if (fieldValue is Int32) { fieldValue = BitConverter.ToSingle(BitConverter.GetBytes((int)fieldValue), 0); } if (comparedValue is Int32) { comparedValue = BitConverter.ToSingle(BitConverter.GetBytes((int)comparedValue), 0); } switch (condition) { case "<": if ((float)fieldValue < (float)comparedValue) { result = true; } break; case "<=": if ((float)fieldValue <= (float)comparedValue) { result = true; } break; case "==": if (fieldValue.Equals(comparedValue)) { result = true; } break; case ">=": if ((float)fieldValue >= (float)comparedValue) { result = true; } break; case ">": if ((float)fieldValue > (float)comparedValue) { result = true; } break; case "!=": if (!fieldValue.Equals(comparedValue)) { result = true; } break; /*case "contains": * { * //string stringArray = comparedValue.ToString(); * var values = (IList)comparedValue;//stringArray.Split(new char[] { ';' }); * foreach (var val in values.Cast<object>().Where(val => ((IList)fieldValue).Contains(val) == true)) * { * result = true; * } * } * break; * case "!contains": * { * //string stringArray = comparedValue.ToString(); * var values = (IList)comparedValue; //stringArray.Split(new char[] { ';' }); * foreach (var val in values.Cast<object>().Where(val => ((IList)fieldValue).Contains(val) == true)) * { * result = true; * } * } * break;*/ /*case "exists": * { * var values = (IList)comparedValue; * if (values.Contains(fieldValue)) * { * result = true; * } * } * break; * case "!exists": * { * result = true; * var values = (IList)comparedValue; * if (values.Contains(fieldValue)) * { * result = false; * } * } * break;*/ } } catch (Exception e) { ULog.Log("CompareManager:Comparison:Error \n" + e.Message, ULogType.Error); //InvokeCompareError(new[]{fieldValue,comparedValue,condition}, CompareEventType.Error, e.Message); //Debug.LogError("CompareManager:Comparison error - " + e.Message); } return(result); }
internal byte[] Encoding(object sourceObject) { ULog.Log("Encoding " + sourceObject); byte code = 0x0; //null byte[] dataBytes; if (sourceObject == null || sourceObject.Equals(null)) { //Debug.LogWarning("Encoding IS NULL"); return(new[] { code }); } var sourceType = sourceObject.GetType(); //Not overrided rule serialization switch (sourceType.FullName) { #region Primitive 01-09 case "System.Boolean": return(EncodeBoolean((bool)sourceObject)); case "System.Int32": dataBytes = EncodeInteger((int)sourceObject); code = 3; break; case "System.Single": dataBytes = EncodeFloat((float)sourceObject); code = 4; break; case "System.String": dataBytes = EncodeString(sourceObject); code = 5; break; case "System.DateTime": dataBytes = EncodeDateTime((DateTime)sourceObject); code = 9; break; #endregion #region Unity Sctructures 16-~ case "UnityEngine.Vector2": dataBytes = EncodeVector2((Vector2)sourceObject); code = 16; break; case "UnityEngine.Vector3": dataBytes = EncodeVector3((Vector3)sourceObject); code = 17; break; case "UnityEngine.Vector4": dataBytes = EncodeVector4((Vector4)sourceObject); code = 18; break; case "UnityEngine.Quaternion": dataBytes = EncodeQuaternion((Quaternion)sourceObject); code = 19; break; case "UnityEngine.Color": dataBytes = EncodeColor((Color)sourceObject); code = 20; break; case "UnityEngine.Rect": //Rect dataBytes = EncodeRect((Rect)sourceObject); code = 21; break; case "UnityEngine.Matrix4x4": dataBytes = EncodeMatrix((Matrix4x4)sourceObject); code = 28; break; case "UnityEngine.Bounds": dataBytes = EncodeBounds((Bounds)sourceObject); code = 29; break; case "UnityEngine.BoneWeight": dataBytes = EncodeBoneWeight((BoneWeight)sourceObject); code = 30; break; /*case "UnityEngine.Keyframe": * dataBytes = EncodeKeyframe((Keyframe) sourceObject); * code = 31; * break;*/ #endregion default: var baseType = sourceType.BaseType; if (baseType == typeof(Enum)) { dataBytes = EncodeInteger((int)sourceObject); code = 3; break; } //Debug.Log(_objectList); //Debug.Log(sourceObject); if (!_objectList.ContainsValue(sourceObject)) { ULog.Log("New object " + sourceObject); var objectBytes = ResourceEncoding(sourceObject, sourceType, baseType); _objectList.Add(_objectListCount, sourceObject); _bytesList.Add(_objectListCount, objectBytes); _bytesLenght += objectBytes.Length; _objectListCount++; } var resourceIndexBytes = new byte[] { 251, 0, 0, 0, 0 }; Buffer.BlockCopy(EncodeInteger(GetResourceIndex(sourceObject)), 0, resourceIndexBytes, 1, 4); return(resourceIndexBytes); } var dataBytesLength = dataBytes.Length; var result = new byte[1 + dataBytesLength]; result[0] = code; Buffer.BlockCopy(dataBytes, 0, result, 1, dataBytesLength); ULog.Log("End encoding"); return(result); }
/// <summary> /// Returns the result of execution of command /// </summary> /// <param name="command">Command for run</param> /// <returns>Returns null or result</returns> public static object Execute(UCommand command) { object result = null; if (Targets.ContainsKey(command.target)) { try { /*if (command.IsPrevios) * command.value = result;*/ var targetObject = Targets[command.target]; if (Members.ContainsKey(string.Format("{0}.{1}", command.target, command.member))) { var targetMember = Members[string.Format("{0}.{1}", command.target, command.member)]; if (targetMember is FieldInfo) { ((FieldInfo)targetMember).SetValue(targetObject, command.value); } else if (targetMember is PropertyInfo) { ((PropertyInfo)targetMember).SetValue(targetObject, command.value, null); } else { try { /*if (evt.IsPrevios && evt.parameters.Length > evt.parameters.Length - 1)//???? >0 ??? * evt.parameters[evt.parameters.Length - 1] = previosResult;*/ result = ((MethodInfo)targetMember).Invoke(targetObject, command.parameters); } catch (Exception e) { ULog.Log("CommandManager:Execute:Method \n" + e.Message, ULogType.Error); //InvokeCommandError(command, CommandEventType.Error, e); //Debug.Log("Target is " + targetObject); //Debug.LogError("Unable to execute method " + eventTargetM.Name + " in target " + command.target); } } //InvokeCommandError(command, CommandEventType.NotFindMemebr); //Debug.LogWarning("Not find Field/Method : " + command.member + " in target " + command.target); } else { foreach (var member in Members) { ULog.Log("CommandManager:Execute:Member " + member.Key + ":" + member.Value.Name, ULogType.Warning); } ULog.Log("CommandManager:Execute:Member Not Find " + command.member, ULogType.Warning); } } catch (Exception e) { ULog.Log("CommandManager:Execute:Error \n" + e.Message, ULogType.Error); //InvokeCommandError(command,CommandEventType.Error,e); //Console.WriteLine("CommandManager: Execute error {0}", e.Message); } } else { ULog.Log("CommandManager:Execute:Target Not Find " + command.target, ULogType.Warning); } //InvokeCommandError(command, CommandEventType.NotFindTarget); //Debug.LogWarning("Not find target : " + command.target); return(result); }