Example #1
0
        private void SelectRecord(int id)
        {
            flagEdit = 2;

            selectedRecord = id;

            SkinsTable.Skin tRec = listSkins.Find(x => x.ID == id);
            skinName          = tRec.Name;
            bodyModelSelected = bodyModelList.FindIndex(x => x.ID == tRec.IDModel);
            defSkin           = tRec.DefaultSkin;

            FilterSlots(bodyModelSelected);

            List <SkinsTable.SkinSlots> tList = skinTable.GetSlotsList(selectedRecord, true);

            //Fill the material list
            for (int i = 0; i < tList.Count; i++)
            {
                MaterialPrefab tMat = new MaterialPrefab();
                tMat            = materialList.Find(x => x.IDSlot == tList [i].IDSkinSlot);
                tMat.PrefabName = tList [i].MaterialName;

                //Try to find the object
                Material prefabToLoad = (Material)Resources.Load(_config.GetPathName(CSConfig.PathTypeEnum.SkinsPath) + "/" + tMat.PrefabName);
                if (prefabToLoad != null)
                {
                    tMat.Prefab         = prefabToLoad;
                    tMat.PrefabSelected = prefabToLoad;
                }
                else
                {
                    tMat.PrefabError = true;
                }
            }
        }
        //** ApplyBodyModel **
        //Change the actual model used by the actor
        public void ApplyBodyModel(int modelID)
        {
            if (_config == null)
            {
                return;
            }

            //Get the name of the prefab to be used
            BodyModelTable.BodyModel model = tableBodyModel.GetModel(modelID);

            if (model == null)
            {
                Debug.LogError("Cannot retrieve the prefab of Body Model.");
            }

            //Assembly the full name with the path where the models are stored
            string modelPath = _config.GetPathName(CSConfig.PathTypeEnum.BodyModelsPath) + "/" + model.ModelName;

            //Load the model prefab
            GameObject objModel = (GameObject)Resources.Load(modelPath);

            if (objModel == null)
            {
                //Cannot load the model. Don't continue
                Debug.LogError("Cannot retrieve the prefab of Body Model. Prefab not found.");
            }

            //Retrieve the bone estructure that need to be used
            SkinnedMeshRenderer bSource = bonesSource.GetComponent <SkinnedMeshRenderer> ();

            //Remove actual model from actor
            if (actorBody.ActorModel != null)
            {
                Destroy(actorBody.ActorModel);
            }

            //Assign the new model to actor controller
            actorBody.ActorModel = GameObject.Instantiate(objModel) as GameObject;
            actorBody.ActorModel.transform.SetParent(this.gameObject.transform, false);

            //For each sub object of the model set the bone structure to be used
            foreach (Transform child in actorBody.ActorModel.transform)
            {
                SkinnedMeshRenderer bDest = child.GetComponent <SkinnedMeshRenderer> ();
                bDest.bones = bSource.bones;
            }

            oldBodySubtype = actorBody.BodySubtype;

            //Update information about the actor's body model
            actorBody.BodyID        = modelID;
            actorBody.BodyStructure = model.IDBodyStructure;
            actorBody.BodySubtype   = model.IDBodySubtype;
            actorBody.BodyModel     = modelPath;
            actorBody.EyeID         = model.IDEye;
            //Find the bone structure object
            actorBody.BonesArmature = transform.Find(model.ArmatureName);

            //Retrieve the clothing method used by this model / body structure
            tableBodyStructure.GetList();

            actorBody.ClothingType = tableBodyStructure.GetRecord(model.IDBodyStructure).ClothingMethod;

            if (AutoChangeCloth)
            {
                ChangeClothesForModel();
            }

            //Apply the default skin
            SkinsTable.Skin tSkin = tableSkins.GetDefaultSkin(actorBody.BodyID);
            if (tSkin != null)
            {
                actorBody.SkinID = tSkin.ID;
                ApplyBodySkin(actorBody.SkinID);
            }
            else
            {
                Debug.LogWarning("Body model doesn't have a default skin.");
            }
        }