public BaseEntityBehaviourComponent Create([NotNull] NetworkEntityGuid context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } IEntityDataFieldContainer dataFieldContainer = EntityDataMappable.RetrieveEntity(context); GameObject worldObject = WorldObjectMappable.RetrieveEntity(context); Type behaviourType = ComputeExpectedBehaviourType(dataFieldContainer.GetEnumFieldValue <GameObjectType>(GameObjectField.GAMEOBJECT_TYPE_ID)); using (var scope = ReflectionContainer.BeginLifetimeScope(cb => { cb.RegisterInstance(context) .AsSelf(); cb.RegisterInstance(worldObject) .As <GameObject>(); cb.RegisterInstance(dataFieldContainer) .As <IEntityDataFieldContainer>() .As <IReadonlyEntityDataFieldContainer>() .SingleInstance(); cb.RegisterType(behaviourType); })) { return((BaseEntityBehaviourComponent)scope.Resolve(behaviourType)); } }
private void Awake() { ReflectionContainer container = new ReflectionContainer { field = "Value 1" }; Type containerType = container.GetType(); FieldInfo fieldInfo = containerType.GetField("field"); Debug.Log($"container.field = {container.field}"); Debug.Log($"fieldInfo.GetValue(container) = {fieldInfo.GetValue(container)}"); Debug.Log($"Calling fieldInfo.SetValue(container, \"Value 2\")"); fieldInfo.SetValue(container, "Value 2"); Debug.Log($"container.field = {container.field}"); Debug.Log($"fieldInfo.GetValue(container) = {fieldInfo.GetValue(container)}"); }