コード例 #1
0
        static void AddPartToList(PartBundleDescriptor partBundleDesc, PartDescriptor partDesc)
        {
            PartEditor.PartList partList = null;

            //add to the right list
            switch (partDesc.partType)
            {
            case (PartInfo.PartType.Blade):
                partList = PartEditor.BladeList;
                break;

            case (PartInfo.PartType.Guard):
                partList = PartEditor.GuardList;
                break;

            case (PartInfo.PartType.FingerGuard):
                partList = PartEditor.GuardList;
                break;

            case (PartInfo.PartType.Handle):
                partList = PartEditor.HandleList;
                break;

            case (PartInfo.PartType.Pommel):
                partList = PartEditor.PommelList;
                break;

            case (PartInfo.PartType.Accessory):
                partList = PartEditor.AccAList;
                break;
            }

            //create part key
            string partRefName = partBundleDesc.partBundleAuthor + "." + partBundleDesc.partBundleName + "." + partDesc.partType.ToString() + "." + partDesc.partName;

            foreach (PartInfo part in partList.parts)
            {
                if (part.partReferenceName == partRefName)
                {
                    Logger.log.Debug("A part with the name " + part.partReferenceName + " has already been added - skipping. Make sure all part and bundle names are unique!");
                    return;
                }
            }

            PartInfo newPart = new PartInfo(partDesc.partType, partDesc.gameObject, partRefName, partDesc.partDisplayName);

            partList.parts.Add(newPart);
            Logger.log.Debug("Added " + partRefName + " to the list of " + partDesc.partType.ToString());;
        }
コード例 #2
0
        public static void AddMaterialToList(PartBundleDescriptor partBundleDesc, MaterialDescriptor matDesc, Material mat)
        {
            PartEditor.MatList matList = null;

            switch (matDesc.materialType)
            {
            case (MaterialInfo.MaterialType.Glow):
                matList = PartEditor.GlowList;
                break;

            case (MaterialInfo.MaterialType.Secondary):
                matList = PartEditor.SecondaryList;
                break;

            case (MaterialInfo.MaterialType.Trail):
                matList = PartEditor.TrailList;
                break;

            case (MaterialInfo.MaterialType.NamePlate):
                matList = PartEditor.NamePlateList;
                break;

            case (MaterialInfo.MaterialType.Template):
                matList = PartEditor.TemplateList;
                break;
            }

            string trimmedName = mat.name.Replace(" (Instance)", "");

            string matRefName = partBundleDesc.partBundleAuthor + "." + partBundleDesc.partBundleName + "." + matDesc.materialType.ToString() + "." + trimmedName;

            foreach (MaterialInfo listMatInfo in matList.mats)
            {
                if (listMatInfo.materialReferenceName == matRefName)
                {
                    Logger.log.Debug("A material with the name " + listMatInfo.materialReferenceName + " has already been added - skipping. Make sure all material and bundle names are unique!");
                    return;
                }
            }

            MaterialInfo matInfo = new MaterialInfo(matDesc.materialType, mat, matRefName, matDesc.materialDisplayName, matDesc.supportsCustomColors);

            matList.mats.Add(matInfo);
            Logger.log.Debug("Added " + matRefName + " to the list of " + matInfo.materialType.ToString() + " materials");
        }
コード例 #3
0
        public static void GenerateUserMaterial(string texturePath, string textureName, Material templateMat, bool supportsCustomColors, MaterialInfo.MaterialType matType)
        {
            //stolen from http://gyanendushekhar.com/2017/07/08/load-image-runtime-unity/
            byte[] byteArray = File.ReadAllBytes(texturePath);
            //create a texture and load byte array to it
            // Texture size does not matter
            Texture2D sampleTexture = new Texture2D(2, 2);
            // the size of the texture will be replaced by image size
            bool isLoaded = sampleTexture.LoadImage(byteArray);
            // apply this texure as per requirement on image or material
            GameObject image = GameObject.Find("RawImage");

            Material newMat = Instantiate(templateMat);


            newMat.name = textureName;

            if (isLoaded)
            {
                newMat.SetTexture("_Tex", sampleTexture);

                //Logger.log.Debug("Loaded user texture " + textureName);


                PartBundleDescriptor newBundleDesc = new PartBundleDescriptor();
                newBundleDesc.partBundleAuthor = "User";
                newBundleDesc.partBundleName   = "UserTextures";

                MaterialDescriptor newMatDesc = new MaterialDescriptor();

                newMatDesc.materialType         = matType;
                newMatDesc.materialDisplayName  = textureName;
                newMatDesc.supportsCustomColors = supportsCustomColors;

                AssetLoader.AddMaterialToList(newBundleDesc, newMatDesc, newMat);
            }
        }
コード例 #4
0
        // compose part lists
        public static void CreatePartLists()
        {
            //find all the part lists in the assets files
            List <GameObject> partBundleObjs = new List <GameObject>();

            foreach (string path in RetrievePartBundles())
            {
                GameObject tempObj = AssetBundle.LoadFromFile(path).LoadAsset <GameObject>("_PartBundle");

                if (tempObj.GetComponent <PartBundleDescriptor>() == null)
                {
                    Logger.log.Debug("No Saber Forge part bundle descriptor on " + tempObj.name.ToString() + " - skipped");
                }

                else
                {
                    partBundleObjs.Add(tempObj);
                }
            }

            //look through each loaded bundle
            foreach (GameObject partBundleObj in partBundleObjs)
            {
                PartBundleDescriptor partBundleDesc = partBundleObj.GetComponent <PartBundleDescriptor>();

                if (partBundleDesc.forgeProp != null)
                {
                    ForgeProp = partBundleDesc.forgeProp;
                    Logger.log.Debug("Got Forge Prop Hooray!");
                }

                Logger.log.Debug("Grabbing parts from " + partBundleDesc.partBundleName + " by " + partBundleDesc.partBundleAuthor);

                //find all partDesc components and add them to the lists
                PartDescriptor[] partDescs = partBundleObj.GetComponentsInChildren <PartDescriptor>();
                Logger.log.Debug("Found " + partDescs.Length.ToString() + " parts in " + partBundleDesc.partBundleName);

                foreach (PartDescriptor partDesc in partDescs)
                {
                    AddPartToList(partBundleDesc, partDesc);
                }

                //now find all mat descs in the part bundle
                MaterialDescriptor[] matDescs = partBundleObj.GetComponentsInChildren <MaterialDescriptor>();
                Logger.log.Debug("Found " + matDescs.Length.ToString() + " materials in " + partBundleDesc.partBundleName);

                foreach (MaterialDescriptor matDesc in matDescs)
                {
                    if (matDesc.gameObject.GetComponent <MeshRenderer>() != null)
                    {
                        AddMaterialToList(partBundleDesc, matDesc, matDesc.gameObject.GetComponent <MeshRenderer>().material);
                    }
                    else
                    {
                        Logger.log.Debug("No mesh renderer to grab a material from on " + matDesc.materialDisplayName + " in " + partBundleDesc.partBundleName + " part bundle, skipping");
                    }
                }
            }

            //duplicate Accessory List and Secondary Mats List
            PartEditor.AccBList.parts    = PartEditor.AccAList.parts;
            PartEditor.TertiaryList.mats = PartEditor.SecondaryList.mats;
        }