コード例 #1
1
        internal CharacterAttachmentBrand(CharacterAttachmentSlot slot, XElement element)
        {
            Slot = slot;

            // Set up strings
            var brandNameAttribute = element.Attribute("Name");
            if (brandNameAttribute != null)
                Name = brandNameAttribute.Value;

            var brandThumbnailAttribute = element.Attribute("Thumbnail");
            if (brandThumbnailAttribute != null)
                ThumbnailPath = brandThumbnailAttribute.Value;

            // Get attachments
            var slotAttachmentElements = element.Elements("Attachment");

            int count = slotAttachmentElements.Count();
            if (Slot.CanBeEmpty)
                count++;

            var slotAttachments = new CharacterAttachment[count];

            for (int i = 0; i < slotAttachmentElements.Count(); i++)
            {
                var slotAttachmentElement = slotAttachmentElements.ElementAt(i);

                slotAttachments[i] = new CharacterAttachment(Slot, slotAttachmentElement);
            }

            if (Slot.CanBeEmpty)
                slotAttachments[slotAttachmentElements.Count()] = new CharacterAttachment(Slot, null);

            Attachments = slotAttachments;
        }
コード例 #2
0
        internal CharacterAttachmentBrand(CharacterAttachmentSlot slot, XElement element)
        {
            Slot = slot;

            // Set up strings
            var brandNameAttribute = element.Attribute("Name");

            if (brandNameAttribute != null)
            {
                Name = brandNameAttribute.Value;
            }

            var brandThumbnailAttribute = element.Attribute("Thumbnail");

            if (brandThumbnailAttribute != null)
            {
                ThumbnailPath = brandThumbnailAttribute.Value;
            }

            // Get attachments
            var slotAttachmentElements = element.Elements("Attachment");

            int count = slotAttachmentElements.Count();

            var slotAttachments = new CharacterAttachment[count];

            for (int i = 0; i < slotAttachmentElements.Count(); i++)
            {
                var slotAttachmentElement = slotAttachmentElements.ElementAt(i);

                slotAttachments[i] = new CharacterAttachment(Slot, slotAttachmentElement);
            }

            Attachments = slotAttachments;
        }
コード例 #3
0
        internal CharacterAttachmentSlot(CustomizationManager manager, XElement element)
        {
            Manager = manager;
            Element = element;

            Name = element.Attribute("name").Value;

            var uiNameAttribute = element.Attribute("uiName");

            if (uiNameAttribute != null)
            {
                UIName = uiNameAttribute.Value;
            }

            var categoryAttribute = element.Attribute("category");

            if (categoryAttribute != null)
            {
                Category = categoryAttribute.Value;
            }

            var allowNoneAttribute = element.Attribute("allowNone");

            if (allowNoneAttribute != null)
            {
                CanBeEmpty = allowNoneAttribute.Value == "1";
            }

            if (CanBeEmpty)
            {
                EmptyAttachment = new CharacterAttachment(this, null);
            }

            var hiddenAttribute = element.Attribute("hidden");

            if (hiddenAttribute != null)
            {
                Hidden = hiddenAttribute.Value == "1";
            }

            var subSlotElements = element.Elements("AttachmentSlot");

            if (subSlotElements.Count() > 0)
            {
                SubAttachmentSlots = new CharacterAttachmentSlot[subSlotElements.Count()];
                for (int i = 0; i < subSlotElements.Count(); i++)
                {
                    var subSlotElement = subSlotElements.ElementAt(i);

                    SubAttachmentSlots[i] = new CharacterAttachmentSlot(manager, subSlotElement);
                }
            }

            var mirroredSlotElements = element.Elements("MirroredSlot");

            if (mirroredSlotElements.Count() > 0)
            {
                MirroredSlots = new CharacterAttachmentSlot[mirroredSlotElements.Count()];
                for (int i = 0; i < mirroredSlotElements.Count(); i++)
                {
                    var mirroredSlotElement = mirroredSlotElements.ElementAt(i);

                    MirroredSlots[i] = new CharacterAttachmentSlot(manager, mirroredSlotElement);
                }
            }

            // Set up brands
            var slotBrandElements = element.Elements("Brand");

            int numBrands = slotBrandElements.Count();

            Brands = new CharacterAttachmentBrand[numBrands];

            for (int i = 0; i < numBrands; i++)
            {
                var brandElement = slotBrandElements.ElementAt(i);

                Brands[i] = new CharacterAttachmentBrand(this, brandElement);
            }
        }
