/// <summary>
    /// Verifies a condition on the specified GameObject.
    /// </summary>
    /// <param name="gameObject">The GameObject on which to enforce a condition.</param>
    /// <returns>A List of FieldViolations that are present, or an empty list of no such violations were found.</returns>
    public List <FieldViolation> VerifyCondition(GameObject gameObject)
    {
        Asserter.NotNull(gameObject, "BaseConditionVerifier.VerifyConditions:gameObject is null");

        List <FieldViolation> fieldViolations = new List <FieldViolation>();

        foreach (MonoBehaviour component in gameObject.GetComponents <MonoBehaviour>())
        {
            if (!component)
            {
                continue;
            }
            List <MemberInfo> members = VerifierUtils.GetMembersWithAttribute(component, GetAttributeType);

            foreach (MemberInfo member in members)
            {
                FieldViolation[] fieldViolation;
                if (VerifyMember(component, member, VerifierUtils.GetAttributesOfType <T>(member), out fieldViolation))
                {
                    fieldViolations.AddRange(fieldViolation);
                }
            }
        }

        return(fieldViolations);
    }
Beispiel #2
0
    /// <summary>
    /// Finds all members of the given MonoBehaviour that have been tagged with a ConditionVerifierAttribute of the specified Type T.
    /// </summary>
    /// <param name="component">The MonoBehaviour on which to search for members.</param>
    /// <param name="attributeType">The Type of ConditionVerifierAttribute with which returned members have been tagged.</param>
    /// <returns>A List of MemberInfo representing the members found on the MonoBehaviour tagged with the given attribute type.</returns>
    public static List <MemberInfo> GetMembersWithAttribute(MonoBehaviour component, Type attributeType)
    {
        Asserter.NotNull(component);
        Asserter.NotNull(attributeType);

        Type componentType = component.GetType();

        MemberInfo[] members = componentType.GetMembers();

        List <MemberInfo> membersWithAttribute = new List <MemberInfo>();

        foreach (MemberInfo memberInfo in members)
        {
            if (MemberInfoHasConditionAttribute(memberInfo, attributeType))
            {
                membersWithAttribute.Add(memberInfo);
            }
        }

        if (MemberInfoHasConditionAttribute(component.GetType(), attributeType))
        {
            membersWithAttribute.Add(component.GetType());
        }

        return(membersWithAttribute);
    }
Beispiel #3
0
    /// <summary>
    /// Constructs a new WebOperationCriteria.
    /// </summary>
    /// <param name="URL">The URL of the operation.</param>
    /// <param name="fields">A Dictionary containing the data fields of the operation.</param>
    public WebOperationCriteria(string URL, Dictionary <string, string> fields)
    {
        Asserter.NotNullOrEmpty(URL, "WebOperationCriteria.ctor:URL is null or empty");
        Asserter.NotNull(fields, "WebOperationCriteria.ctor:fields is null or empty");

        this.URL = URL;
        Fields   = fields;
    }
Beispiel #4
0
    /// <summary>
    /// Constructs a FieldViolation object.
    /// </summary>
    /// <param name="ViolatingObject">The GameObject on which the violation occurs.</param>
    /// <param name="Target">The object causing the violation on the GameObject. May be null.</param>
    /// <param name="Message">A message containing details about the violation.</param>
    public FieldViolation(GameObject ViolatingObject, object Target, string Message)
    {
        Asserter.NotNull(ViolatingObject);
        Asserter.NotNullOrEmpty(Message);

        this.ViolatingObject = ViolatingObject;
        this.Target          = Target;
        this.Message         = Message;
    }
Beispiel #5
0
    /// <summary>
    /// Executes the RegisterOperation asynchronously. The RegisterOperationCallback will be invoked when the operation has completed.
    /// </summary>
    /// <param name="registerOperationCallback">The RegisterOperationCallback to be invoked when the operation completes.</param>
    public void ExecuteAsync(RegisterOperationCallback registerOperationCallback)
    {
        Asserter.NotNull(registerOperationCallback, "RegisterOperation.ExecuteAsync:registerOperationCallback is null");
        WebOperationCallback webOperationCallback = (ResultSet results) =>
        {
            RegisterOperationResult result = CreateResultFromResultSet(results);
            registerOperationCallback(result);
        };

        WebOperation.ExecuteAsync(new WebOperationCriteria(WebOperationURLs.GetURL(GetType()), CreateFieldDictionaryFromCriteria(_criteria)), webOperationCallback);
    }
