using System; using UnityEngine; namespace UnityEngine.ProBuilder { /// /// Contains information about the results of a ProBuilder action (success, failure, and other notifications) /// public sealed class ActionResult { /// /// Describes the results of an action. /// public enum Status { /// /// The action was a success. /// Success, /// /// A critical failure prevented the action from running. /// Failure, /// /// The action was not completed due to invalid parameters. /// Canceled, /// /// The action did not run because there was no meaningful action to be made. /// NoChange } /// /// Gets the status of the action following the operation. /// public Status status { get; private set; } /// /// Gets the short description of the results (a few words long). /// public string notification { get; private set; } /// /// Creates a new ActionResult with a specific status value. /// /// Status value to use for the action. /// A short summary of the action performed. public ActionResult(ActionResult.Status status, string notification) { this.status = status; this.notification = notification; } /// /// Converts the specified result to a boolean value, where true indicates success. /// /// ActionResult to convert. /// True if action was ; false otherwise. public static implicit operator bool(ActionResult res) { return res != null && res.status == Status.Success; } /// /// Checks whether the current ActionResult is set to or not. /// /// True if this ActionResult has a status of ; false otherwise. public bool ToBool() { return status == Status.Success; } /// /// Returns the value of the specified `success` value. /// /// Boolean value to check. /// Generic boolean value corresponding to the success parameter. public static bool FromBool(bool success) { return success ? ActionResult.Success : new ActionResult(ActionResult.Status.Failure, "Failure"); } /// /// Creates a generic "Success" action result with no notification text. /// public static ActionResult Success { get { return new ActionResult(ActionResult.Status.Success, ""); } } /// /// Creates a generic "No Selection" action result with "Nothing Selected" notification. /// public static ActionResult NoSelection { get { return new ActionResult(ActionResult.Status.Canceled, "Nothing Selected"); } } /// /// Creates a generic "Canceled" action result with "User Canceled" notification. /// public static ActionResult UserCanceled { get { return new ActionResult(ActionResult.Status.Canceled, "User Canceled"); } } } }