Пример #1
0
 public async override Task Load(ResourcePool pool, CancellationToken token)
 {
     buffer = await pool.GetBuffer();
     var loader = new SpriteLoader(BufferUsageHint.DynamicDraw, buffer);
     tileSet.LoadTileMap(loader, mapIndices, depth);
     sprites = loader.Load();
 }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        State           = TurnState.Draw;
        m_CurrentPlayer = 0;
        DiceObject        diceObject = Resources.Load <DiceObject>("Prefabs/Dice");
        List <DiceObject> dice       = new List <DiceObject>();

        SpriteLoader.Load();
        DiceFaceLoader.Load();

        DiceFace[] faces = new DiceFace[6];
        for (int i = 1; i < 7; i++)
        {
            faces[i - 1] = DiceFaceLoader.Get("DebugCat-" + i); //new PlayFace(i, i, i, FaceType.Play, Color.black, Color.cyan, "DEFAULT-" + i, MaterialLoader.Get("DebugCat"));
            DiceFaceLoader.Serialise(faces[i - 1]);
        }

        for (int i = 0; i < 18; i++)
        {
            DiceObject instance = GameObject.Instantiate <DiceObject>(diceObject);
            instance.SetFaces(faces);
            instance.transform.position = new Vector3(-10.0f, 2.0f, -10.0f);
            instance.GetComponent <Rigidbody>().isKinematic = true;
            dice.Add(instance);
        }
        m_Players = new List <BasePlayer>();
        CreatePlayer(dice, typeof(ControllingPlayer));
    }
Пример #3
0
        public async override Task Load(ResourcePool pool, CancellationToken token)
        {
            buffer = await pool.GetBuffer();

            var loader = new SpriteLoader(BufferUsageHint.DynamicDraw, buffer);

            tileSet.LoadTileMap(loader, mapIndices, depth);
            sprites = loader.Load();
        }
Пример #4
0
        public static Button Create(XmlReader reader, IWidget parent = null)
        {
            Button button = new Button();

            button.ReadElement(reader, parent);

            String type = reader.GetAttribute("type");

            button.SetParent(parent);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Text":
                        button.Text = reader.ReadElementContentAsString();
                        break;

                    case "Sprite":
                        Sprite sprite = SpriteLoader.Load(new SpriteInfo(reader));
                        button.backgroundComponent.sprite = sprite;
                        //button.backgroundComponent.color = new Color(0, 1, 0, 0.5f);
                        //button.buttonComponent.colors. = new ColorBlock();
                        //color
                        break;

                    default:
                        XmlReader subReader = reader.ReadSubtree();
                        GUIController.ReadElement(subReader, button);
                        subReader.Close();
                        break;
                    }
                }
            }

            switch (type)
            {
            case "sliced":
            default:
                button.backgroundComponent.type = Image.Type.Sliced;
                break;

            case "simple":
                button.backgroundComponent.type           = Image.Type.Simple;
                button.backgroundComponent.preserveAspect = true;
                break;
            }

            return(button);
        }
Пример #5
0
    // Use this for initialization
    void Start()
    {
        dropDown.options.Clear();
        dropDownAtlas.options.Clear();
        foreach (string iconName in iconNames)
        {
            Dropdown.OptionData optionData = new Dropdown.OptionData(iconName);
            dropDown.options.Add(optionData);
            dropDownAtlas.options.Add(optionData);
        }

        dropDown.onValueChanged.AddListener((index) =>
        {
            var selectName = iconNames[index];
            Log.Info("切换{0},{1}", selectName, index);
            var spriteLoader = SpriteLoader.Load(string.Format("uiatlas/button/{0}.png", selectName), (isOk, loadSprite) =>
            {
                if (isOk)
                {
                    targetImage.sprite = loadSprite;
                    targetImage.SetNativeSize();
                    Log.Info("图片加载完成:{0}", selectName);
                }
            });
            if (!spriteLoaders.ContainsKey(spriteLoader.Path))
            {
                spriteLoaders.Add(spriteLoader.Path, spriteLoader);
            }
        });

        //从spriteAtlas加载
        dropDownAtlas.onValueChanged.AddListener((index) =>
        {
            var selectName = iconNames[index];
            Log.Info("切换{0},{1}", selectName, index);
            var atlasPath = "uiatlas/buttonatlas.spriteatlas";
            atlasLoader   = KSpriteAtlasLoader.Load(atlasPath, selectName, (isOk, loadSprite) =>
            {
                if (isOk)
                {
                    targetImage.sprite = loadSprite;
                    targetImage.SetNativeSize();
                    Log.Info("图片加载完成:{0}", selectName);
                }
            });
        });
        btnReleaseAtlas.onClick.AddListener(RelaseAtlasLoader);
        btnRelease.onClick.AddListener(RelaseSpriteLoader);
    }
    protected override void DoProcess(string resourcePath)
    {
        var loader = SpriteLoader.Load(resourcePath, (isOk, sprite) =>
        {
            if (!IsDestroy)
            {
                var spriteRenderer = DependencyComponent as SpriteRenderer;
                Debuger.Assert(spriteRenderer);
                spriteRenderer.sprite = sprite;
            }
            OnFinishLoadDependencies(gameObject); // 返回GameObject而已哦
        });

        this.ResourceLoaders.Add(loader);
    }