Beispiel #6
0
    /// <summary>
    /// Executes a WebOperation with the given criteria.
    /// </summary>
    /// <param name="criteria">Criteria that specifies how to invoke the operation.</param>
    /// <returns>A WWW object containing the results of the operation.</returns>
    public static ResultSet Execute(WebOperationCriteria criteria)
    {
        Asserter.NotNull(criteria, "WebOperation.Execute:criteria is null");

        if (_webOperation == null)
        {
            _webOperation = new WebOperation();
        }

        return(_webOperation.ExecuteOperation(criteria));
    }
Beispiel #7
0
    public static T FindGameObjectWithComponent <T>(string GameObjectName) where T : Component
    {
        GameObject gameObject = GameObject.Find(GameObjectName);

        Asserter.NotNull(gameObject, "GameObjectExt.FindGameObjectWithComponent:Could not find gameObject by name \"" + GameObjectName + "\"");
        T component = gameObject.GetComponent <T>();

        Asserter.NotNull(component, "GameObjectExt.FindGameObjectWithComponent:Could not find component of type \"" + typeof(T).Name + "\" on GameObject \"" + GameObjectName + "\"");

        return(component);
    }
Beispiel #8
0
    /// <summary>
    /// Executes a WebOperation with the given criteria asynchronously. Upon completion, the given WebOperationCallback is invoked with the results of the operation.
    /// </summary>
    /// <param name="criteria">Criteria that specifies how to invoke the operation.</param>
    /// <param name="callback">The callback to be invoked upon completion of the operation.</param>
    public static void ExecuteAsync(WebOperationCriteria criteria, WebOperationCallback webOperationCallback)
    {
        Asserter.NotNull(criteria, "WebOperation.ExecuteAsync:criteria is null");
        Asserter.NotNull(webOperationCallback, "WebOpreation.ExecuteAsync:webOperationCallback");

        if (_webOperation == null)
        {
            _webOperation = new WebOperation();
        }

        _webOperation.ExecuteOperationAsync(criteria, webOperationCallback);
    }
Beispiel #9
0
    /// <summary>
    /// Executes the LoginOperation asynchronously. The LoginOperationCallback will be invoked when the results are ready.
    /// </summary>
    /// <param name="loginOperationCallback">The callback to be invoked when the result of the LoginOperation is ready.</param>
    public void ExecuteAsync(LoginOperationCallback loginOperationCallback)
    {
        Asserter.NotNull(loginOperationCallback, "LoginOperation.ExecuteAsync:loginOperationCallback is null");
        Dictionary <string, string> fields = new Dictionary <string, string>();

        fields.Add(kUSERNAME_FIELD, _criteria.Username);
        fields.Add(kPASSWORD_FIELD, _criteria.Password);

        WebOperationCallback webOperationCallback = (ResultSet resultSet) =>
        {
            LoginOperationResult result = CreateResultFromResultSet(resultSet);
            loginOperationCallback(result);
        };

        WebOperation.ExecuteAsync(new WebOperationCriteria(WebOperationURLs.GetURL(GetType()), fields), webOperationCallback);
    }
Beispiel #10
0
    /// <summary>
    /// Constructs a WebOperationURLs object.
    /// </summary>
    private WebOperationURLs()
    {
        TextAsset text = (TextAsset)Resources.Load(kURL_PATH, typeof(TextAsset));

        Asserter.NotNull(text, "WebOperationURLs.ctor:failed to load WebOperations.txt");

        StreamReader reader = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(text.text)));

        while (!reader.EndOfStream)
        {
            string   line      = reader.ReadLine();
            string[] splitLine = line.Split(' ');

            Asserter.IsTrue(splitLine.Length == 2, "WebOperationURLs.ctor:unexpected input from WebOperations.txt");
            _urlsByType.Add(splitLine[0], splitLine[1]);
        }
    }