コード例 #4
0
        internal CharacterAttachment(CharacterAttachmentSlot slot, XElement element, bool child = false)
        {
            Element = element;
            Slot = slot;

            if (element == null)
            {
                Name = "None";
                ThumbnailPath = slot.Manager.InitParameters.EmptyThumbnailPath;
            }
            else
            {
                var slotAttachmentNameAttribute = element.Attribute("Name");
                if (slotAttachmentNameAttribute != null)
                    Name = slotAttachmentNameAttribute.Value;

                var slotAttachmentThumbnailAttribute = element.Attribute("Thumbnail");
                if (slotAttachmentThumbnailAttribute != null)
                    ThumbnailPath = slotAttachmentThumbnailAttribute.Value;

                var slotAttachmentTypeAttribute = element.Attribute("Type");
                if (slotAttachmentTypeAttribute != null)
                    Type = slotAttachmentTypeAttribute.Value;

                var slotAttachmentBoneNameAttribute = element.Attribute("BoneName");
                if (slotAttachmentBoneNameAttribute != null)
                    BoneName = slotAttachmentBoneNameAttribute.Value;

                var slotAttachmentObjectAttribute = element.Attribute("Binding");
                if (slotAttachmentObjectAttribute != null)
                    Object = slotAttachmentObjectAttribute.Value;

                var slotAttachmentFlagsAttribute = element.Attribute("Flags");
                if (slotAttachmentFlagsAttribute != null)
                    Flags = slotAttachmentFlagsAttribute.Value;

                var slotAttachmentPositionAttribute = element.Attribute("Position");
                if (slotAttachmentPositionAttribute != null)
                    Position = slotAttachmentPositionAttribute.Value;

                var slotAttachmentRotationAttribute = element.Attribute("Rotation");
                if (slotAttachmentRotationAttribute != null)
                    Rotation = slotAttachmentRotationAttribute.Value;

                var slotAttachmentMaterials = new List<CharacterAttachmentMaterial>();

                foreach (var materialElement in element.Elements("Material"))
                    slotAttachmentMaterials.Add(new CharacterAttachmentMaterial(this, materialElement));

                Materials = slotAttachmentMaterials.ToArray();
                Material = Materials.FirstOrDefault();

                if (!child)
                {
                    var subCharacterAttachments = new List<CharacterAttachment>();

                    foreach (var subAttachmentElement in element.Elements("SubAttachment"))
                    {
                        var subAttachmentSlotName = subAttachmentElement.Attribute("Slot").Value;

                        var subAttachmentSlot = Slot.SubAttachmentSlots.FirstOrDefault(x => x.Name == subAttachmentSlotName);
                        if (subAttachmentSlot == null)
                            throw new CustomizationConfigurationException(string.Format("Failed to find subattachment slot {0} for attachment {1} for primary slot {2}", subAttachmentSlotName, Name, Slot.Name));

                        subCharacterAttachments.Add(new CharacterAttachment(subAttachmentSlot, subAttachmentElement, true));
                    }

                    SubAttachmentVariations = subCharacterAttachments.ToArray();
                    SubAttachment = SubAttachmentVariations.FirstOrDefault();
                }

                if (slot.MirroredSlots != null)
                {
                    MirroredChildren = new CharacterAttachment[slot.MirroredSlots.Length];
                    for (int i = 0; i < slot.MirroredSlots.Length; i++)
                    {
                        var mirroredSlot = slot.MirroredSlots.ElementAt(i);
                        var mirroredAttachmentElement = element.Element(mirroredSlot.Name);
                        if (mirroredAttachmentElement == null)
                            throw new CustomizationConfigurationException(string.Format("Failed to get mirrored element from slot {0} and name {1}", slot.Name, mirroredSlot.Name));

                        MirroredChildren[i] = new CharacterAttachment(mirroredSlot, mirroredAttachmentElement);
                    }
                }
            }
        }
