public void GetRest(SkelType mon) { switch (mon) { case SkelType.WARRIOR: skel.GetRest(); break; case SkelType.KNIGHT: knight.GetRest(); break; case SkelType.SLAVE: slave.GetRest(); break; } }
public void DeActive(SkelType mon) { switch (mon) { case SkelType.WARRIOR: skel.DeActive(); break; case SkelType.KNIGHT: knight.DeActive(); break; case SkelType.SLAVE: slave.DeActive(); break; } }
public void SetRandomNum(SkelType mon) { switch (mon) { case SkelType.WARRIOR: skel.RandomAttack(); break; case SkelType.KNIGHT: knight.RandomAttack(); break; case SkelType.SLAVE: slave.RandomAttack(); break; } }
void GenSkelPrefab(SkelType skelType) { int count = Selection.instanceIDs.Length; if (count == 0) { Debug.LogError("请选择骨骼所在的文件夹1"); } List <string> paths = new List <string>(); for (int i = 0; i < count; i++) { string path = AssetDatabase.GetAssetPath(Selection.instanceIDs[i]); if (path.Contains(".") || !path.Contains("sk")) { continue; } paths.Add(path); } if (paths == null || paths.Count == 0) { Debug.LogError("请选择骨骼所在的文件夹2"); } Dictionary <Slot, List <BoundingBoxAttachment> > boundingBoxTable = new Dictionary <Slot, List <BoundingBoxAttachment> >(); for (int i = 0; i < paths.Count; ++i) { string path = paths[i]; string targetpath = ""; switch (skelType) { case SkelType.Bullet: targetpath = "Assets/GameRes/Prefab/Battle/Bullet/"; break; case SkelType.Effect: targetpath = "Assets/GameRes/Prefab/Effect/"; break; case SkelType.Item: targetpath = "Assets/GameRes/Prefab/Skeleton/"; break; case SkelType.Role: targetpath = "Assets/GameRes/Prefab/Skeleton/"; break; case SkelType.Boss: targetpath = "Assets/GameRes/Prefab/Skeleton/"; break; } if (string.IsNullOrEmpty(targetpath)) { Util.LogError("目标路径 Unkown"); return; } boundingBoxTable.Clear(); int lastidx = path.LastIndexOf('/') + 1 + 3; //3跳掉sk_ string name = path.Substring(lastidx, path.Length - lastidx); string skelPath = path.Substring(0, path.LastIndexOf('/') + 1); string prefabName = name + ".prefab"; string prefabPath = targetpath + prefabName; Debug.Log("name:" + prefabPath); if (File.Exists(prefabPath)) { File.Delete(prefabPath); } GameObject go = new GameObject(); go.transform.localPosition = Vector3.zero; go.transform.localScale = Vector3.one; go.layer = LayerMask.NameToLayer("UI"); //设置RectTransform RectTransform rt = go.AddComponent <RectTransform>(); rt.anchoredPosition = Vector2.zero; rt.sizeDelta = new Vector2(80, 80); rt.localEulerAngles = Vector3.zero; GameObject skelGo = new GameObject(); skelGo.name = "Skeleton"; skelGo.transform.localPosition = Vector3.zero; skelGo.transform.localScale = new Vector3(100, 100); skelGo.transform.SetParent(go.transform); //获取骨骼数据 string skelDataPath = skelPath + "sk_" + name + "/" + name + "_SkeletonData.asset"; Object obj = AssetDatabase.LoadAssetAtPath <Object>(skelDataPath); SkeletonDataAsset skelData = AssetDatabase.LoadAssetAtPath <SkeletonDataAsset>(skelDataPath); if (null == skelData) { Debug.LogError(name + "获取骨骼数据失败"); return; } //创建骨骼 SkeletonAnimation skelAnim = SkeletonAnimation.AddToGameObject(skelGo, skelData); //展开spine个骨骼结点到unity SkeletonUtility util = skelGo.AddComponent <SkeletonUtility>(); util.SpawnHierarchy(SkeletonUtilityBone.Mode.Follow, true, true, true); if (skelType == SkelType.Bullet) { BoxCollider2D collider = go.AddComponent <BoxCollider2D>(); go.tag = "Bullet"; collider.isTrigger = true; Rigidbody2D rbody = go.AddComponent <Rigidbody2D>(); rbody.gravityScale = 0f; } if (skelType == SkelType.Effect) { // go.AddComponent<SkeletonEffect>(); } if (skelType == SkelType.Boss) { BoxCollider2D collider = go.AddComponent <BoxCollider2D>(); go.tag = "MonsterDying"; collider.isTrigger = true; collider.enabled = false; //创建多边形碰撞 Skeleton skeleton = skelAnim.Skeleton; int slotCount = skeleton.Slots.Count; Skin skin = skeleton.Skin; if (skin == null) { skin = skeleton.Data.DefaultSkin; } //遍历所有的骨骼结点 for (int m = 0; m < slotCount; ++m) { Slot slot = skeleton.Slots.Items[m]; List <Attachment> slotAttachments = new List <Attachment>(); skin.FindAttachmentsForSlot(skeleton.FindSlotIndex(slot.Data.Name), slotAttachments); for (int n = 0; n < slotAttachments.Count; ++n) { BoundingBoxAttachment bounding = slotAttachments[n] as BoundingBoxAttachment; if (bounding != null) { string childName = GetChildName(slot.Bone); Transform transform = util.boneRoot.Find(childName); if (null != transform) { SkeletonUtility.AddBoundingBoxGameObject(null, bounding, slot, transform); } } } } } if (skelType == SkelType.Role) { BoxCollider2D collider = go.AddComponent <BoxCollider2D>(); collider.isTrigger = true; go.tag = "Hero"; collider.size = new Vector2(30, 50); Rigidbody2D body = go.AddComponent <Rigidbody2D>(); body.gravityScale = 0.0f; body.velocity = Vector2.zero; body.freezeRotation = true; } //创建预置 Object prefab = PrefabUtility.CreateEmptyPrefab(prefabPath); PrefabUtility.ReplacePrefab(go, prefab, ReplacePrefabOptions.ConnectToPrefab); AssetImporter ai = AssetImporter.GetAtPath(prefabPath); ai.assetBundleName = name; ai.assetBundleVariant = "assetbundle"; GameObject.DestroyImmediate(go); } }