Beispiel #11
0
    // Use this for initialization
    void Start()
    {
        Asserter.NotNull(StartNode, "RailCrawler.Start:StartNode is null");
        Asserter.NotNull(StartNode.NextNode, "RailCrawler.Start:StartNode.NextNode is null");
        Asserter.NotNull(StartNode.NextNode.NextNode, "RailCrawler.Start:StartNode.NextNode.NextNode is null");
        Asserter.NotNull(StartNode.NextNode.NextNode.NextNode, "RailCrawler.StartNode.NextNode.NextNode.NextNode is null");

        _previousNode = StartNode;
        _currentNode  = StartNode.NextNode;

        _lastRailPosition = StartNode.transform.position;

        Vector3 startingPoint = GetPosition(_previousNode, 0, Tau);
        Vector3 nextPoint     = GetPosition(_previousNode, 0.0166667f, Tau);

        Direction = (nextPoint - startingPoint).normalized;
        Position  = startingPoint;
    }
Beispiel #12
0
    /// <summary>
    /// Finds all members of the given GameObject's MonoBehaviours that have been tagged with a ConditionVerifierAttribute of a specified type.
    /// </summary>
    /// <param name="gameObject">The GameObject on which to search for members.</param>
    /// <param name="attributeType">The Type of ConditionVerifierAttribute with which returned members have been tagged.</param>
    /// <returns>A List of MemberInfo representing the members found on the GameObject's MonoBehaviours tagged with the given attribute type.</returns>
    public static List <MemberInfo> GetMembersWithAttribute(GameObject gameObject, Type attributeType)
    {
        Asserter.NotNull(gameObject);
        Asserter.NotNull(attributeType);
        List <MemberInfo> membersWithAttribute = new List <MemberInfo>();

        MonoBehaviour[] components = gameObject.GetComponents <MonoBehaviour>();
        foreach (MonoBehaviour component in components)
        {
            if (!component)
            {
                // stupid; missing components will be null but still show up.
                continue;
            }
            membersWithAttribute.AddRange(GetMembersWithAttribute(component, attributeType));
        }

        return(membersWithAttribute);
    }
Beispiel #13
0
 public static IAsserter NotNull(object arg)
 {
     return(_instance.NotNull(arg));
 }
Beispiel #14
0
    /// <summary>
    /// Returns true if the given MemberInfo has been tagged with a ConditionVerifierAttribute of the type T.
    /// </summary>
    /// <typeparam name="T">The Type of ConditionVerifierAttribute to look for.</typeparam>
    /// <param name="memberInfo">The MemberInfo on which to search for ConditionVerifierAttributes.</param>
    /// <returns>True if the given MemberInfo has been tagged with a ConditionVerifierAttribute of type T.</returns>
    public static bool MemberInfoHasConditionAttribute <T>(MemberInfo memberInfo) where T : ConditionVerifierAttribute
    {
        Asserter.NotNull(memberInfo);

        return(MemberInfoHasConditionAttribute(memberInfo, typeof(T)));
    }
Beispiel #15
0
 // TODO re-enable asserter.
 public static T Load <T>(string path) where T : UnityEngine.Object
 {
     UnityEngine.Object asset = Resources.Load(path, typeof(T));
     Asserter.NotNull(asset, "ResourcesExt.Load<T>:Asset at path \"" + path + "\" could not be found, or is not of specified type \"" + typeof(T).Name + "\"");
     return((T)asset);
 }
