Exemplo n.º 1
0
 private static bool HasFlag(TrackBindingErrors errors, TrackBindingErrors flag)
 {
     return((errors & flag) != 0);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the error text for the specified track.
        /// </summary>
        /// <param name="track">The track to retrieve options for.</param>
        /// <param name="boundObject">The binding for the track.</param>
        /// <param name="detectErrors">The errors to check for.</param>
        /// <returns>An error to be displayed on the track, or string.Empty if there is no error.</returns>
        public string GetErrorText(TrackAsset track, UnityEngine.Object boundObject, TrackBindingErrors detectErrors)
        {
            if (track == null || boundObject == null)
            {
                return(string.Empty);
            }

            var bindingType = GetBindingType(track);

            if (bindingType != null)
            {
                // bound to a prefab asset
                if (HasFlag(detectErrors, TrackBindingErrors.PrefabBound) && PrefabUtility.IsPartOfPrefabAsset(boundObject))
                {
                    return(k_PrefabBound);
                }

                // If we are a component, allow for bound game objects (legacy)
                if (typeof(Component).IsAssignableFrom(bindingType))
                {
                    var gameObject = boundObject as GameObject;
                    var component  = boundObject as Component;
                    if (component != null)
                    {
                        gameObject = component.gameObject;
                    }

                    // game object is bound with no component
                    if (HasFlag(detectErrors, TrackBindingErrors.NoValidComponent) && gameObject != null && component == null)
                    {
                        component = gameObject.GetComponent(bindingType);
                        if (component == null)
                        {
                            return(k_NoValidComponent);
                        }
                    }

                    // attached gameObject is disables (ignores Activation Track)
                    if (HasFlag(detectErrors, TrackBindingErrors.BoundGameObjectDisabled) && gameObject != null && !gameObject.activeInHierarchy)
                    {
                        return(k_BoundGameObjectDisabled);
                    }

                    // component is disabled
                    var behaviour = component as Behaviour;
                    if (HasFlag(detectErrors, TrackBindingErrors.BehaviourIsDisabled) && behaviour != null && !behaviour.enabled)
                    {
                        return(k_RequiredComponentIsDisabled);
                    }

                    // mismatched binding
                    if (HasFlag(detectErrors, TrackBindingErrors.InvalidBinding) && component != null && !bindingType.IsAssignableFrom(component.GetType()))
                    {
                        return(k_InvalidBinding);
                    }
                }
                // Mismatched binding (non-component)
                else if (HasFlag(detectErrors, TrackBindingErrors.InvalidBinding) && !bindingType.IsAssignableFrom(boundObject.GetType()))
                {
                    return(k_InvalidBinding);
                }
            }

            return(string.Empty);
        }