Esempio n. 1
0
        /// <summary>
        /// Skinning mesh to new skinned mesh renderer with choosed weight markers settings
        /// </summary>
        public void SkinMesh(bool addTailAnimator, Vector3 newObjectOffset)
        {
            // Remembering data and preparing objects with components
            List <Color32> baseVertColors = new List <Color32>();

            GetBaseMesh().GetColors(baseVertColors);

            // Doing skinning
            vertexDatas = FTail_Skinning.CalculateVertexWeightingData(
                GetBaseMesh(), ghostBones, SpreadOffset, LimitBoneWeightCount, SpreadValue, SpreadPower);

            SkinnedMeshRenderer newSkinnedMesh = FTail_Skinning.SkinMesh(baseMesh, transform, ghostBones, vertexDatas);

            if (newSkinnedMesh == null)
            {
                Debug.LogError("[Tail Animator Skinning] Creating skinned mesh failed!"); return;
            }


            // Skin renderer quality
            switch (LimitBoneWeightCount)
            {
            case 1: newSkinnedMesh.quality = SkinQuality.Bone1; break;

            case 2: newSkinnedMesh.quality = SkinQuality.Bone2; break;

            case 4: newSkinnedMesh.quality = SkinQuality.Bone4; break;

            default: newSkinnedMesh.quality = SkinQuality.Auto; break;
            }

            // Filling new mesh with materials
            MeshRenderer meshRend = GetComponent <MeshRenderer>();

            if (meshRend)
            {
                newSkinnedMesh.materials       = meshRend.sharedMaterials;
                newSkinnedMesh.sharedMaterials = meshRend.sharedMaterials;
            }

            // Adding tail animator
            if (addTailAnimator)
            {
                TailAnimator2 t = newSkinnedMesh.bones[0].gameObject.AddComponent <TailAnimator2>();
                t.StartBone = newSkinnedMesh.bones[0];
                t.EndBone   = newSkinnedMesh.bones[newSkinnedMesh.bones.Length - 1];
            }

            // Setting new object position to be next to current model
            newSkinnedMesh.transform.position = transform.position + new Vector3(1f, 1f, 1f);

            // Create asset for new model so it not disappear when we create prefab from this gameObject
            string newMeshPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(baseMesh));

            AssetDatabase.CreateAsset(newSkinnedMesh.sharedMesh, newMeshPath + "/" + newSkinnedMesh.name + ".mesh");
            AssetDatabase.SaveAssets();

            Debug.Log("New skinned mesh '" + newSkinnedMesh.name + ".mesh" + "' saved under path: '" + newMeshPath + "'");
        }
Esempio n. 2
0
 /// <summary>
 /// Generating wind component if needed and adding tail animator component to wind affected components list
 /// </summary>
 public static void Refresh(TailAnimator2 tail)
 {
     if (!_instance)
     {
         GenerateWindComponentInstance();
     }
     if (_instance.WindAffected == null)
     {
         _instance.WindAffected = new List <TailAnimator2>();
     }
     if (tail != null)
     {
         if (!_instance.WindAffected.Contains(tail))
         {
             _instance.WindAffected.Add(tail);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Getting editor selected objects with tail animators to apply changes to multiple tail animator objects
        /// </summary>
        private List <TailAnimator2> GetSelectedTailAnimators()
        {
            List <TailAnimator2> anims = new List <TailAnimator2>();

            for (int i = 0; i < Selection.gameObjects.Length; i++)
            {
                TailAnimator2 t = Selection.gameObjects[i].GetComponent <TailAnimator2>();
                if (t)
                {
                    if (!anims.Contains(t))
                    {
                        anims.Add(t);
                    }
                }
            }

            lastSelected = anims;
            return(anims);
        }
        public override void OnInspectorGUI()
        {
            Undo.RecordObject(target, "Spine Animator Inspector");

            serializedObject.Update();

            TailAnimator2 Get   = (TailAnimator2)target;
            string        title = drawDefaultInspector ? " Default Inspector" : (" " + Get._editor_Title);

            HeaderBoxMain(title, ref Get.DrawGizmos, ref drawDefaultInspector, _TexTailAnimIcon, Get, 27);

            if (drawDefaultInspector)
            {
                DrawDefaultInspector();
            }
            else
            {
                DrawNewGUI();
            }

            serializedObject.ApplyModifiedProperties();
        }