Example #1
0
        private void SetupHashAndData(Texture2D texture)
        {
            if (_key == null)
            {
                if (Settings.TextureHashGenerationStrategy == TextureHashGenerationStrategy.FromImageData)
                {
                    var result = TextureHelper.GetData(texture);

                    _originalData = result.Data;
                    _nonReadable  = result.NonReadable;
                    _key          = HashHelper.Compute(_originalData);
                }
                else if (Settings.TextureHashGenerationStrategy == TextureHashGenerationStrategy.FromImageName)
                {
                    var name = texture.name; // name may be duplicate, WILL be duplicate!
                    if (string.IsNullOrEmpty(name))
                    {
                        return;
                    }

                    var result = SetupKeyForNameWithFallback(name, texture);

                    if (Settings.EnableTextureToggling || Settings.DetectDuplicateTextureNames)
                    {
                        if (result == null)
                        {
                            result = TextureHelper.GetData(texture);
                        }

                        _originalData = result.Data;
                        _nonReadable  = result.NonReadable;
                    }
                }
                else if (Settings.TextureHashGenerationStrategy == TextureHashGenerationStrategy.FromImageNameAndScene)
                {
                    var name = texture.name; // name may be duplicate, WILL be duplicate!
                    if (string.IsNullOrEmpty(name))
                    {
                        return;
                    }

                    name += "|" + SceneManagerHelper.GetActiveSceneId();

                    var result = SetupKeyForNameWithFallback(name, texture);

                    if (Settings.EnableTextureToggling || Settings.DetectDuplicateTextureNames)
                    {
                        if (result == null)
                        {
                            result = TextureHelper.GetData(texture);
                        }

                        _originalData = result.Data;
                        _nonReadable  = result.NonReadable;
                    }
                }
            }
        }