public static void IfNullThrow <TType>(this ComponentBase obj, TType modal, string errorMessage = "") { if (string.IsNullOrEmpty(errorMessage)) { var modalTypeName = typeof(TType).Name; var meTypeName = obj.GetType().Name; errorMessage = $"Component {meTypeName} must be a child of {modalTypeName}"; } if (modal == null) { throw new ArgumentNullException(errorMessage); } }
public EntityTreeItem(ComponentBase entity) { Entity = entity; currentName = entity.Name; if (entity.GetType() == typeof(Entity)) { Entity castEntity = (Entity)entity; if (castEntity == null || castEntity.Transform == null || castEntity.Transform.Children == null) { Children = new ObservableCollection <EntityTreeItem>(); } else { Children = new ObservableCollection <EntityTreeItem>(castEntity.Transform.Children.Select(e => new EntityTreeItem(e.Entity))); } } if (entity.GetType() == typeof(Scene)) { Children = new ObservableCollection <EntityTreeItem>(); } }
/// <summary> /// Register component in corresponding pool /// </summary> /// <param name="icomp"></param> public static void Register(ComponentBase comp) { Pool reg = null; Type t = comp.GetType(); if (registers.TryGetValue(t, out reg)) { reg.register(comp); } else { reg = CreatePool(t); reg.register(comp); } }
static public void CompareComponents(ComponentBase cb1, ComponentBase cb2) { Type type = cb1.GetType(); Assert.IsTrue(type == cb2.GetType(), "Types do not match"); FieldInfo[] fields = type.GetFields(); PropertyInfo[] properties = type.GetProperties(); foreach (FieldInfo field in fields) { if (field.GetCustomAttributes(typeof(SerializedAttribute), true).Length > 0) { object obj1 = field.GetValue(cb1); object obj2 = field.GetValue(cb2); if (field.FieldType.IsArray) { CompareArrays(obj1 as Array, obj2 as Array, field.Name); } else { Assert.IsTrue(object.Equals(obj1, obj2), field.Name + " does not match"); } } } foreach (PropertyInfo prop in properties) { if (prop.GetCustomAttributes(typeof(SerializedAttribute), true).Length > 0) { object obj1 = prop.GetValue(cb1, null); object obj2 = prop.GetValue(cb2, null); if (prop.PropertyType.IsArray) { CompareArrays(obj1 as Array, obj2 as Array, prop.Name); } else { Assert.IsTrue(object.Equals(obj1, obj2), prop.Name + " does not match"); } } } }
private RenderFragment?GetInstanceRenderFragment(ComponentBase component) { FieldInfo?fieldInfo = null; var type = component.GetType(); do { fieldInfo = type.GetField("_renderFragment", BindingFlags.NonPublic | BindingFlags.Instance); if (fieldInfo == null) { type = type.BaseType; } if (type == null) { break; } }while (fieldInfo == null); return(fieldInfo?.GetValue(component) as RenderFragment); }
public static bool Prefix(ComponentBase __instance) { var type = __instance.GetType(); if (liveContexts.ContainsKey(type)) { var context = liveContexts[type]; if (!context.Components.Contains(__instance)) { context.Components.Add(__instance); } } //if (context.NewType != null) //{ // Type newCompiledType = context.NewType; // var newRenderTree = newCompiledType.GetMethod("BuildRenderTree", BindingFlags.NonPublic | BindingFlags.Instance); // newRenderTree.Invoke(__instance, new object[] { null }); // return false; //} return(true); }
public void OnEntityRemoveComponent(ComponentBase component) { if (!component) { return; } HashSet <ComponentBase> coll = null; if (ComponentDic.TryGetValue(component.GetType(), out coll)) { try { coll.Remove(component); } catch (System.Exception e) { Debug.LogError(e); } } }
public async void SetComponent(ComponentBase component) { try { _currentComponent = component; this.Content = null; var newControl = component.MainControl; if (newControl == null) { throw new Exception("The component " + component.GetType().Name + " does not define a Control. Every component needs a control"); } this.Content = newControl; } catch (Exception e) { var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); System.IO.File.WriteAllText(folder + "/InstallerError.txt", e.ToString()); } await component.Show(); }
public async void SetComponent(ComponentBase component) { _currentComponent = component; Controls.Clear(); var newControl = component.MainControl; if (newControl == null) { throw new Exception("The component " + component.GetType().Name + " does not define a Control. Every component needs a control"); } var host = new ElementHost(); host.Child = newControl; Controls.Add(host); host.Dock = DockStyle.Fill; host.Margin = new System.Windows.Forms.Padding(0); await component.Show(); }
/// <summary> /// 绘制单个组件 /// </summary> /// <param name="component"></param> private void DrawComponent(ComponentBase component) { Type t = component.GetType(); string typeName = GetTypeName(component); GUILayout.Box(typeName, "WarningOverlay", GUILayout.MaxWidth(Screen.width - 20)); FieldInfo[] fields = t.GetFields(); if (fields.Length == 0) { return; } GUILayout.BeginVertical("box"); EditorDrawGUIUtil.IsDrawPropertyInClass = false; EditorDrawGUIUtil.CanEdit = false; foreach (var item in fields) { component = (ComponentBase)EditorDrawGUIUtil.DrawBaseValue(component, item, EditorUIOpenState.OpenFirstFold); } EditorDrawGUIUtil.IsDrawPropertyInClass = true; EditorDrawGUIUtil.CanEdit = true; GUILayout.EndVertical(); }
private static void Reload() { var hot = DllHelper.GetHotfixAssembly(); Type[] types = hot.GetTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(ObjectEventAttribute), false); if (attrs.Length == 0) { continue; } object obj = Activator.CreateInstance(type); ComponentBase objectEvent = obj as ComponentBase; if (objectEvent == null) { Console.WriteLine($"组件事件没有继承IObjectEvent: {type.Name}"); continue; } ety.AddComponent(objectEvent.GetType(), objectEvent); } }
private void ContextMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e) { // determine allowed connection types and populate the Connect To menu ConnectToMenuItem.DropDownItems.Clear(); ComponentBase tagComponent = (ComponentBase)Tag; foreach (ComponentBase component in Form1.design.Components.Where(c => c != Tag)) { // skip if connection is not allowed List <AllowedConnection> allowedConnections = AllowedConnections.Allowed.Where(a => a.Item1 == tagComponent.GetType() && a.Item2 == component.GetType() || a.Item1 == component.GetType() && a.Item2 == tagComponent.GetType()).ToList(); if (allowedConnections.Count == 0) { continue; } // skip if connection already exists if (Form1.design.Connections.Any(c => c.Item1Id == component.Id && c.Item2Id == tagComponent.Id || c.Item1Id == tagComponent.Id && c.Item2Id == component.Id)) { continue; } ToolStripButton toolStripButton = new ToolStripButton { Text = component.Name, Tag = new Tuple <ComponentBase, ComponentBase, Type>(component, tagComponent, allowedConnections.First().Item3), Width = 128 }; toolStripButton.Click += ComponentControl_Click; ConnectToMenuItem.DropDownItems.Add(toolStripButton); } }
public void RegisterComponent(ComponentBase component) { ComponentsStorage.Add(component.GetType(), component); }
public void ChangeCompIndex(int index, ComponentBase comp) { //int index = world.componentType.GetComponentIndex(compName); ComponentBase oldComp = comps[index]; if (oldComp == null) { throw new System.Exception("EntityID " + ID + " GetComp not exist comp !" + comp.GetType().Name); } else { oldComp.Entity = null; comps[index] = comp; comp.Entity = this; comp.World = world; if (OnComponentReplaced != null) { OnComponentReplaced(this, index, oldComp, comp); } world.heapComponentPool.PutObject(index, oldComp); } }
public ComponentDto(ComponentBase component, int tick) { StartTick = tick; Type = ComponentBase.GetComponentType(component.GetType()); Component = JsonConvert.SerializeObject(component); }
/// <summary> /// Write a simgle component in file /// </summary> /// <param name="component">Component to be writen</param> /// <param name="writer">File generator</param> private static void WriteComponent(ComponentBase component, XmlWriter writer) { string componentTypeName = component.GetType().ToString().Replace("Core.Components.", string.Empty); writer.WriteStartElement(componentTypeName); if (component is NameableComponent) { writer.WriteStartAttribute("Name"); writer.WriteValue((component as NameableComponent).Name); writer.WriteEndAttribute(); } switch (componentTypeName) { #region Basic case "Coil": writer.WriteStartAttribute("Mode"); writer.WriteValue((component as Coil).Mode.ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute("Type"); writer.WriteValue((component as Coil).Type.ToString()); writer.WriteEndAttribute(); break; case "Contact": writer.WriteStartAttribute("IsClosed"); writer.WriteValue((component as Contact).IsClosed); writer.WriteEndAttribute(); writer.WriteStartAttribute("IsInverted"); writer.WriteValue((component as Contact).IsInverted); writer.WriteEndAttribute(); writer.WriteStartAttribute("Type"); writer.WriteValue((component as Contact).Type.ToString()); writer.WriteEndAttribute(); break; #endregion Basic #region Compare Components case "EQU": case "GEQ": case "GRT": case "LEG": case "LES": case "NEQ": writer.WriteStartAttribute("VarA"); writer.WriteValue((component as CompareComponent).VarA); writer.WriteEndAttribute(); writer.WriteStartAttribute("VarB"); writer.WriteValue((component as CompareComponent).VarB); writer.WriteEndAttribute(); break; #endregion Compare Components #region Counter Components case "CTC": case "CTD": case "CTU": writer.WriteStartAttribute("Limit"); writer.WriteValue((component as CounterComponent).Limit); writer.WriteEndAttribute(); break; #endregion Counter Components #region Math Components case "ADD": case "DIV": case "MUL": case "SUB": case "MOV": writer.WriteStartAttribute("Destination"); writer.WriteValue((component as MathComponent).Destination); writer.WriteEndAttribute(); writer.WriteStartAttribute("VarA"); writer.WriteValue((component as MathComponent).VarA); writer.WriteEndAttribute(); writer.WriteStartAttribute("VarB"); writer.WriteValue((component as MathComponent).VarB); writer.WriteEndAttribute(); break; #endregion Math Components #region Analog Components case "ADC": writer.WriteStartAttribute("Destination"); writer.WriteValue((component as ADC).Destination); writer.WriteEndAttribute(); break; case "PWM": writer.WriteStartAttribute("DudyCycle"); writer.WriteValue((component as PWM).DudyCycle); writer.WriteEndAttribute(); break; #endregion Analog Components #region Function Components case "ELF": writer.WriteStartAttribute("Name"); writer.WriteValue((component as ELF).Name); writer.WriteEndAttribute(); break; #endregion Function Components #region Components that do not require any extra processing case "OSF": case "OSR": case "SC": case "RES": //Nothing to do were break; #endregion Components that do not require any extra processing default: throw new ArgumentException("Unknow Component", "component"); } writer.WriteStartAttribute("Comment"); writer.WriteValue(component.Comment); writer.WriteEndAttribute(); writer.WriteEndElement(); }
private void CompareComponents(ComponentBase cb1, ComponentBase cb2) { Type type = cb1.GetType(); Assert.IsTrue(type == cb2.GetType(), "Types do not match"); FieldInfo[] fields = type.GetFields(); foreach (FieldInfo field in fields) { if (field.GetCustomAttributes(typeof(NotSerialized), true).Length == 0) { object obj1 = field.GetValue(cb1); object obj2 = field.GetValue(cb2); if (field.FieldType.IsArray) CompareArrays(obj1 as Array, obj2 as Array, field.Name); else Assert.IsTrue(object.Equals(obj1, obj2), field.Name + " does not match"); } } }
static public void CompareComponents(ComponentBase cb1, ComponentBase cb2) { Type type = cb1.GetType(); Assert.IsTrue(type == cb2.GetType(), "Types do not match"); FieldInfo[] fields = type.GetFields(); PropertyInfo[] properties = type.GetProperties(); foreach (FieldInfo field in fields) { if (field.GetCustomAttributes(typeof(Serialized), true).Length > 0) { object obj1 = field.GetValue(cb1); object obj2 = field.GetValue(cb2); if (field.FieldType.IsArray) CompareArrays(obj1 as Array, obj2 as Array, field.Name); else Assert.IsTrue(object.Equals(obj1, obj2), field.Name + " does not match"); } } foreach (PropertyInfo prop in properties) { if (prop.GetCustomAttributes(typeof(Serialized), true).Length > 0) { object obj1 = prop.GetValue(cb1, null); object obj2 = prop.GetValue(cb2, null); if (prop.PropertyType.IsArray) CompareArrays(obj1 as Array, obj2 as Array, prop.Name); else Assert.IsTrue(object.Equals(obj1, obj2), prop.Name + " does not match"); } } }
public void RemoveComponent(ComponentBase component) { Components.Remove(component); Game.I.SystemController.Systems[component.GetType()].RemoveComponent(Id); }