Пример #7
0
    void PreInit()
    {
        inputController = gameObject.AddComponent <MouseAndKeyboardController>();
        inputController.worldController = this;
        creativeController = gameObject.AddComponent <CreativeController>();
        creativeController.worldController = this;
        cameraController = gameObject.GetComponent <CameraController>();
        cameraController.worldController = this;

        SpriteLoader.Load();
        new LUA.ScriptLoader();

        guiController = gameObject.AddComponent <GUIController>();
        guiController.worldController = this;
    }
        //see Triangle2DDrawTest for a general tutorial of the resource loading pattern
        public override void OnLoad(GameState state)
        {
            base.OnLoad(state);
            var tex = Texture.Allocate();
            tex.LoadImageFile("assets/sprite-example.png");

            var loader = new SpriteLoader(BufferUsageHint.DynamicDraw, VertexBuffer.Allocate());
            //TODO: test depth sorting
            loader.AddSprite(
                tex,
                new Vector2(0, 0),             //sprite position (top-left corner)
                new Rectangle(0, 0, 48, 21)    //source rectangle in sprite sheet
            );

            sprites = new DrawableSet(loader.Load());
        }
Пример #9
0
    private void Start()
    {
        // いいね!スプライトロード
        sploader = new SpriteLoader();
        sploader.Load("LikeEffects");

        _overray = Overray.GetComponent <Image>();
        Effect.SetActive(false);
        Arrow.SetActive(false);

        // 乱数シードの設定
        Random.InitState(System.Environment.TickCount + 114514);

        // 縦画面にする
        Screen.orientation = ScreenOrientation.Portrait;
    }
Пример #10
0
        //see Triangle2DDrawTest for a general tutorial of the resource loading pattern
        public override void OnLoad(GameState state)
        {
            base.OnLoad(state);
            var tex = Texture.Allocate();

            tex.LoadImageFile("assets/sprite-example.png");

            var loader = new SpriteLoader(BufferUsageHint.DynamicDraw, VertexBuffer.Allocate());

            //TODO: test depth sorting
            loader.AddSprite(
                tex,
                new Vector2(0, 0),             //sprite position (top-left corner)
                new Rectangle(0, 0, 48, 21)    //source rectangle in sprite sheet
                );

            sprites = new DrawableSet(loader.Load());
        }
Пример #11
0
    // Use this for initialization
    void Start()
    {
        dropDown.options.Clear();
        foreach (string iconName in iconNames)
        {
            Dropdown.OptionData optionData = new Dropdown.OptionData(iconName);
            dropDown.options.Add(optionData);
        }

        dropDown.onValueChanged.AddListener((index) =>
        {
            var selectName = iconNames[index];
            Log.Info("切换{0},{1}", selectName, index);
            SpriteLoader.Load(string.Format("uiatlas/button/{0}.png", selectName), (isOk, loadSprite) =>
            {
                if (isOk)
                {
                    targetImage.sprite = loadSprite;
                    targetImage.SetNativeSize();
                    Log.Info("图片加载完成:{0}", selectName);
                }
            });
        });
    }
Пример #12
0
    private void Start()
    {
        // いいね!スプライトロード
        sploader = new SpriteLoader();
        sploader.Load("LikeEffects");

        // 全てのエフェクトのチェックボックスと画像の表示
        var parent      = this.transform.Find("Viewport").Find("Content");
        var effectNames = sploader.GetSpritesName();

        Effects = effectNames.ToDictionary(eff => eff, val => true);
        foreach (var name in effectNames)
        {
            var item = Object.Instantiate(Template, parent) as GameObject;
            item.SetActive(true);
            var image = item.transform.Find("Image").GetComponent <Image>();
            image.sprite = sploader.GetSprite(name);
            image.color  = Color.black;
            item.transform.Find("Toggle").GetComponent <Toggle>().onValueChanged.AddListener((value) =>
            {
                Effects[name] = value;
            });
        }
    }
