public override void Drop(object[] dragObjects, PointerEventData pointerEventData) { base.Drop(dragObjects, pointerEventData); m_isSpawningPrefab = true; if (CanDrop(dragObjects)) { for (int i = 0; i < dragObjects.Length; ++i) { object dragObject = dragObjects[i]; AssetItem assetItem = dragObject as AssetItem; if (assetItem != null) { m_project.Load(assetItem, (error, obj) => { if (obj is GameObject) { GameObject prefab = (GameObject)obj; bool wasPrefabEnabled = prefab.activeSelf; prefab.SetActive(false); GameObject prefabInstance = Instantiate(prefab, Vector3.zero, Quaternion.identity, ((GameObject)m_treeView.DropTarget).transform); prefab.SetActive(wasPrefabEnabled); ExposeToEditor exposeToEditor = prefabInstance.GetComponent <ExposeToEditor>(); if (exposeToEditor == null) { exposeToEditor = prefabInstance.AddComponent <ExposeToEditor>(); } exposeToEditor.SetName(obj.name); exposeToEditor.Parent = ((GameObject)m_treeView.DropTarget).GetComponent <ExposeToEditor>(); prefabInstance.SetActive(true); RuntimeUndo.BeginRecord(); RuntimeUndo.RecordSelection(); RuntimeUndo.BeginRegisterCreateObject(prefabInstance); RuntimeUndo.EndRecord(); bool isEnabled = RuntimeUndo.Enabled; RuntimeUndo.Enabled = false; RuntimeSelection.activeGameObject = prefabInstance; RuntimeUndo.Enabled = isEnabled; RuntimeUndo.BeginRecord(); RuntimeUndo.RegisterCreatedObject(prefabInstance); RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); m_isSpawningPrefab = false; } }); } } m_treeView.ExternalItemDrop(); } }
protected override void UpdateOverride() { base.UpdateOverride(); if (!RuntimeEditorApplication.IsPointerOverWindow(this)) { return; } if (InputController.GetKeyDown(SelectAllKey)) { if (InputController.GetKey(ModifierKey)) { if (RuntimeEditorApplication.IsActiveWindow(this)) { m_treeView.SelectedItems = m_treeView.Items; } } } if (RuntimeTools.SpawnPrefab == null) { return; } m_treeView.ExternalItemDrag(Input.mousePosition); if (Input.GetMouseButtonUp(0)) { m_isSpawningPrefab = true; GameObject prefabInstance = RuntimeTools.SpawnPrefab.InstantiatePrefab(Vector3.zero, Quaternion.identity); prefabInstance.SetActive(true); ExposeToEditor exposeToEditor = prefabInstance.GetComponent <ExposeToEditor>(); if (exposeToEditor == null) { exposeToEditor = prefabInstance.AddComponent <ExposeToEditor>(); } exposeToEditor.SetName(RuntimeTools.SpawnPrefab.name); RuntimeUndo.BeginRecord(); RuntimeUndo.RecordSelection(); RuntimeUndo.BeginRegisterCreateObject(prefabInstance); RuntimeUndo.EndRecord(); bool isEnabled = RuntimeUndo.Enabled; RuntimeUndo.Enabled = false; RuntimeSelection.activeGameObject = prefabInstance; RuntimeUndo.Enabled = isEnabled; RuntimeUndo.BeginRecord(); RuntimeUndo.RegisterCreatedObject(prefabInstance); RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); RuntimeTools.SpawnPrefab = null; } }
public void Spawn() { m_editor = EditorDemo.Instance; if (m_editor == null) { Debug.LogError("Editor.Instance is null"); return; } Vector3 point; m_dragPlane = new Plane(Vector3.up, m_editor.Pivot); if (GetPointOnDragPlane(out point)) { m_instance = Prefab.InstantiatePrefab(point, Quaternion.identity); enabled = true; m_spawn = true; } else { m_instance = Prefab.InstantiatePrefab(m_editor.Pivot, Quaternion.identity); } ExposeToEditor exposeToEditor = m_instance.GetComponent <ExposeToEditor>(); if (!exposeToEditor) { exposeToEditor = m_instance.AddComponent <ExposeToEditor>(); } exposeToEditor.SetName(Prefab.name); m_instance.SetActive(true); RuntimeUndo.BeginRecord(); RuntimeUndo.RecordSelection(); RuntimeUndo.BeginRegisterCreateObject(m_instance); RuntimeUndo.EndRecord(); bool isEnabled = RuntimeUndo.Enabled; RuntimeUndo.Enabled = false; RuntimeSelection.activeGameObject = m_instance; RuntimeUndo.Enabled = isEnabled; RuntimeUndo.BeginRecord(); RuntimeUndo.RegisterCreatedObject(m_instance); RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); }
public void Duplicate() { Object[] selectedObjects = RuntimeSelection.objects; if (selectedObjects != null && selectedObjects.Length > 0) { RuntimeUndo.BeginRecord(); Object[] duplicates = new Object[selectedObjects.Length]; for (int i = 0; i < duplicates.Length; ++i) { GameObject go = selectedObjects[i] as GameObject; Object duplicate = Instantiate(go, go.transform.position, go.transform.rotation); GameObject duplicateGo = duplicate as GameObject; if (go != null && duplicateGo != null) { duplicateGo.SetActive(true); duplicateGo.SetActive(go.activeSelf); if (go.transform.parent != null) { duplicateGo.transform.SetParent(go.transform.parent, true); } } duplicates[i] = duplicate; RuntimeUndo.BeginRegisterCreateObject(duplicateGo); } RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); bool isEnabled = RuntimeUndo.Enabled; RuntimeUndo.Enabled = false; RuntimeSelection.objects = duplicates; RuntimeUndo.Enabled = isEnabled; RuntimeUndo.BeginRecord(); for (int i = 0; i < duplicates.Length; ++i) { GameObject selectedObj = (GameObject)duplicates[i]; if (selectedObj != null) { RuntimeUndo.RegisterCreatedObject(selectedObj); } } RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); } }
public void Duplicate() { GameObject[] selection = RuntimeSelection.gameObjects; if (selection == null) { return; } RuntimeUndo.BeginRecord(); for (int i = 0; i < selection.Length; ++i) { GameObject selectedObj = selection[i]; if (selectedObj != null) { Transform p = selectedObj.transform.parent; GameObject copy = Instantiate(selectedObj, selectedObj.transform.position, selectedObj.transform.rotation); copy.transform.SetParent(p, true); selection[i] = copy; RuntimeUndo.BeginRegisterCreateObject(copy); } } RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); bool isEnabled = RuntimeUndo.Enabled; RuntimeUndo.Enabled = false; RuntimeSelection.objects = selection; RuntimeUndo.Enabled = isEnabled; RuntimeUndo.BeginRecord(); for (int i = 0; i < selection.Length; ++i) { GameObject selectedObj = selection[i]; if (selectedObj != null) { RuntimeUndo.RegisterCreatedObject(selectedObj); } } RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); }
public void Delete() { GameObject[] selection = RuntimeSelection.gameObjects; if (selection == null || selection.Length == 0) { return; } RuntimeUndo.BeginRecord(); for (int i = 0; i < selection.Length; ++i) { GameObject selectedObj = selection[i]; if (selectedObj != null) { RuntimeUndo.BeginDestroyObject(selectedObj); } } RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); bool isEnabled = RuntimeUndo.Enabled; RuntimeUndo.Enabled = false; RuntimeSelection.objects = null; RuntimeUndo.Enabled = isEnabled; RuntimeUndo.BeginRecord(); for (int i = 0; i < selection.Length; ++i) { GameObject selectedObj = selection[i]; if (selectedObj != null) { RuntimeUndo.DestroyObject(selectedObj); } } RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); }
public void CompleteSpawn() { if (RuntimeEditorApplication.IsPointerOverWindow(RuntimeWindowType.SceneView)) { if (m_resource is Material) { Material material = (Material)m_resource; Camera sceneCamera = RuntimeEditorApplication.ActiveSceneCamera; if (sceneCamera) { Ray ray = sceneCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { MeshRenderer renderer = hitInfo.collider.GetComponentInChildren <MeshRenderer>(); SkinnedMeshRenderer sRenderer = hitInfo.collider.GetComponentInChildren <SkinnedMeshRenderer>(); if (renderer != null || sRenderer != null) { RuntimeUndo.BeginRecord(); } if (renderer != null) { RuntimeUndo.RecordValue(renderer, Strong.PropertyInfo((MeshRenderer x) => x.sharedMaterials)); Material[] materials = renderer.sharedMaterials; for (int i = 0; i < materials.Length; ++i) { materials[i] = material; } renderer.sharedMaterials = materials; } if (sRenderer != null) { RuntimeUndo.RecordValue(sRenderer, Strong.PropertyInfo((SkinnedMeshRenderer x) => x.sharedMaterials)); Material[] materials = sRenderer.sharedMaterials; for (int i = 0; i < materials.Length; ++i) { materials[i] = material; } sRenderer.sharedMaterials = materials; } if (renderer != null || sRenderer != null) { RuntimeUndo.EndRecord(); } if (renderer != null || sRenderer != null) { RuntimeUndo.BeginRecord(); } if (renderer != null) { RuntimeUndo.RecordValue(renderer, Strong.PropertyInfo((MeshRenderer x) => x.sharedMaterials)); } if (sRenderer != null) { RuntimeUndo.RecordValue(sRenderer, Strong.PropertyInfo((SkinnedMeshRenderer x) => x.sharedMaterials)); } if (renderer != null || sRenderer != null) { RuntimeUndo.EndRecord(); } } } } else { if (m_state == State.AfterSpawn) { bool isEnabled = RuntimeUndo.Enabled; RuntimeUndo.Enabled = false; RuntimeSelection.objects = m_selection; RuntimeUndo.Enabled = isEnabled; RuntimeUndo.BeginRecord(); RuntimeUndo.RecordSelection(); RuntimeUndo.BeginRegisterCreateObject(m_instance); RuntimeUndo.EndRecord(); RuntimeUndo.Enabled = false; RuntimeSelection.activeGameObject = m_instance; RuntimeUndo.Enabled = isEnabled; RuntimeUndo.BeginRecord(); RuntimeUndo.RegisterCreatedObject(m_instance); RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); } } EndSpawn(); RuntimeEditorApplication.ActivateWindow(RuntimeWindowType.SceneView); } else { if (!RuntimeEditorApplication.IsPointerOverWindow(RuntimeWindowType.Hierarchy)) { EndSpawn(); } } }