Beispiel #16
0
 /// <summary>
 /// Returns true if the given MemberInfo has been tagged with a ConditionVerifierAttribute of the type T.
 /// </summary>
 /// <param name="memberInfo">The MemberInfo on which to search for ConditionVerifierAttributes.</param>
 /// <param name="attributeType">The Type of ConditionVerifierAttribute to look for.</param>
 /// <returns>True if the given MemberInfo has been tagged with a ConditionVerifierAttribute of the specified type.</returns>
 public static bool MemberInfoHasConditionAttribute(MemberInfo memberInfo, Type attributeType)
 {
     Asserter.NotNull(memberInfo);
     Asserter.NotNull(attributeType);
     return(memberInfo.GetCustomAttributes(attributeType, true).Length > 0 ? true : false);
 }
        public T Resolve <T>()
        {
            Asserter.NotNull(container);

            return(container.Resolve <T>());
        }
Beispiel #18
0
 /// <summary>
 /// Returns all ConditionVerifierAttributes present on the given MemberInfo.
 /// </summary>
 /// <typeparam name="T">The Type of ConditionVerifierAttributes to return.</typeparam>
 /// <param name="memberInfo">The MemberInfo on which to search for ConditionVerifierAttributes.</param>
 /// <returns>An array of type T containing the ConditionVerifierAttributes found on the given MemberInfo.</returns>
 public static T[] GetAttributesOfType <T>(MemberInfo memberInfo) where T : ConditionVerifierAttribute
 {
     Asserter.NotNull(memberInfo);
     return(memberInfo.GetCustomAttributes(typeof(T), true) as T[]);
 }
Beispiel #19
0
 /// <summary>
 /// Finds all members of the given GameObject's MonoBehaviours that have been tagged with a ConditionVerifierAttribute of the specified Type T.
 /// </summary>
 /// <typeparam name="T">The Type of ConditionVerifierAttribute with which returned members have been tagged.</typeparam>
 /// <param name="gameObject">The GameObject on which to search for members.</param>
 /// <returns>A List of MemberInfo representing the members found on the GameObject's MonoBehaviours tagged with the T attribute.</returns>
 public static List <MemberInfo> GetMembersWithAttribute <T>(GameObject gameObject) where T : ConditionVerifierAttribute
 {
     Asserter.NotNull(gameObject);
     return(GetMembersWithAttribute(gameObject, typeof(T)));
 }
Beispiel #20
0
 public static GetGroupsOperation Create(GetGroupsOperationCriteria getGroupsOperationCriteria)
 {
     Asserter.NotNull(getGroupsOperationCriteria, "GetGroupOperation.Create:GetGroupsOperationCriteria is null");
     return(new GetGroupsOperation(getGroupsOperationCriteria));
 }
Beispiel #21
0
 /// <summary>
 /// Finds all members of the given MonoBehaviour that have been tagged with a ConditionVerifierAttribute of the specified Type T.
 /// </summary>
 /// <typeparam name="T">The Type of ConditionVerifierAttribute with which returned members have been tagged.</typeparam>
 /// <param name="component">The MonoBehaviour on which to search for members.</param>
 /// <returns>A List of MemberInfo representing the members found on the MonoBehaviour tagged with the T attribute.</returns>
 public static List <MemberInfo> GetMembersWithAttribute <T>(MonoBehaviour component) where T : ConditionVerifierAttribute
 {
     Asserter.NotNull(component);
     return(GetMembersWithAttribute(component, typeof(T)));
 }
Beispiel #22
0
 /// <summary>
 /// Creates a LoginOperation object.
 /// </summary>
 /// <param name="criteria">Criteria containing the data required to login.</param>
 /// <returns>A LoginOperation object ready to execute.</returns>
 /// <throws>AssertionFailureException if the given criteria is null.</throws>
 public static LoginOperation Create(LoginCriteria criteria)
 {
     Asserter.NotNull(criteria, "LoginOperation.Create:criteria is null");
     return(new LoginOperation(criteria));
 }
Beispiel #23
0
 /// <summary>
 /// Creates a RegisterOperation object.
 /// </summary>
 /// <param name="criteria">Criteria containing the data required to register a new account.</param>
 /// <returns>A RegisterOperation object ready to execute, or null if the criteria contains invalid data.</returns>
 public static RegisterOperation Create(RegisterOperationCriteria criteria)
 {
     Asserter.NotNull(criteria, "RegisterOperation.Create:criteria is null");
     return(new RegisterOperation(criteria));
 }