-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add menu to create template object
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace Coffee.UIExtensions.Editors | ||
{ | ||
internal class MenuOptions_UIUnmask | ||
{ | ||
[MenuItem("GameObject/UI/Unmask/Tutorial Button")] | ||
private static void CreateTutorialButton2(MenuCommand menuCommand) | ||
{ | ||
EditorApplication.ExecuteMenuItem("GameObject/UI/Button"); | ||
var button = Selection.activeGameObject.GetComponent<Button>(); | ||
button.name = "Tutorial Button"; | ||
|
||
var unmaskedPanel = CreateUnmaskedPanel(AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd"), Image.Type.Sliced); | ||
var unmask = unmaskedPanel.GetComponentInChildren<Unmask>(); | ||
unmask.fitTarget = button.transform as RectTransform; | ||
unmask.fitOnLateUpdate = true; | ||
|
||
var screen = unmaskedPanel.transform.Find("Screen").GetComponent<Image>(); | ||
screen.gameObject.AddComponent<UnmaskRaycastFilter>().targetUnmask = unmask; | ||
|
||
Selection.activeGameObject = button.gameObject; | ||
} | ||
|
||
[MenuItem("GameObject/UI/Unmask/Iris Shot")] | ||
private static void CreateTransition(MenuCommand menuCommand) | ||
{ | ||
var unmaskedPanel = CreateUnmaskedPanel(AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd"), Image.Type.Simple); | ||
unmaskedPanel.name = "Iris Shot"; | ||
Selection.activeGameObject = unmaskedPanel; | ||
} | ||
|
||
private static GameObject CreateUnmaskedPanel(Sprite unmaskSprite, Image.Type spriteType) | ||
{ | ||
EditorApplication.ExecuteMenuItem("GameObject/UI/Panel"); | ||
var mask = Selection.activeGameObject.AddComponent<Mask>(); | ||
mask.showMaskGraphic = false; | ||
mask.name = "Unmasked Panel"; | ||
mask.GetComponent<Image>().sprite = null; | ||
|
||
EditorApplication.ExecuteMenuItem("GameObject/UI/Image"); | ||
var unmask = Selection.activeGameObject.AddComponent<Unmask>(); | ||
unmask.name = "Unmask"; | ||
unmask.transform.SetParent(mask.transform); | ||
unmask.GetComponent<Image>().sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd"); | ||
|
||
var image = unmask.GetComponent<Image>(); | ||
image.sprite = unmaskSprite; | ||
image.type = spriteType; | ||
|
||
EditorApplication.ExecuteMenuItem("GameObject/UI/Panel"); | ||
var screen = Selection.activeGameObject.GetComponent<Image>(); | ||
screen.name = "Screen"; | ||
screen.sprite = null; | ||
screen.color = new Color(0, 0, 0, 0.8f); | ||
screen.transform.SetParent(mask.transform); | ||
|
||
return mask.gameObject; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.