// Setup element. public void SetAttributes(MinimalPuzzle2DCustomData.AssetClass _data) { if (FieldGraphic) { FieldGraphic.type = _data.ImageType; } if (FieldGraphic) { FieldGraphic.sprite = _data.Graphic; } }
// Draw group box void DrawGraphicThumb(MinimalPuzzle2DCustomData.AssetClass _data) { buttonStyle = EditorStyles.centeredGreyMiniLabel; // Force White draw GUI.color = Color.white; if (GUILayout.Button(_data.Graphic.texture, buttonStyle, GUILayout.Width(ThumbSize), GUILayout.Height(ThumbSize))) { var parent = GetParent(); // Replace element if (Source) { Source.SetAttributes(_data); EditorUtility.SetDirty(Selection.activeGameObject); this.Close(); return; } // Create a new UI element // ----------------------- var obj = Resources.Load <GameObject>("Minimal2D/Prefabs/[UI_Image]"); var clone = Editor.Instantiate(obj); clone.name = obj.name; if (parent) { clone.transform.SetParent(parent.transform, false); } Selection.activeObject = clone; clone.GetComponent <MinimalPuzzle2DComponent>().SetAttributes(_data); clone.GetComponent <MinimalPuzzle2DComponent>().RefreshSize(); // Auto add Color Palette on creation. var type = System.Type.GetType("ColorPaletteComponent"); if (type != null) { clone.AddComponent(type); } } }