コード例 #5
0
        internal CharacterAttachmentMaterial(CharacterAttachment attachment, XElement element, CharacterAttachmentMaterial parentMaterial = null)
        {
            Element    = element;
            Attachment = attachment;

            ParentMaterial = parentMaterial;

            var subMaterialElements = element.Elements("Submaterial");

            Submaterials = new CharacterAttachmentMaterial[subMaterialElements.Count()];

            for (var i = 0; i < subMaterialElements.Count(); i++)
            {
                var subMaterialElement = subMaterialElements.ElementAt(i);

                Submaterials[i] = new CharacterAttachmentMaterial(attachment, subMaterialElement, this);
            }

            if (parentMaterial == null)
            {
                var pathAttribute = element.Attribute("path");
                if (pathAttribute != null)
                {
                    BaseFilePath = pathAttribute.Value;
                }
            }
            else
            {
                var nameAttribute = element.Attribute("name");
                if (nameAttribute != null)
                {
                    BaseFilePath = nameAttribute.Value;
                }
            }

            var colorModifierElement = element.Element("ColorModifier");

            if (colorModifierElement != null)
            {
                var redAttribute = colorModifierElement.Attribute("red");
                if (redAttribute != null)
                {
                    ColorRed = ParseColor(redAttribute.Value);
                }

                var greenAttribute = colorModifierElement.Attribute("green");
                if (greenAttribute != null)
                {
                    ColorGreen = ParseColor(greenAttribute.Value);
                }

                var blueAttribute = colorModifierElement.Attribute("blue");
                if (blueAttribute != null)
                {
                    ColorBlue = ParseColor(blueAttribute.Value);
                }

                var alphaAttribute = colorModifierElement.Attribute("alpha");
                if (alphaAttribute != null)
                {
                    ColorAlpha = ParseColor(alphaAttribute.Value);
                }
            }

            var diffuseElement = element.Element("Diffuse");

            DiffuseColor = UnusedMarker.Vec3;

            if (diffuseElement != null)
            {
                var texPathAttribute = diffuseElement.Attribute("path");
                if (texPathAttribute != null)
                {
                    DiffuseTexture = texPathAttribute.Value;
                }

                var colorAttribute = diffuseElement.Attribute("color");
                if (colorAttribute != null)
                {
                    DiffuseColor = ParseColor(colorAttribute.Value);
                }
            }

            var specularElement = element.Element("Specular");

            SpecularColor = UnusedMarker.Vec3;

            if (specularElement != null)
            {
                var texPathAttribute = specularElement.Attribute("path");
                if (texPathAttribute != null)
                {
                    SpecularTexture = texPathAttribute.Value;
                }

                var colorAttribute = specularElement.Attribute("color");
                if (colorAttribute != null)
                {
                    SpecularColor = ParseColor(colorAttribute.Value);
                }
            }

            var bumpmapElement = element.Element("Bumpmap");

            if (bumpmapElement != null)
            {
                var texPathAttribute = bumpmapElement.Attribute("path");
                if (texPathAttribute != null)
                {
                    BumpmapTexture = texPathAttribute.Value;
                }
            }

            var customTexElement = element.Element("Custom");

            if (customTexElement != null)
            {
                var texPathAttribute = customTexElement.Attribute("path");
                if (texPathAttribute != null)
                {
                    CustomTexture = texPathAttribute.Value;
                }
            }
        }
