Exemple #1
0
        void Update()
        {
            StringBuilder sb = new StringBuilder()
                               .Append("Entity_")
                               .Append(entityId)
                               .Append("(*")
                               .Append(GetEntityRetainCount(poolName, entityId))
                               .Append(")")
                               .Append("(");

            int[] componentIds = GetEntityComponentIds(poolName, entityId);
            for (int i = 0; i < componentIds.Length; i++)
            {
                if (i != 0)
                {
                    sb.Append(",");
                }
                sb.Append(GetComponentStruct(componentIds[i]).name);
            }
            sb.Append(")");
            name = sb.ToString();

            bool       hidden = true;
            List <int> ids    = LuaPool.Get(poolName).entityDisplayMatcherIds;

            if (ids.Count == 0)
            {
                hidden = false;
            }
            else
            {
                foreach (int matcherId in ids)
                {
                    isMatch.BeginPCall();
                    isMatch.Push(poolName);
                    isMatch.Push(entityId);
                    isMatch.Push(matcherId);
                    isMatch.PCall();
                    hidden = !isMatch.CheckBoolean();
                    isMatch.EndPCall();

                    if (!hidden)
                    {
                        break;
                    }
                }
            }

            gameObject.hideFlags = hidden ? HideFlags.HideInHierarchy : HideFlags.None;
        }
Exemple #2
0
        public static void RegToLua(LuaState l)
        {
            l.LuaPushFunction(L =>
            {
                object[] componentNames   = l.GetTable("ecs.component.allcomponentnames").ToArray();
                object[] propertyNameArrs = l.GetTable("ecs.component.allcomponentpropertys").ToArray();
                List <string> componentSelectTextsList = new List <string>();
                for (int i = 1; i <= componentNames.Length; i++)
                {
                    ComponentStruct cstruct = new ComponentStruct();
                    cstruct.fullName        = componentNames[i - 1].ToString();
                    cstruct.name            = cstruct.fullName.Substring(cstruct.fullName.LastIndexOf('.') + 1);
                    cstruct.id = i;

                    object[] pnames       = (propertyNameArrs[i - 1] as LuaTable).ToArray();
                    cstruct.propertyNames = new string[pnames.Length];
                    for (int j = 0; j < pnames.Length; j++)
                    {
                        cstruct.propertyNames[j] = pnames[j].ToString();
                    }

                    componentSelectTextsList.Add(cstruct.fullName.Replace(".", "/"));
                    componentSelectIds.Add(i);
                    componentStructs.Add(cstruct);
                }
                componentSelectTexts = componentSelectTextsList.ToArray();

                getEntityComponentIds           = l.GetFunction("ecs.bridge.getentitycomponentids");
                getEntityComponetnPropertyValue = l.GetFunction("ecs.bridge.getentitycomponetnpropertyvalue");
                setEntityComponetnPropertyValue = l.GetFunction("ecs.bridge.setentitycomponetnpropertyvalue");
                addComponent         = l.GetFunction("ecs.bridge.addcomponent");
                removeComponent      = l.GetFunction("ecs.bridge.removecomponent");
                getEntityOwners      = l.GetFunction("ecs.bridge.getentityowners");
                getEntityRetainCount = l.GetFunction("ecs.bridge.getentityretaincount");
                isMatch       = l.GetFunction("ecs.bridge.ismatch");
                destroyEntity = l.GetFunction("ecs.bridge.destroyentity");
                return(0);
            });
            l.LuaSetGlobal("ECS_INIT_EDITOR_ENTITY");

            l.LuaPushFunction(L =>
            {
                LuaEntity entity            = new GameObject().AddComponent <LuaEntity>();
                entity.poolName             = ToLua.CheckString(L, 1);
                entity.entityId             = System.Convert.ToInt32(LuaDLL.luaL_checknumber(L, 2));
                entity.transform.parent     = LuaPool.Get(entity.poolName).transform;
                entity.name                 = "Entity_" + entity.entityId;
                entity.gameObject.hideFlags = HideFlags.HideInHierarchy;

                if (!entities.ContainsKey(entity.poolName))
                {
                    entities.Add(entity.poolName, new Dictionary <int, LuaEntity>());
                }
                entities[entity.poolName].Add(entity.entityId, entity);

                return(0);
            });
            l.LuaSetGlobal("ECS_POOL_ONENTITYCREATE");

            l.LuaPushFunction(L =>
            {
                string poolName = ToLua.CheckString(L, 1);
                int id          = System.Convert.ToInt32(LuaDLL.luaL_checknumber(L, 2));
                Destroy(entities[poolName][id].gameObject);
                entities[poolName].Remove(id);
                return(0);
            });
            l.LuaSetGlobal("ECS_POOL_ONENTITYDESTROY");
        }