/// <summary> /// 部件位置归位 /// </summary> /// <param name="unitGroup"></param> public void UnitPositionToOriginal(UnitGroupT1 unitGroup) { if (groupOperation) { if (Selection.activeGameObject) { for (int i = 0; i < currentGameObjects.Length; i++) { //记录初始位置 currentGameObjects[i].transform.localPosition = position_original[i]; currentGameObjects[i].transform.localRotation = rotation_original[i]; } } } }
/// <summary> /// 部件信息展示 /// </summary> /// <param name="unitGroup"></param> public void ShowUnitPartInfo(UnitGroupT1 unitGroup) { unitName = unitGroup.unitName; unitContent = unitGroup.unitContent; unitColor = unitGroup.unitColor; unitLoadtexture2D = unitGroup.unitLoadtexture2D; unitObservePointCount = unitGroup.pointPositionList.Count; observePointPositionList = unitGroup.pointPositionList; observePointRotationList = unitGroup.pointRotationList; groupOperation = unitGroup.groupOperation; operationToolbarOption = unitGroup.operationToolbarOption; hasGears = unitGroup.hasGears; angle_R = unitGroup.angle_R; axis_R = unitGroup.axis_R; gearCount = unitGroup.gearCount; isUpComplete = unitGroup.isUpComplete; depth = unitGroup.depth; axis_P = unitGroup.axis_P; angle_RP_R = unitGroup.angle_RP_R; axis_RP_R = unitGroup.axis_RP_R; depth_RP_P = unitGroup.depth_RP_P; axis_RP_P = unitGroup.axis_RP_P; //observePointPositionList = unitGroup.observePointPositionList; if (groupOperation) { if (Selection.activeGameObject) { currentGameObjects = Selection.gameObjects; position_original = new Vector3[currentGameObjects.Length]; rotation_original = new Quaternion[currentGameObjects.Length]; for (int i = 0; i < currentGameObjects.Length; i++) { //记录初始位置 position_original[i] = currentGameObjects[i].transform.localPosition; rotation_original[i] = currentGameObjects[i].transform.localRotation; } } } Repaint(); }
/// <summary> /// 添加部件信息 /// </summary> private void OnAddUnitButtonClick() { if (Selection.gameObjects.Length != 0) { bool canAdd = true; foreach (GameObject go in Selection.gameObjects) { if (go.GetComponent <UnitMemberT1>()) { canAdd = false; } } if (canAdd) { GameObject unitLabelGameObject = Instantiate(UnitGameObject, unitParentTransform, UnitParentTransform); UnitGroupT1 unitGroup = unitLabelGameObject.GetComponent <UnitGroupT1>(); List <UnitMemberT1> mems = new List <UnitMemberT1>(); mems.Clear(); foreach (GameObject go in Selection.gameObjects) { mems.Add(go.AddComponent <UnitMemberT1>()); go.AddComponent <MeshCollider>(); } //关于button GameObject button = Instantiate(unitButton); button.transform.parent = GameObject.FindGameObjectWithTag("GameUI_PC_T1").transform.GetChild(1).GetChild(1).GetChild(0).GetChild(0); button.transform.localScale = new Vector3(1, 1, 1); button.transform.GetChild(0).GetComponent <Text>().text = unitName; button.GetComponent <ForUnitButtonT1>().group = unitGroup; unitGroup.SaveUnitGroupValue(unitName, unitContent, unitColor, unitLoadtexture2D, groupOperation, operationToolbarOption, observePointPositionList, observePointRotationList, hasGears, angle_R, axis_R, gearCount, isUpComplete, depth, axis_P, angle_RP_R, axis_RP_R, depth_RP_P, axis_RP_P, mems, button); unitGroup.MemberInfoSave(); gm.unitGroups.Add(unitGroup); if (UnitManagerWindowT1.Instance) { UnitManagerWindowT1.Instance.UpdateWindow(); UnitManagerWindowT1.Instance.selGridInt = -1; UnitManagerWindowT1.Instance.Repaint(); } if (isLockGameObjects) { isLockGameObjects = false; for (int i = 0; i < currentGameObjects.Length; i++) { currentGameObjects[i].transform.localPosition = position_original[i]; currentGameObjects[i].transform.localRotation = rotation_original[i]; } position_original = new Vector3[0]; rotation_original = new Quaternion[0]; } ClearUnitPart(); GUI.FocusControl(""); } else { EditorUtility.DisplayDialog("提示", "存在已编辑的部件", "确定"); } } else { } }