コード例 #1
0
        protected virtual void Update()
        {
            cooldown -= Time.deltaTime;

            if (cooldown <= 0.0f)
            {
                cooldown = DelayPerHeal;

                if (destructible == null)
                {
                    destructible = GetComponent <D2dDestructible>();
                }

                // Make sure the snapshot matches the current destructible
                if (snapshot.AlphaWidth == destructible.AlphaWidth && snapshot.AlphaHeight == destructible.AlphaHeight)
                {
                    destructible.BeginAlphaModifications();
                    {
                        // Go through all pixels
                        for (var y = snapshot.AlphaHeight - 1; y >= 0; y--)
                        {
                            for (var x = snapshot.AlphaWidth - 1; x >= 0; x--)
                            {
                                // Find current and snapshot alpha values
                                var index    = x + y * snapshot.AlphaWidth;
                                var oldAlpha = destructible.AlphaData[index];
                                var newAlpha = snapshot.AlphaData[index];

                                // Are they different?
                                if (oldAlpha != newAlpha)
                                {
                                    // Move old alpha toward new alpha
                                    newAlpha = (byte)Mathf.MoveTowards(oldAlpha, newAlpha, HealAmount);

                                    // Write the new value
                                    destructible.WriteAlpha(x, y, newAlpha);
                                }
                            }
                        }
                    }
                    destructible.EndAlphaModifications();
                }
            }
        }