Beispiel #1
0
        public override void OnInspectorGUI()
        {
            LuaEntity entity = target as LuaEntity;

            var bgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("Destroy Entity"))
            {
                LuaEntity.DestroyEntity(entity.poolName, entity.entityId);
            }
            GUI.backgroundColor = bgColor;

            DrawComponents(entity.poolName, entity.entityId);

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Retained by (" + LuaEntity.GetEntityRetainCount(entity.poolName, entity.entityId) + ")", EditorStyles.boldLabel);

            EntitasEditorLayout.BeginVerticalBox();
            {
                string[] owners = LuaEntity.GetEntityOwners(entity.poolName, entity.entityId);
                foreach (var owner in owners)
                {
                    EditorGUILayout.LabelField(owner);
                }
            }
            EntitasEditorLayout.EndVertical();
        }
        static int _s_set_luaAssetName(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                LuaEntity gen_to_be_invoked = (LuaEntity)translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.luaAssetName = LuaAPI.lua_tostring(L, 2);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(0);
        }
Beispiel #3
0
    void Start()
    {
        lua = new LuaState();
        lua.Start();
        LuaBinder.Bind(lua);
        LuaSystems.RegToLua(lua);
        LuaPool.RegToLua(lua);
        LuaEntity.RegToLua(lua);

        lua.DoFile("main.lua");

        func = lua.GetFunction("UPDATE");
    }
Beispiel #4
0
        void DrawAndSetElement(string poolName, int entityId, int componentId, string propertyName)
        {
            object value = LuaEntity.GetEntityComponetnPropertyValue(poolName, entityId, componentId, propertyName);

            EntitasEditorLayout.BeginHorizontal();
            {
                object nvalue;
                if (draw(propertyName, value, true, out nvalue))
                {
                    LuaEntity.SetEntityComponetnPropertyValue(poolName, entityId, componentId, propertyName, nvalue);
                }
            }
            EntitasEditorLayout.EndHorizontal();
        }
        static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 1)
                {
                    LuaEntity gen_ret = new LuaEntity();
                    translator.Push(L, gen_ret);

                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to LuaEntity constructor!"));
        }
Beispiel #6
0
        void DrawComponent(string poolName, int entityId, int componentId, Dictionary <int, bool> state)
        {
            LuaEntity.ComponentStruct componentStruct = LuaEntity.GetComponentStruct(componentId);

            if (componentStruct.fullName.ToLower().Contains(componentNameSearchTerm.ToLower()))
            {
                var boxStyle = getColoredBoxStyle(LuaEntity.GetComponentSelectText().Length, componentStruct.id);
                EntitasEditorLayout.BeginVerticalBox(boxStyle);
                {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        if (componentStruct.propertyNames.Length == 0)
                        {
                            EditorGUILayout.LabelField(componentStruct.fullName, EditorStyles.boldLabel);
                        }
                        else
                        {
                            state[componentId] = EditorGUILayout.Foldout(state[componentId], componentStruct.fullName, foldoutStyle);
                        }
                        if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14)))
                        {
                            LuaEntity.RemoveComponent(poolName, entityId, componentId);
                        }
                    }
                    EntitasEditorLayout.EndHorizontal();

                    if (state[componentId])
                    {
                        foreach (var propertyName in componentStruct.propertyNames)
                        {
                            DrawAndSetElement(poolName, entityId, componentId, propertyName);
                        }
                    }
                }
                EntitasEditorLayout.EndVertical();
            }
        }
Beispiel #7
0
        void DrawComponents(string poolName, int entityId)
        {
            Dictionary <int, bool> componentState;

            if (!poolComponentState.TryGetValue(poolName, out componentState))
            {
                componentState = new Dictionary <int, bool>();
                poolComponentState.Add(poolName, componentState);
            }

            int[] componentTypeIds = LuaEntity.GetEntityComponentIds(poolName, entityId);

            EntitasEditorLayout.BeginVerticalBox();
            {
                EntitasEditorLayout.BeginHorizontal();
                {
                    bool forceSet = false, state = false;
                    EditorGUILayout.LabelField("Components (" + componentTypeIds.Length + ")", EditorStyles.boldLabel);
                    if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14)))
                    {
                        forceSet = true;
                        state    = false;
                    }
                    if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14)))
                    {
                        forceSet = true;
                        state    = true;
                    }

                    for (int i = 0; i < componentTypeIds.Length; i++)
                    {
                        if (forceSet || !componentState.ContainsKey(componentTypeIds[i]))
                        {
                            componentState[componentTypeIds[i]] = state;
                        }
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                EditorGUILayout.Space();

                var index = EditorGUILayout.Popup("Add Component", -1, LuaEntity.GetComponentSelectText());
                if (index >= 0)
                {
                    int componentId = LuaEntity.GetComponentIdByIndex(index);
                    LuaEntity.AddComponent(poolName, entityId, componentId);
                }

                EditorGUILayout.Space();

                EntitasEditorLayout.BeginHorizontal();
                {
                    componentNameSearchTerm = EditorGUILayout.TextField("Search", componentNameSearchTerm);

                    const string clearButtonControlName = "Clear Button";
                    GUI.SetNextControlName(clearButtonControlName);
                    if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14)))
                    {
                        componentNameSearchTerm = string.Empty;
                        GUI.FocusControl(clearButtonControlName);
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                EditorGUILayout.Space();

                for (int i = 0; i < componentTypeIds.Length; i++)
                {
                    DrawComponent(poolName, entityId, componentTypeIds[i], componentState);
                }
            }
            EntitasEditorLayout.EndVertical();
        }