Exemple #1
0
 public static PropertyGUI Material(string materialDirectory, bool allowAlpha     = false,
                                    MaterialSelectorGUI.ColorModeSet colorModeSet = MaterialSelectorGUI.ColorModeSet.DEFAULT,
                                    bool colorOnly = false)
 {
     return((Property property) =>
     {
         GUILayout.BeginHorizontal();
         AlignedLabel(property);
         GUILayout.FlexibleSpace();
         // TODO: magic numbers
         RectOffset tagFieldStyleMargin = tagFieldStyle.Value.margin;
         Rect buttonRect = GUILayoutUtility.GetRect(150, 150);
         Rect textureRect = new Rect(
             buttonRect.xMin + 20, buttonRect.yMin + 20,
             buttonRect.width - 20 * 2, buttonRect.height - 20 * 2);
         if (GUI.Button(buttonRect, "  ", tagFieldStyle.Value))
         {
             MaterialSelectorGUI materialSelector
                 = GUIManager.guiGameObject.AddComponent <MaterialSelectorGUI>();
             materialSelector.title = "Change " + property.name;
             materialSelector.rootDirectory = materialDirectory;
             materialSelector.highlightMaterial = (Material)property.value;
             materialSelector.allowAlpha = allowAlpha;
             materialSelector.colorModeSet = colorModeSet;
             materialSelector.colorOnly = colorOnly;
             materialSelector.handler = (Material mat) =>
             {
                 property.setter(mat); // skip equality check, it could be the same material with a different color
             };
         }
         MaterialSelectorGUI.DrawMaterialTexture((Material)property.value,
                                                 textureRect, allowAlpha);
         GUILayout.EndHorizontal();
     });
 }
Exemple #2
0
    private void DrawPaint(VoxelFace paint, Rect rect)
    {
        float   rotation    = VoxelFace.GetOrientationRotation(paint.orientation) * 90;
        Vector2 scaleFactor = Vector2.one;

        if (VoxelFace.GetOrientationMirror(paint.orientation))
        {
            scaleFactor = new Vector2(-1, 1);
            rotation   += 90;
        }
        Matrix4x4 baseMatrix = GUI.matrix;

        RotateAboutPoint(rect.center, rotation, scaleFactor);
        MaterialSelectorGUI.DrawMaterialTexture(paint.material, rect, false);
        MaterialSelectorGUI.DrawMaterialTexture(paint.overlay, rect, true);
        GUI.matrix = baseMatrix;
    }
Exemple #3
0
 private void UpdateMaterialSelector()
 {
     if (materialSelector != null)
     {
         Destroy(materialSelector);
     }
     materialSelector                   = gameObject.AddComponent <MaterialSelectorGUI>();
     materialSelector.enabled           = false;
     materialSelector.allowNullMaterial = true; // TODO: disable if no substances selected
     materialSelector.closeOnSelect     = false;
     if (selectedLayer == 0)
     {
         materialSelector.rootDirectory = "Materials";
         materialSelector.handler       = (Material mat) =>
         {
             if (mat != null || paint.overlay != null)
             {
                 paint.material = mat;
             }
             handler(paint);
         };
         materialSelector.highlightMaterial = paint.material;
     }
     else
     {
         materialSelector.rootDirectory = "Overlays";
         materialSelector.allowAlpha    = true;
         materialSelector.handler       = (Material mat) =>
         {
             if (mat != null || paint.material != null)
             {
                 paint.overlay = mat;
             }
             handler(paint);
         };
         materialSelector.highlightMaterial = paint.overlay;
     }
     materialSelector.Start(); // not enabled so wouldn't be called normally
 }