Esempio n. 1
0
        /// <summary>
        /// Attempts to extract the data from a given file. The data is expected
        /// to be in a JSON format, and is expected to fall between a line that
        /// contains "START VARIABLE OBJECT INFO" and another that contains
        /// "END VARIABLE OBJECT INFO". Only the first of such blocks is
        /// heeded, and the rest are ignored.
        ///
        /// Looks for string fields named "name", "type", and "referability".
        /// </summary>
        /// <returns>The data from the file.</returns>
        /// <param name="path">Path of file.</param>
        private static VObjData ExtractDataFromFile(string path)
        {
            const string DATA_HEADER = "START VARIABLE OBJECT INFO";
            const string DATA_FOOTER = "END VARIABLE OBJECT INFO";

            VObjData     data = new VObjData();
            StreamReader reader;

            string rawJSON    = "";
            bool   foundStart = false;
            bool   foundEnd   = false;


            reader = new StreamReader(path);

            try {
                // Read until we find the start of the data
                while (!foundStart && !reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    foundStart = line.Contains(DATA_HEADER);
                }

                // Now read until we find the end of data or end of file
                while (!foundEnd && !reader.EndOfStream)
                {
                    string line = reader.ReadLine();

                    if (line.Contains(DATA_FOOTER))
                    {
                        foundEnd = true;
                    }
                    else
                    {
                        rawJSON += line;
                    }
                }
            }
            finally {
                reader.Close();
            }

            data = JsonUtility.FromJson <VObjData>(rawJSON);

            return(data);
        }
Esempio n. 2
0
        /// <summary>
        /// Builds the type info, based on all of the files that match the given
        /// label. The keys are the human-readable names, NOT the type-names
        /// which the objects might handle.
        /// </summary>
        /// <returns>
        /// The type info dictionary, with the human-readable
        /// type names being the keys.
        /// </returns>
        /// <param name="label">Label which to search for.</param>
        private static Dictionary <string, ScriptInfo> BuildTypeInfo(string label)
        {
            Dictionary <string, ScriptInfo> allTypeInfo =
                new Dictionary <string, ScriptInfo>();

            string[] allGuids = AssetDatabase.FindAssets("l:" + label);

            foreach (string guid in allGuids)
            {
                ScriptInfo typeInfo;

                /*
                 * ExtractNameAndTypeFromFile(
                 *      AssetDatabase.GUIDToAssetPath(guid),
                 *      out typeName,
                 *      out type,
                 *      out referability
                 * );*/
                VObjData fileData = ExtractDataFromFile(AssetDatabase.GUIDToAssetPath(guid));

                if (!allTypeInfo.TryGetValue(fileData.name, out typeInfo))
                {
                    // First file of this typeName; typeInfo will be null
                    typeInfo = new ScriptInfo(fileData.name, fileData.type, fileData.referabilityMode);

                    if (fileData.referabilityMode == ReferabilityMode.Unknown)
                    {
                        Debug.LogWarning(
                            "Unable to identify the referability mode for "
                            + AssetDatabase.GUIDToAssetPath(guid)
                            );
                    }
                }                 // End if(!allTypeInfo.TryGetValue(typeName, out typeInfo))
                else
                {
                    if (typeInfo.Type != fileData.type)
                    {
                        Debug.LogWarning(
                            "Type mismatch in "
                            + AssetDatabase.GUIDToAssetPath(guid) + '\n'
                            + "Expected '" + typeInfo.Type
                            + "' but found '" + fileData.type + "'"
                            );
                    }

                    if (typeInfo.Referability != fileData.referabilityMode)
                    {
                        Debug.LogWarning(
                            "Referability mismatch in "
                            + AssetDatabase.GUIDToAssetPath(guid) + '\n'
                            + "Expected '" + typeInfo.Referability.ToString()
                            + "' but found '" + fileData.referabilityMode.ToString() + "'"
                            );
                    }
                }                 // End if(!allTypeInfo.TryGetValue(typeName, out typeInfo))

                //typeInfo.GUIDs.Add(guid);
                typeInfo.AddGUID(guid);
                allTypeInfo[fileData.name] = typeInfo;
            }             // End foreach(string guid in allGuids)

            return(allTypeInfo);
        }