Example #1
0
    public static float GetPanelAlpha(int id)
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            UIPanel panel = go.GetComponent <UIPanel>();
            if (panel)
            {
                return(panel.alpha);
            }
        }
        return(0);
    }
Example #2
0
    public static int GetPanelDepth(int id)
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            UIPanel panel = go.GetComponent <UIPanel>();
            if (panel)
            {
                return(panel.depth);
            }
        }
        return(0);
    }
Example #3
0
    public static void SetUITouchable(int id, int touchable)
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            UICamera uiCamera = go.GetComponent <UICamera>();
            if (uiCamera)
            {
                uiCamera.useTouch = touchable == 1;
                uiCamera.useMouse = touchable == 1;
            }
        }
    }
Example #4
0
    public static void DestroyComponent(int id, int type)
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            var componet = go.GetComponent(LuaReference.GetComponentType(type));

            if (componet)
            {
                UnityEngine.Object.DestroyImmediate(componet);
            }
        }
    }
Example #5
0
    public static void TransformVector(int id, float x, float y, float z, out float ox, out float oy, out float oz)
    {
        var go = LuaReference.Get(id);

        ox = oy = oz = 0;

        if (go)
        {
            Vector3 pos = go.transform.TransformVector(x, y, z);
            ox = pos.x;
            oy = pos.y;
            oz = pos.z;
        }
    }
Example #6
0
    public static int FindChild(int id, string path)
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            var child = go.transform.Find(path);
            if (child)
            {
                return(LuaReference.Add(child.gameObject));
            }
        }
        return(LuaReference.INVALID_GAMEOBJECT_ID);
    }
Example #7
0
    private static T GetComponent <T>(int id, string path) where T : Component
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            Transform t = go.transform.Find(path);
            if (t)
            {
                return(t.GetComponent <T>());
            }
        }
        return(null);
    }
Example #8
0
    public static int IsEnable(int id, int type)
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            var behaviour = go.GetComponent(LuaReference.GetComponentType(type)) as Behaviour;
            if (behaviour)
            {
                return(behaviour.enabled ? 1:0);
            }
        }
        return(0);
    }
Example #9
0
    public static int FindChildWithComponent(int id, int type)
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            var component = go.GetComponentInChildren(LuaReference.GetComponentType(type));
            if (component)
            {
                return(LuaReference.Add(component.gameObject));
            }
        }
        return(LuaReference.INVALID_GAMEOBJECT_ID);
    }
Example #10
0
    public static void GetLocalRotation(int id, out float x, out float y, out float z, out float w)
    {
        var go = LuaReference.Get(id);

        x = y = z = w = 0;

        if (go)
        {
            x = go.transform.localRotation.x;
            y = go.transform.localRotation.y;
            z = go.transform.localRotation.z;
            w = go.transform.localRotation.w;
        }
    }
Example #11
0
        public static void Copy(LuaReference TableFrom, LuaReference TableTo, string FromName, string ToName = null)
        {
            if (ToName == null)
            {
                ToName = FromName;
            }

            TableTo.GetRef();

            TableFrom.GetRef();
            LL.lua_getfield(L, -1, FromName);

            LL.lua_setfield(L, -3, ToName);
            LL.lua_pop(L, 2);
        }
Example #12
0
        public static void Set(LuaReference Table, string Name, object Obj)
        {
            Table.GetRef();

            if (Obj is LuaReference Ref)
            {
                Ref.GetRef();
            }
            else
            {
                Advanced.Push(L, Obj);
            }

            LL.lua_setfield(L, -2, Name);
            LL.lua_pop(L, 1);
        }
Example #13
0
        public static LuaReference CreateNewEnvironment(LuaReference OldEnvironment = null)
        {
            if (OldEnvironment != null)
            {
                OldEnvironment.GetRef();
                CopyTable();
            }
            else
            {
                LL.lua_newtable(L);
            }

            LuaReference Ref = new LuaReference(L);

            if (OldEnvironment != null)
            {
                LL.lua_pop(L, 1);
            }

            return(Ref);
        }
Example #14
0
 public override bool Equals(LuaReference r)
 {
     // This singleton table is only ever equal to itself.
     return object.ReferenceEquals(r, this);
 }
Example #15
0
        internal object ToObject(int index, LuaType?typeHint = null, IntPtr?stateOverride = null)
        {
            var state = stateOverride ?? MainState;

            Debug.Assert(LuaApi.GetMainState(state) == MainState, "State override did not match main state.");
            var type = typeHint ?? LuaApi.Type(state, index);

            Debug.Assert(type == LuaApi.Type(state, index), "Type hint did not match type.");

            switch (type)
            {
            case LuaType.None:
            case LuaType.Nil:
                return(null);

            case LuaType.Boolean:
                return(LuaApi.ToBoolean(state, index));

            case LuaType.Number:
                var isInteger = LuaApi.IsInteger(state, index);
                return(isInteger ? LuaApi.ToInteger(state, index) : (object)LuaApi.ToNumber(state, index));

            case LuaType.String:
                return(LuaApi.ToString(state, index));

            case LuaType.Userdata:
                var handle = LuaApi.ToHandle(state, index);
                return(handle.Target);
            }

            LuaReference luaReference = null;
            var          pointer      = LuaApi.ToPointer(state, index);

            if (_cachedLuaReferences.TryGetValue(pointer, out var weakReference))
            {
                luaReference = (LuaReference)weakReference.Target;
                if (luaReference != null)
                {
                    return(luaReference);
                }
            }

            LuaApi.PushValue(state, index);
            var referenceId = LuaApi.Ref(state, LuaApi.RegistryIndex);

            switch (type)
            {
            case LuaType.Table:
                luaReference = new LuaTable(this, referenceId);
                break;

            case LuaType.Function:
                luaReference = new LuaFunction(this, referenceId);
                break;

            case LuaType.Thread:
                luaReference = new LuaThread(this, referenceId, pointer);
                break;
            }

            if (weakReference != null)
            {
                weakReference.Target = luaReference;
            }
            else
            {
                _cachedLuaReferences[pointer] = new WeakReference(luaReference);
            }
            _pointerToReferenceId[pointer] = referenceId;
            return(luaReference);
        }
Example #16
0
    public static int GameObject(string name)
    {
        var go = new GameObject(name);

        return(LuaReference.Add(go));
    }