// Use this for initialization void Start() { if (frames != null) { f = 1.0f / frames.Fps; } combine = GetComponent <CombineChildren>(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); CombineChildren l = target as CombineChildren; //EditorUtility.SetDirty(l); if (GUILayout.Button("Bake Mesh")) { Mesh m = l.GetCombineMesh(); AssetDatabase.CreateAsset(m, "Assets/mesh.asset"); } }
public override void OnInspectorGUI() { combine = (CombineChildren)target; base.OnInspectorGUI(); if (GUILayout.Button("Combine to Save")) { combine.combineChildren(true); EditorUtility.SetDirty(combine); } if (GUILayout.Button("Combine")) { combine.combineChildren(); } if (GUILayout.Button("Explain")) { combine.explainChildren(); } }
//检查root下的材质能否合并,能则尝试合并 void CombineItem() { bool combine = true; Material mat = null; //金华城 D_itBBox33 for (int i = 0; i < root.childCount; i++) { MeshRenderer mr = root.GetChild(i).GetComponent <MeshRenderer>(); if (mr != null && mr.sharedMaterial != mat && mat != null) { combine = false; break; } if (mat == null) { mat = mr.sharedMaterial; } } if (combine) { CombineChildren cm = root.gameObject.AddComponent <CombineChildren>(); cm.Combine(); BoxCollider b = root.gameObject.AddComponent <BoxCollider>(); b.isTrigger = true; MeshCollider[] co = GetComponentsInChildren <MeshCollider>(); for (int i = 0; i < co.Length; i++) { Destroy(co[i]); } } else { Debug.LogError("无法合并材质"); } }
public void Build() { Clear(); // delete everything in the map before loading the tiles JSONNode json = JSON.Parse(Map.ToString()); int layerCount = json["layers"].Count; int width = json["width"].AsInt; int height = json["height"].AsInt; for (int layer = 0; layer < layerCount; layer++) { GameObject layerObject = new GameObject(); CombineChildren combine = layerObject.AddComponent <CombineChildren>(); layerObject.transform.parent = transform; JSONArray map = json["layers"][layer]["data"].AsArray; string layerName = json["layers"][layer]["name"]; layerObject.name = "Layer" + layerName; int depth; if (!int.TryParse(layerName, out depth)) { depth = 0; } if (depth != PreviousDepth) { CurrentDepth += LayerDepth * LayerScales[depth].y; } PreviousDepth = depth; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int i = x + y * width; int tile = map[i].AsInt - 1; if (tile == -1) { continue; // bit of spaghetti } GameObject obj = Tiles[tile].obj; if (obj == null) { continue; // skip if undefined } float angle = Tiles[tile].angle; float objectX = (x - width / 2) * TileSize; float objectY = CurrentDepth; float objectZ = (y - height / 2) * TileSize; Vector3 position = new Vector3(objectX, objectY, objectZ) + transform.position; Quaternion rotation = Quaternion.Euler(0, angle, 0); GameObject instance = (GameObject)Instantiate(obj, position, rotation); instance.transform.parent = layerObject.transform; instance.transform.position = position; instance.layer = layerObject.layer; // check if this object has a script that needs to be run on map build RunOnMapBuild[] scripts = instance.GetComponents <RunOnMapBuild>(); foreach (RunOnMapBuild script in scripts) { script.Run(); } } } if (CombineMeshes) { combine.Combine(); } foreach (Transform child in layerObject.transform) { child.gameObject.layer = gameObject.layer; } if (LayerScales.Length > 0 && LayerScales[depth] != null) { layerObject.transform.localScale = LayerScales[depth]; } } foreach (Transform child in transform) { child.gameObject.isStatic = true; } }
//受击框 public void RefreshCollision() { collisions.Clear(); if (MethodOnAttack != null || OnAttackCallBack != null) { ///针对能击碎的物件,合并碰撞盒放到顶级 if (name.StartsWith("D_BBox") || name.StartsWith("D_BBBox") || name.StartsWith("D_RJug")) { CombineChildren combine = gameObject.GetComponent <CombineChildren>(); if (combine != null) { combine.Combine(); } BoxCollider b = gameObject.GetComponent <BoxCollider>(); if (b == null) { b = gameObject.AddComponent <BoxCollider>(); } //部分官卡不会合并网格,圣诞夜,宝箱材质是多个无法合并 if (combine == null) { if (name.StartsWith("D_BBox")) { b.size = new Vector3(40, 40, 40); b.center = new Vector3(0, 20, 0); } } MeshCollider[] co = GetComponentsInChildren <MeshCollider>(); for (int i = 0; i < co.Length; i++) { Destroy(co[i]); } } if (name.ToLower().Contains("chair") || name.ToLower().Contains("desk")) { } else { Collider[] co = GetComponentsInChildren <Collider>(); for (int i = 0; i < co.Length; i++) { //不显示出来的都没有受击框 MeshRenderer mr = co[i].GetComponent <MeshRenderer>(); if (mr != null && mr.enabled) { collisions.Add(co[i]); } } } } else //不能受击的物件,可能可以拾取,或者 { if (ItemInfo != null && ItemInfo.IsItem() && root != null) { //炼化 if (ItemInfo.Idx == 9 || ItemInfo.Idx == 23 || ItemInfo.Idx == 24 || ItemInfo.Idx == 25) { BoxCollider b = root.GetComponent <BoxCollider>(); if (b == null) { b = root.gameObject.AddComponent <BoxCollider>(); } b.center = new Vector3(0, 7.5f, 0); b.size = new Vector3(15, 15, 15); b.isTrigger = true; MeshCollider[] co = GetComponentsInChildren <MeshCollider>(); for (int i = 0; i < co.Length; i++) { Destroy(co[i]); } } else { //其他道具类 ReplaceMeshCollider(); } } else if (name.StartsWith("D_itBBox")) { ReplaceMeshCollider(); } else if (name.StartsWith("D_wpBBox")) { ProcessWeaponCollider(); } else if (name.StartsWith("D_wpBBBox")) { ProcessWeaponCollider(); } else if (name.StartsWith("D_Wpn") || name.StartsWith("D_wpn") || name.StartsWith("D_Wp") || name.StartsWith("D_wp")) { ProcessWeaponCollider(); } else if (name.StartsWith("D_sn03")) { //尖刺-如果有box的对象,取消box对象上的触发器 ProcessSn03Collider(); } else if (name.StartsWith("D_ston")) { //可击碎的石头-击碎后可攻击角色 } else if (name.StartsWith("D_tp")) { } /*else*/ //Debug.LogError("not processed:" + name); } }
public void Load(string file) { string s = file; if (!string.IsNullOrEmpty(file)) { //查看此物体属于什么,A:武器 B:道具 C:镖物 if (ItemInfo == null) { for (int i = 0; i < MenuResLoader.Ins.Info.Count; i++) { if (MenuResLoader.Ins.Info[i].model != "0" && 0 == string.Compare(MenuResLoader.Ins.Info[i].model, s, true)) { ApplyPrev(MenuResLoader.Ins.Info[i]); break; } string rh = s.ToUpper(); string rh2 = MenuResLoader.Ins.Info[i].model.ToUpper(); if (rh2.StartsWith(rh)) { s = MenuResLoader.Ins.Info[i].model; ApplyPrev(MenuResLoader.Ins.Info[i]); break; } } //不是一个Meteor.res里的物件 if (ItemInfo == null) { List <ItemData> its = DataMgr.Ins.GetItemDatas(); for (int i = 0; i < its.Count; i++) { if (its[i].MainType == (int)UnitType.Weapon) { WeaponData weapon = U3D.GetWeaponProperty(its[i].UnitId); if (weapon.WeaponR == s) { ItemInfoEx = its[i]; break; } } } } } //证明此物品不是可拾取物品 //gameObject.layer = (ItemInfo != null || ItemInfoEx != null) ? LayerManager.Trigger : LayerManager.Scene; gameObject.layer = LayerManager.Trigger; root.gameObject.layer = gameObject.layer; //箱子椅子桌子酒坛都不允许为场景物品. Utility.ShowMeteorObject(s, root); DesFile fIns = DesLoader.Ins.Load(s); //把子物件的属性刷到一起. for (int i = 0; i < fIns.SceneItems.Count; i++) { LoadCustom(fIns.SceneItems[i].name, fIns.SceneItems[i].custom); } //雪人不能合并材质,不然没法动画 if (CombatData.Ins.GLevelItem.Scene != "Meteor_21") { if (name.StartsWith("D_Item") || name.StartsWith("D_RJug") || name.StartsWith("D_itRJug") || name.StartsWith("D_BBox") || name.StartsWith("D_BBBox") || name.StartsWith("D_Box")) { if (root != null) { CombineChildren combine = root.gameObject.AddComponent <CombineChildren>(); combine.generateTriangleStrips = false; } else { CombineChildren combine = gameObject.AddComponent <CombineChildren>(); combine.generateTriangleStrips = false; } } } FMCFile f = FMCLoader.Ins.Load(s); if (f != null) { player = GetComponent <FMCPlayer>(); if (player == null) { player = gameObject.AddComponent <FMCPlayer>(); } player.Init(s, f); } else { player = GetComponent <FMCPlayer>(); if (player != null) { Destroy(player); player = null; } } } }