Beispiel #1
0
        /// <summary>
        /// Gets all properties exposable in Inspector.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="exposers"></param>
        /// <returns></returns>
        public static PropertyInfo[]    GetExposedProperties(Type type, ComponentExposer[] exposers)
        {
            Stack <Type>        inheritances = new Stack <Type>();
            List <PropertyInfo> properties   = new List <PropertyInfo>();

            inheritances.Push(type);
            type = type.BaseType();

            while (type != null && type != typeof(Component) && type != typeof(object))
            {
                inheritances.Push(type);
                type = type.BaseType();
            }

            foreach (Type ty in inheritances)
            {
                int j = 0;

                for (; j < exposers.Length; j++)
                {
                    if (exposers[j].type == ty)
                    {
                        properties.AddRange(exposers[j].GetPropertyInfos());
                        break;
                    }
                }

                if (j < exposers.Length)
                {
                    continue;
                }

                PropertyInfo[] pis = ty.GetProperties(Utility.ExposedBindingFlags | BindingFlags.DeclaredOnly);

                for (int i = 0; i < pis.Length; i++)
                {
                    if (Utility.CanExposePropertyInInspector(pis[i]) == false)
                    {
                        continue;
                    }

                    // GetGetMethod can return null ns a weird case even if a real getter is present.
                    MethodInfo getMethod = pis[i].GetGetMethod();
                    if (getMethod != null && RemoteUtility.CheckPropertyIsOverriding(getMethod.GetBaseDefinition(), properties) == true)                     // Skip overriden properties.
                    {
                        continue;
                    }

                    properties.Add(pis[i]);
                }
            }

            return(properties.ToArray());
        }
Beispiel #2
0
        public ServerComponent(Component component)
        {
            this.component  = component;
            this.instanceID = this.component.GetInstanceID();

            Type type = this.component.GetType();

            ComponentExposer[] exposers = ComponentExposersManager.GetComponentExposers(type);
            PropertyInfo[]     pis      = RemoteUtility.GetExposedProperties(type, exposers);
            FieldInfo[]        fis      = RemoteUtility.GetExposedFields(type, exposers);
            int i = 0;

            ServerComponent.tempFields.Clear();

            for (; i < pis.Length; ++i)
            {
                if (ServerComponent.ExcludedProperties.Contains(pis[i].Name) == false)
                {
                    ServerComponent.tempFields.Add(new PropertyModifier(pis[i]));
                }
            }

            for (int j = 0; j < fis.Length; ++i, ++j)
            {
                ServerComponent.tempFields.Add(new FieldModifier(fis[j]));
            }

            this.fields = ServerComponent.tempFields.ToArray();

            List <MethodInfo> methods = new List <MethodInfo>(type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public));

            for (int j = 0; j < methods.Count; j++)
            {
                if (methods[j].IsGenericMethod == true)
                {
                    methods.RemoveAt(j--);
                }
            }

            this.methods = new ServerMethodInfo[methods.Count];

            for (i = 0; i < methods.Count; i++)
            {
                this.methods[i] = new ServerMethodInfo(methods[i]);
            }
        }
Beispiel #3
0
        protected void  MonitorSubData(Type type, Func <object> getInstance)
        {
            object instance = getInstance();

            if (instance == null || typeof(Object).IsAssignableFrom(type) == true)
            {
                return;
            }

            if (type.IsUnityArray() == true)
            {
                this.children = new List <MonitorData>();

                IEnumerable array = instance as IEnumerable;
                IEnumerator it    = array.GetEnumerator();
                int         i     = 0;

                while (it.MoveNext())
                {
                    this.children.Add(new MonitorArrayItem(this.path + NGServerScene.ValuePathSeparator + i.ToString(), getInstance, i));
                    ++i;
                }
            }
            else if (type.IsClass() == true ||
                     type.IsStruct() == true)
            {
                ComponentExposer[] exposers   = ComponentExposersManager.GetComponentExposers(type);
                PropertyInfo[]     properties = RemoteUtility.GetExposedProperties(type, exposers);
                FieldInfo[]        fields     = RemoteUtility.GetExposedFields(type, exposers);

                this.children = new List <MonitorData>(properties.Length + fields.Length);

                for (int i = 0; i < properties.Length; ++i)
                {
                    CustomMonitorData customMonitor = MonitorDataManager.CreateMonitorData(properties[i].PropertyType, this.path + NGServerScene.ValuePathSeparator + properties[i].Name, getInstance, new PropertyModifier(properties[i]));

                    if (customMonitor != null)
                    {
                        this.children.Add(customMonitor);
                    }
                    else
                    {
                        if (properties[i].PropertyType.IsUnityArray() == true)
                        {
                            this.children.Add(new MonitorArray(this.path + NGServerScene.ValuePathSeparator + properties[i].Name, new PropertyModifier(properties[i]), getInstance));
                        }
                        else
                        {
                            this.children.Add(new MonitorProperty(this.path + NGServerScene.ValuePathSeparator + properties[i].Name, getInstance, properties[i]));
                        }
                    }
                }

                for (int i = 0; i < fields.Length; ++i)
                {
                    CustomMonitorData customMonitor = MonitorDataManager.CreateMonitorData(fields[i].FieldType, this.path + NGServerScene.ValuePathSeparator + fields[i].Name, getInstance, new FieldModifier(fields[i]));

                    if (customMonitor != null)
                    {
                        this.children.Add(customMonitor);
                    }
                    else
                    {
                        if (fields[i].FieldType.IsUnityArray() == true)
                        {
                            this.children.Add(new MonitorArray(this.path + NGServerScene.ValuePathSeparator + fields[i].Name, new FieldModifier(fields[i]), getInstance));
                        }
                        else
                        {
                            this.children.Add(new MonitorField(this.path + NGServerScene.ValuePathSeparator + fields[i].Name, getInstance, fields[i]));
                        }
                    }
                }
            }
        }