Beispiel #1
0
 public void Initialize(ColorSwapConfigurator colorSwapData, Material presetMaterial, Color[] sourceColors)
 {
     this.colorSwapData  = colorSwapData;
     this.presetMaterial = presetMaterial;
     colorVariants       = new Color[sourceColors.Length];
     for (int i = 0; i < sourceColors.Length; i++)
     {
         Color c = sourceColors [i];
         colorVariants[i] = new Color(c.r, c.g, c.b, c.a);
     }
 }
Beispiel #2
0
    private void CreateColorSwapConfigurator()
    {
        // Create the correct resource path
        string resourcePath = CreateResourceDirectory();

        if (resourcePath == null)
        {
            return;
        }

        // Create Texture:
        byte[] textureBytes          = generatedTexture.EncodeToPNG();
        string blackWhiteTexturePath = resourcePath + "/" + presetName + "_texture.png";

        File.WriteAllBytes(blackWhiteTexturePath, textureBytes);

        // Create Material:
        string materialPath = CreatePresetMaterial(resourcePath);

        // Delay the using of this texture and material since the editor does not recognize it yet
        EditorApplication.delayCall = () => {
            AssetDatabase.Refresh();

            // Get references to the created assets
            Texture2D createdTexture = AssetDatabase.LoadAssetAtPath <Texture2D> (blackWhiteTexturePath);
            Material  presetMaterial = AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material)) as Material;

            // Create Texture:
            string sourceTexturePath = AssetDatabase.GetAssetPath(selectedTexture);
            CopyTextureImportSettings(sourceTexturePath, blackWhiteTexturePath);

            // Create ColorSwapPreset if it does not yet exist
            string colorSwapPresetPath            = resourcePath + "/" + presetName + ".asset";
            ColorSwapConfigurator colorSwapHolder = AssetDatabase.LoadAssetAtPath(colorSwapPresetPath, typeof(ColorSwapConfigurator)) as ColorSwapConfigurator;
            if (colorSwapHolder == null)
            {
                colorSwapHolder = ScriptableObject.CreateInstance <ColorSwapConfigurator> ();
                AssetDatabase.CreateAsset(colorSwapHolder, colorSwapPresetPath);
            }
            colorSwapHolder.Initialize(colorVariants, selectedTexture, createdTexture, defaultMaterial, presetMaterial);

            AssetDatabase.Refresh();
            EditorGUIUtility.PingObject(colorSwapHolder);
        };
    }
Beispiel #3
0
 private void OnEnable()
 {
     targetScript  = (ColorSwapConfigurator)target;
     newPresetName = DEFAULT_PRESET_NAME;
 }