Beispiel #1
0
    void Awake()
    {
        Debug.Log("GM Awake called.");
        instance = this;

        SpriteResourceManager.Initialize();
        ItemFactory.Initialize();

        inventoryCanvas = GameObject.Find("InventoryCanvas");
        ToggleInventory();
    }
Beispiel #2
0
    public void SetInfo(string t, string icon)
    {
        textbox = transform.FindChild("foo").GetComponent <Text>();
        image   = transform.FindChild("Image").GetComponent <Image>();

        var tt = textbox.GetComponent <Text>();

        tt.text = t;

        image.sprite = SpriteResourceManager.Get(icon);
    }
        public void EquipWeapon(Item item)
        {
            var gfx = transform.FindChild("WeaponSlot").FindChild("Quad");
            var ren = gfx.GetComponent <MeshRenderer>();

            //if (item == null || item.ItemIcon==null)
            if (item == null || String.IsNullOrEmpty(item.Icon))
            {
                ren.enabled = false;
                return;
            }

            //ren.material.mainTexture = item.ItemIcon.texture;
            ren.material.mainTexture = SpriteResourceManager.Get(item.Icon).texture;
            ren.enabled = true;
        }
    public void UpdateGraphics()
    {
        if (_visual == null)
        {
            Debug.LogError("Trying to set Graphics before visual exists.");
            return;
        }

        var mr = _visual.GetComponent <MeshRenderer>();

        if (mr != null)
        {
            Material material = Instantiate(mr.material);
            material.mainTexture = SpriteResourceManager.Get(Item.Icon).texture;
            mr.material          = material;
        }
    }
Beispiel #5
0
    public void initialize(string spriteName, Vector2 coords, Color blendColor, int depth = 0, bool pixelCoords = false)
    {
        if (spriteRenderer == null)
        {
            spriteRenderer = GetComponent <SpriteRenderer>();
        }
        spriteRenderer.sprite       = SpriteResourceManager.loadSprite("InteractionIcons/" + spriteName);
        spriteRenderer.sortingOrder = depth;
        spriteRenderer.color        = blendColor;

        if (pixelCoords)
        {
            transform.position = coords;
        }
        else
        {
            transform.position = TileController.hexCoordToPixelCoord(coords);
        }
    }
