protected override void ParseElementConditions(XElement elemtype, Content content)
    {
        var elemMaterials = elemtype.Elements("material");

        foreach (XElement elemMaterial in elemMaterials)
        {
            XAttribute elemToken = elemMaterial.Attribute("token");
            if (elemToken != null)
            {
                if (elemToken.Value == "NONE")
                {
                    defaultMaterial = content;
                }
                else
                {
                    if (content.overloadedItem != null || thisMaterialMatcher == null)
                    {
                        materialMatcher[elemToken.Value] = content;
                    }
                    if (thisMaterialMatcher != null)
                    {
                        thisMaterialMatcher[elemToken.Value] = content.defaultItem;
                    }
                }
                continue;
            }

            //if there's no material token, fall back to the out-dated system.
            XAttribute elemValue = elemMaterial.Attribute("value");
            MatBasic   elemType  = MatBasic.INVALID;
            if (elemValue != null)
            {
                elemType = ContentLoader.lookupMaterialType(elemValue.Value);
            }
            if (elemType == MatBasic.INVALID)
            {
                //throw error here
                continue;
            }

            //parse subtype elements
            if (elemMaterial.Element("subtype") == null)
            {
                //handle here the elements without subtypes.
                MatPairStruct material = new MatPairStruct((int)elemType, -1);
                if (content.overloadedItem != null || thisMaterialMatcher == null)
                {
                    materialMatcher[material] = content;
                }
                if (thisMaterialMatcher != null)
                {
                    thisMaterialMatcher[material] = content.defaultItem;
                }
            }
            else
            {
                var elemSubtypes = elemMaterial.Elements("subtype");
                foreach (XElement elemSubtype in elemSubtypes)
                {
                    XAttribute subtypeValue = elemSubtype.Attribute("value");
                    if (subtypeValue == null)
                    {
                        //Oh no!
                        continue;
                    }
                    string subtype = subtypeValue.Value;
                    string token   = "";
                    switch (elemType)
                    {
                    case MatBasic.INORGANIC:
                        token = "INORGANIC:" + subtype;
                        break;

                    case MatBasic.ICHOR:
                        token = "CREATURE:" + subtype + ":ICHOR";
                        break;

                    case MatBasic.LEATHER:
                        token = "CREATURE:" + subtype + ":LEATHER";
                        break;

                    case MatBasic.BLOOD_1:
                        token = "CREATURE:" + subtype + ":BLOOD";
                        break;

                    case MatBasic.BLOOD_2:
                        token = "CREATURE:" + subtype + ":BLOOD";
                        break;

                    case MatBasic.BLOOD_3:
                        token = "CREATURE:" + subtype + ":BLOOD";
                        break;

                    case MatBasic.BLOOD_4:
                        token = "CREATURE:" + subtype + ":BLOOD";
                        break;

                    case MatBasic.BLOOD_5:
                        token = "CREATURE:" + subtype + ":BLOOD";
                        break;

                    case MatBasic.BLOOD_6:
                        token = "CREATURE:" + subtype + ":BLOOD";
                        break;

                    case MatBasic.PLANT:
                        token = "PLANT:" + subtype + ":STRUCTURAL";
                        break;

                    case MatBasic.WOOD:
                        token = "PLANT:" + subtype + ":WOOD";
                        break;

                    case MatBasic.PLANTCLOTH:
                        token = "PLANT:" + subtype + ":THREAD";
                        break;

                    default:
                        //make some kind of error here
                        continue;
                    }
                    if (content.overloadedItem != null || thisMaterialMatcher == null)
                    {
                        materialMatcher[token] = content;
                    }
                    if (thisMaterialMatcher != null)
                    {
                        thisMaterialMatcher[token] = content.defaultItem;
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    private static void ConvertColorXML(XElement doc)
    {
        foreach (var item in doc.Elements())
        {
            Color32 color32 = new Color32();

            color32.r = byte.Parse(item.Attribute("red").Value);
            color32.g = byte.Parse(item.Attribute("green").Value);
            color32.b = byte.Parse(item.Attribute("blue").Value);

            XAttribute colorAlphaAtt = item.Attribute("metal");
            if (colorAlphaAtt != null)
            {
                switch (colorAlphaAtt.Value)
                {
                case "yes":
                    color32.a = 255;
                    break;

                case "no":
                    color32.a = 128;
                    break;

                default:
                    color32.a = byte.Parse(colorAlphaAtt.Value);
                    break;
                }
            }
            else
            {
                color32.a = 128;
            }

            foreach (var elemMaterial in item.Elements("material"))
            {
                MaterialTag tag       = new MaterialTag();
                XAttribute  elemToken = elemMaterial.Attribute("token");
                if (elemToken != null)
                {
                    if (!MaterialTag.TryParse(elemMaterial.Attribute("token").Value, out tag))
                    {
                        continue;
                    }
                }
                else
                {
                    //if there's no material token, fall back to the out-dated system.
                    XAttribute elemValue = elemMaterial.Attribute("value");
                    MatBasic   elemType  = MatBasic.INVALID;
                    if (elemValue != null)
                    {
                        elemType = ContentLoader.lookupMaterialType(elemValue.Value);
                    }
                    if (elemType == MatBasic.INVALID)
                    {
                        //throw error here
                        continue;
                    }

                    //parse subtype elements
                    if (elemMaterial.Element("subtype") == null)
                    {
                        tag.SetBasic(elemType);
                    }
                    else
                    {
                        var elemSubtypes = elemMaterial.Elements("subtype");
                        foreach (XElement elemSubtype in elemSubtypes)
                        {
                            XAttribute subtypeValue = elemSubtype.Attribute("value");
                            if (subtypeValue == null)
                            {
                                //Oh no!
                                continue;
                            }
                            string subtype = subtypeValue.Value;
                            string token   = "";
                            switch (elemType)
                            {
                            case MatBasic.INORGANIC:
                                token = "INORGANIC:" + subtype;
                                break;

                            case MatBasic.ICHOR:
                                token = "CREATURE:" + subtype + ":ICHOR";
                                break;

                            case MatBasic.LEATHER:
                                token = "CREATURE:" + subtype + ":LEATHER";
                                break;

                            case MatBasic.BLOOD_1:
                                token = "CREATURE:" + subtype + ":BLOOD";
                                break;

                            case MatBasic.BLOOD_2:
                                token = "CREATURE:" + subtype + ":BLOOD";
                                break;

                            case MatBasic.BLOOD_3:
                                token = "CREATURE:" + subtype + ":BLOOD";
                                break;

                            case MatBasic.BLOOD_4:
                                token = "CREATURE:" + subtype + ":BLOOD";
                                break;

                            case MatBasic.BLOOD_5:
                                token = "CREATURE:" + subtype + ":BLOOD";
                                break;

                            case MatBasic.BLOOD_6:
                                token = "CREATURE:" + subtype + ":BLOOD";
                                break;

                            case MatBasic.PLANT:
                                token = "PLANT:" + subtype + ":STRUCTURAL";
                                break;

                            case MatBasic.WOOD:
                                token = "PLANT:" + subtype + ":WOOD";
                                break;

                            case MatBasic.PLANTCLOTH:
                                token = "PLANT:" + subtype + ":THREAD";
                                break;

                            default:
                                //make some kind of error here
                                continue;
                            }
                            MaterialTag.TryParse(token, out tag);
                        }
                    }
                }
                Debug.Log(tag);

                string subFolder = Path.GetFileNameWithoutExtension(doc.BaseUri) + "/";
                string assetPath = "Assets/Resources/Materials/" + subFolder + tag.ToFileName() + ".mat";
                var    saveMat   = AssetDatabase.LoadAssetAtPath <Material>(assetPath);
                if (saveMat == null)
                {
                    if (!Directory.Exists(Path.GetDirectoryName(assetPath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(assetPath));
                    }
                    saveMat = new Material(Shader.Find("Custom/MaterialStore"));
                    AssetDatabase.CreateAsset(saveMat, assetPath);
                }
                saveMat.SetColor("_Color", color32);

                Debug.Log(assetPath);
            }
        }
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
Exemplo n.º 3
0
        public void SetBasic(MatBasic basic)
        {
            switch (basic)
            {
            case MatBasic.INVALID:
                type = MaterialType.NONE;
                break;

            case MatBasic.INORGANIC:
                type = MaterialType.INORGANIC;
                break;

            case MatBasic.AMBER:
                type = MaterialType.AMBER;
                break;

            case MatBasic.CORAL:
                type = MaterialType.CORAL;
                break;

            case MatBasic.GREEN_GLASS:
                type = MaterialType.GLASS_GREEN;
                break;

            case MatBasic.CLEAR_GLASS:
                type = MaterialType.GLASS_CLEAR;
                break;

            case MatBasic.CRYSTAL_GLASS:
                type = MaterialType.GLASS_CRYSTAL;
                break;

            case MatBasic.ICE:
                type = MaterialType.WATER;
                break;

            case MatBasic.COAL:
                type = MaterialType.COAL;
                break;

            case MatBasic.POTASH:
                type = MaterialType.POTASH;
                break;

            case MatBasic.ASH:
                type = MaterialType.ASH;
                break;

            case MatBasic.PEARLASH:
                type = MaterialType.PEARLASH;
                break;

            case MatBasic.LYE:
                type = MaterialType.LYE;
                break;

            case MatBasic.MUD:
                type = MaterialType.MUD;
                break;

            case MatBasic.VOMIT:
                type = MaterialType.VOMIT;
                break;

            case MatBasic.SALT:
                type = MaterialType.SALT;
                break;

            case MatBasic.FILTH:
                type = MaterialType.FILTH_B;
                break;

            case MatBasic.FILTH_FROZEN:
                type = MaterialType.FILTH_Y;
                break;

            case MatBasic.UNKOWN_FROZEN:
                type = MaterialType.UNKNOWN_SUBSTANCE;
                break;

            case MatBasic.GRIME:
                type = MaterialType.GRIME;
                break;

            case MatBasic.ICHOR:
                type = MaterialType.CREATURE;
                tag2 = "ICHOR";
                break;

            case MatBasic.LEATHER:
                type = MaterialType.CREATURE;
                tag2 = "LEATHER";
                break;

            case MatBasic.BLOOD_1:
            case MatBasic.BLOOD_2:
            case MatBasic.BLOOD_3:
            case MatBasic.BLOOD_4:
            case MatBasic.BLOOD_5:
            case MatBasic.BLOOD_6:
            case MatBasic.BLOOD_NAMED:
                type = MaterialType.CREATURE;
                tag2 = "BLOOD";
                break;

            case MatBasic.PLANT:
                type = MaterialType.PLANT;
                break;

            case MatBasic.WOOD:
                type = MaterialType.PLANT;
                tag2 = "WOOD";
                break;

            case MatBasic.PLANTCLOTH:
                type = MaterialType.PLANT;
                tag2 = "THREAD";
                break;

            case MatBasic.DESIGNATION:
                type = MaterialType.DESIGNATION;
                break;

            case MatBasic.CONSTRUCTION:
                type = MaterialType.NONE;
                break;

            default:
                type = MaterialType.NONE;
                break;
            }
        }