public override void Emplace <T>(T t) { UnityEngine.GameObject obj = t as UnityEngine.GameObject; if (obj != null) { transform.Emplace <UnityEngine.Transform>(obj.transform); obj.name = prefab; if (EnableLog) { Debug.Log("emplace object name=" + obj.name); } CustomerPropertyBase com = obj.GetComponent <CustomerPropertyBase>(); //自定义属性 if ((com != null) && (extPropJson != "")) { com.OnDeseriazlie(extPropJson); //Type type = com.GetType(); //FieldInfo field = type.GetField("serialization"); //if (field != null) //{ // extPropJson = JsonMapper.ToJson(field.GetValue(com)); // extPropClassName = field.GetValue(com).GetType().Name; // extPropClassIndex = MapEditor.MapEditorUtils.GetClassIndex(extPropClassName); //} } } else { Debug.LogWarning("type error cast " + t.GetType().ToString() + " to " + this.GetType().ToString()); } }
private void OnSelectedParameterChanged(int index) { print("Parameter Select index: " + index); filedIndex = index; FieldInfo fi = fields[filedIndex]; if (fi.GetType() == typeof(System.Boolean)) { sliderParameter.gameObject.SetActive(false); txtParameter.gameObject.SetActive(false); } else { sliderParameter.gameObject.SetActive(true); txtParameter.gameObject.SetActive(true); if (componentObj != null) { CustomerPropertyBase com = componentObj.GetComponent <CustomerPropertyBase>(); if (com != null) { Type type = com.GetType(); FieldInfo field = type.GetField("serialization"); if (field != null) { var value = field.GetValue(com); var subFiledValue = fi.GetValue(value); if (fi.FieldType == typeof(System.Int32)) { txtParameter.gameObject.SetActive(true); sliderParameter.gameObject.SetActive(true); sliderParameter.value = (int)subFiledValue; txtParameter.text = subFiledValue.ToString(); } else if (fi.FieldType == typeof(System.Single)) { txtParameter.gameObject.SetActive(true); sliderParameter.gameObject.SetActive(true); sliderParameter.value = (float)subFiledValue; txtParameter.text = subFiledValue.ToString(); } else { txtParameter.gameObject.SetActive(false); sliderParameter.gameObject.SetActive(false); } } } } } }
public void InitData(GameObject objRoot) { componentObj = objRoot; if (objRoot != null) { CustomerPropertyBase com = objRoot.GetComponent <CustomerPropertyBase>(); if (com != null) { Type type = com.GetType(); FieldInfo field = type.GetField("serialization"); if (field != null) { List <Dropdown.OptionData> options = new List <Dropdown.OptionData>(); Debug.Log("field.FieldType: " + field.FieldType.ToString()); fields = Reflection.GetSerializableFields(field.FieldType); var value = field.GetValue(com); for (int i = 0; i < fields.Length; ++i) { MemberInfo memberInfo = fields[i]; Type type1 = fields[i].FieldType; //Debug.Log("sub type name: " + type1.ToString()); Debug.Log("Filed Name: " + memberInfo.Name); Debug.Log("Filed Value: " + fields[i].GetValue(value)); var v = (DescriptionAttribute[])memberInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); var descriptionName = v[0].Description; //options.Add(new Dropdown.OptionData(memberInfo.Name)); options.Add(new Dropdown.OptionData(descriptionName)); } dropDownParameterList.options = options; } else { dropDownParameterList.gameObject.SetActive(false); } } } }
public override void Fill <T>(T t) { if (t is UnityEngine.GameObject) { var obj = t as UnityEngine.GameObject; this.transform = SerializeBase.Create <Serializable.Transform, UnityEngine.Transform>(obj.transform); prefab = obj.name; //从父节点名字获取所属层 int.TryParse(obj.transform.parent.gameObject.name.Substring(5), out layerIndex); decorateIndex = MapEditorMgr.ins.GetDecorateIndex(obj); if (EnableLog) { Debug.Log("fill map ojbect name=" + obj.name); } CustomerPropertyBase com = obj.GetComponent <CustomerPropertyBase>(); //自定义属性 if (com != null) { Type type = com.GetType(); FieldInfo field = type.GetField("serialization"); if (field != null) { //extPropJson = JsonMapper.ToJson(field.GetValue(com)); //extPropClassName = field.GetValue(com).GetType().Name; //extPropClassIndex = MapEditor.MapEditorUtils.GetClassIndex(extPropClassName); } } return; } else { Debug.LogWarning("type error cast " + t.GetType().ToString() + " to " + this.GetType().ToString()); } }
private void OnParameterChanged(float value) { if (txtParameter != null) { txtParameter.text = value.ToString(); } FieldInfo fi = fields[filedIndex]; if ((fi.FieldType == typeof(System.Int32)) || (fi.FieldType == typeof(System.Single))) { if (componentObj != null) { CustomerPropertyBase com = componentObj.GetComponent <CustomerPropertyBase>(); if (com != null) { Type type = com.GetType(); FieldInfo field = type.GetField("serialization"); if (field != null) { var rootValue = field.GetValue(com); if (fi.FieldType == typeof(System.Int32)) { fi.SetValue(rootValue, (int)value); } else { fi.SetValue(rootValue, value); } Debug.Log("@@@@@subFiledValue setNewValue: " + value); } } } } }
//------------地图额外配置信息 //--------------------------- public void Reload(MapEditorStroageData data) { data.ReloadJson(); {//reload spawn point var list = this.GetComponentsInChildren <MapObjectSpawnPoint>(true); if (list.Length != data._spawn_points.Count) { Debug.LogError("0check length is right when reload MapEditor.Reload " + list.Length + " " + data._spawn_points.Count); } for (int i = 0; i < list.Length; i++) { list[i].transform.position = data._spawn_points[i].position; } } {//reload weapon spawn point var list = this.GetComponentsInChildren <MapObjectWeaponSpawnPoint>(true); if (list.Length != data._weapon_spawn_points.Count) { Debug.LogError("1check length is right when reload MapEditor.Reload " + list.Length + " " + data._weapon_spawn_points.Count); } for (int i = 0; i < list.Length; i++) { list[i].transform.position = data._weapon_spawn_points[i].position; list[i]._weapon_ids = new List <int>(data._weapon_spawn_points[i].ids); } } {//reload layer and map obect and map object decroate LayerMgr.ins.Clear(); foreach (var l in data._layer_objs) { LayerMgr.ins.CreateLayer(l); //GameObject layer = new GameObject("layer" + l.layerIndex.ToString()); //layer.transform.parent = LayerMgr.ins.transform; //layers[l.layerIndex-1] = layer.transform; } GameObject obj = null; foreach (var p in data._map_objs) { if (p.layerIndex > 0) { obj = CreateObject(p.prefab, LayerMgr.ins.GetLayerByIndex(p.layerIndex)); if (obj != null) { obj.transform.position = p.position; CustomerPropertyBase com = obj.GetComponent <CustomerPropertyBase>(); //自定义属性 if ((com != null) && (p.extPropJson != "")) { com.OnDeseriazlie(p.extPropJson); } } } else { obj = CreateObject(p.prefab, LayerMgr.ins.transform); if (obj != null) { obj.transform.position = p.position; CustomerPropertyBase com = obj.GetComponent <CustomerPropertyBase>(); //自定义属性 if ((com != null) && (p.extPropJson != "")) { com.OnDeseriazlie(p.extPropJson); } } } } } // this.map_brief = data.map_brief; // this.map_name = data.map_name; //加载了目标地图 需要恢复状态 MapEditorStroageData.current_map_brief = data.map_brief; MapEditorStroageData.current_map_name = data.map_name; //在编辑地图入口时会设置 MapEditor.MapObjectRoot.record_json ; #if UNITY_EDITOR //修改 边缘 大小 if (UIPanelMapInfoParkour.ins != null && MapEditor.MapEditorConfig.CurrentMapGameMode == MapGameMode.Parkour) { UIPanelMapInfoParkour.ins.Reset(); } #endif }