コード例 #6
0
        internal CharacterAttachmentMaterial(CharacterAttachment attachment, XElement element, CharacterAttachmentMaterial parentMaterial = null)
        {
            Element = element;
            Attachment = attachment;

            ParentMaterial = parentMaterial;

            var subMaterialElements = element.Elements("Submaterial");
            Submaterials = new CharacterAttachmentMaterial[subMaterialElements.Count()];

            for(var i = 0; i < subMaterialElements.Count(); i++)
            {
                var subMaterialElement = subMaterialElements.ElementAt(i);

                Submaterials[i] = new CharacterAttachmentMaterial(attachment, subMaterialElement, this);
            }

            if (parentMaterial == null)
            {
                var pathAttribute = element.Attribute("path");
                if (pathAttribute != null)
                    BaseFilePath = pathAttribute.Value;
            }
            else
            {
                var nameAttribute = element.Attribute("name");
                if (nameAttribute != null)
                    BaseFilePath = nameAttribute.Value;
            }

            var colorModifierElement = element.Element("ColorModifier");
            if (colorModifierElement != null)
            {
                var redAttribute = colorModifierElement.Attribute("red");
                if (redAttribute != null)
                    ColorRed = ParseColor(redAttribute.Value);

                var greenAttribute = colorModifierElement.Attribute("green");
                if (greenAttribute != null)
                    ColorGreen = ParseColor(greenAttribute.Value);

                var blueAttribute = colorModifierElement.Attribute("blue");
                if (blueAttribute != null)
                    ColorBlue = ParseColor(blueAttribute.Value);

                var alphaAttribute = colorModifierElement.Attribute("alpha");
                if (alphaAttribute != null)
                    ColorAlpha = ParseColor(alphaAttribute.Value);
            }

            var diffuseElement = element.Element("Diffuse");
            DiffuseColor = UnusedMarker.Vec3;

            if (diffuseElement != null)
            {
                var texPathAttribute = diffuseElement.Attribute("path");
                if (texPathAttribute != null)
                    DiffuseTexture = texPathAttribute.Value;

                var colorAttribute = diffuseElement.Attribute("color");
                if (colorAttribute != null)
                    DiffuseColor = ParseColor(colorAttribute.Value);
            }

            var specularElement = element.Element("Specular");
            SpecularColor = UnusedMarker.Vec3;

            if (specularElement != null)
            {
                var texPathAttribute = specularElement.Attribute("path");
                if (texPathAttribute != null)
                    SpecularTexture = texPathAttribute.Value;

                var colorAttribute = specularElement.Attribute("color");
                if (colorAttribute != null)
                    SpecularColor = ParseColor(colorAttribute.Value);
            }

            var bumpmapElement = element.Element("Bumpmap");
            if (bumpmapElement != null)
            {
                var texPathAttribute = bumpmapElement.Attribute("path");
                if (texPathAttribute != null)
                    BumpmapTexture = texPathAttribute.Value;
            }

            var customTexElement = element.Element("Custom");
            if (customTexElement != null)
            {
                var texPathAttribute = customTexElement.Attribute("path");
                if (texPathAttribute != null)
                    CustomTexture = texPathAttribute.Value;
            }
        }
