/// <summary>
        /// Get animations for current spellcast.
        /// This happens the first time a spell is cast and stored for re-casting.
        /// It's likely player will use a wide variety of spell types in normal play.
        /// </summary>
        void SetCurrentAnims(ElementTypes elementType, int border = 0, bool dilate = false)
        {
            // Attempt to get current anims
            if (castAnims.ContainsKey(elementType))
            {
                currentAnimType = elementType;
                currentAnims    = castAnims[elementType];
                return;
            }

            // Load spellcast file
            string     filename = WeaponBasics.GetMagicAnimFilename(elementType);
            string     path     = Path.Combine(DaggerfallUnity.Instance.Arena2Path, filename);
            CifRciFile cifFile  = new CifRciFile();

            if (!cifFile.Load(path, FileUsage.UseMemory, true))
            {
                throw new Exception(string.Format("Could not load spell anims file {0}", path));
            }

            // Load CIF palette
            cifFile.Palette.Load(Path.Combine(DaggerfallUnity.Instance.Arena2Path, cifFile.PaletteName));

            // Load textures - spells have a single frame per record unlike weapons
            Texture2D[] frames = new Texture2D[cifFile.RecordCount];
            for (int record = 0; record < cifFile.RecordCount; record++)
            {
                Texture2D texture = null;

                // Get Color32 array
                DFSize    sz;
                Color32[] colors = cifFile.GetColor32(record, 0, 0, border, out sz);

                // Dilate edges
                if (border > 0 && dilate)
                {
                    ImageProcessing.DilateColors(ref colors, sz);
                }

                // Create Texture2D
                texture = new Texture2D(sz.Width, sz.Height, TextureFormat.ARGB32, false);
                texture.SetPixels32(colors);
                texture.Apply(true);

                // Set filter mode and store in frames array
                if (texture)
                {
                    texture.filterMode = (FilterMode)DaggerfallUnity.Settings.MainFilterMode;
                    frames[record]     = texture;
                }
            }

            // Add frames array to dictionary
            castAnims.Add(elementType, frames);

            // Use as current anims
            currentAnimType = elementType;
            currentAnims    = frames;
        }
Esempio n. 2
0
        private void LoadWeaponAtlas()
        {
            // Get weapon filename
            string filename = WeaponBasics.GetWeaponFilename(WeaponType);

            // Load the weapon texture atlas
            // Texture is dilated into a transparent coloured border to remove dark edges when filtered
            // Important to use returned UV rects when drawing to get right dimensions
            weaponAtlas            = GetWeaponTextureAtlas(filename, MetalType, out weaponRects, out weaponIndices, 2, 2, true);
            weaponAtlas.filterMode = dfUnity.MaterialReader.MainFilterMode;

            // Get weapon anims
            weaponAnims = (WeaponAnimation[])WeaponBasics.GetWeaponAnims(WeaponType).Clone();

            // Store current weapon
            currentWeaponType = WeaponType;
            currentMetalType  = MetalType;
        }