private void DetectInteractable() { bool can_interact = false; var scene = Universe.GetScene <PhysicsScene>(); Vec3 origin = m_CameraEntity.Position; Vec3 dir = -m_CameraEntity.Direction; RaycastHit hit = new RaycastHit(); scene.RaycastEx(origin, dir, 1.5f, ref hit, entity); if (hit.EntityID != -1) { Entity e = Universe.GetEntity(hit.EntityID); Holdable holdable = e.GetComponent <Holdable>(); if (holdable != null) { can_interact = true; if (m_IsKeyPressed.ContainsKey('e')) { Hold(e); } } } m_HoldNoticeUI.GetComponent <GuiRect>().IsEnabled = can_interact; }
public void OnUndo(IntPtr editor, string property, string value) { var field = this.GetType().GetField(property); if (field == null) { return; } Type field_type = field.FieldType; if (field_type == typeof(int)) { field.SetValue(this, int.Parse(value)); } else if (field_type == typeof(float)) { field.SetValue(this, float.Parse(value)); } else if (field_type == typeof(bool)) { field.SetValue(this, bool.Parse(value)); } else if (field_type == typeof(string)) { field.SetValue(this, value); } else if (field_type == typeof(Lumix.Entity)) { int entity_id = int.Parse(value); Entity e = Universe.GetEntity(entity_id); field.SetValue(this, e); } else if (field_type.BaseType == typeof(Lumix.Resource)) { var resource = Activator.CreateInstance(field_type, new object[] { value }); field.SetValue(this, resource); } else { string msg = "Unsupported type " + field_type.FullName + " = " + value; Engine.logError(msg); throw new Exception(msg); } }
public void Deserialize(string data) { var this_type = this.GetType(); string[] values = data.Split('|'); int version = int.Parse(values[0]); if (version > 0) { return; } for (int i = 1; i < values.Length - 1; i += 3) { string type = values[i]; string name = values[i + 1]; string value = values[i + 2]; var field = this_type.GetField(name); if (field != null) { Type field_type = field.FieldType; if (field_type.Name != type) { continue; } if (field_type == typeof(Entity)) { int entity_id = int.Parse(value); Entity e = Universe.GetEntity(entity_id); field.SetValue(this, e); } else if (field_type.BaseType == typeof(Resource)) { var resource = Activator.CreateInstance(field_type, new object[] { value }); field.SetValue(this, resource); } else { var converter = TypeDescriptor.GetConverter(field_type); field.SetValue(this, converter.ConvertFrom(value)); } } } }
public Entity Raycast(Vec3 a0, Vec3 a1, Entity a2) { var ret = raycast(instance_, a0, a1, a2.entity_Id_); return(Universe.GetEntity(ret)); }