Esempio n. 1
0
        private static ScriptMemberInfo GetVisibleIfSource(ScriptType type, VisibleIfAttribute visibleIf)
        {
            var property = type.GetProperty(visibleIf.MemberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            if (property != ScriptMemberInfo.Null)
            {
                if (!property.HasGet)
                {
                    Debug.LogError("Invalid VisibleIf rule. Property has missing getter " + visibleIf.MemberName);
                    return(ScriptMemberInfo.Null);
                }

                if (property.ValueType.Type != typeof(bool))
                {
                    Debug.LogError("Invalid VisibleIf rule. Property has to return bool type " + visibleIf.MemberName);
                    return(ScriptMemberInfo.Null);
                }

                return(property);
            }

            var field = type.GetField(visibleIf.MemberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            if (field != ScriptMemberInfo.Null)
            {
                if (field.ValueType.Type != typeof(bool))
                {
                    Debug.LogError("Invalid VisibleIf rule. Field has to be bool type " + visibleIf.MemberName);
                    return(ScriptMemberInfo.Null);
                }

                return(field);
            }

            Debug.LogError("Invalid VisibleIf rule. Cannot find member " + visibleIf.MemberName);
            return(ScriptMemberInfo.Null);
        }