Exemplo n.º 1
0
        /// <summary>
        /// Gets the size of the asset storage memory.
        /// </summary>
        /// <param name="asset">The asset object.</param>
        /// <returns>The storage memory size of this asset object.</returns>
        public static long GetAssetStorageMemorySize(UnityEngine.Object asset)
        {
            long size = 0;

            if (asset is Texture)
            {
                size = (int)UnityReflectionUtil.InvokeStaticMethod("UnityEditor.TextureUtil", "GetStorageMemorySize", new object[] { asset });
            }
            else
            {
                string path = AssetDatabase.GetAssetPath(asset);

                if (!string.IsNullOrEmpty(path))
                {
                    FileInfo fileInfo = new FileInfo(path);

                    if (fileInfo != null)
                    {
                        size = fileInfo.Length;
                    }
                }
            }

            return(size);
        }
Exemplo n.º 2
0
        private void Start()
        {
            //Only search for attributes if they're needed/wanted
            if (searchForAttributes)
            {
                //Look for all monobehaviour components
                var components = FindObjectsOfType <MonoBehaviour> ();

                //Iterate through
                for (int i = 0; i < components.Length; i++)
                {
                    var  component     = components[i];
                    Type componentType = component.GetType();

                    //Get all fields
                    FieldInfo[] types = UnityReflectionUtil.GetFields(componentType, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Default);

                    //Iterate over fields and look for the DebugAttribute, if it exists, add it to the correct place

                    for (int j = 0; j < types.Length; j++)
                    {
                        var field = types[j];

                        Attribute attribute = field.GetCustomAttribute(typeof(DebugAttribute));

                        if (attribute != null)
                        {
                            DebugAttribute debugAttr = attribute as DebugAttribute;
                            AddInformationToCatergory(debugAttr.Catergory, new DebugInformation(debugAttr.Name, component, field.Name), true);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private UnityHttpResponse CreateHttpResponse()
        {
            Type downloadHandlerType = unityWebRequest.downloadHandler.GetType();
            Type responseType        = responseTypeMaps[downloadHandlerType];

            return((UnityHttpResponse)UnityReflectionUtil.CreateInstance(responseType.FullName, BindingFlags.Instance | BindingFlags.NonPublic,
                                                                         new object[] { unityWebRequest, request.StateObject }));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generates the data table row collection.
        /// </summary>
        /// <param name="table">The data table.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="rowInfos">The list of DataTableRow.</param>
        /// <returns>The data collection of data table row.</returns>
        private static List <DataTableRow> GenerateDataTableRowCollection(DataTable table, string namespaceString, string className, List <DataTableRowInfo> rowInfos)
        {
            List <DataTableRow> dataCollection = new List <DataTableRow>();
            string classFullName = className;

            if (!string.IsNullOrEmpty(namespaceString))
            {
                classFullName = string.Format("{0}.{1}", namespaceString, classFullName);
            }

            DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData();

            if (preferencesData)
            {
                int rowCount = table.Rows.Count;

                for (int i = preferencesData.DataRowsStartRow - 1; i < rowCount; ++i)
                {
                    DataTableRow rowData = (DataTableRow)UnityReflectionUtil.CreateInstance(classFullName);

                    for (int j = 0, propertiesCount = rowInfos.Count; j < propertiesCount; ++j)
                    {
                        string cellValue = table.Rows[i][j].ToString().Trim();

                        if (!string.IsNullOrEmpty(cellValue))
                        {
                            DataTableRowInfo rowInfo    = rowInfos[j];
                            ITypeParser      typeParser = GetTypeParser(rowInfo.Type);

                            if (typeParser != null)
                            {
                                object value = typeParser.Parse(cellValue);
                                ReflectionUtil.SetObjectPropertyValue(rowData, rowInfo.PropertyName, value);
                            }
                            else
                            {
                                Debug.LogWarningFormat("Type '{0}' is not supported!", rowInfo.Type);
                            }
                        }
                    }

                    dataCollection.Add(rowData);
                }
            }

            return(dataCollection);
        }
Exemplo n.º 5
0
        private void SetupCategories()
        {
            if (DisplayGroups != null && DisplayGroups.Count > 0)
            {
                return;
            }

            // Add all states to list for lookup
            Type[]        assemblyTypes = UnityReflectionUtil.GetTypesInAssembly(typeof(State));
            List <string> groupsTypes   = new List <string> ();

            // We only want to check once as they'll update when Unity recompiles
            DisplayGroups = new Dictionary <string, List <StateName> > ();

            // Create cached arrays to have quick references
            StateNames = new string[assemblyTypes.Length];

            // Get each state
            for (int i = 0; i < assemblyTypes.Length; i++)
            {
                // Get state data
                string stateName   = assemblyTypes[i].FullName;
                string displayName = GetStateName(stateName);

                string group = GetGroupName(stateName);

                StateName name = new StateName(stateName, displayName);
                if (DisplayGroups.ContainsKey(group))
                {
                    DisplayGroups[group].Add(name);
                }
                else
                {
                    DisplayGroups.Add(group, new List <StateName> ()
                    {
                        name
                    });
                }

                StateNames[i] = stateName;
                groupsTypes.Add(group);
            }

            GroupNames = groupsTypes.ToArray();
        }
Exemplo n.º 6
0
        private void OnSerialize()
        {
            //Get state types
            if (StateTypes == null)
            {
                StateTypes = UnityReflectionUtil.GetTypesInAssembly(typeof(State));
            }

            //Return if no states exist
            if (StateTypes == null || StateTypes.Length == 0)
            {
                Debug.LogWarning("Cannot find any state types in the project.");
                return;
            }
            else
            if (RegisteredStates == null)
            {
                Initialize();
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Clears messages of console.
 /// </summary>
 public static void ClearConsole()
 {
     UnityReflectionUtil.InvokeStaticMethod("UnityEditorInternal.LogEntries", "Clear");
 }