using UnityEngine;
namespace UnityEngine.ProBuilder
{
///
/// Contains information about a ProBuilder action (success, failure, notification, etc)
///
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 was not run because there was no meaningful action to be made.
///
NoChange
}
///
/// State of affairs after the operation.
///
public Status status { get; private set; }
///
/// Short description of the results. Should be no longer than a few words.
///
public string notification { get; private set; }
///
/// Create a new ActionResult.
///
/// State of affairs after an action.
/// A short summary of the action performed.
public ActionResult(ActionResult.Status status, string notification)
{
this.status = status;
this.notification = notification;
}
///
/// Convert a result to a boolean value, true if successful and false if not.
///
///
/// True if action was successful, false otherwise.
public static implicit operator bool(ActionResult res)
{
return res != null && res.status == Status.Success;
}
public bool ToBool()
{
return status == Status.Success;
}
public static bool FromBool(bool success)
{
return success ? ActionResult.Success : new ActionResult(ActionResult.Status.Failure, "Failure");
}
///
/// Generic "Success" action result with no notification text.
///
public static ActionResult Success
{
get { return new ActionResult(ActionResult.Status.Success, ""); }
}
///
/// Generic "No Selection" action result with "Nothing Selected" notification.
///
public static ActionResult NoSelection
{
get { return new ActionResult(ActionResult.Status.Canceled, "Nothing Selected"); }
}
///
/// Generic "Canceled" action result with "User Canceled" notification.
///
public static ActionResult UserCanceled
{
get { return new ActionResult(ActionResult.Status.Canceled, "User Canceled"); }
}
}
}