예제 #1
0
    static public Font GetFont(string s)
    {
        if (s == null)
        {
            return(null);
        }
        if (fonts.ContainsKey(s))
        {
            return(fonts [s]);
        }

        Font font = null;

        if (s.Equals("Arial"))
        {
            font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
        }

        if (font == null)
        {
            font = (Font)PlanetUnityOverride.LoadResource(typeof(Font), s);
        }

        if (font == null)
        {
            return(null);
        }
        fonts [s] = font;
        return(font);
    }
예제 #2
0
    static public string GetTextFile(string s)
    {
        if (s == null)
        {
            return(null);
        }
        if (stringFiles.ContainsKey(s))
        {
            return(stringFiles [s]);
        }

        TextAsset stringData = (TextAsset)PlanetUnityOverride.LoadResource(typeof(TextAsset), s);

        if (stringData == null)
        {
            return(null);
        }
        string t = stringData.text;

                #if UNITY_EDITOR
                #else
        stringFiles [s] = t;
                #endif
        return(t);
    }
예제 #3
0
    public override void gaxb_init()
    {
        gameObject = new GameObject("<Movie/>", typeof(RectTransform));

        canvasRenderer = gameObject.AddComponent <CanvasRenderer> ();
        image          = gameObject.AddComponent <RawImage> ();

        if (color != null)
        {
            image.color = color.Value;
        }

        if (resourcePath != null)
        {
            // Why, oh why are movie textures not supported in iOS?
                        #if (UNITY_IOS || UNITY_ANDROID || UNITY_WEBGL || UNITY_TVOS)
                        #else
            // Set texture
            MovieTexture tex = (MovieTexture)PlanetUnityOverride.LoadResource(typeof(MovieTexture), resourcePath);
            if (tex != null)
            {
                image.texture = tex;

                tex.Stop();
                tex.Play();
                tex.loop = looping;
            }
                        #endif
        }
    }
예제 #4
0
    static public Texture2D GetTexture(string s)
    {
        if (s == null)
        {
            return(null);
        }

        if (s.StartsWith("/") && (s.EndsWith(".png") || s.EndsWith(".jpg")))
        {
            if (File.Exists(s))
            {
                Texture2D fileImage = new Texture2D(512, 512, TextureFormat.ARGB32, false);
                fileImage.LoadImage(File.ReadAllBytes(s));
                fileImage.filterMode = FilterMode.Bilinear;
                fileImage.wrapMode   = TextureWrapMode.Clamp;
                return(fileImage);
            }
        }

        TextAsset fileData = (TextAsset)PlanetUnityOverride.LoadResource(typeof(TextAsset), s);

        if (fileData != null)
        {
            Texture2D tex = new Texture2D(2, 2, TextureFormat.ARGB32, false);
            tex.LoadImage(fileData.bytes);
            tex.filterMode = FilterMode.Bilinear;
            tex.wrapMode   = TextureWrapMode.Clamp;
            return(tex);
        }

        Texture2D t = (Texture2D)PlanetUnityOverride.LoadResource(typeof(Texture2D), s);

        if (t == null)
        {
                        #if (UNITY_WEBPLAYER == false && UNITY_WEBGL == false)
            if (s.EndsWith(".png") || s.EndsWith(".jpg"))
            {
                string filePath = Application.streamingAssetsPath + "/" + s;
                if (File.Exists(filePath))
                {
                    t = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                    t.LoadImage(File.ReadAllBytes(filePath));
                    t.filterMode = FilterMode.Bilinear;
                    t.wrapMode   = TextureWrapMode.Clamp;
                }
            }
                        #endif

            if (t == null)
            {
                Debug.Log("Unable to load streaming asset: " + Application.streamingAssetsPath + "/" + s);
                return(null);
            }
        }
        t.filterMode = FilterMode.Bilinear;
        return(t);
    }
예제 #5
0
    static public T GetAsset <T>(string s)
    {
        if (s == null)
        {
            return(default(T));
        }

        return((T)PlanetUnityOverride.LoadResource(typeof(T), s));
    }
예제 #6
0
    static public AudioClip GetAudioClip(string s)
    {
        if (s == null)
        {
            return(null);
        }

        return((AudioClip)PlanetUnityOverride.LoadResource(typeof(AudioClip), s));
    }