Пример #13
0
        private static object DoLoad(string file, string ext)
        {
            if (ext == "grf")
            {
                return(File.OpenRead(file));
            }
            else
            {
                using (var br = ReadSync(file)) {
                    if (br == null)
                    {
                        throw new Exception($"Could not load file: {file}");
                    }

                    switch (ext)
                    {
                    // Images
                    case "jpg":
                    case "jpeg":
                    case "png":
                        return(new RawImage()
                        {
                            data = br.ToArray()
                        });

                    case "bmp":
                        return(loader.LoadBMP(br));

                    case "tga":
                        return(TGALoader.LoadTGA(br));

                    // Text
                    case "txt":
                    case "xml":
                    case "lua":
                        return(Encoding.UTF8.GetString(br.ToArray()));

                    case "spr":
                        SPR spr = SpriteLoader.Load(br);
                        spr.SwitchToRGBA();
                        spr.Compile();
                        spr.filename = file;
                        return(spr);

                    case "str":
                        return(EffectLoader.Load(br, Path.GetDirectoryName(file).Replace("\\", "/")));

                    case "act":
                        return(ActionLoader.Load(br));

                    // Binary
                    case "gat":
                        return(AltitudeLoader.Load(br));

                    case "rsw":
                        return(WorldLoader.Load(br));

                    case "gnd":
                        return(GroundLoader.Load(br));

                    case "rsm":
                        return(ModelLoader.Load(br));

                    // Audio
                    case "wav":
                        WAVLoader.WAVFile wav  = WAVLoader.OpenWAV(br.ToArray());
                        AudioClip         clip = AudioClip.Create(file, wav.samples, wav.channels, wav.sampleRate, false);
                        clip.SetData(wav.leftChannel, 0);
                        return(clip);

                    case "mp3":
                    case "ogg":
                        break;

                    case "json":
                        return(JObject.Parse(Encoding.UTF8.GetString(br.ToArray())));

                    default:
                        throw new Exception($"Unsuported file format: {ext} for file {file}");
                    }
                }
            }
            return(null);
        }
Пример #14
0
    private static object DoLoad(string file, string ext)
    {
        //string fileWOExt = file.Replace("." + ext, "");

        switch (ext)
        {
        case "grf":
            return(File.OpenRead(file));

        // Regular images files
        case "jpg":
        case "jpeg":
        case "png":
            using (var br = ReadSync(file)) {
                return(new RawImage()
                {
                    data = br.ToArray()
                });
            }

        case "bmp":
            using (var br = ReadSync(file))
                return(loader.LoadBMP(br));

        case "tga":
            using (var br = ReadSync(file))
                return(TGALoader.LoadTGA(br));

        // Texts
        case "txt":
        case "xml":
        case "lua":
            using (var br = ReadSync(file)) {
                if (br != null)
                {
                    return(Encoding.UTF8.GetString(br.ToArray()));
                }
                else
                {
                    return(null);
                }
            }

        case "spr":
            using (var br = ReadSync(file)) {
                if (br != null)
                {
                    SPR spr = SpriteLoader.Load(br);
                    spr.SwitchToRGBA();
                    spr.Compile();
                    spr.filename = file;
                    return(spr);
                }
                else
                {
                    return(null);
                }
            }

        case "str":
            using (var br = ReadSync(file)) {
                if (br != null)
                {
                    STR str = EffectLoader.Load(br);
                    return(str);
                }
                else
                {
                    return(null);
                }
            }

        // Binary
        case "gat":
            using (var br = ReadSync(file))
                return(new Altitude(br));

        case "rsw":
            using (var br = ReadSync(file))
                return(WorldLoader.Load(br));

        case "gnd":
            using (var br = ReadSync(file))
                return(GroundLoader.Load(br));

        case "rsm":
            using (var br = ReadSync(file))
                return(ModelLoader.Load(br));

        // Audio
        case "wav":
            using (var br = ReadSync(file)) {
                WAVLoader.WAVFile wav  = WAVLoader.OpenWAV(br.ToArray());
                AudioClip         clip = AudioClip.Create(file, wav.samples, wav.channels, wav.sampleRate, false);
                clip.SetData(wav.leftChannel, 0);
                return(clip);
            }

        case "mp3":
        case "ogg":

        case "act":
            //return new Action(ReadSync(file)).compile();
            Debug.LogWarning("Can't read " + file + "\nLoader for " + ext + " is not implemented");
            break;

        default:
            throw new System.Exception("Unknown file format: " + file);
        }
        return(null);
    }