示例#1
0
    public static int CreateUI(int width, int height)
    {
        var p = NGUITools.CreateUI(false);

        var uiCamera = p.GetComponentInChildren <UICamera>();
        var camera   = uiCamera.GetComponent <Camera>();

        camera.clearFlags = CameraClearFlags.Depth;

        UnityEngine.Object.DestroyImmediate(camera.GetComponent <AudioListener>());

        var uiRoot = p.GetComponent <UIRoot>();

        uiRoot.scalingStyle = UIRoot.Scaling.Constrained;
        uiRoot.manualWidth  = width;
        uiRoot.manualHeight = height;

        float screenAspectRatio = (Screen.width * 1.0f) / Screen.height;
        float designAspectRatio = (width * 1.0f) / height;

        if ((screenAspectRatio * 100) < (designAspectRatio * 100))
        {
            uiRoot.fitWidth  = true;
            uiRoot.fitHeight = false;
        }
        else if ((screenAspectRatio * 100) > (designAspectRatio * 100))
        {
            uiRoot.fitWidth  = false;
            uiRoot.fitHeight = true;
        }

        return(LuaReference.Add(p.gameObject));
    }
示例#2
0
    public static int GetParent(int id)
    {
        var go = LuaReference.Get(id);

        if (go && go.transform.parent)
        {
            return(LuaReference.Add(go.transform.parent.gameObject));
        }
        return(LuaReference.INVALID_GAMEOBJECT_ID);
    }
示例#3
0
    public static int Instantiate(int id)
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            return(LuaReference.Add(UnityEngine.Object.Instantiate(go)));
        }
        return(LuaReference.INVALID_GAMEOBJECT_ID);
    }
示例#4
0
    public static int GetChild(int id, int index)
    {
        var go = LuaReference.Get(id);

        if (go)
        {
            if (index < go.transform.childCount)
            {
                return(LuaReference.Add(go.transform.GetChild(index).gameObject));
            }
        }
        return(LuaReference.INVALID_GAMEOBJECT_ID);
    }
示例#5
0
    public static int  LoadAsset(string path)
    {
#if UNITY_EDITOR
        var asset = UnityEditor.AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path);
        if (asset)
        {
            var go = UnityEngine.Object.Instantiate(asset) as GameObject;
            return(LuaReference.Add(go));
        }
        return(LuaReference.INVALID_GAMEOBJECT_ID);
#else
        return(INVALID_GAMEOBJECT_ID);
#endif
    }
示例#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);
    }
示例#7
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);
    }
示例#8
0
    public static int GameObject(string name)
    {
        var go = new GameObject(name);

        return(LuaReference.Add(go));
    }