Beispiel #1
0
    static public void SetImage(Transform t, string name)
    {
        if (name == null)
        {
            return;
        }

        if (name == "")
        {
            return;
        }

        if (name.IndexOf("http:") == 0)
        {
            netImage.SetImage(t, name);
            return;
        }

        if (imgList == null)
        {
            var        obj     = ResTools.Load("res/cards");
            GameObject gameObj = GameObject.Instantiate(obj) as GameObject;
            imgList = gameObj.GetComponent <ImageList>();
        }

        if (t != null)
        {
            Image s = t.GetComponent <Image>();
            s.sprite = imgList.Get(name);
        }
    }
Beispiel #2
0
    static public Transform CreateChild(Transform t, string res, bool zero_size)
    {
        var prefab = ResTools.Load(res);

        if (prefab == null)
        {
            Debug.Log("can't found res:" + res);
            return(null);
        }
        else
        {
            GameObject obj = GameObject.Instantiate(prefab, t) as GameObject;

            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = Vector3.zero;

            if (zero_size)
            {
                RectTransform rt = obj.GetComponent <RectTransform>();
                if (rt)
                {
                    rt.sizeDelta = new Vector2(0, 0);
                }
            }

            int pos = res.LastIndexOf('/');
            obj.name = res.Substring(pos + 1);

            return(obj.transform);
        }
    }
Beispiel #3
0
    static public Transform CreateUI(string res, bool zero_size)
    {
        var prefab = ResTools.Load("ui/" + res);

        Debug.Assert(prefab, "can't find [" + res + "] in resource.");


        GameObject obj = GameObject.Instantiate(prefab) as GameObject;

        obj.transform.SetParent(gCanvas);

        obj.transform.localScale    = Vector3.one;
        obj.transform.localPosition = Vector3.zero;

        if (zero_size)
        {
            RectTransform rt = obj.GetComponent <RectTransform>();
            if (rt)
            {
                rt.sizeDelta = new Vector2(0, 0);
            }
        }

        int pos = res.LastIndexOf('/');

        obj.name = res.Substring(pos + 1);

        return(obj.transform);
    }
Beispiel #4
0
    public static GameObject Create2Dimage(string res)
    {
        var        r   = ResTools.Load("res/" + res);
        GameObject obj = GameObject.Instantiate(r, t2d) as GameObject;

        obj.transform.localPosition = Vector3.zero;
        obj.name = res;
        return(obj);
    }
Beispiel #5
0
    public static GameObject Create3D(string res, Vector3 pos)
    {
        var        r   = ResTools.Load("3d/" + res);
        GameObject obj = GameObject.Instantiate(r, t3d) as GameObject;

        obj.transform.localPosition = pos;

        obj.name = res;

        return(obj);
    }
Beispiel #6
0
    public static void PlayMusic(string name, int value)
    {
        InitAudio();

        audioSource.volume = value / 100.0f;


        audioSource.clip = ResTools.Load("ogg/" + name) as AudioClip;
        audioSource.loop = true;
        audioSource.Play();
    }
Beispiel #7
0
    public static GameObject Set2DImage(Transform t, string res)
    {
        //Debug.Log(res);
        var        r   = ResTools.Load("res/" + res);
        GameObject obj = GameObject.Instantiate(r, t2d) as GameObject;

        //obj.transform.localPosition = Vector3.zero;
        //obj.name = res;
        t.GetComponent <Image>().sprite = obj.GetComponent <Image>().sprite;
        GameObject.Destroy(obj);
        return(t.gameObject);
    }
Beispiel #8
0
    public static void PlaySound(string name, int value)
    {
        InitAudio();

        if (gPauseAllSound)
        {
            return;
        }

        var clip = ResTools.Load("ogg/" + name) as AudioClip;

        soundSource.PlayOneShot(clip, value / 100.0f);
    }
Beispiel #9
0
    static public void SetEmImage(Transform t, int n)
    {
        if (emsList == null)
        {
            var        obj     = ResTools.Load("res/emotions");
            GameObject gameObj = GameObject.Instantiate(obj) as GameObject;
            emsList = gameObj.GetComponent <ImageList>();
        }

        if (t != null)
        {
            Image s = t.GetComponent <Image>();
            s.sprite = emsList.items [n];
        }
    }
