Ejemplo n.º 1
0
 void Components_ComponentRemoved(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
     {
         m_physics = null;
     }
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
     {
         m_syncObject = null;
     }
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
     {
         m_gameLogic = null;
     }
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
     {
         PositionComp = new MyNullPositionComponent();
     }
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
     {
         m_hierarchy = null;
     }
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         Render = new MyNullRenderComponent();
     }
 }
Ejemplo n.º 2
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
     {
         m_physics = c as MyPhysicsBody;
     }
     else if (t == typeof(MySyncComponentBase))
     {
         m_syncObject = c as MySyncComponentBase;
     }
     else if (t == typeof(MyGameLogicComponent))
     {
         m_gameLogic = c as MyGameLogicComponent;
     }
     else if (t == typeof(MyPositionComponentBase))
     {
         m_position = c as MyPositionComponentBase;
     }
     else if (t == typeof(MyHierarchyComponentBase))
     {
         m_hierarchy = c as MyHierarchyComponentBase;
     }
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = c as MyRenderComponentBase;
     }
 }
Ejemplo n.º 3
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
     {
         m_physics = c as MyPhysicsBody;
     }
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
     {
         m_syncObject = c as MySyncComponentBase;
     }
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
     {
         m_gameLogic = c as MyGameLogicComponent;
     }
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
     {
         m_position = c as MyPositionComponentBase;
         if (m_position == null)
         {
             PositionComp = new MyNullPositionComponent();
         }
     }
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
     {
         m_hierarchy = c as MyHierarchyComponentBase;
     }
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         m_render = c as MyRenderComponentBase;
         if (m_render == null)
         {
             Render = new MyNullRenderComponent();
         }
     }
 }
Ejemplo n.º 4
0
 public static void RmComponent(MyGameLogicComponent comp)
 {
     if (iterating)
     {
         to_remove.Add(comp);
     }
     else
     {
         blocks.Remove(comp);
     }
 }
Ejemplo n.º 5
0
 public override T GetAs <T>() where T : MyComponentBase
 {
     using (IEnumerator <MyGameLogicComponent> enumerator = this.m_logicComponents.GetEnumerator())
     {
         while (true)
         {
             if (!enumerator.MoveNext())
             {
                 break;
             }
             MyGameLogicComponent current = enumerator.Current;
             if (current is T)
             {
                 return(current as T);
             }
         }
     }
     return(default(T));
 }
Ejemplo n.º 6
0
        public static void AddScriptGameLogic(MyEntity entity, MyObjectBuilderType builderType, string subTypeName = null)
        {
            MyScriptManager @static = MyScriptManager.Static;

            if ((@static != null) && (entity != null))
            {
                HashSet <Type> emptySet;
                if (subTypeName == null)
                {
                    emptySet = m_emptySet;
                }
                else
                {
                    Tuple <Type, string> key = new Tuple <Type, string>((Type)builderType, subTypeName);
                    emptySet = @static.SubEntityScripts.GetValueOrDefault <Tuple <Type, string>, HashSet <Type> >(key, m_emptySet);
                }
                HashSet <Type> first    = @static.EntityScripts.GetValueOrDefault <Type, HashSet <Type> >((Type)builderType, m_emptySet);
                int            capacity = emptySet.Count + first.Count;
                if (capacity != 0)
                {
                    List <MyGameLogicComponent> logicComponents = new List <MyGameLogicComponent>(capacity);
                    foreach (Type local1 in first.Concat <Type>(emptySet))
                    {
                        MyGameLogicComponent        item       = (MyGameLogicComponent)Activator.CreateInstance(local1);
                        MyEntityComponentDescriptor descriptor = (MyEntityComponentDescriptor)local1.GetCustomAttribute(typeof(MyEntityComponentDescriptor), false);
                        if (descriptor.EntityUpdate == null)
                        {
                            ((IMyGameLogicComponent)item).EntityUpdate = true;
                        }
                        else if (descriptor.EntityUpdate.Value)
                        {
                            ((IMyGameLogicComponent)item).EntityUpdate = true;
                        }
                        logicComponents.Add(item);
                    }
                    MyGameLogicComponent component = MyCompositeGameLogicComponent.Create(logicComponents, entity);
                    entity.GameLogic = component;
                }
            }
        }
