void RegisterAllChildPrefab() { var childCount = transform.childCount; var pip = new List <PrefabInPrefab> (GetComponents <PrefabInPrefab> ()); for (int i = 0; i < childCount; i++) { var child = transform.GetChild(i); var type = PrefabUtility.GetPrefabType(child); if (type == PrefabType.PrefabInstance) { var root = (Transform)PrefabUtility.GetPrefabParent(child); if (pip.Find((item) => item.prefab == root.gameObject) == null) { var prefabInPrefab = gameObject.AddComponent <PrefabInPrefab> (); prefabInPrefab.prefab = root.gameObject; var prefabItem = new PrefabItem() { prefabInPrefab = prefabInPrefab, instancedObject = child.gameObject, }; registerPrefabList.Add(prefabItem); } } } }
private void BuildAssetLists() { itemPrefabs = new List <PrefabItem>(); string[] itemPrefabPaths = Directory.GetFiles((@"Assets\Prefabs\Items\").Replace(@"\", Path.AltDirectorySeparatorChar.ToString()), "*.prefab"); foreach (string objectPath in itemPrefabPaths) // Build list of item prefabs { PrefabItem newItemObject = new PrefabItem(); newItemObject.prefab = ( GameObject )AssetDatabase.LoadAssetAtPath(objectPath, typeof(GameObject)); newItemObject.itemName = newItemObject.prefab.name.Replace("_", "\n"); newItemObject.parent = "items"; itemPrefabs.Add(newItemObject); } levelPrefabs = new List <PrefabItem>(); string[] levelPrefabPaths = Directory.GetFiles((@"Assets\Prefabs\Level\").Replace(@"\", Path.AltDirectorySeparatorChar.ToString()), "*.prefab"); foreach (string objectPath in levelPrefabPaths) // Build list of level prefabs { PrefabItem newLevelObject = new PrefabItem(); newLevelObject.prefab = ( GameObject )AssetDatabase.LoadAssetAtPath(objectPath, typeof(GameObject)); newLevelObject.itemName = newLevelObject.prefab.name.Replace("_", "\n"); newLevelObject.parent = "level"; levelPrefabs.Add(newLevelObject); } }
public void CreatPrefab() { #region cloths EditorUtility.DisplayProgressBar(sex.ToString(), "clothes resources are dealing...", 1 / 7f); IEditorCloth cloths = EditorClothFactory.Creat(sex, restype); cloths.CreatPrefab(); #endregion #region race EditorUtility.DisplayProgressBar(sex.ToString(), "create race...", 2 / 7f); TPoseEditor pose = TPoseEditorFactory.Creat(sex, obj, restype); RaceData rd = pose.CreatTPose(); #endregion #region animator EditorUtility.DisplayProgressBar(sex.ToString(), "animations resources are dealing...", 3 / 7f); IEditorAnimation anim = EditorAnimationFactory.Creat(sex, restype); RuntimeAnimatorController controller = anim.Creat(); #endregion #region base EditorUtility.DisplayProgressBar(sex.ToString(), "body parts resources are dealing...", 5 / 7f); List <SlotOverlayItem> sos = new List <SlotOverlayItem>(); SlotOverlayItem eyeItem = new SlotOverlayItem(); BaseClothItemEditor eyes = new EyesEditor(obj, restype); SlotDataAsset eyes_slot = eyes.CreatSlot(); OverlayDataAsset eyes_overlay = eyes.CreatOverlay(); eyeItem.slot = eyes_slot; eyeItem.overlay = eyes_overlay; eyeItem.partIndex = eyes.WearPos; SlotOverlayItem faceItem = new SlotOverlayItem(); BaseClothItemEditor face = new FaceEditor(obj, restype); SlotDataAsset face_slot = face.CreatSlot(); OverlayDataAsset face_overlay = face.CreatOverlay(); faceItem.slot = face_slot; faceItem.overlay = face_overlay; faceItem.partIndex = face.WearPos; sos.Add(eyeItem); sos.Add(faceItem); #endregion #region CharacterPlayer EditorUtility.DisplayProgressBar(sex.ToString(), "create character...", 7 / 7f); Dictionary <string, object> dic = new Dictionary <string, object>(); dic["animatorController"] = controller; dic["race"] = rd; dic["sos"] = sos; string assetpath = string.Format("{0}/{1}.prefab", prefabFold, obj.Name); IPrefabItem prefab = new PrefabItem(assetpath); prefab.CreatPrefab(null, CreatPrefabFinish, dic); #endregion }
private void DrawPrefabButton(Rect btnPos, PrefabItem prefabItem) { if (GUI.Button(btnPos, new GUIContent(prefabItem.icon))) { GameObject itemParent = GameObject.Find("/" + prefabItem.parent); GameObject go = (GameObject)PrefabUtility.InstantiatePrefab(prefabItem.prefab); if (itemParent == null) // Instantiate new parent object if none was found in the scene. { itemParent = new GameObject(prefabItem.parent); } Vector3 itemPos = Vector3.zero; go.transform.parent = itemParent.transform; if (Selection.gameObjects.Length > 0) // Spawn the new object at the position of the selected object if there is one. { itemPos = Selection.gameObjects[0].transform.position; } go.transform.position = itemPos; Selection.objects = new Object[] { go }; // Select the newly created object. } GUI.Label(btnPos, new GUIContent(prefabItem.itemName)); }
static void ClickToAddPattern() { GameObject PatternObj = GameObject.Find("PatternManager"); if (PatternObj != null) { Patternmanager patternmanager = PatternObj.GetComponent <Patternmanager>(); if (Selection.gameObjects.Length == 1) { Transform currenChild = Selection.gameObjects[0].transform.Find("Root"); if (currenChild != null) { Pattern pattern = new Pattern(); foreach (Transform child in currenChild) { var prefab = UnityEditor.PrefabUtility.GetPrefabParent(child.gameObject); if (prefab != null) { PrefabItem prefabItem = new PrefabItem { name = prefab.name, pos = child.localPosition }; pattern.ItemList.Add(prefabItem); } } patternmanager.PatternList.Add(pattern); } } } }
static void SaveToText(string name, bool isActive) { var prefabInfo = new PrefabItem(name, isActive); var jsonText = JsonUtility.ToJson(prefabInfo); sb.AppendLine(jsonText + ","); // Debug.Log ("jsonText:" + jsonText); }
void AddItem() { PrefabItem newItem = new PrefabItem(); newItem.name = "New Item"; list.itemList.Add(newItem); viewIndex = list.itemList.Count; }
private void InitPoolOfType(PrefabItem prefabItem, Transform parent) { PoolObject instantiatedPoolObject; List <PoolObject> instantiatedPoolObjects = new List <PoolObject>(); for (int i = 0; i < prefabItem.poolSize; i++) { instantiatedPoolObject = GameObject.Instantiate(prefabItem.poolItem, parent).GetComponent <PoolObject>(); instantiatedPoolObject.ObjectType = prefabItem.poolType; instantiatedPoolObject.ReleasePoolObject(); instantiatedPoolObjects.Add(instantiatedPoolObject); } pools.Add(prefabItem.poolType, new Pool(instantiatedPoolObjects)); }
private void AddPrefabToItems(List <PrefabItem> collection, GameObject objectToInclude) { bool updated = false; foreach (PrefabItem o in collection) { if (objectToInclude == o.prefab) { updated = true; o.count++; break; } } if (!updated) { PrefabItem other = new PrefabItem(objectToInclude, 1); collection.Add(other); } }
void Update() { if (viewingMode == ViewingMode.Interior) { for (int i = 0; i < wallFaces.Count; i++) { if (!wallFaces[i].IsFacingCamera || wallFaces[i].WallFaceType == WallFaceType.Outer) { wallFaces[i].Wireframe = true; wallFaces[i].Solid = false; for (int j = 0; j < wallFaces[i].RelatedLine.Doors.Count; j++) { wallFaces [i].RelatedLine.Doors [j].Door.SetActive(false); } for (int j = 0; j < wallFaces[i].RelatedLine.Windows.Count; j++) { wallFaces [i].RelatedLine.Windows [j].Window.SetActive(false); } wallFaces [i].gameObject.GetComponent <Collider> ().enabled = false; } else { wallFaces[i].Wireframe = false; wallFaces[i].Solid = true; for (int j = 0; j < wallFaces[i].RelatedLine.Doors.Count; j++) { wallFaces [i].RelatedLine.Doors [j].Door.SetActive(true); } for (int j = 0; j < wallFaces[i].RelatedLine.Windows.Count; j++) { wallFaces [i].RelatedLine.Windows [j].Window.SetActive(true); } wallFaces [i].gameObject.GetComponent <Collider> ().enabled = true; } } } else { for (int i = 0; i < wallFaces.Count; i++) { wallFaces[i].Wireframe = false; wallFaces[i].Solid = true; for (int j = 0; j < wallFaces[i].RelatedLine.Doors.Count; j++) { wallFaces [i].RelatedLine.Doors [j].Door.SetActive(true); } for (int j = 0; j < wallFaces[i].RelatedLine.Windows.Count; j++) { wallFaces [i].RelatedLine.Windows [j].Window.SetActive(true); } wallFaces [i].gameObject.GetComponent <Collider> ().enabled = true; } } //if (!planningMode) { switch (Mode) { case BuildingEditMode.None: { if (Input.GetMouseButtonUp(0)) { if (SelectedItem == null) { WallFace wallface = getSelectedWallFace(); if (wallface != null) { selectedWallFace = wallface; Mode = BuildingEditMode.WallFaceSelected; } } else { for (int i = 0; i < floorColliders.Count; i++) { floorColliders [i].enabled = true; } if (SelectedItem.itemType == type.Window || SelectedItem.itemType == type.Door) { WallFace wallface = getSelectedWallFace(); if (wallface != null) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, float.MaxValue) && !EventSystem.current.IsPointerOverGameObject()) { Vector2 location; Vector2?correctedLocation; if (wallface.RelatedLine.LocateItemInWall(hit.point, SelectedItem, out location, 100, out correctedLocation)) { if (SelectedItem.itemType == type.Window) { wallface.RelatedLine.Windows.Add(new WallWindow(wallface.RelatedLine, location, SelectedItem.prefabItem.Size.z, SelectedItem.prefabItem.Size.y, Instantiate(SelectedItem.prefabItem.gameObject))); regeneratePath(false); } else if (SelectedItem.itemType == type.Door) { wallface.RelatedLine.Doors.Add(new WallDoor(wallface.RelatedLine, location.x, SelectedItem.prefabItem.Size.z, SelectedItem.prefabItem.Size.y, Instantiate(SelectedItem.prefabItem.gameObject))); regeneratePath(false); } } else if (correctedLocation.HasValue) { if (SelectedItem.itemType == type.Window) { wallface.RelatedLine.Windows.Add(new WallWindow(wallface.RelatedLine, correctedLocation.Value, SelectedItem.prefabItem.Size.z, SelectedItem.prefabItem.Size.y, Instantiate(SelectedItem.prefabItem.gameObject))); regeneratePath(false); } else if (SelectedItem.itemType == type.Door) { wallface.RelatedLine.Doors.Add(new WallDoor(wallface.RelatedLine, correctedLocation.Value.x, SelectedItem.prefabItem.Size.z, SelectedItem.prefabItem.Size.y, Instantiate(SelectedItem.prefabItem.gameObject))); regeneratePath(false); } } } } } else // not window and not door { Vector3 location; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, float.MaxValue) && !EventSystem.current.IsPointerOverGameObject()) { location = hit.point - ray.direction * SelectedItem.prefabItem.Size.z * 0.5f; if (SelectedItem.alignToFloor) { RaycastHit floorHit; if (hit.collider.Raycast(new Ray(location, Vector3.down), out floorHit, float.MaxValue)) { Bounds aabb = new Bounds(floorHit.point + Vector3.up * SelectedItem.prefabItem.Size.y, SelectedItem.prefabItem.Size); Bounds?nAABB = alignToFloor(aabb, 10); if (nAABB.HasValue) { GameObject go = Instantiate(SelectedItem.prefabItem.gameObject); PrefabItem pItem = go.GetComponent <PrefabItem> (); Draggable draggable = go.AddComponent <Draggable> (); draggable.XEnabled = true; draggable.YEnabled = false; draggable.ZEnabled = true; draggable.XSnapDistance = 0; draggable.ZSnapDistance = 0; draggable.Enabled = true; draggable.StartMoving += delegate(GameObject sender, Vector3 oldPosition, Vector3 newPosition) { Bounds _aabb = new Bounds(newPosition + Vector3.up * pItem.Size.y, pItem.Size); Debug.Log("start " + newPosition); Bounds?_nAABB = alignToFloor(_aabb, 10); if (_nAABB != null) { sender.transform.position = newPosition; } }; draggable.Moving += delegate(GameObject sender, Vector3 oldPosition, Vector3 newPosition) { Bounds _aabb = new Bounds(newPosition + Vector3.up * pItem.Size.y, pItem.Size); Bounds?_nAABB = alignToFloor(_aabb, 10); if (_nAABB != null) { sender.transform.position = newPosition; } }; draggable.EndMoving += delegate(GameObject sender, Vector3 oldPosition, Vector3 newPosition) { Bounds _aabb = new Bounds(newPosition + Vector3.up * pItem.Size.y, pItem.Size); Debug.Log("end " + newPosition); Bounds?_nAABB = alignToFloor(_aabb, 10); if (_nAABB != null) { sender.transform.position = newPosition; } }; go.transform.position = nAABB.Value.center; items.Add(go); } } } } } for (int i = 0; i < floorColliders.Count; i++) { floorColliders [i].enabled = false; } } } } break; case BuildingEditMode.WallFaceSelected: { if (Input.GetMouseButtonUp(0) && getSelectedWallFace() != null) { selectedWallFace = null; Mode = BuildingEditMode.None; } } break; case BuildingEditMode.WallFaceMoving: { } break; } if (Input.GetMouseButtonDown(0)) { if (selectedWallFace != null) { cameraTarget = (selectedWallFace.a + selectedWallFace.b) * 0.5f + Vector3.up * selectedWallFace.Height * 0.5f; } if (Time.time - lastClickTime < DoubleClickCatchTime) { gameCamera.TargetObject = cameraTarget; } lastClickTime = Time.time; } } //else { if ((Mode == BuildingEditMode.None || Mode == BuildingEditMode.Drawing) && SelectedItem == null) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Collider coll = GetComponent <MeshCollider>(); RaycastHit hit; snapObject.SetActive(false); if (Physics.Raycast(ray, out hit, float.MaxValue) && hit.collider == coll && !EventSystem.current.IsPointerOverGameObject()) { //if (coll.Raycast (ray, out hit, float.MaxValue)) { if (snapEnabled) { hit.point = snapToGrid(hit.point); // Debug.Log (hit.point); } if (verticesSelected.Count != 0) { for (int i = 0; i < verticesSelected.Count; i++) { if (verticesSelected[i] % 2 == 0) { lines[verticesSelected[i] / 2].a = hit.point; } else { lines[verticesSelected[i] / 2].b = hit.point; } } } if (DraggedLine != null) { DraggedLine.b = hit.point; } snapObject.SetActive(true); snapObject.transform.position = hit.point; if (Input.GetMouseButtonDown(0) && verticesSelected.Count == 0) { if (!pointASelected) { DraggedLine.Enabled = true; //DraggedLine = new Line (hit.point, hit.point, DraggedLineMaterial); pointA = hit.point; DraggedLine.a = hit.point; DraggedLine.b = hit.point; pointASelected = true; } else { Vector3 pointB = hit.point; lines = Line.Split(lines, pointA); lines = Line.Split(lines, pointB); int id1 = lineVertices.IndexOf(pointA); int id2 = lineVertices.IndexOf(pointB); if (id1 == -1) { id1 = lineVertices.Count; lineVertices.Add(pointA); } if (id2 == -1) { id2 = lineVertices.Count; lineVertices.Add(pointB); } lines.Add(new Line(lineVertices, id1, id2, 0.2f, LineMaterial, DefaultInnerWallMaterial, DefaultOuterWallMaterial, DefaultSideMaterial)); lines[lines.Count - 1].Parent = this.transform; pointASelected = false; DraggedLine.Enabled = false; // DraggedLine.Destroy (); // DraggedLine = null; for (int i = 0; i < lines.Count; i++) { lines[i].Enabled = false; } regeneratePath(true); } } else if (Input.GetMouseButtonDown(1) || (Input.GetMouseButton(0) && verticesSelected.Count != 0)) { if (verticesSelected.Count == 0) { for (int i = 0; i < lines.Count; i++) { if (hit.point == lines[i].a) { verticesSelected.Add(i * 2); } if (hit.point == lines[i].b) { verticesSelected.Add(i * 2 + 1); } } } else { verticesSelected.Clear(); } } } } if (Input.GetKeyDown(KeyCode.K)) { // List<Vector3> verts = new List<Vector3> (); // for (int i = 0; i < lines.Count; i++) // { // if (!verts.Contains (lines [i].a)) // verts.Add (lines [i].a); // // if (!verts.Contains (lines [i].b)) // verts.Add (lines [i].b); // } // List<Line> nlines = new List<Line> (); // { // List<Vector3> vvv = new List<Vector3> (); // vvv.Add (new Vector3 (0, 0, 0)); // vvv.Add (new Vector3 (0, 0, -1)); // vvv.Add (new Vector3 (-1, 0, -1)); // vvv.Add (new Vector3 (-1, 0, 0)); // nlines.Add (new Line (vvv, 0, 1, 0.1f, LineMaterial, null, null, null)); // nlines.Add (new Line (vvv, 1, 2, 0.1f, LineMaterial, null, null, null)); // nlines.Add (new Line (vvv, 2, 3, 0.1f, LineMaterial, null, null, null)); // nlines.Add (new Line (vvv, 3, 0, 0.1f, LineMaterial, null, null, null)); // } // // // List<int> triangles; // List<Vector3> vs; // List<Vector2> uvs; // List<Vector3> normals; // // Line.FillCap (nlines, out triangles, out vs, out uvs, out normals); //// // Mesh m = new Mesh (); // m.vertices = vs.ToArray (); // m.uv = uvs.ToArray (); // m.triangles = triangles.ToArray (); // m.normals = normals.ToArray (); // GameObject go = new GameObject ("wal"); // go.AddComponent<MeshFilter> ().mesh = m; // go.AddComponent<UpperWallFace> ().CreateFromLines (nlines); // MeshRenderer mr = go.AddComponent<MeshRenderer> (); // mr.material = LineMaterial; } } }