Beispiel #10
0
    static public Transform CreateUIEx(string res)
    {
        var prefab = ResTools.Load("UI/" + res);

        Debug.Assert(prefab, "can't find [" + res + "] in resource.");


        GameObject obj = GameObject.Instantiate(prefab) as GameObject;

        obj.transform.SetParent(gCanvas);

        int pos = res.LastIndexOf('/');

        obj.name = res.Substring(pos + 1);

        return(obj.transform);
    }
Beispiel #11
0
        public virtual byte[] ReadFile(string fileName)
        {
            if (!beZip)
            {
                string path = FindFile(fileName);

                if (path == null)
                {
                    if ((fileName [0] == '/') || (fileName [0] == '\\'))
                    {
                        fileName = "Lua" + fileName;
                    }
                    else
                    {
                        fileName = "Lua/" + fileName;
                    }

                    if (!fileName.EndsWith(".lua"))
                    {
                        fileName += ".lua";
                    }

                    TextAsset a = ResTools.Load(fileName) as TextAsset;

                    return(a.bytes);
                }

                byte[] str = null;

                if (!string.IsNullOrEmpty(path) && File.Exists(path))
                {
#if !UNITY_WEBPLAYER
                    str = File.ReadAllBytes(path);
#else
                    throw new LuaException("can't run in web platform, please switch to other platform");
#endif
                }

                return(str);
            }
            else
            {
                return(ReadZipFile(fileName));
            }
        }
Beispiel #12
0
    static public void ShowImageEffectColor(Transform t, string name, string img, byte r, byte g, byte b)
    {
        if (imgList == null)
        {
            var        obj     = ResTools.Load("res/cards");
            GameObject gameObj = GameObject.Instantiate(obj) as GameObject;
            imgList = gameObj.GetComponent <ImageList>();
        }

        if (t != null)
        {
            Transform child = CreateChild(t, "effect/" + name, false);

            Image s = child.GetComponent <Image>();
            s.sprite = imgList.Get(img);
            s.color  = new Color(r, g, b);
        }
    }
Beispiel #13
0
    byte[] ReadResourceFile(string fileName)
    {
        if (!fileName.EndsWith(".lua"))
        {
            fileName += ".lua";
        }

        byte[]    buffer = null;
        string    path   = "Lua/" + fileName;
        TextAsset text   = ResTools.Load(path) as TextAsset;

        if (text != null)
        {
            buffer = text.bytes;
            Resources.UnloadAsset(text);
        }

        return(buffer);
    }
Beispiel #14
0
    public static GameObject Create3DEx(string res, Transform t)
    {
        var        r   = ResTools.Load("3d/" + res);
        GameObject obj = GameObject.Instantiate(r, t) as GameObject;

        obj.transform.localPosition = Vector3.zero;
        obj.transform.localScale    = Vector3.one;

        obj.name  = res;
        obj.layer = t.gameObject.layer;

        Transform p = obj.transform;

        for (int i = 0; i < p.childCount; i++)
        {
            p.GetChild(i).gameObject.layer = t.gameObject.layer;
        }

        return(obj);
    }
Beispiel #15
0
    static public Transform ShowImageEffect(Transform t, string name, string img)
    {
        if (imgList == null)
        {
            var        obj     = ResTools.Load("res/cards");
            GameObject gameObj = GameObject.Instantiate(obj) as GameObject;
            imgList = gameObj.GetComponent <ImageList>();
        }

        if (t != null)
        {
            Transform child = CreateChild(t, "effect/" + name, false);

            Image s = child.GetComponent <Image>();
            s.sprite = imgList.Get(img);

            return(child);
        }

        return(null);
    }
Beispiel #16
0
    protected void Start()
    {
        ResTools r = gameObject.AddComponent <ResTools> ();

        r.Init("InitClient");
    }
Beispiel #17
0
 static public void EndDown()
 {
     ResTools.EndDown();
 }
Beispiel #18
0
 static public void WriteDown(byte[] datas)
 {
     ResTools.WriteDown(datas);
 }
Beispiel #19
0
 static public int BeginDown(int step)
 {
     return(ResTools.BeginDown(step));
 }
Beispiel #20
0
 static public bool CheckVer(int[] ver)
 {
     return(ResTools.CheckVer(ver));
 }