private void OnDestroy() { if (Instance == this) { Instance = null; } }
private void Awake() { if (Instance) { Debug.LogWarning("MaterialDict already in scene! Deleting myself!"); Destroy(this); return; } Instance = this; }
public void SetProgram(string displayName) { if (!MaterialDict.TryGetValue(displayName ?? "unrecognized", out var material)) { var color = random.NextColor(); color.Alpha = 0.5; MaterialDict[displayName] = new Material(displayName, color); material = MaterialDict[displayName]; } this.Material = material; this.ProgramName = displayName; this.Name = Requirements.TryGetValue(displayName, out var fullReq) ? fullReq.HyparSpaceType : displayName; }
public static SpaceBoundary Make(Profile profile, string displayName, Transform xform, double height, Vector3?parentCentroid = null, Vector3?individualCentroid = null) { MaterialDict.TryGetValue(displayName ?? "unspecified", out var material); var representation = new Representation(new[] { new Extrude(profile, height, Vector3.ZAxis, false) }); var name = Requirements.TryGetValue(displayName, out var fullReq) ? fullReq.HyparSpaceType : displayName; var sb = new SpaceBoundary(profile, new List <Polygon> { profile.Perimeter }, xform, material ?? MaterialDict["unrecognized"], representation, false, Guid.NewGuid(), name); sb.ProgramName = displayName; sb.AdditionalProperties.Add("ParentCentroid", parentCentroid ?? xform.OfPoint(profile.Perimeter.Centroid())); sb.AdditionalProperties.Add("IndividualCentroid", individualCentroid ?? xform.OfPoint(profile.Perimeter.Centroid())); return(sb); }
/// <summary> /// CreateRawMaterial creates new record in Raw Materials table, inserts/updates Note table and inserts/updates /// </summary> /// <param name="rawMObject"></param> /// <param name="userId"></param> /// <returns>int</returns> public int CreateRawMaterial(int userId, RawMaterialObject rawMObject) { //define method execution return value to be false by default int retMthdExecResult = 0; int materialDictID = 0; int distillerId = _dl.GetDistillerId(userId); if (rawMObject != null) { try { MaterialDict matDict = new MaterialDict(); matDict.Name = rawMObject.RawMaterialName; matDict.UnitOfMeasurementID = rawMObject.UnitTypeId; matDict.DistillerID = distillerId; if (rawMObject.Note != string.Empty && rawMObject.Note != null) { matDict.Note = rawMObject.Note; } _db.MaterialDict.Add(matDict); _db.SaveChanges(); materialDictID = matDict.MaterialDictID; // build relationships between given raw material and purchase material types if (rawMObject.PurchaseMaterialTypes.Additive) { MaterialType matType = new MaterialType(); matType.MaterialDictID = materialDictID; matType.Name = "Additive"; _db.MaterialType.Add(matType); _db.SaveChanges(); } if (rawMObject.PurchaseMaterialTypes.Distilled) { MaterialType matType = new MaterialType(); matType.MaterialDictID = materialDictID; matType.Name = "Distilled"; _db.MaterialType.Add(matType); _db.SaveChanges(); } if (rawMObject.PurchaseMaterialTypes.Fermentable) { MaterialType matType = new MaterialType(); matType.MaterialDictID = materialDictID; matType.Name = "Fermentable"; _db.MaterialType.Add(matType); MaterialDict2MaterialCategory md2mc = new MaterialDict2MaterialCategory(); md2mc.MaterialDictID = materialDictID; md2mc.ProductionReportMaterialCategoryID = rawMObject.MaterialCategoryID; _db.MaterialDict2MaterialCategory.Add(md2mc); _db.SaveChanges(); } if (rawMObject.PurchaseMaterialTypes.Fermented) { MaterialType matType = new MaterialType(); matType.MaterialDictID = materialDictID; matType.Name = "Fermented"; _db.MaterialType.Add(matType); MaterialDict2MaterialCategory md2mc = new MaterialDict2MaterialCategory(); md2mc.MaterialDictID = materialDictID; md2mc.ProductionReportMaterialCategoryID = rawMObject.MaterialCategoryID; _db.MaterialDict2MaterialCategory.Add(md2mc); _db.SaveChanges(); } if (rawMObject.PurchaseMaterialTypes.Supply) { MaterialType matType = new MaterialType(); matType.MaterialDictID = materialDictID; matType.Name = "Supply"; _db.MaterialType.Add(matType); _db.SaveChanges(); } retMthdExecResult = materialDictID; } catch { retMthdExecResult = 0; throw; } } return(retMthdExecResult); }