void SetActiveMaterial(MaterialData materialData) { foreach (var mat in materials) { materialData.Apply(mat); } }
public override float Load() { LoadingBay loadingBay = MapManager.map.GetParcel <LoadingBay>(VehiclePos); if (materialQuantity != 0 && loadingBay.CanUnload(materialCurTransport)) { int materialSucessful = loadingBay.TryToInteract(materialCurTransport, materialQuantity); materialQuantity -= materialSucessful; return(2f); } else { foreach (MaterialData curMaterial in vehicleData.materialCanTransport) { if (loadingBay.GetMaterial(false).ContainsKey(curMaterial) && loadingBay.GetMaterial(false)[curMaterial].quantity > 0) { int materialSucessful = loadingBay.TryToInteract(curMaterial, materialQuantity - vehicleData.maxMaterialTransport); materialQuantity -= materialSucessful; materialCurTransport = curMaterial; return(2f); } } } return(0f); }
public static void SetUV(MaterialData mat, Mesh mesh, UVMapFn mapFn) { List <Vector2> uvs = new List <Vector2>(); for (int i = 0; i < mesh.vertices.Length; ++i) { uvs.Add(Vector2.zero); } for (int i = 0; i < mesh.triangles.Length; i += 3) { int t1 = mesh.triangles[i]; int t2 = mesh.triangles[i + 1]; int t3 = mesh.triangles[i + 2]; TriangleData td = new TriangleData(t1, t2, t3); Vector3 va = mesh.vertices[t1]; Vector3 vb = mesh.vertices[t2]; Vector3 vc = mesh.vertices[t3]; TriangleData.SetX(td, va.x, vb.x, vc.x); TriangleData.SetY(td, va.y, vb.y, vc.y); TriangleData.SetZ(td, va.z, vb.z, vc.z); mapFn(mat, td, uvs); } mesh.SetUVs(0, uvs); }
/// <summary> /// Handles <see cref="MaterialImportPackage.AddMaterial"/> as a wrapper around <seealso cref="MaterialData.AddRenderMaterial"/> /// </summary> /// <param name="mat"></param> private void AddMaterialHandler(RenderMaterial mat) { // get data access var materialData = new MaterialData(_doc); // add a different type of preview geometry, depending on the settings switch (RhinoBridgePlugIn.Instance.PreviewType) { case Settings.TexturePreviewGeometryType.Sphere: materialData.AddTexturedSphere(mat); break; case Settings.TexturePreviewGeometryType.Plane: materialData.AddTexturedPlane(mat); break; case Settings.TexturePreviewGeometryType.Cube: materialData.AddTexturedCube(mat); break; case Settings.TexturePreviewGeometryType.None: materialData.AddRenderMaterial(mat); break; } }
///////////////// public void Init(JsonObject json) { if (json == null) { return; } JsonArray equipments = json.Get <JsonArray>("equipments"); for (int i = 0; i < equipments.Count; i++) { string obj = (string)equipments[i]; EquipmentItem item = GameDataStorage.Instance.GetEquipmentByName(obj); PlayerEquipments.Add(item); } JsonArray materials = json.Get <JsonArray>("materials"); foreach (JsonObject item in materials) { MaterialData data = GameDataStorage.Instance.GetMaterialByName((string)item["name"]); int amount = item.GetInt("amount"); PlayerMaterials.Add(new MaterialInfo(data, amount)); } }
protected void Awake() { item = this.GetComponent <Item>(); module = item.data.GetModule <Shared.ProjectileModule>(); bladeMaterial = Catalog.GetData <MaterialData>("Blade", true); fleshMaterial = Catalog.GetData <MaterialData>("Flesh", true); }
//////////////// private void UpdateCurrentRecipe(CraftingData data) { if (data == null) { return; } m_CurrentRecipe = data; IItem craftItem = null; // определяем тип предмета if (m_CurrentRecipe.CraftItemType == ItemType.equipment) { craftItem = GameDataStorage.Instance.GetEquipmentByName(m_CurrentRecipe.CraftItemName); } else { MaterialData matData = GameDataStorage.Instance.GetMaterialByName(m_CurrentRecipe.CraftItemName); craftItem = new MaterialInfo(matData, 0); } // Отображаем иконку создаваевомого предмета m_ItemResultIcon.overrideSprite = craftItem.GetIcon(); // отображаем ингредиенты для крафта UpdateIngredientsView(); // показываем информацию о предмете крафта m_ItemInfoText.text = UIHelper.GetItemInformationText(craftItem); }
private static void SetDepthTesting(MaterialData mat, RenderInfoData r) { if (r.Type == Syroot.NintenTools.Bfres.RenderInfoType.String) { foreach (string value in r.Value_Strings) { switch (r.Name) { case "gsys_depth_test_enable": if (value == "true") { } else { } break; case "gsys_depth_test_func": if (value == "lequal") { } break; case "gsys_depth_test_write": break; default: break; } } } }
//////////////// private void UpdateIngredientsView() { MaterialData ingredient1 = GameDataStorage.Instance.GetMaterialByName(m_CurrentRecipe.Ingredient1); MaterialData ingredient2 = GameDataStorage.Instance.GetMaterialByName(m_CurrentRecipe.Ingredient2); // если у рецепта 2 ингредиента, то показываем вторую ячейку if (ingredient2 != null) { m_Ingredient2Icon.gameObject.SetActive(true); m_Ingredient2Amount.gameObject.SetActive(true); m_Ingredient2Icon.overrideSprite = ingredient2.GetIcon(); string ingredient2text = string.Format("{0} / {1}", InventoryContent.Instance.GetMaterialAmount(ingredient2), m_CurrentRecipe.Ingredient2Amount); m_Ingredient2Amount.text = ingredient2text; } else { m_Ingredient2Icon.gameObject.SetActive(false); m_Ingredient2Amount.gameObject.SetActive(false); } m_Ingredient1Icon.overrideSprite = ingredient1.GetIcon(); string ingredient1text = string.Format("{0} / {1}", InventoryContent.Instance.GetMaterialAmount(ingredient1), m_CurrentRecipe.Ingredient1Amount); m_Ingredient1Amount.text = ingredient1text; }
protected virtual void InitAxis() { materialData = Resources.Load <MaterialData>("ScriptableObjects/MaterialData"); scaleToViewpoint = transform.parent.parent.GetComponent <ScaleToViewpoint>(); root = scaleToViewpoint.transform.parent.gameObject; gizmoController = root.GetComponent <GizmoController>(); }
MaterialData MakeNewMaterial(Sprite sprite) { var newMaterial = new Material(DefaultMaterial); var materialData = new MaterialData(); materialData.Material = newMaterial; Texture spriteTexture = GetSpriteTexture(sprite); if (spriteTexture == null) { return(materialData); } newMaterial.mainTexture = spriteTexture; newMaterial.SetTexture("_EmissionMap", spriteTexture); //set pos materialData.Width = spriteTexture.width / sprite.pixelsPerUnit; materialData.Height = spriteTexture.height / sprite.pixelsPerUnit; materialData.XPos = ((spriteTexture.width / 2) - sprite.pivot.x) / sprite.pixelsPerUnit; materialData.YPos = ((spriteTexture.height / 2) - sprite.pivot.y) / sprite.pixelsPerUnit; return(materialData); }
//setea la info básica y muestra el panel de materiales public void SetPanelInfoMaterial(MaterialData matInfo) { foreach (TextMeshProUGUI a in textsMat) { if (a.name == "txtCaracteristicas") { a.text = "Caracteristicas: \n" + managerNullables(matInfo.Caracteristicas); } if (a.name == "txtPropiedades") { a.text = "Propiedades: \n" + managerNullables(matInfo.Propiedades); } if (a.name == "txtUsos") { a.text = "Usos: \n" + managerNullables(matInfo.Usos); } if (a.name == "txtClasificacion") { a.text = "Clasificación: \n" + managerNullables(matInfo.Clasificacion); } if (a.name == "txtNotas") { a.text = "Resumen: \n" + managerNullables(matInfo.Notas); } } }
public StructureRenderer(StructureData newData, MeshFilter newMeshFilter) { data = newData; meshFilter = newMeshFilter; meshFilter.mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; materials = new MaterialData(); }
public static void DamageCreatureCustom(Creature triggerCreature, float damageApplied, Vector3 hitPoint) { try { if (triggerCreature.currentHealth > 0) { MaterialData sourceMaterial = Catalog.GetData <MaterialData>("Metal", true); MaterialData targetMaterial = Catalog.GetData <MaterialData>("Flesh", true); DamageStruct damageStruct = new DamageStruct(DamageType.Pierce, damageApplied); CollisionInstance collisionStruct = new CollisionInstance(damageStruct, (MaterialData)sourceMaterial, (MaterialData)targetMaterial) { contactPoint = hitPoint }; triggerCreature.Damage(collisionStruct); if (collisionStruct.SpawnEffect(sourceMaterial, targetMaterial, false, out EffectInstance effectInstance)) { effectInstance.Play(); } } } catch { Debug.Log("[F-L42-RayCast][ERROR] Unable to damage enemy!"); } }
public override int TryToInteract(MaterialData material, int materialQuantityGive) { Debug.Log("TryToInteract: " + materialQuantityGive); if (material != PeopleMatarial) { return(0); } if (materialQuantityGive > 0) { return(materialQuantityGive); } if (-materialQuantityGive > PeopleWait) { GameManager.Money -= PeopleMatarial.buyPrice * PeopleWait; PeopleWait = 0; return(PeopleWait); } else { GameManager.Money -= PeopleMatarial.buyPrice * materialQuantityGive; PeopleWait += materialQuantityGive; return(materialQuantityGive); } }
private void BuildDataDictionnary() { Shader.ShaderUniformData[] shaderData = this._Shader.Uniforms; this._Data = new MaterialData[shaderData.Length]; this._DataInMaterial = new MaterialData[shaderData.Length]; for (int i = 0; i < shaderData.Length; i++) { Type csType = GetCsharpType(shaderData[i].Type); if (csType == null) { Debug.LogError("Unknown type \"" + shaderData[i].Type + "\", ignoring."); } else if (csType == typeof(Texture)) { if (Texture.Blank != null) { _Data[i] = _DataInMaterial[i] = new MaterialData(shaderData[i].Name, shaderData[i].Location, Texture.Blank, shaderData[i].Type); } else { _Data[i] = _DataInMaterial[i] = new MaterialData(shaderData[i].Name, shaderData[i].Location, Activator.CreateInstance(csType), shaderData[i].Type); } } else { _Data[i] = _DataInMaterial[i] = new MaterialData(shaderData[i].Name, shaderData[i].Location, Activator.CreateInstance(csType), shaderData[i].Type); } } }
internal void Use() { Shader.Use(); GL.BlendFuncSeparate(SourceColorBlending, DestinationColorBlending, SourceAlphaBlending, DestinationAlphaBlending); //set the lights DirectionalLight main = DirectionalLight.Main; if (main != null) { this.SetData <Vector4>("mainLightColor", main.Color); this.SetData <Vector3>("mainLightDirection", -main.WObject._RendersForward); this.SetData <Vector4>("mainLightAmbiant", main.Ambient); } int texCount = 0; for (int i = 0; i < _Data.Length; i++) { if (ReferenceEquals(_DataInMaterial[i].Data, _Data[i])) { continue; } MaterialData data = _DataInMaterial[i] = _Data[i]; SetGLData(ref data, ref texCount); } }
private static MaterialData GetMaterial(XDocument document, string materialName) { MaterialData matData = new MaterialData(); XElement mate = document.GetByID(materialName); if (mate == null) { return(matData); } XElement node = mate.GetNode("instance_effect"); if (node == null) { return(matData); } XElement effect = document.GetReference(node); //Get Data from Standard Material if (effect != null) { matData.Ambient = GetColor(effect, "ambient"); matData.Diffuse = GetColor(effect, "diffuse"); matData.DiffuseTexture = GetTextureName(effect, "diffuse"); matData.Ambient = GetColor(effect, "ambient"); matData.Emissive = GetColor(effect, "emission"); matData.Specular = GetColor(effect, "specular"); matData.SpecularPower = GetValue(effect, "shininess"); } return(matData); }
/// <summary> /// Created from the material information /// </summary> /// <param name="drawable">IDrawable applies</param> /// <param name="data">Material information</param> /// <returns>MMEEffect for material information</returns> public static MaterialInfo FromMaterialData(IDrawable drawable, MaterialData data) { MaterialInfo info = new MaterialInfo(); info.AmbientColor = new Vector4(data.Ambient, 1f); info.DiffuseColor = data.Diffuse; info.EdgeColor = data.EdgeColor; info.EmissiveColor = new Vector4(1f); info.GroundShadowColor = drawable.GroundShadowColor; info.SpecularColor = new Vector4(data.Specular, 1f); info.SpecularPower = data.SpecularCoefficient; info.ToonColor = new Vector4(0f); info.EdgeSize = data.EdgeSize; info.isEdgeEnable = data.bitFlag.HasFlag(RenderFlag.RenderEdge); info.isGroundShadowEnable = data.bitFlag.HasFlag(RenderFlag.GroundShadow); info.MulMaterialInfo = new MaterialInfo(); info.AddMaterialInfo = new MaterialInfo(); MaterialInfo initialInfo = new MaterialInfo(); initialInfo.AmbientColor = new Vector4(data.Ambient, 1f); initialInfo.DiffuseColor = data.Diffuse; initialInfo.EdgeColor = data.EdgeColor; initialInfo.EmissiveColor = new Vector4(1f); initialInfo.GroundShadowColor = drawable.GroundShadowColor; initialInfo.SpecularColor = new Vector4(data.Specular, 1f); initialInfo.SpecularPower = data.SpecularCoefficient; initialInfo.ToonColor = new Vector4(0f); initialInfo.EdgeSize = data.EdgeSize; info.InitialMaterialInfo = initialInfo; info.ResetMorphMember(); return(info); }
///////////////// public void AddMaterial(MaterialData material, int amount = 1) { if (material == null) { return; } MaterialInfo materialToAdd = null; foreach (MaterialInfo materialInfo in PlayerMaterials) { // если в инвентаре есть такой материал, то добавляем if (materialInfo.Data.Name == material.Name) { materialInfo.AddMaterial(amount); materialToAdd = materialInfo; break; } } // если материала в инвентаре не было, то создаем и прибавляем if (materialToAdd == null) { materialToAdd = new MaterialInfo(material, amount); PlayerMaterials.Add(materialToAdd); } if (OnInventoryContentChanged != null) { OnInventoryContentChanged(materialToAdd); } }
public WorldData(Accelerator device) { this.device = device; worldBuffer = new hWorldBuffer(device); worldBuffer.addGPUMesh(MeshLoader.LoadMeshFromFile(new Vec3(0, -1.5, 2), this, "Assets/defaultcube/defaultcube")); //worldBuffer.addGPUMesh(MeshLoader.LoadMeshFromFile(new Vec3(), this, "Assets/Tree/LowPolyTree")); //worldBuffer.addGPUMesh(MeshLoader.LoadMeshFromFile(new Vec3(0, 0.5, 0), this, "Assets/cat/cat")); //worldBuffer.addGPUMesh(MeshLoader.LoadMeshFromFile(new Vec3(), this, "Assets/cornellbox/cornellbox")); worldBuffer.addSphere(new Sphere(new Vec3(0, -1000, 0), 1, worldBuffer.addMaterial(MaterialData.makeLight(new Vec3(1, 1, 1))))); //worldBuffer.addSphere(new Sphere(new Vec3(0, 1000.5, -1), 1000, worldBuffer.addMaterial(MaterialData.makeDiffuse(new Vec3(0.99f, 0.99f, 0.99f))))); worldBuffer.addSphere(new Sphere(new Vec3(1.5, -1, -1), 0.5f, worldBuffer.addMaterial(MaterialData.makeGlass(new Vec3(0.99f, 0.99f, 0.99f), 1.3f)))); worldBuffer.addSphere(new Sphere(new Vec3(-1.5, -1, -1), 0.5f, worldBuffer.addMaterial(MaterialData.makeMirror(new Vec3(0.99f, 0.99f, 0.99f), 0f)))); Random random = new Random(5); for (int i = 0; i < 25; i++) { float size = (float)((random.NextDouble() * 0.25f) + 0.25f); Vec3 pos = new Vec3((random.NextDouble() * 10f) - 5f, (size / 2f) - 1f, (random.NextDouble() * 10f) - 5f); worldBuffer.addSphere(new Sphere(pos, size, worldBuffer.addMaterial(MaterialData.makeDiffuse(new Vec3( random.NextDouble() > 0.5 ? 0 : 1, random.NextDouble() > 0.5 ? 0 : 1, random.NextDouble() > 0.5 ? 0 : 1))))); } }
private static void SetDepthTesting(MaterialData mat, RenderInfoData r) { switch (r.Name) { case "gsys_depth_test_enable": if (r.Value_String == "true") { } else { } break; case "gsys_depth_test_func": if (r.Value_String == "lequal") { } break; case "gsys_depth_test_write": break; default: break; } }
public Material GetMaterial(MaterialData md) { Material m; if (md.illumType == 2) { string shaderName = (md.bumpTex != null)? "Bumped Specular" : "Specular"; m = new Material(Shader.Find(shaderName)); m.SetColor("_SpecColor", md.specular); m.SetFloat("_Shininess", md.shininess); } else { string shaderName = (md.bumpTex != null)? "Bumped Diffuse" : "Diffuse"; m = new Material(Shader.Find(shaderName)); } if (md.diffuseTex != null) { m.SetTexture("_MainTex", md.diffuseTex); } else { m.SetColor("_Color", md.diffuse); } if (md.bumpTex != null) { m.SetTexture("_BumpMap", md.bumpTex); } m.name = md.name; return(m); }
private void SetRenderMode(MaterialData mat, RenderInfoData r, Mesh m) { switch (r.Name) { case "gsys_render_state_mode": if (r.Value_String == "transparent") { m.isTransparent = true; } if (r.Value_String == "alpha") { m.isTransparent = true; } if (r.Value_String == "mask") { m.isTransparent = true; } break; case "mode": if (r.Value_Int == 1) { } if (r.Value_Int == 2) { m.isTransparent = true; } break; } }
public SubmeshData(MaterialData data, int[] _triangles) { materialData = data; triangles.Add(_triangles[0]); triangles.Add(_triangles[1]); triangles.Add(_triangles[2]); }
public static MaterialData ToMaterialData(this MaterialData data, MaterialPlanData planData) { return(new MaterialData(planData.Target, planData.DateAndAction, data.Actual, data.Comment)); }
internal MaterialState(BuildingType buildingType) { this.BuildingType = buildingType; this.BuildingId = (int)buildingType; this.materialData = player.materials.materials[BuildingId]; this.properties = tracker.buildingProperties.properties[BuildingId]; }
private Material GetMaterial(MaterialData md) { Material m; // commenter le 24 if (md.illumType == 2) { m = new Material(Shader.Find("Bumped Specular cut")); // m = new Material(Shader.Find("Diffuse")); m.SetColor("_Color", Color.black); m.SetFloat("_Shininess", md.shininess); // m.SetFloat("_Shininess", 10); } else { m = new Material(Shader.Find("Diffuse")); } m.SetColor("_Color", md.diffuse); if (md.diffuseTex != null) { m.SetTexture("_MainTex", md.diffuseTex); } return(m); }
public static MaterialData ToMaterialData(this MaterialData data, MaterialReportData reportData) { return(new MaterialData(data.Target, data.DateAndAction, reportData.Actual, reportData.Comment)); }
private void SetAlphaBlending(MaterialData mat, RenderInfoData r) { switch (r.Name) { case "gsys_color_blend_rgb_src_func": if (r.Value_String == "src_alpha") { mat.srcFactor = 1; } break; case "gsys_color_blend_rgb_dst_func": if (r.Value_String == "one_minus_src_alpha") { mat.dstFactor = 1; } break; case "gsys_color_blend_rgb_op": if (r.Value_String == "add") { } break; case "gsys_color_blend_alpha_op": if (r.Value_String == "add") { } break; case "gsys_color_blend_alpha_src_func": if (r.Value_String == "one") { } break; case "gsys_color_blend_alpha_dst_func": if (r.Value_String == "zero") { } break; case "gsys_alpha_test_func": break; case "gsys_alpha_test_value": break; case "sourceColorBlendFactor": if (r.Value_String == "sourceAlpha") { mat.srcFactor = 1; } break; default: break; } }
private Material GetMaterial(MaterialData md) { Material m; m = new Material(Shader.Find("Diffuse")); m.SetColor("_Color", md.diffuse); md.diffuseTex.Apply(); if(md.diffuseTex != null) m.SetTexture("_MainTex", md.diffuseTex); Debug.Log("paoku load texture wide=" + md.diffuseTex.width + ",height=" + md.diffuseTex.height); return m; }
public IEnumerator Load(string path) { WWW loader = new WWW(path); yield return loader; SetGeometryData(loader.text); if(hasMaterials) { loader = new WWW(basepath + mtllib); yield return loader; //ALTERATION 4:- Lets say the user moved the material library elsewhere //See also new function in GeometryBuffer ReturnMaterialNames() //and correction to OBJ.GetMaterial() to cater for this. if (loader.error != null) { //Could allow user to choose new path here for material library or create alert! string[] emats=buffer.ReturnMaterialNames(); //retrieves material names from groups // builds material data with defaults materialData = new List<MaterialData>(); MaterialData nmd = new MaterialData(); foreach(string mname in emats) { nmd = new MaterialData(); nmd.name = mname; nmd.diffuse = new Color(0.5f, 0.5f, 0.5f, 1.0f); materialData.Add(nmd); } } else { SetMaterialData(loader.text); foreach(MaterialData m in materialData) { if(m.diffuseTexPath != null) { WWW texloader = new WWW(basepath + m.diffuseTexPath); yield return texloader; m.diffuseTex = texloader.texture; } } } } Build(); }
void IConstructable.Construct(IDictionary<string, string> param) { var physData = ResourceFactory.LoadAsset<PhysicsData>(param["physData"]); materials = ResourceFactory.LoadAsset<MaterialData>(param["physData"]); octree = physData.Octree; }
private void SetMaterialData(string data) { //ALTERATION 1:- Major Problems with different OBJ file format whitespace, this helped:-. data = data.Replace("\r\n","\n"); string[] lines = data.Split("\n".ToCharArray()); materialData = new List<MaterialData>(); MaterialData current = new MaterialData(); for(int i = 0; i < lines.Length; i++) { string l = lines[i]; if(l.IndexOf("#") != -1) l = l.Substring(0, l.IndexOf("#")); //ALTERATION 1:- whitespace leading to null values, this helped:- l=Regex.Replace(l,@"\s+"," "); l=l.Trim(); string[] p = l.Split(" ".ToCharArray()); switch(p[0]) { case NML: current = new MaterialData(); current.name = p[1].Trim(); materialData.Add(current); break; case KA: current.ambient = gc(p); break; case KD: current.diffuse = gc(p); break; case KS: current.specular = gc(p); break; case NS: current.shininess = cf(p[1]) / 1000; break; case D: case TR: current.alpha = cf(p[1]); break; case MAP_KD: current.diffuseTexPath = p[1].Trim(); break; case ILLUM: current.illumType = ci(p[1]); break; } } }
private Material GetMaterial(MaterialData md) { Material m; if(md.illumType == 2) { m = new Material(Shader.Find("Specular")); m.SetColor("_SpecColor", md.specular); m.SetFloat("_Shininess", md.shininess); } else { m = new Material(Shader.Find("Diffuse")); } m.SetColor("_Color", md.diffuse); if(md.diffuseTex != null) m.SetTexture("_MainTex", md.diffuseTex); return m; }
private void SetMaterialData(string data) { string[] lines = data.Split("\n".ToCharArray()); materialData = new List<MaterialData>(); MaterialData current = new MaterialData(); for(int i = 0; i < lines.Length; i++) { string l = lines[i]; if(l.IndexOf("#") != -1) l = l.Substring(0, l.IndexOf("#")); string[] p = l.Split(" ".ToCharArray()); switch(p[0]) { case NML: current = new MaterialData(); current.name = p[1].Trim(); materialData.Add(current); break; case KA: current.ambient = gc(p); break; case KD: current.diffuse = gc(p); break; case KS: current.specular = gc(p); break; case NS: current.shininess = cf(p[1]) / 1000; break; case D: case TR: current.alpha = cf(p[1]); break; case MAP_KD: current.diffuseTexPath = p[1].Trim(); break; case ILLUM: current.illumType = ci(p[1]); break; } } }
/// <summary> /// 保存记录 /// </summary> /// <returns></returns> public SaveResult Save() { SaveResult result = new SaveResult(); //save new if(this.m_id == 0) { if(this.m_huohao.Trim() == string.Empty) { result.Code = CodeType.Error; result.Message = "[产品货号]不能为空或输入的不合法,无法保存!"; return result; } if (CheckProductHuoHaoExist(this.m_huohao.Trim())) { result.Code = CodeType.Error; result.Message = "[产品货号]重复,无法保存!"; return result; } if(this.m_partname_id == 0) { result.Code = CodeType.Error; result.Message = "[产品种类]不能为空,无法保存!"; return result; } if(this.m_dengji_id == 0) { result.Code = CodeType.Error; result.Message = "[产品等级]不能为空,无法保存!"; return result; } if(this.m_madeplace_id == 0) { result.Code = CodeType.Error; result.Message = "[产品产地]不能为空,无法保存!"; return result; } if(this.m_price == 0) { result.Code = CodeType.Error; result.Message = "[产品价格]不能为空,无法保存!"; return result; } if(this.m_safedata_id == 0) { result.Code = CodeType.Error; result.Message = "[安全标准]不能为空,无法保存!"; return result; } if(this.m_standarddata_id == 0) { result.Code = CodeType.Error; result.Message = "[执行标准]不能为空,无法保存!"; return result; } if(this.m_material_data_list.Count == 0) { result.Code = CodeType.Error; result.Message = "[面料成份信息列表]不能为空,无法保存!"; return result; } //当填充材质不为空时处理填充数据 if(!string.IsNullOrEmpty(this.MaterialFillInfo.material_type)) { foreach(MaterialFillInfoObject.MaterialFillData data in this.MaterialFillInfo.m_material_fill_list) { if(data.Fill == "0") { result.Code = CodeType.Error; result.Message = "填充规则数据制定不完整,请重新制定!"; return result; } } } ProductData info = new ProductData(); info.huohao = this.m_huohao; info.partname_id = this.m_partname_id; info.dengji_id = this.m_dengji_id; info.madeplace_id = this.m_madeplace_id; info.price = this.m_price; info.safedata_id = this.m_safedata_id; info.standarddata_id = this.m_standarddata_id; info.pwash = this.m_pwash == true ? 1:0; info.pbad = this.m_pbad == true ? 1:0; info.tag_id = this.GetTagFileNameId(); info.memo = this.m_memo; info.wash_id = this.GetWashFileNameId(); info.color_id = this.m_color_id; info.gyear = this.m_gyear; info.gmonth = this.m_gmonth; info.lastamp = System.Guid.NewGuid(); if(this.m_ptemplate) { info.ptemplate = 1; info.template_data = this.m_template_data; } if(info.tag_id == 0) { result.Code = CodeType.Error; result.Message = "系统未能找到对应的吊牌模板文件,保存无法继续!"; return result; } if(info.wash_id == 0) { if (this.m_partname_id == 21) info.wash_id = 1; else { result.Code = CodeType.Error; result.Message = "系统未能找到对应的洗唛模板文件,保存无法继续!"; return result; } } using (ProductContext ctx = new ProductContext()) { ctx.ProductData.Add(info); if(ctx.SaveChanges() == 0) { result.Code = CodeType.Error; result.Message = "产品基本信息保存失败"; return result; } } using (ProductContext ctx = new ProductContext()) { this.m_id = (from product in ctx.ProductData where product.huohao == this.m_huohao select product.id).FirstOrDefault(); } int index = 1; foreach(MaterialDataInfo ob in this.m_material_data_list) { using (ProductContext ctx = new ProductContext()) { MaterialData entity = new MaterialData(); entity.product_id = this.m_id; entity.sel = ob.Sel; entity.type = ob.Type; entity.order_index = index++; entity.memo = ob.Memo; entity.lastamp = System.Guid.NewGuid(); ctx.MaterialData.Add(entity); ctx.SaveChanges(); } } if(!string.IsNullOrEmpty(this.MaterialFillInfo.material_type)) { foreach(MaterialFillInfoObject.MaterialFillData fill in this.MaterialFillInfo.m_material_fill_list) { using (ProductContext ctx = new ProductContext()) { MaterialFill entity = new MaterialFill(); entity.product_id = this.m_id; entity.size_name = fill.SizeName; entity.type = this.MaterialFillInfo.material_type; entity.fill = fill.Fill; entity.lastamp = System.Guid.NewGuid(); ctx.MaterialFill.Add(entity); ctx.SaveChanges(); } } } result.Code = CodeType.Ok; result.Message = "保存成功!"; return result; } //Edit Save if(this.m_id > 0) { if (this.m_huohao.Trim() == string.Empty) { result.Code = CodeType.Error; result.Message = "[产品货号]不能为空或输入的不合法,无法保存!"; return result; } using (ProductContext ctx = new ProductContext()) { int count = (from product in ctx.ProductData where product.id == this.m_id && product.huohao == this.m_huohao select product).Count(); if(count > 1) { result.Code = CodeType.Error; result.Message = "[产品货号]重复,无法保存!"; return result; } } if (this.m_price == 0) { result.Code = CodeType.Error; result.Message = "[产品价格]不能为空,无法保存!"; return result; } if (this.m_safedata_id == 0) { result.Code = CodeType.Error; result.Message = "[安全标准]不能为空,无法保存!"; return result; } if (this.m_standarddata_id == 0) { result.Code = CodeType.Error; result.Message = "[执行标准]不能为空,无法保存!"; return result; } if (this.m_material_data_list.Count == 0) { result.Code = CodeType.Error; result.Message = "[面料成份信息列表]不能为空,无法保存!"; return result; } //当填充材质不为空时处理填充数据 if (!string.IsNullOrEmpty(this.MaterialFillInfo.material_type)) { foreach(MaterialFillInfoObject.MaterialFillData data in this.MaterialFillInfo.m_material_fill_list) { if(data.Fill == "0") { result.Code = CodeType.Error; result.Message = "填充规则数据制定不完整,请重新制定!"; return result; } } } using (ProductContext ctx = new ProductContext()) { System.Guid entity_lastamp = (from product in ctx.ProductData where product.id == this.m_id select product.lastamp).FirstOrDefault(); if(entity_lastamp != this.m_lastamp) { result.Code = CodeType.Error; result.Message = "当前编辑的记录已经变更,无法保存!"; return result; } } using (ProductContext ctx = new ProductContext()) { ProductData info = (from entity in ctx.ProductData where entity.id == this.m_id select entity).FirstOrDefault(); info.huohao = this.m_huohao; info.partname_id = this.m_partname_id; info.dengji_id = this.m_dengji_id; info.madeplace_id = this.m_madeplace_id; info.price = this.m_price; info.safedata_id = this.m_safedata_id; info.standarddata_id = this.m_standarddata_id; info.pwash = this.m_pwash == true ? 1:0; info.pbad = this.m_pbad == true ?1:0; info.memo = this.m_memo; info.tag_id = this.GetTagFileNameId(); info.wash_id = this.GetWashFileNameId(); info.color_id = this.m_color_id; info.gyear = this.m_gyear; info.gmonth = this.m_gmonth; info.lastamp = System.Guid.NewGuid(); if (this.m_ptemplate) { info.ptemplate = 1; info.template_data = this.m_template_data; } if (info.tag_id == 0) { result.Code = CodeType.Error; result.Message = "系统未能找到对应的吊牌模板文件,保存无法继续!"; return result; } if (info.wash_id == 0 ) { if(this.m_partname_id == 21) { info.wash_id = 1; } else { result.Code = CodeType.Error; result.Message = "系统未能找到对应的洗唛模板文件,保存无法继续!"; return result; } } if (ctx.SaveChanges() == 0) { result.Code = CodeType.Error; result.Message = "产品基本信息保存失败"; return result; } } //保存成份信息 using (ProductContext ctx = new ProductContext()) { var mi = from entity in ctx.MaterialData where entity.product_id == this.m_id select entity; foreach(var obj in mi) { ctx.MaterialData.Remove(obj); } ctx.SaveChanges(); } int index = 1; foreach (MaterialDataInfo ob in this.m_material_data_list) { using (ProductContext ctx = new ProductContext()) { MaterialData entity = new MaterialData(); entity.product_id = this.m_id; entity.sel = ob.Sel; entity.type = ob.Type; entity.order_index = index++; entity.memo = ob.Memo; entity.lastamp = System.Guid.NewGuid(); ctx.MaterialData.Add(entity); ctx.SaveChanges(); } } //////////////////////////////////////////////////////// using (ProductContext ctx = new ProductContext()) { var mi = from entity in ctx.MaterialFill where entity.product_id == this.m_id select entity; foreach (var obj in mi) { ctx.MaterialFill.Remove(obj); } ctx.SaveChanges(); } if (!string.IsNullOrEmpty(this.MaterialFillInfo.material_type)) { foreach (MaterialFillInfoObject.MaterialFillData fill in this.MaterialFillInfo.m_material_fill_list) { using (ProductContext ctx = new ProductContext()) { MaterialFill entity = new MaterialFill(); entity.product_id = this.m_id; entity.size_name = fill.SizeName; entity.type = this.MaterialFillInfo.material_type; entity.fill = fill.Fill; entity.lastamp = System.Guid.NewGuid(); ctx.MaterialFill.Add(entity); ctx.SaveChanges(); } } } result.Code = CodeType.Ok; result.Message = "保存成功!"; return result; } return result; }
private void BumpParameter(MaterialData m, string[] p) { Regex regexNumber = new Regex(@"^[-+]?[0-9]*\.?[0-9]+$"); var bumpParams = new Dictionary<String, BumpParamDef>(); bumpParams.Add("bm",new BumpParamDef("bm","string", 1, 1)); bumpParams.Add("clamp",new BumpParamDef("clamp", "string", 1,1)); bumpParams.Add("blendu",new BumpParamDef("blendu", "string", 1,1)); bumpParams.Add("blendv",new BumpParamDef("blendv", "string", 1,1)); bumpParams.Add("imfchan",new BumpParamDef("imfchan", "string", 1,1)); bumpParams.Add("mm",new BumpParamDef("mm", "string", 1,1)); bumpParams.Add("o",new BumpParamDef("o", "number", 1,3)); bumpParams.Add("s",new BumpParamDef("s", "number", 1,3)); bumpParams.Add("t",new BumpParamDef("t", "number", 1,3)); bumpParams.Add("texres",new BumpParamDef("texres", "string", 1,1)); int pos = 1; string filename = null; while (pos < p.Length) { if (!p[pos].StartsWith("-")) { filename = p[pos]; pos++; continue; } // option processing string optionName = p[pos].Substring(1); pos++; if (!bumpParams.ContainsKey(optionName)) { continue; } BumpParamDef def = bumpParams[optionName]; ArrayList args = new ArrayList(); int i=0; bool isOptionNotEnough = false; for (;i<def.valueNumMin ; i++, pos++) { if (pos >= p.Length) { isOptionNotEnough = true; break; } if (def.valueType == "number") { Match match = regexNumber.Match(p[pos]); if (!match.Success) { isOptionNotEnough = true; break; } } args.Add(p[pos]); } if (isOptionNotEnough) { Debug.Log("bump variable value not enough for option:"+optionName+" of material:"+m.name); continue; } for (;i<def.valueNumMax && pos < p.Length ; i++, pos++) { if (def.valueType == "number") { Match match = regexNumber.Match(p[pos]); if (!match.Success) { break; } } args.Add(p[pos]); } // TODO: some processing of options Debug.Log("found option: "+optionName+" of material: "+m.name+" args: "+String.Concat(args.ToArray())); } if (filename != null) { m.bumpTexPath = filename; } }
private WWW GetTextureLoader(MaterialData m, string texpath) { char[] separators = {'/', '\\'}; string[] components = texpath.Split(separators); string filename = components[components.Length-1]; string ext = Path.GetExtension(filename).ToLower(); if (ext != ".png" && ext != ".jpg") { Debug.LogWarning("maybe unsupported texture format:"+ext); } WWW texloader = new WWW(basepath + filename); Debug.Log("texture path for material("+m.name+") = "+(basepath + filename)); return texloader; }
public void setType(MaterialData dataToSet) { this.data = dataToSet; }
private Material GetMaterial(MaterialData md) { Material m; if(md.illumType == 2) { string shaderName = (md.bumpTex != null)? "Bumped Specular" : "Specular"; m = new Material(Shader.Find(shaderName)); m.SetColor("_SpecColor", md.specular); m.SetFloat("_Shininess", md.shininess); } else { string shaderName = (md.bumpTex != null)? "Bumped Diffuse" : "Diffuse"; m = new Material(Shader.Find(shaderName)); } if(md.diffuseTex != null) { m.SetTexture("_MainTex", md.diffuseTex); } else { m.SetColor("_Color", md.diffuse); } if(md.bumpTex != null) m.SetTexture("_BumpMap", md.bumpTex); m.name = md.name; return m; }
private Material GetMaterial(MaterialData md) { Material m; string shaderName; if(md.illumType == 2) { if (useLegacyShaders) { shaderName = (md.bumpTex != null)? LEGACY_BUMPED_SPECULAR_SHADER : LEGACY_SPECULAR_SHADER; } else { shaderName = (md.bumpTex != null)? BUMPED_SPECULAR_SHADER : SPECULAR_SHADER; } m = new Material(Shader.Find(shaderName)); m.SetColor("_SpecColor", md.specular); m.SetFloat("_Shininess", md.shininess); } else { if (useLegacyShaders) { shaderName = (md.bumpTex != null)? LEGACY_BUMPED_DIFFUSE_SHADER : LEGACY_DIFFUSE_SHADER; } else { shaderName = (md.bumpTex != null)? BUMPED_DIFFUSE_SHADER : DIFFUSE_SHADER; } m = new Material(Shader.Find(shaderName)); } if(md.diffuseTex != null) { m.SetTexture("_MainTex", md.diffuseTex); } else { m.SetColor("_Color", md.diffuse); } if(md.bumpTex != null) m.SetTexture("_BumpMap", md.bumpTex); m.name = md.name; return m; }
private void SetMaterialData(string data) { string[] lines = data.Split("\n".ToCharArray()); materialData = new List<MaterialData>(); MaterialData current = new MaterialData(); Regex regexWhitespaces = new Regex(@"\s+"); for(int i = 0; i < lines.Length; i++) { string l = lines[i].Trim(); if(l.IndexOf("#") != -1) l = l.Substring(0, l.IndexOf("#")); string[] p = regexWhitespaces.Split(l); if (p[0].Trim() == "") continue; switch(p[0]) { case NML: current = new MaterialData(); current.name = p[1].Trim(); materialData.Add(current); break; case KA: current.ambient = gc(p); break; case KD: current.diffuse = gc(p); break; case KS: current.specular = gc(p); break; case NS: current.shininess = cf(p[1]) / 1000; break; case D: case TR: current.alpha = cf(p[1]); break; case MAP_KD: current.diffuseTexPath = p[p.Length-1].Trim(); break; case MAP_BUMP: case BUMP: BumpParameter(current, p); break; case ILLUM: current.illumType = ci(p[1]); break; default: Debug.Log("this line was not processed :" +l ); break; } } }
public Block(MaterialData d) { this.data = d; }