Ejemplo n.º 1
0
    /// <summary>
    /// Verify given <see cref="Material"/> arrays are valid (not empty nor containing any null
    /// entries, and both arrays of the same length).
    /// </summary>
    private void Awake()
    {
        // Verify that at least one Wall Material and at least one Roof Material has been given.
        if (WallMaterials.Length == 0)
        {
            Debug.LogError(ExampleErrors.EmptyArray(this, WallMaterials, "Wall Materials"));
            return;
        }
        if (RoofMaterials.Length == 0)
        {
            Debug.LogError(ExampleErrors.EmptyArray(this, RoofMaterials, "Roof Materials"));
            return;
        }

        // Verify that the same number of Wall and Roof Materials have been given.
        if (WallMaterials.Length != RoofMaterials.Length)
        {
            Debug.LogErrorFormat("Incorrect number of Building Roof Materials defined for {0}.{1}: {2} "
                                 + "Building Wall Materials were given, but {3} Building Roof Materials were given.\n{1} "
                                 + "needs the same number of Building Roof Materials as Building Wall Materials, i.e. {2} "
                                 + "of each.",
                                 name, GetType(), WallMaterials.Length, RoofMaterials.Length);
            return;
        }

        // Verify that no null Materials have been given.
        for (int i = 0; i < WallMaterials.Length; i++)
        {
            if (WallMaterials[i] == null)
            {
                Debug.LogError(ExampleErrors.NullArrayElement(this, WallMaterials, "Wall Materials", i));
                return;
            }
            if (RoofMaterials[i] == null)
            {
                Debug.LogError(ExampleErrors.NullArrayElement(this, RoofMaterials, "Roof Materials", i));
                return;
            }
        }

        // If have reached this point then have verified that all required parts are present and
        // properly set up.
    }