public void saveObjectProps(ObjectProps objectProps, int id) { var serProps = json.Serialize(objectProps); var sel = context.Properties.Where(c => c.ObjectId == id && c.PropId == 0).FirstOrDefault(); sel.Value = serProps; context.SaveChanges(); }
public ObjectProps getObjectProps(int id) { var sel1 = context.Properties.AsNoTracking().Where(c => c.ObjectId == id && c.PropId == 0).FirstOrDefault(); var sel2 = context.Objects.Find(id); var Props = new ObjectProps(); string JSONprop = sel1.Value; var propsDes = json.Deserialize(JSONprop, Props.GetType()); Props = (ObjectProps)propsDes; Props.Id = id; Props.Name = sel2.Name; return(Props); }
/* * Questo script gestisce la descrizione degli oggetti nella finestra nella parte in alto a sinistra dello schermo * Vengono gestite anche le interazioni con gli oggetti integibili e le armi. * Quando si interagisce con le armi la logica di tale operazione viene gestita in parte qui e in parte nello script WeaponHolderManager * Quando si interagisce con gli oggetti essi vengono gestiti tramite un'interfaccia che comunichera' l'evento agli script che sono in ascolto */ void WriteDescription() { // quando un oggetto nella scena ha questo tag, il sistema lo vede come un'arma equipaggiabile // le informazioni dell'arma che vengono scritte nella finestra delle informazioni vengono prese direttamente dallo script che presente nell'oggetto if (objectToDescribe.CompareTag("DetailedWeapon") || objectToDescribe.GetComponent <WeaponProps>() != null || objectToDescribe.transform.GetComponent <WeaponProps>() != null) { WeaponProps weapon = objectToDescribe.GetComponent <WeaponProps>(); // impostazione delle informazioni dell'oggetto sulla finestra // l'oggetto deve avere per forza un componente WeaponProps per essere descritto if (objectToDescribe.GetComponent <WeaponProps>() != null) { weapon = objectToDescribe.GetComponent <WeaponProps>(); titleText.text = weapon._name; descriptionText.text = weapon._description + "\n\nAmmo: " + weapon._currentAmmo + "/" + weapon._maxAmmo + "\nDamage: " + weapon._damage; } else { // in caso non ci siano informazioni sull'arma SetDefaultDescriptionInformations(); } // gestione dell'interazione con l'arma ManageWeaponInteraction(weapon); } else if (objectToDescribe.CompareTag("DetailedObject") || objectToDescribe.GetComponent <ObjectProps>() != null) { ObjectProps obj = objectToDescribe.GetComponent <ObjectProps>(); // impostazione delle informazioni dell'oggetto sulla finestra // l'oggetto deve avere per forza un componente ObjectProps per essere descritto if (objectToDescribe.GetComponent <ObjectProps>() != null) { obj = objectToDescribe.GetComponent <ObjectProps>(); titleText.text = obj._name; descriptionText.text = obj._description; } else { // in caso non ci siano informazioni sull'oggetto SetDefaultDescriptionInformations(); } // gestione dell'interazione con gli oggetti interagibili ManageObjectInteraction(obj); } }
public void ShowProperties(object obj) { object selObj = obj; if (MainForm.PropertiesUserControl.SelectedObject == selObj) { return; } string caption = Locale.Get("_properties"); if (obj is GObject) { GObject gobj = (GObject)obj; selObj = new ObjectProps(gobj); caption = Locale.Get("_gobject"); mainForm.TypesUserControl.SelectType(gobj.Type); } else if (obj is GType) { selObj = new TypeProps((GType)obj); caption = Locale.Get("_gtype"); } else if (obj is GLib) { selObj = new LibProps((GLib)obj); caption = Locale.Get("_glib"); } else if (obj is BgImage) { selObj = new BgImageProps((BgImage)obj); caption = Locale.Get("_bgimage"); } /* else if (obj is Config) * { * selObj = new OptionsProps((Config)obj); * caption = Locale.Get("_optionsprops"); * }*/ else if (obj is Stat) { selObj = new StatProps((Stat)obj); caption = Locale.Get("_stat"); } else if (obj is LibStatProps || obj is StatProps) { caption = Locale.Get("_stat"); } StringUtils.RemoveHotKey(ref caption); MainForm.PropertiesUserControl.Text = caption; MainForm.PropertiesUserControl.SelectedObject = selObj; }
public static void saveSceneData () { JsonData gjson; GameObject[] objs = FindObjectsOfType(typeof(GameObject)) as GameObject[]; ObjectProps[] elms = new ObjectProps[objs.Length]; for (int i=0; i<objs.Length; i++) { Vector3 rotation = new Vector3 ( objs[i].transform.localRotation.x , objs[i].transform.localRotation.y,objs[i].transform.localRotation.z); elms[i] = new ObjectProps(objs[i].name ,objs[i].transform.position, rotation ,objs[i].transform.localScale); } gjson = JsonMapper.ToJson(elms); Debug.Log("object json "+ gjson); File.WriteAllText(Application.dataPath+"/Resources/Data/SceneData.json", gjson.ToString()); }
public static void saveEnvironmentData() { JsonData gjson; GameObject[] objs = GameObject.FindGameObjectsWithTag("Environment") as GameObject[]; ObjectProps[] elms = new ObjectProps[objs.Length]; for (int i = 0; i < objs.Length; i++) { Vector3 rotation = new Vector3(objs[i].transform.localRotation.x, objs[i].transform.localRotation.y, objs[i].transform.localRotation.z); elms[i] = new ObjectProps(objs[i].name, objs[i].transform.position, rotation, objs[i].transform.localScale); } gjson = JsonMapper.ToJson(elms); Debug.Log("object json " + gjson); File.WriteAllText(Application.dataPath + "/Resources/Data/SceneEnvironmentData.json", gjson.ToString()); }
public ActionResult EditObjectProps(ObjectProps model) { if (ModelState.IsValid) { var IdForSave = model.Id; tagConfigurator.saveObjectProps(model, IdForSave); ViewBag.Notification = 1; } else { ViewBag.Notification = 0; } List <moduleCondition> ActiveModules = connectedModules.Where(m => m.isConnected == true).ToList(); ViewBag.ActiveModules = ActiveModules; ViewBag.SelectChannel = tagConfigurator.getChannels(model.Id); return(PartialView("ObjectPartial", model)); }
public ActionResult EditObjectProps(ObjectProps model) { if (ModelState.IsValid) { var IdForSave = model.Id; tagConfigurator.saveObjectProps(model, IdForSave); ViewBag.Notification = 1; } else { ViewBag.Notification = 0; //ModelState.AddModelError("", "Введены некорректные данные!"); } ViewBag.ActiveModules = tagConfigurator.GetConnectedModules(); var userProps = tagConfigurator.getUserProps(model.Id); ViewBag.UserProps = userProps; ViewBag.SelectChannel = tagConfigurator.getChannels(); return(PartialView("ObjectPartial", model)); }
// gestione dell'interazione con gli oggetti private void ManageObjectInteraction(ObjectProps obj) { if (obj != null) { if (obj._interactable) { textWindow.alpha = 1; buttonToPressText.text = obj._InteractText; // se l'oggetto e' interactable lo script che deve gestire l'interazione viene avvisato grazie all'interrfaccia implementata IOnActionButtonPressed onButton = objectToDescribe.GetComponent <IOnActionButtonPressed>(); if (Input.GetButtonDown("Interact")) { if (onButton != null) { onButton.OnButtonPressed(); textWindow.alpha = 0; } } } } }
private void LateUpdate() { // Moving distant objects to farLayer foreach (Transform child in transform) { if (child.position.sqrMagnitude > sqrThreshold) { int objID = child.gameObject.GetInstanceID(); ObjectProps childProps = new ObjectProps() { scale = child.localScale, physical = false, }; Debug.LogFormat("moving object with scale {0}:{1}:{2} to far layer.", child.localScale.x, child.localScale.y, child.localScale.z); // Normal rigidbodies go nuts after rescaling Rigidbody rb = child.gameObject.GetComponent <Rigidbody>(); if (rb != null) { Debug.Log("Has rigidbody: " + rb); childProps.physical = !rb.isKinematic; rb.Sleep(); rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; rb.isKinematic = true; } if (objectPropsDict.ContainsKey(objID)) { objectPropsDict[objID] = childProps; } else { objectPropsDict.Add(objID, childProps); } child.localScale = child.localScale * layerScale; child.position = child.position * layerScale; child.parent = farLayerContainer; SetLayerRecursively(child.gameObject, farLayerID); } } // Moving close objects to mainLayer foreach (Transform child in farLayerContainer) { int objID = child.gameObject.GetInstanceID(); if (child.position.sqrMagnitude < sqrReverseThreshold && !farObjIDsToIgnore.Contains(objID)) { child.parent = transform; child.position = child.position / layerScale; if (objectPropsDict.ContainsKey(objID)) { child.localScale = objectPropsDict[objID].scale; // Make rigidbody physical again if applicable Rigidbody rb = child.gameObject.GetComponent <Rigidbody>(); if (rb != null) { rb.isKinematic = !objectPropsDict[objID].physical; rb.WakeUp(); } } else { child.localScale = child.localScale / layerScale; Debug.LogErrorFormat("Original scale of object {0} was not found while moving to main layer", objID); } SetLayerRecursively(child.gameObject, mainLayerID); } } }