using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using UnityEngine.AI; public class SceneTool { // Use this for initialization //[MenuItem("SceneTool/ShiNeiFloorRename")] ////设置每一层的室内结构父对象的名称,方法:选中每层室内父对象后设置 //public static void ShiNeiFloorRename() //{ // bool containBuildNum = true;//生成名字是否包含楼号 // Transform[] obj = Selection.GetTransforms(SelectionMode.Unfiltered); // for (int i = 0; i < obj.Length; i++) // { // if (obj[i].GetComponent()) // { // var buildNum = obj[i].GetComponent().buildNum; // var floorNum = obj[i].GetComponent().floorNum; // var interlayerNum = obj[i].GetComponent().interlayerNum; // string name = "nei" + floorNum; // if (containBuildNum) // { // name = buildNum + name; // } // if (interlayerNum != 0) // { // name = name + "*" + interlayerNum; // } // obj[i].name = name; // obj[i].tag = "nei"; // } // } //} //[MenuItem("SceneTool/ShiWaiFloorRename")] ////设置每一层的室外结构父对象的名称,方法:选中每层室外父对象后设置 //public static void ShiWaiFloorRename() //{ // bool containBuildNum = true;//生成名字是否包含楼号 // Transform[] obj = Selection.GetTransforms(SelectionMode.Unfiltered); // for (int i = 0; i < obj.Length; i++) // { // if (obj[i].GetComponent()) // { // var buildNum = obj[i].GetComponent().buildNum; // var floorNum = obj[i].GetComponent().floorNum; // var interlayerNum = obj[i].GetComponent().interlayerNum; // string name = "wai" + floorNum; // if (containBuildNum) // { // name = buildNum + name; // } // if (interlayerNum != 0) // { // name = name + "*" + interlayerNum; // } // obj[i].name = name; // } // } //} //[MenuItem("SceneTool/SetShiNeiFloor")] ////设置室内寻路,地面、楼梯、墙设置Layer加MeshCollider,墙加NavMeshModifier,地面、楼梯加静态Id脚本 ////方法:选中每层室内父对象后设置 //public static void SetShiNeiFloor() //{ // int[] NUM = { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; // Transform[] obj = Selection.GetTransforms(SelectionMode.Unfiltered); // for (int i = 0; i < obj.Length; i++) // { // if (obj[i].GetComponent()) // { // var buildNum = obj[i].GetComponent().buildNum; // var floorNum = obj[i].GetComponent().floorNum; // var interlayerNum = obj[i].GetComponent().interlayerNum; // string layerName = ""; // if (floorNum < 0) // { // layerName = buildNum + "-10--1"; // } // else // { // for (int k = 0; k < NUM.Length; k++) // { // if (floorNum > NUM[k] && floorNum <= NUM[k + 1]) // { // var begin = NUM[k] + 1; // var end = NUM[k + 1]; // layerName = buildNum + begin + "-" + end; // break; // } // } // } // var childObj = obj[i].GetComponentsInChildren(); // for (int j = 0; j < childObj.Length; j++) // { // if (childObj[j].gameObject.name.ToUpper().Contains("LT") || childObj[j].gameObject.name.ToUpper().Contains("LOUTI")) // { // childObj[j].gameObject.layer = LayerMask.NameToLayer(layerName); // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // var objInfo = childObj[j].gameObject.GetComponent(); // objInfo.gameObjType = CloneObjType.staticGameObject; // objInfo.buildNum = buildNum; // objInfo.floorNum = floorNum; // objInfo.interlayerNum = interlayerNum; // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // } // if (childObj[j].gameObject.name.ToUpper().Contains("FLOOR")) // { // childObj[j].gameObject.layer = LayerMask.NameToLayer(layerName); // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // var objInfo = childObj[j].gameObject.GetComponent(); // objInfo.gameObjType = CloneObjType.staticGameObject; // objInfo.buildNum = buildNum; // objInfo.floorNum = floorNum; // objInfo.interlayerNum = interlayerNum; // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // } // if (childObj[j].gameObject.name.ToUpper().Contains("WALL")) // { // childObj[j].gameObject.layer = LayerMask.NameToLayer(layerName); // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // if (!childObj[j].gameObject.GetComponent()) // { // childObj[j].gameObject.AddComponent(); // } // NavMeshModifier modifier = childObj[j].gameObject.GetComponent(); // modifier.overrideArea = true; // modifier.area = NavMesh.GetAreaFromName("Not Walkable"); // } // } // } // } //} //[MenuItem("SceneTool/SetShiWaiFloor")] ////室外地面添加静态Id脚本,加MeshCollider,方法:选中整个场景后设置 //public static void SetShiWaiFloor() //{ // Transform[] obj = Selection.GetTransforms(SelectionMode.Deep); // for (int i = 0; i < obj.Length; i++) // { // if (obj[i].gameObject.layer == LayerMask.NameToLayer("Road")) // { // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // var objInfo = obj[i].gameObject.GetComponent(); // objInfo.gameObjType = CloneObjType.staticGameObject; // if (!obj[i].GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // } // } //} //[MenuItem("SceneTool/SetXHS")] ////给消火栓添加静态Id脚本,加MeshCollider,加水源的标记脚本,方法:选中消火栓后设置 //public static void SetXHS() //{ // Transform[] obj = Selection.GetTransforms(SelectionMode.Unfiltered); // for (int i = 0; i < obj.Length; i++) // { // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // var objInfo = obj[i].gameObject.GetComponent(); // objInfo.gameObjType = CloneObjType.staticGameObject; // Transform pTrans = TransformHelper.FindParentByTag(obj[i], "nei"); // if (pTrans != null) // { // FloorMessage floorMsg = pTrans.GetComponent(); // objInfo.buildNum = floorMsg.buildNum; // objInfo.floorNum = floorMsg.floorNum; // objInfo.interlayerNum = floorMsg.interlayerNum; // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // var waterSource = obj[i].gameObject.GetComponent(); // waterSource.water = true; // waterSource.foam = false; // } //} //[MenuItem("SceneTool/SetJHQ")] ////给水泵接合器添加静态Id脚本,加MeshCollider,方法:选中接合器后设置 //public static void SetJHQ() //{ // Transform[] obj = Selection.GetTransforms(SelectionMode.Unfiltered); // for (int i = 0; i < obj.Length; i++) // { // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // var objInfo = obj[i].gameObject.GetComponent(); // objInfo.gameObjType = CloneObjType.staticGameObject; // Transform pTrans = TransformHelper.FindParentByTag(obj[i], "nei"); // if (pTrans != null) // { // FloorMessage floorMsg = pTrans.GetComponent(); // objInfo.buildNum = floorMsg.buildNum; // objInfo.floorNum = floorMsg.floorNum; // objInfo.interlayerNum = floorMsg.interlayerNum; // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // } //} //[MenuItem("SceneTool/CreateFloorTarget")] ////在楼层中创建切层的相机跟随目标位置 //public static void CreateFloorTarget() //{ // Transform[] obj = Selection.GetTransforms(SelectionMode.Unfiltered); // for (int i = 0; i < obj.Length; i++) // { // if (obj[i].GetComponent()) // { // var buildNum = obj[i].GetComponent().buildNum; // var floorNum = obj[i].GetComponent().floorNum; // var interlayerNum = obj[i].GetComponent().interlayerNum; // var target = obj[i].Find("TargetPosition"); // if (!target) // { // var targetObj = GameObject.CreatePrimitive(PrimitiveType.Cube); // targetObj.name = "TargetPosition"; // targetObj.transform.parent = obj[i]; // targetObj.GetComponent().enabled = false; // targetObj.GetComponent().enabled = false; // //对象名称 // var childObj = obj[i].GetComponentsInChildren(); // for (int j = 0; j < childObj.Length; j++) // { // if (childObj[j].gameObject.name.ToUpper().Contains("FLOOR")) // { // targetObj.transform.position = childObj[j].gameObject.transform.position; // } // } // } // } // } //} [MenuItem("SceneTool/CleanupMissingScripts")] //清除场景中挂的丢失的脚本,完成后需重新打开项目 public static void CleanupMissingScripts() { Transform[] obj = Selection.GetTransforms(SelectionMode.Deep); for (int i = 0; i < obj.Length; i++) { var gameObject = obj[i].gameObject; // We must use the GetComponents array to actually detect missing components var components = gameObject.GetComponents(); // Create a serialized object so that we can edit the component list var serializedObject = new SerializedObject(gameObject); // Find the component list property var prop = serializedObject.FindProperty("m_Component"); // Track how many components we've removed int r = 0; // Iterate over all components for (int j = 0; j < components.Length; j++) { // Check if the ref is null if (components[j] == null) { // If so, remove from the serialized component array prop.DeleteArrayElementAtIndex(j - r); // Increment removed count r++; } } // Apply our changes to the game object serializedObject.ApplyModifiedProperties(); } } [MenuItem("SceneTool/ChangeBuildName")] static void ChangeBuildName() { //Transform zhuti = GameObject.Find("Scene").transform.Find("ZhuTi/A0ZhuTi"); //Transform shinei= GameObject.Find("Scene").transform.Find("ShiNei/A0ShiNei"); Transform zhuti = GameObject.Find("Scene").transform.Find("ZhuTi"); Transform shinei= GameObject.Find("Scene").transform.Find("ShiNei"); for (int i = 0; i < zhuti.childCount; i++) { change(zhuti.GetChild(i), 1); } for (int i = 0; i < shinei.childCount; i++) { change(shinei.GetChild(i), 1); } } static void change(Transform target, int index) { string build = target.name.Substring(0, index); string neiwai = target.name.Contains("ShiNei") ? "nei" : "wai"; if (target.childCount < 1) { return; } for (int i = 0; i < target.childCount; i++) { //if (!target.GetChild(i).name.Contains("nei")|| // !target.GetChild(i).name.Contains("wai")) //{ // return; //} target.GetChild(i).name = build + target.GetChild(i).name; if (!target.GetChild(i).GetComponent()) { target.GetChild(i).gameObject.AddComponent(); } int floor; if (!target.GetChild(i).name.Contains("M")) { int indexI = target.GetChild(i).name.IndexOf("i"); floor = int.Parse(target.GetChild(i).name.Substring(indexI + 1)); } else { if (target.GetChild(i).name.StartsWith("M") && !target.GetChild(i).name.EndsWith("M")) { int indexJ = target.GetChild(i).name.IndexOf("i"); floor = int.Parse(target.GetChild(i).name.Substring(indexJ + 1)); } else { int indexM = target.GetChild(i).name.IndexOf("M"); int indexI = target.GetChild(i).name.IndexOf("i"); Debug.Log(target.GetChild(i).name.Substring(indexI+1, indexM-indexI-1)); floor = int.Parse(target.GetChild(i).name.Substring(indexI + 1, indexM - indexI - 1)); } } //floor = int.Parse(target.GetChild(i).name.Substring(target.GetChild(i).name.IndexOf(neiwai))); FloorMessage mess = target.GetChild(i).GetComponent(); mess.buildNum = build; mess.floorNum = floor; mess.interlayerNum = target.GetChild(i).name.Contains("M") ? 1 : 0; } } [MenuItem("SceneTool/SetGameObjType")] static void SetGameObjType() { Transform scenc = GameObject.Find("SceneAll").transform; CloneGameObjInfo[] infos = scenc.GetComponentsInChildren(true); for (int i = 0; i < infos.Length; i++) { if (!infos[i].GetComponent()) { infos[i].gameObject.AddComponent(); } if(!infos[i].gameObject.GetComponent()) { infos[i].gameObjType = CloneObjType.StaticGameObject; } } } [MenuItem("SceneTool/SetXHS")] static void SetSetXHS() { Transform Scene = GameObject.Find("SceneAll").transform;//.Find("ShiNei/AShiNei"); WaterSupplier[] ws = Scene.GetComponentsInChildren(true); for (int i = 0; i < ws.Length; i++) { if (!ws[i].GetComponent()) { ws[i].gameObject.AddComponent(); } if (!ws[i].GetComponent()) { ws[i].WaterReceiverType = WaterType.water; ws[i].gameObject.AddComponent(); ws[i].GetComponent().CloneableTypes.Add(CloneObjType.TwinkleLine); ws[i].GetComponent().CloneableTypes.Add(CloneObjType.WaterLine); ws[i].GetComponent().gameObjType = CloneObjType.StaticGameObject; } else { } ws[i].GetComponent().gameObjType = CloneObjType.XHS; } } [MenuItem("SceneTool/AddFireNormalShiNei")] static void AddFireNormal() { Transform Ashinei = GameObject.Find("Scene").transform.Find("ShiNei"); CloneableEnums[] enums = Ashinei.GetComponentsInChildren(true); for (int i = 0; i < enums.Length; i++) { if (enums[i].gameObject.GetComponent().gameObjType!=CloneObjType.XHS) { if (!enums[i].CloneableTypes.Contains(CloneObjType.FireNormal)) { enums[i].CloneableTypes.Add(CloneObjType.FireNormal); } } } } [MenuItem("SceneTool/SetFloorMessage")] static void SetFloorMessage() { Transform shinei = GameObject.Find("Scene").transform.Find("ShiNei"); CloneGameObjInfo[] infos = shinei.GetComponentsInChildren(); for (int i = 0; i < infos.Length; i++) { if (infos[i].name.ToLower().Contains("floor")) { infos[i].buildNum = infos[i].GetComponentInParent().buildNum; infos[i].floorNum = infos[i].GetComponentInParent().floorNum; infos[i].interlayerNum= infos[i].GetComponentInParent().interlayerNum; } } } [MenuItem("SceneTool/AddFloorSprite")] static void AddFloorSprite() { Transform shinei = GameObject.Find("Scene").transform.Find("ShiNei"); getFloor(shinei); } static Transform getFloor(Transform parent) { CloneableEnums ce = GameObject.Find("CloneEnums").transform.Find("ShiNei").GetComponent(); Transform target = null; for (int i = 0; i < parent.childCount; i++) { if (parent.GetChild(i).childCount > 0) { getFloor(parent.GetChild(i)); } if (parent.GetChild(i).name.ToLower().Contains("floor")) { //Debug.Log(parent.GetChild(i).name); if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } parent.GetChild(i).gameObject.GetComponent().CloneableTypes = ce.CloneableTypes; parent.GetChild(i).gameObject.GetComponent().gameObjType = CloneObjType.StaticGameObject; parent.GetChild(i).gameObject.layer = 30; FloorMessage mess = parent.GetChild(i).gameObject.GetComponentInParent(); parent.GetChild(i).gameObject.GetComponent().buildNum = mess.buildNum; parent.GetChild(i).gameObject.GetComponent().floorNum = mess.floorNum; parent.GetChild(i).gameObject.GetComponent().interlayerNum = mess.interlayerNum; } else { } } return target; } [MenuItem("SceneTool/AddLTSprite")] static void AddLTSprite() { Transform shinei = GameObject.Find("Scene").transform.Find("ShiNei"); getlt(shinei); } static Transform getlt(Transform parent) { CloneableEnums ce = GameObject.Find("CloneEnums").transform.Find("ShiNei").GetComponent(); Transform target = null; for (int i = 0; i < parent.childCount; i++) { if (parent.GetChild(i).childCount > 0) { getlt(parent.GetChild(i)); } if (parent.GetChild(i).name.ToLower().Contains("lt") && parent.GetChild(i).GetComponent()) { if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } parent.GetChild(i).gameObject.GetComponent().CloneableTypes = ce.CloneableTypes; parent.GetChild(i).gameObject.GetComponent().gameObjType = CloneObjType.StaticGameObject; parent.GetChild(i).gameObject.layer = 30; FloorMessage mess = parent.GetChild(i).gameObject.GetComponentInParent(); parent.GetChild(i).gameObject.GetComponent().buildNum = mess.buildNum; parent.GetChild(i).gameObject.GetComponent().floorNum = mess.floorNum; parent.GetChild(i).gameObject.GetComponent().interlayerNum = mess.interlayerNum; } else { } } return target; } [MenuItem("SceneTool/AddFTSprite")] static void AddFTSprite() { Transform shinei = GameObject.Find("Scene").transform.Find("ShiNei"); getft(shinei); } static Transform getft(Transform parent) { CloneableEnums ce = GameObject.Find("CloneEnums").transform.Find("ShiNei").GetComponent(); Transform target = null; for (int i = 0; i < parent.childCount; i++) { if (parent.GetChild(i).childCount > 0) { getft(parent.GetChild(i)); } if ((parent.GetChild(i).name.ToLower().Contains("futi")|| parent.GetChild(i).name.ToLower().Contains("ft")) && parent.GetChild(i).GetComponent()) { // Debug.Log(parent.GetChild(i).name); if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } parent.GetChild(i).gameObject.GetComponent().CloneableTypes = ce.CloneableTypes; parent.GetChild(i).gameObject.GetComponent().gameObjType = CloneObjType.StaticGameObject; parent.GetChild(i).gameObject.layer = 30; FloorMessage mess = parent.GetChild(i).gameObject.GetComponentInParent(); parent.GetChild(i).gameObject.GetComponent().buildNum = mess.buildNum; parent.GetChild(i).gameObject.GetComponent().floorNum = mess.floorNum; parent.GetChild(i).gameObject.GetComponent().interlayerNum = mess.interlayerNum; } else { } } return target; } [MenuItem("SceneTool/SetWall")] static void SetWallSprite() { Transform shinei = GameObject.Find("Scene").transform.Find("ShiNei"); setwall(shinei); } static Transform setwall(Transform parent) { CloneableEnums ce = GameObject.Find("CloneEnums").transform.Find("ShiNei").GetComponent(); Transform target = null; for (int i = 0; i < parent.childCount; i++) { if (parent.GetChild(i).childCount > 0) { setwall(parent.GetChild(i)); } if (parent.GetChild(i).name.ToLower().Contains("wall") && parent.GetChild(i).GetComponent()) { parent.GetChild(i).gameObject.layer = 29; } } return target; } [MenuItem("SceneTool/SetShiNeiXHS")] static void SetShiNeiXHS() { Transform shinei = GameObject.Find("Scene").transform.Find("ShiNei"); setxhs(shinei); } static Transform setxhs(Transform parent) { CloneableEnums ce = GameObject.Find("CloneEnums").transform.Find("xhs").GetComponent(); Transform target = null; for (int i = 0; i < parent.childCount; i++) { if (parent.GetChild(i).childCount > 0) { setxhs(parent.GetChild(i)); } if (parent.GetChild(i).name.ToLower().Contains("xhs") && parent.GetChild(i).GetComponent()) { if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } parent.GetChild(i).GetComponent().WaterReceiverType = WaterType.water; if (!parent.GetChild(i).gameObject.GetComponent()) { parent.GetChild(i).gameObject.AddComponent(); } parent.GetChild(i).GetComponent().CloneableTypes.Clear(); parent.GetChild(i).GetComponent().CloneableTypes.Add(CloneObjType.TwinkleLine); parent.GetChild(i).GetComponent().CloneableTypes.Add(CloneObjType.WaterLine); parent.GetChild(i).GetComponent().gameObjType = CloneObjType.XHS; } } return target; } [MenuItem("SceneTool/SetOilRodeCarCloneEnum")] public static void SetOilRodeCarCloneEnum() { CloneableEnums ce = GameObject.Find("CloneEnums").transform.Find("OilCarRode").GetComponent(); CloneableEnums[] allenums = GameObject.Find("SceneAll").GetComponentsInChildren(true); for (int i = 0; i < allenums.Length; i++) { if (!allenums[i].GetComponent()) { if (!allenums[i].GetComponent()) { if (!allenums[i].GetComponent()) { allenums[i].GetComponent().CloneableTypes = ce.CloneableTypes; } } } } } [MenuItem("SceneTool/SetOilRodeManCloneEnum")] public static void SetOilRodeManCloneEnum() { CloneableEnums ce = GameObject.Find("CloneEnums").transform.Find("OilManRode").GetComponent(); CloneableEnums[] allenums = GameObject.Find("SceneAll").GetComponentsInChildren(true); for (int i = 0; i < allenums.Length; i++) { if (allenums[i].GetComponent()) { if (!allenums[i].GetComponent()) { if (!allenums[i].GetComponent()) { allenums[i].GetComponent().CloneableTypes = ce.CloneableTypes; } } } } } [MenuItem("SceneTool/SetOilWallCloneEnum")] public static void SetOilWallCloneEnum() { CloneableEnums ce = GameObject.Find("CloneEnums").transform.Find("OilWall").GetComponent(); CloneableEnums[] allenums = GameObject.Find("SceneAll").GetComponentsInChildren(true); for (int i = 0; i < allenums.Length; i++) { if (allenums[i].GetComponent()) { if (!allenums[i].GetComponent()) { allenums[i].GetComponent().CloneableTypes = ce.CloneableTypes; } } } } //[MenuItem("SceneTool/RemoveNone")] //public static void ReMoveNone() //{ // CloneableEnums ce = GameObject.Find("CloneEnums").transform.Find("OilManRode").GetComponent(); // for (int i = 0; i < ce.CloneableTypes.Count; i++) // { // if (ce.CloneableTypes[i]==CloneObjType.None) // { // ce.CloneableTypes.Remove(ce.CloneableTypes[i]); // } // } //} [MenuItem("CloneTypeEditor/AddNewTrucksToolsCloneable")] static void AddNewTrucksToolsCloneable() { Transform[] obj = Selection.GetTransforms(SelectionMode.Deep); for (int i = 0; i < obj.Length; i++) { var cloneableEnums = obj[i].GetComponent(); if (cloneableEnums != null) { var cloneableTypes = cloneableEnums.CloneableTypes; if (cloneableTypes != null && cloneableTypes.Contains(CloneObjType.WaterTanker)) { AddType(cloneableTypes, CloneObjType.RemoteWaterSupplyTruck); AddType(cloneableTypes, CloneObjType.DecontaminationTruck); AddType(cloneableTypes, CloneObjType.LiquidSupplyTruck); AddType(cloneableTypes, CloneObjType.FoodSecurityTruck); AddType(cloneableTypes, CloneObjType.EquipmentTransportTruck); AddType(cloneableTypes, CloneObjType.EquipmentRepairTruck); AddType(cloneableTypes, CloneObjType.MedicalSupportTruck); AddType(cloneableTypes, CloneObjType.DryPowderFireTruck); AddType(cloneableTypes, CloneObjType.TrafficPoliceCar); AddType(cloneableTypes, CloneObjType.EnvironmentalCar); AddType(cloneableTypes, CloneObjType.WeatherBureauCar); AddType(cloneableTypes, CloneObjType.PowerSupplyCar); } } } } private static void AddType(List cloneableTypes, CloneObjType type) { if (!cloneableTypes.Contains(type)) { cloneableTypes.Add(type); } } [MenuItem("CloneTypeEditor/SetCloneNei")] //给罐区地面设置克隆类型,方法:选中整个场景后设置 public static void SetCloneNei() { List CloneableTypes = new List(); for (int i = (int)CloneObjType.WarningLine; i <= (int)CloneObjType.FireMan; i++) { if ((CloneObjType)i != CloneObjType.Splash && (CloneObjType)i != CloneObjType.Boilover)//&& //(CloneObjType)i != CloneObjType.FireInside&& //(CloneObjType)i != CloneObjType.SmokeInside) CloneableTypes.Add((CloneObjType)i); } List CloneableTypesXHS = new List(); CloneableTypesXHS.Add(CloneObjType.WaterLine); CloneableTypesXHS.Add(CloneObjType.TwinkleLine); Transform[] obj = Selection.GetTransforms(SelectionMode.Deep); for (int i = 0; i < obj.Length; i++) { if (obj[i].gameObject.name.ToUpper().Contains("-FLOOR") || obj[i].gameObject.name.ToUpper().Contains("_FLOOR")) { Debug.Log(obj[i].gameObject.name); if (!obj[i].gameObject.GetComponent()) { obj[i].gameObject.AddComponent(); } var cloneableEnums = obj[i].GetComponent(); cloneableEnums.CloneableTypes = CloneableTypes; if (!obj[i].gameObject.GetComponent()) { obj[i].gameObject.AddComponent(); } if (!obj[i].gameObject.GetComponent()) { obj[i].gameObject.AddComponent(); } if (!obj[i].gameObject.GetComponent()) { obj[i].gameObject.AddComponent(); } obj[i].gameObject.layer = LayerMask.NameToLayer("ShiNei"); CloneGameObjInfo info = obj[i].gameObject.GetComponent(); info.buildNum = obj[i].parent.GetComponent().buildNum; info.floorNum = obj[i].parent.GetComponent().floorNum; info.interlayerNum = obj[i].parent.GetComponent().interlayerNum; } //if (obj[i].gameObject.name.ToUpper().Contains("LT") && obj[i].childCount == 0 // && obj[i].gameObject.name.ToUpper().IndexOf("LT") == 0) //{ // Debug.Log(obj[i].gameObject.name); // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // CloneGameObjInfo info = obj[i].gameObject.GetComponent(); // info.buildNum = obj[i].parent.parent.GetComponent().buildNum; // info.floorNum = obj[i].parent.parent.GetComponent().floorNum; // info.interlayerNum = obj[i].parent.parent.GetComponent().interlayerNum; // obj[i].gameObject.layer = LayerMask.NameToLayer("ShiNei"); //} //if (obj[i].gameObject.name.ToUpper().Contains("XHS") && obj[i].childCount == 0) //{ // Debug.Log(obj[i].gameObject.name); // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // if (!obj[i].gameObject.GetComponent()) // { // obj[i].gameObject.AddComponent(); // } // CloneGameObjInfo info = obj[i].gameObject.GetComponent(); // if (obj[i].parent.parent.GetComponent()) // { // info.buildNum = obj[i].parent.parent.GetComponent().buildNum; // info.floorNum = obj[i].parent.parent.GetComponent().floorNum; // info.interlayerNum = obj[i].parent.parent.GetComponent().interlayerNum; // } // info.gameObjType = CloneObjType.XHS; // obj[i].gameObject.GetComponent().WaterReceiverType = WaterType.water; // var cloneableEnums = obj[i].GetComponent(); // cloneableEnums.CloneableTypes = CloneableTypesXHS; //} } } }