/// <summary> /// Copy constructor. Initializes a new ScaledRect. /// </summary> /// <param name='source'> /// Source to copy. /// </param> public ScaledRect(ScaledRect source) { if (source != null) { this.origin = source.origin; this.alignment = source.alignment; this.x = new ScaledValue(source.x); this.y = new ScaledValue(source.y); this.width = new ScaledValue(source.width); this.height = new ScaledValue(source.height); this.minPixelWidth = source.minPixelWidth; this.minPixelHeight = source.minPixelHeight; } }
public static void CreateUnityGUIQuestLogWindow() { // Create GUI root: GameObject questLogWindowObject = AddChildGameObject("Quest Log Window", typeof(UnityGUIQuestLogWindow)); Selection.activeGameObject = questLogWindowObject; GameObject root = AddChildGameObject("GUI Root", typeof(GUIRoot)); Selection.activeGameObject = root; GameObject window = AddChildGameObject("Window", typeof(GUIWindow)); GameObject abandonQuestPopup = AddChildGameObject("Abandon Quest Popup", typeof(GUIWindow)); // Create quest window: Selection.activeObject = window; GameObject scrollView = AddChildGameObject("Scroll View", typeof(GUIScrollView)); Selection.activeGameObject = window; ScaledRect activeButtonRect = new ScaledRect(ScaledRectAlignment.TopCenter, ScaledRectAlignment.TopRight, ScaledValue.FromPixelValue(0), ScaledValue.FromPixelValue(0), ScaledValue.FromNormalizedValue(0.5f), ScaledValue.FromNormalizedValue(0.1f), 0, 0); GUIButton activeButton = CreateButton(activeButtonRect, "Active Quests", "ClickShowActiveQuests", questLogWindowObject); ScaledRect completedButtonRect = new ScaledRect(ScaledRectAlignment.TopCenter, ScaledRectAlignment.TopLeft, ScaledValue.FromPixelValue(0), ScaledValue.FromPixelValue(0), ScaledValue.FromNormalizedValue(0.5f), ScaledValue.FromNormalizedValue(0.1f), 0, 0); GUIButton completedButton = CreateButton(completedButtonRect, "Completed Quests", "ClickShowCompletedQuests", questLogWindowObject); ScaledRect closeRect = new ScaledRect(ScaledRectAlignment.BottomCenter, ScaledRectAlignment.BottomCenter, ScaledValue.FromPixelValue(0), ScaledValue.FromPixelValue(0), ScaledValue.FromNormalizedValue(1), ScaledValue.FromNormalizedValue(0.1f), 0, 0); CreateButton(closeRect, "Close", "OnClose", questLogWindowObject); UnityGUIQuestLogWindow questLogWindow = questLogWindowObject.GetComponent<UnityGUIQuestLogWindow>(); questLogWindow.guiRoot = root.GetComponent<GUIRoot>(); questLogWindow.scrollView = scrollView.GetComponent<GUIScrollView>(); questLogWindow.activeButton = activeButton; questLogWindow.completedButton = completedButton; // Create abandon quest popup: Selection.activeObject = abandonQuestPopup; ScaledRect okButtonRect = new ScaledRect(ScaledRectAlignment.BottomCenter, ScaledRectAlignment.BottomRight, ScaledValue.FromPixelValue(0), ScaledValue.FromPixelValue(0), ScaledValue.FromNormalizedValue(0.5f), ScaledValue.FromNormalizedValue(0.1f), 0, 0); GUIButton okButton = CreateButton(okButtonRect, "Abandon", "ClickConfirmAbandonQuest", questLogWindowObject); ScaledRect cancelButtonRect = new ScaledRect(ScaledRectAlignment.BottomCenter, ScaledRectAlignment.BottomLeft, ScaledValue.FromPixelValue(0), ScaledValue.FromPixelValue(0), ScaledValue.FromNormalizedValue(0.5f), ScaledValue.FromNormalizedValue(0.1f), 0, 0); GUIButton cancelButton = CreateButton(cancelButtonRect, "Cancel", "ClickCancelAbandonQuest", questLogWindowObject); GameObject questTitle = AddChildGameObject("Quest Title Label", typeof(GUILabel)); questLogWindow.abandonQuestPopup.panel = abandonQuestPopup.GetComponent<GUIWindow>(); questLogWindow.abandonQuestPopup.ok = okButton; questLogWindow.abandonQuestPopup.cancel = cancelButton; questLogWindow.abandonQuestPopup.questTitleLabel = questTitle.GetComponent<GUILabel>(); // Select main window: Selection.activeGameObject = questLogWindowObject; }
private static GUIButton CreateButton(ScaledRect scaledRect, string name, string message, GameObject target) { GameObject buttonObject = AddChildGameObject(name, typeof(GUIButton)); GUIButton button = buttonObject.GetComponent<GUIButton>(); button.scaledRect = scaledRect; button.text = name; button.message = message; button.target = target.transform; return button; }