BetterBurnTime.SafeText.of C# (CSharp) Метод

of() публичный статический Метод

Get a new SafeText that wraps the specified text object.
public static of ( TextMeshProUGUI text ) : SafeText
text TextMeshProUGUI
Результат SafeText
        public static SafeText of(TextMeshProUGUI text)
        {
            // use ReferenceEquals here because Unity does weird overloading of operator ==
            if (Object.ReferenceEquals(text, null)) throw new ArgumentNullException("text cannot be null");
            return new SafeText(text);
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Try to initialize the needed components. Returns true if initialized, false if not.
        /// If this function returns true, you're guaranteed that burn vector and the needed GUI
        /// text objects are available and non-null.
        /// </summary>
        /// <returns></returns>
        private bool AttemptInitialize()
        {
            if (isInitialized)
            {
                return(true);               // already initialized
            }
            DateTime now = DateTime.Now;

            if (lastUpdate + UPDATE_INTERVAL > now)
            {
                return(false);                                    // too soon to try again
            }
            lastUpdate = now;

            // Try to get the navball's burn vector.  This check is needed because it turns
            // out that the timing of when this object becomes available isn't super reliable,
            // so various MonoBehaviour implementations in the mod can't just initialize at
            // Start() time and use it.
            NavBallBurnVector theBurnVector = GameObject.FindObjectOfType <NavBallBurnVector>();

            if (theBurnVector == null)
            {
                return(false);                       // nope, couldn't get it yet!
            }
            // Make sure the burn vector components that we need are there
            if (theBurnVector.ebtText == null)
            {
                return(false);
            }
            if (theBurnVector.TdnText == null)
            {
                return(false);
            }

            TextMeshProUGUI theClonedDurationText = CloneBehaviour(theBurnVector.ebtText);

            if (theClonedDurationText == null)
            {
                return(false);
            }

            TextMeshProUGUI theClonedTimeUntilText = CloneBehaviour(theBurnVector.TdnText);

            if (theClonedTimeUntilText == null)
            {
                Destroy(theClonedDurationText);
                return(false);
            }

            TextMeshProUGUI theCountdownText = CloneBehaviour(theBurnVector.ebtText);

            if (theCountdownText == null)
            {
                Destroy(theClonedDurationText);
                Destroy(theClonedTimeUntilText);
                return(false);
            }
            theCountdownText.enabled            = false;
            theCountdownText.transform.position = Interpolate(
                theBurnVector.TdnText.transform.position,
                theBurnVector.ebtText.transform.position,
                2.0F);

            // Got everything we need!
            burnVector             = theBurnVector;
            originalDurationText   = SafeText.of(burnVector.ebtText);
            originalTimeUntilText  = SafeText.of(burnVector.TdnText);
            alternateDurationText  = SafeText.of(theClonedDurationText);
            alternateTimeUntilText = SafeText.of(theClonedTimeUntilText);
            countdownText          = SafeText.of(theCountdownText);
            isInitialized          = true;

            return(true);
        }