コード例 #1
0
ファイル: TmxHelper.cs プロジェクト: dayfox5317/tiled2unity
        public static TmxProperties GetPropertiesWithTypeDefaults(TmxHasProperties hasProperties, TmxObjectTypes objectTypes)
        {
            TmxProperties tmxProperties = new TmxProperties();
            string        key           = null;

            if (hasProperties is TmxObject)
            {
                key = (hasProperties as TmxObject).Type;
            }
            TmxObjectType valueOrNull = objectTypes.GetValueOrNull(key);

            if (valueOrNull != null)
            {
                foreach (TmxObjectTypeProperty value in valueOrNull.Properties.Values)
                {
                    tmxProperties.PropertyMap[value.Name] = new TmxProperty
                    {
                        Name  = value.Name,
                        Type  = value.Type,
                        Value = value.Default
                    };
                }
            }
            foreach (TmxProperty value2 in hasProperties.Properties.PropertyMap.Values)
            {
                tmxProperties.PropertyMap[value2.Name] = value2;
            }
            return(tmxProperties);
        }
コード例 #2
0
ファイル: TmxObjectType.cs プロジェクト: mm250/Tiled2Unity
        public static TmxObjectType FromXml(XElement xml)
        {
            TmxObjectType tmxObjectType = new TmxObjectType();

            tmxObjectType.Name       = TmxHelper.GetAttributeAsString(xml, "name", "");
            tmxObjectType.Color      = TmxHelper.GetAttributeAsColor(xml, "color", Color.Gray);
            tmxObjectType.Properties = TmxObjectTypeProperty.FromObjectTypeXml(xml);

            return(tmxObjectType);
        }
コード例 #3
0
        public static TmxObjectType FromXml(XElement xml)
        {
            TmxObjectType tmxObjectType = new TmxObjectType();

            tmxObjectType.Name = TmxHelper.GetAttributeAsString(xml, "name", "");
            tmxObjectType.Color = TmxHelper.GetAttributeAsColor(xml, "color", Color.Gray);
            tmxObjectType.Properties = TmxObjectTypeProperty.FromObjectTypeXml(xml);

            return tmxObjectType;
        }
コード例 #4
0
        public static TmxObjectTypes FromXmlFile(string xmlPath)
        {
            TmxObjectTypes tmxObjectTypes = new TmxObjectTypes();

            foreach (XElement item in XDocument.Load(xmlPath).Element("objecttypes").Elements("objecttype"))
            {
                TmxObjectType tmxObjectType = TmxObjectType.FromXml(item);
                tmxObjectTypes.TmxObjectTypeMapping[tmxObjectType.Name] = tmxObjectType;
            }
            return(tmxObjectTypes);
        }
コード例 #5
0
ファイル: TmxObjectTypes.cs プロジェクト: mm250/Tiled2Unity
        public static TmxObjectTypes FromXmlFile(string xmlPath)
        {
            TmxObjectTypes xmlObjectTypes = new TmxObjectTypes();

            XDocument doc = XDocument.Load(xmlPath);

            foreach (var xml in doc.Element("objecttypes").Elements("objecttype"))
            {
                TmxObjectType tmxObjectType = TmxObjectType.FromXml(xml);
                xmlObjectTypes.TmxObjectTypeMapping[tmxObjectType.Name] = tmxObjectType;
            }

            return(xmlObjectTypes);
        }
コード例 #6
0
        private void DrawColliders(Graphics g)
        {
            for (int l = 0; l < this.tmxMap.Layers.Count; ++l)
            {
                TmxLayer layer = this.tmxMap.Layers[l];

                if (layer.Visible == true && layer.Ignore != TmxLayer.IgnoreSettings.Collision)
                {
                    foreach (TmxLayer collisionLayer in layer.CollisionLayers)
                    {
                        TmxObjectType type = this.tmxMap.ObjectTypes.GetValueOrDefault(collisionLayer.Name);

                        Color lineColor = type.Color;
                        Color polyColor = Color.FromArgb(128, lineColor);

                        DrawLayerColliders(g, collisionLayer, polyColor, lineColor);
                    }
                }
            }
        }
コード例 #7
0
        public static TmxProperties GetPropertiesWithTypeDefaults(TmxHasProperties hasProperties, TmxObjectTypes objectTypes)
        {
            TmxProperties tmxProperties = new TmxProperties();

            // Fill in all the default properties first
            // (Note: At the moment, only TmxObject has default properties it inherits from TmxObjectType)
            string objectTypeName = null;

            if (hasProperties is TmxObject)
            {
                TmxObject tmxObject = hasProperties as TmxObject;
                objectTypeName = tmxObject.Type;
            }
            else if (hasProperties is TmxLayer)
            {
                TmxLayer tmxLayer = hasProperties as TmxLayer;
                objectTypeName = tmxLayer.Name;
            }

            // If an object type has been found then copy over all the default values for properties
            TmxObjectType tmxObjectType = objectTypes.GetValueOrNull(objectTypeName);

            if (tmxObjectType != null)
            {
                foreach (TmxObjectTypeProperty tmxTypeProp in tmxObjectType.Properties.Values)
                {
                    tmxProperties.PropertyMap[tmxTypeProp.Name] = new TmxProperty()
                    {
                        Name = tmxTypeProp.Name, Type = tmxTypeProp.Type, Value = tmxTypeProp.Default
                    };
                }
            }

            // Now add all the object properties (which may override some of the default properties)
            foreach (TmxProperty tmxProp in hasProperties.Properties.PropertyMap.Values)
            {
                tmxProperties.PropertyMap[tmxProp.Name] = tmxProp;
            }

            return(tmxProperties);
        }