示例#1
0
        private void FillCustomObjectTypes(SuperSettingsImporter importer)
        {
            m_CustomObjectTypes = new List <CustomObjectType>();

            if (m_ObjectTypesXml != null)
            {
                XDocument xdoc = XDocument.Parse(m_ObjectTypesXml.text);

                if (xdoc.Root.Name != "objecttypes")
                {
                    importer.ReportError("'{0}' is not a valid object types xml file.", m_ObjectTypesXml.name);
                    return;
                }

                // Create a dependency on our Object Types xml file so that settings are automatically updated if it changes
                importer.AddAssetPathDependency(AssetDatabase.GetAssetPath(m_ObjectTypesXml));

                // Import the data from the objecttype elements
                foreach (var xObjectType in xdoc.Descendants("objecttype"))
                {
                    var cot = new CustomObjectType();
                    cot.m_Name             = xObjectType.GetAttributeAs("name", "NoName");
                    cot.m_Color            = xObjectType.GetAttributeAsColor("color", Color.gray);
                    cot.m_CustomProperties = CustomPropertyLoader.LoadCustomPropertyList(xObjectType);

                    m_CustomObjectTypes.Add(cot);
                }
            }
        }
示例#2
0
        private void OnGUICustomObjectType(CustomObjectType obj)
        {
            using (new GUILayout.VerticalScope(EditorStyles.helpBox))
            {
                EditorGUILayout.LabelField(obj.m_Name);
                GUI.enabled = false;
                EditorGUILayout_ColorFieldNoEdit(GUIContent.none, obj.m_Color);
                GUI.enabled = true;

                EditorGUILayout.Space();

                if (obj.m_CustomProperties.Any())
                {
                    using (new GuiScopedIndent())
                    {
                        using (new GUILayout.VerticalScope(EditorStyles.helpBox))
                        {
                            foreach (var customProperty in obj.m_CustomProperties)
                            {
                                using (new GUILayout.HorizontalScope())
                                {
                                    EditorGUILayout.LabelField(customProperty.m_Name);
                                    EditorGUILayout.LabelField(customProperty.m_Value, EditorStyles.textField);
                                    EditorGUILayout.LabelField(customProperty.m_Type);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        // Invoke this to ensure that Xml Object Types are up-to-date
        // Our importers that depend on Object Types from tiled will want to call this early in their import process
        internal void RefreshCustomObjectTypes()
        {
            m_CustomObjectTypes = new List <CustomObjectType>();
            m_ParseXmlError     = string.Empty;

            if (m_ObjectTypesXml != null)
            {
                try
                {
                    XDocument xdoc = XDocument.Parse(m_ObjectTypesXml.text);

                    if (xdoc.Root.Name != "objecttypes")
                    {
                        m_ParseXmlError = string.Format("'{0}' is not a valid object types xml file.", m_ObjectTypesXml.name);
                    }

                    // Import the data from the objecttype elements
                    foreach (var xObjectType in xdoc.Descendants("objecttype"))
                    {
                        var cot = new CustomObjectType();
                        cot.m_Name             = xObjectType.GetAttributeAs("name", "NoName");
                        cot.m_Color            = xObjectType.GetAttributeAsColor("color", Color.gray);
                        cot.m_CustomProperties = CustomPropertyLoader.LoadCustomPropertyList(xObjectType);

                        m_CustomObjectTypes.Add(cot);
                    }
                }
                catch (XmlException xe)
                {
                    m_ParseXmlError = string.Format("'{0}' is not a valid XML file.\n\nError: {1}", m_ObjectTypesXml.name, xe.Message);
                    m_CustomObjectTypes.Clear();
                }
                catch (Exception e)
                {
                    m_ParseXmlError = e.Message;
                    m_CustomObjectTypes.Clear();
                }
            }
        }
示例#4
0
        public static bool TryGetCustomObjectType(this List <CustomObjectType> list, string type, out CustomObjectType customObjectType)
        {
            if (list.IsEmpty())
            {
                customObjectType = null;
                return(false);
            }

            customObjectType = list.FirstOrDefault(o => o.m_Name.Equals(type, StringComparison.OrdinalIgnoreCase));
            return(customObjectType != null);
        }