public static bool Validate(bool forOpeningWindow, out string reasonIfNotValid) { if (!BaseValidate(out reasonIfNotValid)) { return(false); } if (forOpeningWindow) { // Commented: it's safe to re-open the create window //if (IsOpen()) //{ // reasonIfNotValid = "Creation window already opened"; // return false; //} if (InitSRIAWindow.IsOpen()) { reasonIfNotValid = "Initialization window already opened"; return(false); } } if (Selection.gameObjects.Length != 1) { reasonIfNotValid = "One UI Game Object needs to be selected"; return(false); } var asRT = Selection.gameObjects[0].transform as RectTransform; if (!asRT) { reasonIfNotValid = "The selected Game Object doesn't have a RectTransform component"; return(false); } if (asRT.rect.height <= 0f) { reasonIfNotValid = "The selected Game Object has an invalid height"; return(false); } if (asRT.rect.width <= 0f) { reasonIfNotValid = "The selected Game Object has an invalid width"; return(false); } if (!GameObject.FindObjectOfType <EventSystem>()) { reasonIfNotValid = "No EventSystem was found in the scene. Please add one"; return(false); } reasonIfNotValid = null; var tr = asRT as Transform; while (tr) { if (!(tr is RectTransform)) { reasonIfNotValid = "Found a non-RectTransform intermediary parent before first Canvas ancestor. " + "Your hierarchy may be something like: ...Canvas->...->Transform->...-><SelectedObject>. " + "There should only be RectTransforms between the selected object and its most close Canvas ancestor"; return(false); } var c = tr.GetComponent <Canvas>(); if (c) { return(true); } tr = tr.parent; } reasonIfNotValid = "Couldn't find a Canvas in the parents of the selected Game Object"; return(false); }