コード例 #7
0
        public bool Write(CharacterAttachment attachment, XElement attachmentElement = null, bool overwrite = true)
        {
            if (attachment == null)
                throw new NullReferenceException("attachment");

            if (attachmentElement == null)
            {
                if (MirroredSlots != null && attachment.MirroredChildren != null)
                {
                    foreach (var mirroredAttachment in attachment.MirroredChildren)
                    {
                        Write(attachment, GetWriteableElement(mirroredAttachment.Slot.Name));
                        mirroredAttachment.Slot.Write(mirroredAttachment, null, false);
                    }

                    return true;
                }

                var currentAttachment = Current;
                if (currentAttachment != null)
                {
                    if (currentAttachment.SubAttachmentVariations != null)
                    {
                        foreach (var subAttachment in currentAttachment.SubAttachmentVariations)
                            subAttachment.Slot.Clear();
                    }
                }

                attachmentElement = GetWriteableElement();
                if (attachmentElement == null)
                    throw new CustomizationConfigurationException(string.Format("Failed to locate attachments for slot {0}!", Name));
            }

            if (overwrite || attachment.Name != null)
                attachmentElement.SetAttributeValue("Name", attachment.Name);

            if (overwrite || attachment.Type != null)
                attachmentElement.SetAttributeValue("Type", attachment.Type);
            if (overwrite || attachment.BoneName != null)
                attachmentElement.SetAttributeValue("BoneName", attachment.BoneName);

            if (overwrite || attachment.Object != null)
                attachmentElement.SetAttributeValue("Binding", attachment.Object);
            if (overwrite || attachment.Material != null)
            {
                var material = attachment.Material;
                string materialPath = null;

                if (material != null)
                    materialPath = material.FilePath ?? material.BaseFilePath;

                attachmentElement.SetAttributeValue("Material", materialPath);
            }

            if (overwrite || attachment.Flags != null)
                attachmentElement.SetAttributeValue("Flags", attachment.Flags);

            if (overwrite || attachment.Position != null)
                attachmentElement.SetAttributeValue("Position", attachment.Position);
            if (overwrite || attachment.Rotation != null)
                attachmentElement.SetAttributeValue("Rotation", attachment.Rotation);

            if (attachment.SubAttachment != null)
                attachment.SubAttachment.Slot.Write(attachment.SubAttachment);

            return true;
        }
コード例 #8
0
ファイル: CharacterAttachment.cs プロジェクト: yonder/CryMono
        internal CharacterAttachment(CharacterAttachmentSlot slot, XElement element, bool child = false)
        {
            Element = element;
            Slot    = slot;

            if (element == null)
            {
                Name          = "None";
                ThumbnailPath = slot.Manager.InitParameters.EmptyThumbnailPath;
            }
            else
            {
                var slotAttachmentNameAttribute = element.Attribute("Name");
                if (slotAttachmentNameAttribute != null)
                {
                    Name = slotAttachmentNameAttribute.Value;
                }

                var slotAttachmentThumbnailAttribute = element.Attribute("Thumbnail");
                if (slotAttachmentThumbnailAttribute != null)
                {
                    ThumbnailPath = slotAttachmentThumbnailAttribute.Value;
                }

                var slotAttachmentTypeAttribute = element.Attribute("Type");
                if (slotAttachmentTypeAttribute != null)
                {
                    Type = slotAttachmentTypeAttribute.Value;
                }

                var slotAttachmentBoneNameAttribute = element.Attribute("BoneName");
                if (slotAttachmentBoneNameAttribute != null)
                {
                    BoneName = slotAttachmentBoneNameAttribute.Value;
                }

                var slotAttachmentObjectAttribute = element.Attribute("Binding");
                if (slotAttachmentObjectAttribute != null)
                {
                    Object = slotAttachmentObjectAttribute.Value;
                }

                var slotAttachmentFlagsAttribute = element.Attribute("Flags");
                if (slotAttachmentFlagsAttribute != null)
                {
                    Flags = slotAttachmentFlagsAttribute.Value;
                }

                var slotAttachmentPositionAttribute = element.Attribute("Position");
                if (slotAttachmentPositionAttribute != null)
                {
                    Position = slotAttachmentPositionAttribute.Value;
                }

                var slotAttachmentRotationAttribute = element.Attribute("Rotation");
                if (slotAttachmentRotationAttribute != null)
                {
                    Rotation = slotAttachmentRotationAttribute.Value;
                }

                var slotAttachmentMaterials = new List <CharacterAttachmentMaterial>();

                foreach (var materialElement in element.Elements("Material"))
                {
                    slotAttachmentMaterials.Add(new CharacterAttachmentMaterial(this, materialElement));
                }

                Materials = slotAttachmentMaterials.ToArray();
                Material  = Materials.FirstOrDefault();

                if (!child)
                {
                    var subCharacterAttachments = new List <CharacterAttachment>();

                    foreach (var subAttachmentElement in element.Elements("SubAttachment"))
                    {
                        var subAttachmentSlotName = subAttachmentElement.Attribute("Slot").Value;

                        var subAttachmentSlot = Slot.SubAttachmentSlots.FirstOrDefault(x => x.Name == subAttachmentSlotName);
                        if (subAttachmentSlot == null)
                        {
                            throw new CustomizationConfigurationException(string.Format("Failed to find subattachment slot {0} for attachment {1} for primary slot {2}", subAttachmentSlotName, Name, Slot.Name));
                        }

                        subCharacterAttachments.Add(new CharacterAttachment(subAttachmentSlot, subAttachmentElement, true));
                    }

                    SubAttachmentVariations = subCharacterAttachments.ToArray();
                    SubAttachment           = SubAttachmentVariations.FirstOrDefault();
                }

                if (slot.MirroredSlots != null)
                {
                    MirroredChildren = new CharacterAttachment[slot.MirroredSlots.Length];
                    for (int i = 0; i < slot.MirroredSlots.Length; i++)
                    {
                        var mirroredSlot = slot.MirroredSlots.ElementAt(i);
                        var mirroredAttachmentElement = element.Element(mirroredSlot.Name);
                        if (mirroredAttachmentElement == null)
                        {
                            throw new CustomizationConfigurationException(string.Format("Failed to get mirrored element from slot {0} and name {1}", slot.Name, mirroredSlot.Name));
                        }

                        MirroredChildren[i] = new CharacterAttachment(mirroredSlot, mirroredAttachmentElement);
                    }
                }
            }
        }
