/// <summary>
        /// Hide the given entity class from Sandbox.
        /// </summary>
        /// <param name="className">Entity class name.</param>
        public bool Disable(string className)
        {
            if (String.IsNullOrEmpty(className) || !_registry.ContainsKey(className))
            {
                return(false);
            }

            EntityClass managedClass = _registry [className];

            managedClass.Description.flags           |= (int)EEntityClassFlags.ECLF_MODIFY_EXISTING | (int)EEntityClassFlags.ECLF_INVISIBLE;
            managedClass.Description.pPropertyHandler = null;
            managedClass.NativeClass = Global.gEnv.pEntitySystem.GetClassRegistry().RegisterStdClass(managedClass.Description);

            //TODO: Disable all entity instance handlers

            return(true);
        }
Example #2
0
        /// <summary>
        /// Called when CRYENGINE's entity system is spawning an entity. Will check if the entity class is registered with the managed entity class registry and if yes, it will create a managed CESharp entity instance.
        /// </summary>
        private static void OnSpawn(IEntity pEntity, SEntitySpawnParams arg1)
        {
            if (s_managedEntities.ContainsKey(pEntity.GetId()))
            {
                return;
            }

            EntityClass managedClass = s_entityClassRegistry.GetEntityClass(arg1);

            if (managedClass == null)
            {
                return;
            }

            Log.Info("[EntityFramework] Spawn entity: {0} ({1})", arg1.sName, managedClass.ProtoType.Name);
            s_managedEntities.Add(pEntity.GetId(), managedClass.CreateInstance(pEntity, arg1.HasEntityNode() ? arg1.entityNode : null));
        }
Example #3
0
        /// <summary>
        /// Setup the CESharp EntityFramework, including registering of discovered CESharp entity classes and assumption of already spawned CESharp entites.
        /// </summary>
        public static void Instantiate(InterDomainHandler handler)
        {
            EntityProperty.RegisterConverters();
            s_managedEntities     = new Dictionary <uint, BaseEntity> ();
            s_entityClassRegistry = new EntityClassRegistry();
            s_entityClassRegistry.RegisterAll();
            s_entitySystemSink             = new EntitySystemSink();
            s_entitySystemSink.Spawn      += OnSpawn;
            s_entitySystemSink.Event      += OnEvent;
            s_entitySystemSink.Remove     += OnRemove;
            s_entityUpdateListener         = new EntityUpdateListener();
            s_entityUpdateListener.Update += OnUpdate;

            // Assume already spawned entities
            IEntityIt it = Global.gEnv.pEntitySystem.GetEntityIterator();

            if (it != null)
            {
                it.MoveFirst();

                IEntity pEntity = null;
                while (!it.IsEnd())
                {
                    pEntity = it.Next();

                    EntityClass managedClass = s_entityClassRegistry.GetEntityClass(pEntity);
                    if (managedClass == null)
                    {
                        continue;
                    }

                    Log.Info("[EntityFramework] Assume entity: {0} ({1})", pEntity.GetName(), managedClass.ProtoType.Name);
                    BaseEntity instance = managedClass.CreateInstance(pEntity);
                    handler.RetrieveEntity(instance);
                    s_managedEntities.Add(pEntity.GetId(), instance);
                }
            }
        }
 /// <summary>
 /// Only intended to be used by the EntityFramework itself!
 /// </summary>
 /// <param name="parent">Parent.</param>
 private EntityPropertyHandler(EntityClass parent)
 {
     _parent = parent;
 }