예제 #7
0
    static public string GetTextFileNoCache(string s)
    {
        if (s == null)
        {
            return(null);
        }

        TextAsset stringData = (TextAsset)PlanetUnityOverride.LoadResource(typeof(TextAsset), s);

        if (stringData == null)
        {
            return(null);
        }
        return(stringData.text);
    }
예제 #8
0
    static public TMP_FontAsset GetFont(string path)
    {
        if (fontAssets.ContainsKey(path))
        {
            return(fontAssets [path]);
        }

        TMP_FontAsset font = PlanetUnityOverride.LoadResource(typeof(TMP_FontAsset), path) as TMP_FontAsset;

        if (font != null)
        {
            fontAssets [path] = font;
        }
        return(font);
    }
    // safe to call on a background thread
    static public byte[] GetRawBytesSafe(string s)
    {
        if (PlanetUnityGameObject.IsMainThread())
        {
            return(((TextAsset)PlanetUnityOverride.LoadResource(typeof(TextAsset), s)).bytes);
        }

        // Note: if we get here, we're being called on a background thread.  As such, we need to do a little hairy stuff to make this work
        byte[]         loadedBytes = null;
        AutoResetEvent autoEvent   = new AutoResetEvent(false);

        PlanetUnityGameObject.ScheduleTask(() => {
            loadedBytes = ((TextAsset)PlanetUnityOverride.LoadResource(typeof(TextAsset), s)).bytes;
            autoEvent.Set();
        });

        autoEvent.WaitOne();
        return(loadedBytes);
    }
예제 #10
0
    public override void gaxb_init()
    {
        UnityEngine.Object prefab = (UnityEngine.Object)PlanetUnityOverride.LoadResource(typeof(UnityEngine.Object), name);
        if (prefab == null)
        {
            Debug.Log("Unable to load prefab resource " + name);
            return;
        }
        gameObject = GameObject.Instantiate(prefab) as GameObject;
        if (gameObject == null)
        {
            Debug.Log("Unable to instantiate prefab resource " + name);
            return;
        }

        foreach (Transform t in gameObject.transform)
        {
            t.gameObject.layer = LayerMask.NameToLayer("UI");
        }
    }
예제 #11
0
    static public Sprite GetSprite(string s, bool forceSprite = false)
    {
        if (s == null)
        {
            return(null);
        }

        string spriteKey = s;

        if (sprites.ContainsKey(spriteKey))
        {
            return(sprites [spriteKey]);
        }

        if (forceSprite == true)
        {
            var allSprites = PlanetUnityOverride.LoadAllResources(typeof(Sprite), Path.GetDirectoryName(s));

            foreach (Sprite sprite in allSprites)
            {
                string b = Path.GetDirectoryName(s) + "/" + sprite.name;
                sprites [Path.GetDirectoryName(s) + "/" + sprite.name] = sprite;
            }

            if (sprites.ContainsKey(spriteKey))
            {
                return(sprites [spriteKey]);
            }
        }

        TextAsset fileData = (TextAsset)PlanetUnityOverride.LoadResource(typeof(TextAsset), s);

        if (fileData != null)
        {
            Texture2D tex = new Texture2D(2, 2, TextureFormat.ARGB32, false);
            tex.LoadImage(fileData.bytes);
            tex.filterMode = FilterMode.Bilinear;
            tex.wrapMode   = TextureWrapMode.Clamp;

            Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
            sprites [spriteKey] = sprite;
            return(sprite);
        }

        Texture2D texture2 = (Texture2D)PlanetUnityOverride.LoadResource(typeof(Texture2D), s);

        if (texture2 != null)
        {
            Sprite sprite = Sprite.Create(texture2, new Rect(0, 0, texture2.width, texture2.height), Vector2.zero);
            sprites [spriteKey] = sprite;
            return(sprite);
        }

        // try load all
        var allSprites2 = PlanetUnityOverride.LoadAllResources(typeof(Sprite), Path.GetDirectoryName(s));

        foreach (Sprite sprite in allSprites2)
        {
            sprites [s + sprite.name] = sprite;
        }

        if (sprites.ContainsKey(spriteKey))
        {
            return(sprites [spriteKey]);
        }

        return(null);
    }