Beispiel #6
0
    public void initialize(UnitInfo info, int team = -1)
    {
        SpriteRenderer[] list = GetComponentsInChildren <SpriteRenderer>();
        if (list.Length != 5)
        {
            throw new UnityException("Dude... you need two childern of a unit with spriterenders in them... re-attach them please");
        }
        unitInfo             = info.clone();
        baseSpriteRenderer   = list[0];
        color0SpriteRenderer = list[1];
        color1SpriteRenderer = list[2];
        color2SpriteRenderer = list[3];
        color3SpriteRenderer = list[4];

        //teamNumber = team;

        if (info.baseSpriteName != null)
        {
            getBaseSpriteRenderer().sprite = SpriteResourceManager.loadSprite("Units/" + info.baseSpriteName);
        }
        if (info.color0SpriteName != null)
        {
            getColor0SpriteRenderer().sprite = SpriteResourceManager.loadSprite("Units/" + info.color0SpriteName);
        }
        if (info.color1SpriteName != null)
        {
            getColor1SpriteRenderer().sprite = SpriteResourceManager.loadSprite("Units/" + info.color1SpriteName);
        }
        if (info.color2SpriteName != null)
        {
            getColor2SpriteRenderer().sprite = SpriteResourceManager.loadSprite("Units/" + info.color2SpriteName);
        }
        if (info.color3SpriteName != null)
        {
            getColor3SpriteRenderer().sprite = SpriteResourceManager.loadSprite("Units/" + info.color3SpriteName);
        }

        /*for (int i = 0; i < unitInfo.movementObjects.Count; i++)
         * {
         *  unitInfo.movementObjects[i] = unitInfo.movementObjects[i].clone();//Create unit's own movementtype
         * }*/

        if (team >= 0)
        {
            setTeam(team);
            //getColorsSpriteRenderer().color = TeamControllerScript.getTeamColor(team);
        }


        if (unitInfo.rotationEnabled)
        {
            // Rotation Indicator
            Vector2 pos = TileController.hexCoordToPixelCoord(this.transform.position);
            rotationIndicator = (GameObject)Instantiate(new GameObject(), new Vector3(pos.x, pos.y, 0), Quaternion.identity);

            rotationIndicator.transform.parent = this.transform;

            SpriteRenderer spr = rotationIndicator.AddComponent <SpriteRenderer>();

            spr.sprite           = SpriteResourceManager.loadSprite("Misc/RotationIndicator");
            spr.sortingLayerName = "SpriteLayer";
            spr.sortingOrder     = 1000; // We want this to be above everythign else

            setRotationDirection(AbsoluteDirection.UP);
        }
    }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Renderer" /> class.
        /// </summary>
        /// <param name="gameEngine">The game engine.</param>
        /// <param name="form">The form.</param>
        /// <param name="width">The primary width of the view in pixels.</param>
        /// <param name="height">The primary height of the view in pixels.</param>
        public Renderer(IGameEngine gameEngine, GameForm form, int width, int height)
        {
            if (gameEngine == null)
            {
                throw new ArgumentNullException(nameof(gameEngine));
            }

            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }

            _form   = form;
            _resize = false;
            _scale  = 1.0f;
            _width  = width;
            _height = height;

            _dwFactory = new SharpDX.DirectWrite.Factory();
            InitFonts();

            // DeviceCreationFlags.BgraSupport must be enabled to allow Direct2D interop.
            SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport);

            // Query the default device for the supported device and context interfaces.
            _device     = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>();
            _d3dContext = _device.ImmediateContext.QueryInterface <SharpDX.Direct3D11.DeviceContext1>();

            // Query for the adapter and more advanced DXGI objects.
            using (var dxgiDevice2 = _device.QueryInterface <SharpDX.DXGI.Device2>())
            {
                _d2dFactory = new SharpDX.Direct2D1.Factory2(SharpDX.Direct2D1.FactoryType.SingleThreaded);

                // Get the default Direct2D device and create a context.
                using (var d2dDevice = new SharpDX.Direct2D1.Device1(_d2dFactory, dxgiDevice2))
                {
                    _d2dContext = new SharpDX.Direct2D1.DeviceContext1(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);
                }
            }

            CreateSizeDependentResources();

            _d2dContext.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased;
            _d2dContext.AntialiasMode     = AntialiasMode.Aliased;
            _d2dContext.UnitMode          = UnitMode.Pixels;

            _hudYellow     = new SolidColorBrush(_d2dContext, new Color4(1.0f, 1.0f, 0.0f, 1.0f));
            _hudWhite      = new SolidColorBrush(_d2dContext, new Color4(1.0f, 1.0f, 1.0f, 1.0f));
            _hudTextFormat = new TextFormat(_dwFactory, "Sonic Genesis/Mega Drive Font", _fontCollection, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 14);

            // init game stuff
            _game = gameEngine;

            _texResMan    = new TextureResourceManager(gameEngine, _d2dContext);
            _spriteResMan = new SpriteResourceManager(gameEngine, _d2dContext);

            // get the services
            _mapService       = _game.GetService <IMapService>();
            _varService       = _game.GetService <IVariableService>();
            _entityService    = _game.GetService <IEntityService>();
            _renderService    = _game.GetService <IRenderService>();
            _collisionService = _game.GetService <ICollisionService>();

            _varShowCollisionMaps  = _varService.GetVar <bool>("r_showcollisionmaps");
            _varShowTileFrames     = _varService.GetVar <bool>("r_showtileframes");
            _varShowEntityOrigins  = _varService.GetVar <bool>("r_showentityorigins");
            _varShowTraceLines     = _varService.GetVar <bool>("r_showtracelines");
            _varShowCollisionBoxes = _varService.GetVar <bool>("r_showcollisionboxes");

            _rc = new RenderContext();

            _spriteRenderList = new List <Animatable>(25);
        }
Beispiel #8
0
 /// <summary>
 /// ゲームを変更します。
 /// </summary>
 /// <param name="scene"></param>
 /// <param name="param"></param>
 /// <param name="spriteResourceManager"></param>
 public void ChangeGame(ISceneBase scene, Dictionary <string, object> param, SpriteResourceManager spriteResourceManager)
 {
     InnerPrepareNextScene(null, scene, param, null, true, spriteResourceManager);
 }