コード例 #9
0
        internal CharacterAttachmentSlot(CustomizationManager manager, XElement element)
        {
            Manager = manager;
            Element = element;

            Name = element.Attribute("name").Value;

            var uiNameAttribute = element.Attribute("uiName");
            if(uiNameAttribute != null)
                UIName = uiNameAttribute.Value;

            var categoryAttribute = element.Attribute("category");
            if (categoryAttribute != null)
                Category = categoryAttribute.Value;

            var allowNoneAttribute = element.Attribute("allowNone");
            if(allowNoneAttribute != null)
                CanBeEmpty = allowNoneAttribute.Value == "1";

            if(CanBeEmpty)
                EmptyAttachment = new CharacterAttachment(this, null);

            var hiddenAttribute = element.Attribute("hidden");
            if(hiddenAttribute != null)
                Hidden = hiddenAttribute.Value == "1";

            var subSlotElements = element.Elements("AttachmentSlot");
            if (subSlotElements.Count() > 0)
            {
                SubAttachmentSlots = new CharacterAttachmentSlot[subSlotElements.Count()];
                for(int i = 0; i < subSlotElements.Count(); i++)
                {
                    var subSlotElement = subSlotElements.ElementAt(i);

                    SubAttachmentSlots[i] = new CharacterAttachmentSlot(manager, subSlotElement);
                }
            }

            var mirroredSlotElements = element.Elements("MirroredSlot");
            if (mirroredSlotElements.Count() > 0)
            {
                MirroredSlots = new CharacterAttachmentSlot[mirroredSlotElements.Count()];
                for (int i = 0; i < mirroredSlotElements.Count(); i++)
                {
                    var mirroredSlotElement = mirroredSlotElements.ElementAt(i);

                    MirroredSlots[i] = new CharacterAttachmentSlot(manager, mirroredSlotElement);
                }
            }

            // Set up brands
            var slotBrandElements = element.Elements("Brand");

            int numBrands = slotBrandElements.Count();
            Brands = new CharacterAttachmentBrand[numBrands];

            for(int i = 0; i < numBrands; i++)
            {
                var brandElement = slotBrandElements.ElementAt(i);

                Brands[i] = new CharacterAttachmentBrand(this, brandElement);
            }
        }