Ejemplo n.º 7
0
        public static void AddGameLogic(this IMyEntity entity, MyGameLogicComponent logic)
        {
            var comp = entity.GameLogic as MyCompositeGameLogicComponent;

            if (comp != null)
            {
                entity.GameLogic = MyCompositeGameLogicComponent.Create(new List <MyGameLogicComponent>(2)
                {
                    comp, logic
                }, entity as MyEntity);
            }
            else if (entity.GameLogic != null)
            {
                entity.GameLogic = MyCompositeGameLogicComponent.Create(new List <MyGameLogicComponent>(2)
                {
                    entity.GameLogic as MyGameLogicComponent, logic
                }, entity as MyEntity);
            }
            else
            {
                entity.GameLogic = logic;
            }
        }
        private void LoadAsync(long entityId, Action <MyCraftingComponentBase> loadingDoneHandler)
        {
            MyEntity entity;
            MyCraftingComponentBase craftComp = null;
            MyGameLogicComponent    gameLogic = null;

            if (MyEntities.TryGetEntityById(entityId, out entity) &&
                (entity.Components.TryGet <MyCraftingComponentBase>(out craftComp) ||
                 (entity.Components.TryGet <MyGameLogicComponent>(out gameLogic) && gameLogic is MyCraftingComponentBase)))
            {
                if (craftComp == null)
                {
                    craftComp = gameLogic as MyCraftingComponentBase;
                }
                // TODO: If something needs to be initialized etc. it should probably go here..
            }
            else
            {
                System.Diagnostics.Debug.Fail("MyCraftingComponentReplicable - trying to init crafting component on entity, but either entity or component wasn't found!");
            }

            loadingDoneHandler(craftComp);
        }
Ejemplo n.º 9
0
 void Components_ComponentRemoved(Type t, MyEntityComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
         m_physics = null;
     else if (t == typeof(MySyncComponentBase))
         m_syncObject = null;
     else if (t == typeof(MyGameLogicComponent))
         m_gameLogic = null;
     else if (t == typeof(MyPositionComponentBase))
         m_position = null;
     else if (t == typeof(MyHierarchyComponentBase))
         m_hierarchy = null;
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = null;
     }
 }
Ejemplo n.º 10
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if (t == typeof(MyPhysicsComponentBase))
         m_physics = c as MyPhysicsBody;
     else if (t == typeof(MySyncComponentBase))
         m_syncObject = c as MySyncComponentBase;
     else if (t == typeof(MyGameLogicComponent))
         m_gameLogic = c as MyGameLogicComponent;
     else if (t == typeof(MyPositionComponentBase))
         m_position = c as MyPositionComponentBase;
     else if (t == typeof(MyHierarchyComponentBase))
         m_hierarchy = c as MyHierarchyComponentBase;
     else if (t == typeof(MyRenderComponentBase))
     {
         m_render = c as MyRenderComponentBase;
     }
 }
Ejemplo n.º 11
0
 public MyEntityGameLogic()
 {
     GameLogic = new MyNullGameLogicComponent();
 }
Ejemplo n.º 12
0
 public MyEntityGameLogic()
 {
     GameLogic = new MyNullGameLogicComponent();
 }
Ejemplo n.º 13
0
 public static void AddComponent(MyGameLogicComponent comp)
 {
     blocks.Add(comp);
 }
Ejemplo n.º 14
0
 void Components_ComponentRemoved(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
         m_physics = null;
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
         m_syncObject = null;
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
         m_gameLogic = null;
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
         PositionComp = new MyNullPositionComponent();
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
         m_hierarchy = null;
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         Render = new MyNullRenderComponent();
     }
 }
Ejemplo n.º 15
0
 void Components_ComponentAdded(Type t, MyEntityComponentBase c)
 {
     if ((typeof(MyPhysicsComponentBase)).IsAssignableFrom(t))
         m_physics = c as MyPhysicsBody;
     else if ((typeof(MySyncComponentBase)).IsAssignableFrom(t))
         m_syncObject = c as MySyncComponentBase;
     else if ((typeof(MyGameLogicComponent)).IsAssignableFrom(t))
         m_gameLogic = c as MyGameLogicComponent;
     else if ((typeof(MyPositionComponentBase)).IsAssignableFrom(t))
     {
         m_position = c as MyPositionComponentBase;
         if (m_position == null)
             PositionComp = new MyNullPositionComponent();
     }
     else if ((typeof(MyHierarchyComponentBase)).IsAssignableFrom(t))
         m_hierarchy = c as MyHierarchyComponentBase;
     else if ((typeof(MyRenderComponentBase)).IsAssignableFrom(t))
     {
         m_render = c as MyRenderComponentBase;
         if (m_render == null)
             Render = new MyNullRenderComponent();
     }
 }