Object Command 리팩토링 #54
@@ -64,25 +64,6 @@ namespace XED.Asset
|
||||
renderObjectPrefab = Resources.Load<GameObject>("Prefabs/PRF_RenderObject");
|
||||
}
|
||||
|
||||
public void OnRemoveObject(List<CustomAssetRenderObject> objects)
|
||||
{
|
||||
if (objects.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
List<ConnectedAsset> removeList = new List<ConnectedAsset>();
|
||||
List<int> siblingIndex = new List<int>();
|
||||
for (int i = 0; i < objects.Count; i++)
|
||||
{
|
||||
ConnectedAsset searchAsset = connectedAssets.Find((x) => x.renderObject == objects[i]);
|
||||
removeList.Add(searchAsset);
|
||||
siblingIndex.Add(searchAsset.hierarchyItem.GetSiblingIndex());
|
||||
}
|
||||
var command = new RemoveObjectCommand(removeList, siblingIndex, this);
|
||||
EventConnector.instance.GetCanvas<Canvas_Popup>().panel_objectinfo.ResetObjectInfo();
|
||||
CommandInvoker.instance.Invoke(command);
|
||||
}
|
||||
|
||||
public void OnCopyObject(List<CustomAssetRenderObject> objects)
|
||||
{
|
||||
if (objects.Count == 0)
|
||||
@@ -99,8 +80,8 @@ namespace XED.Asset
|
||||
copyList.Add(copyAsset);
|
||||
connectedAssets.Add(copyAsset);
|
||||
}
|
||||
var command = new CopyObjectCommand(copySources, copyList, this);
|
||||
CommandInvoker.instance.Invoke(command);
|
||||
var command = new CopyObjectCommand();
|
||||
|
||||
}
|
||||
|
||||
IEnumerator ChangeSelectedAssetTransform()
|
||||
@@ -197,18 +178,21 @@ namespace XED.Asset
|
||||
selectRenderObject.transform.localScale = new Vector3(asset.scale.x, asset.scale.y, asset.scale.z);
|
||||
OnAssetDropped(item);
|
||||
}
|
||||
|
||||
public void OnRestoreHierarchy(HierarchyItem parentItem, HierarchyItem childItem)
|
||||
{
|
||||
componentScrollView.selectedItems.Add(childItem);
|
||||
componentScrollView.SetToChildItem(childItem, parentItem);
|
||||
componentScrollView.DeselectAll();
|
||||
}
|
||||
|
||||
public void OnDeselectAll()
|
||||
{
|
||||
var canvas_Popup = EventConnector.instance.GetCanvas<Canvas_Popup>();
|
||||
canvas_Popup.panel_objectinfo.gameObject.SetActive(false);
|
||||
componentScrollView.DeselectAll();
|
||||
}
|
||||
|
||||
public void OrderByHierarchy(List<CustomAssetRenderObject> objectsToOrder)
|
||||
{
|
||||
SortedDictionary<int, CustomAssetRenderObject> itemToObject = new SortedDictionary<int, CustomAssetRenderObject>();
|
||||
@@ -220,6 +204,7 @@ namespace XED.Asset
|
||||
}
|
||||
objectsToOrder = itemToObject.Values.ToList();
|
||||
}
|
||||
|
||||
Vector3? GetMousePointOnYPlane(float maxDistance)
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
@@ -234,12 +219,6 @@ namespace XED.Asset
|
||||
return null;
|
||||
}
|
||||
|
||||
internal void ClearObjects()
|
||||
{
|
||||
List<CustomAssetRenderObject> objects = connectedAssets.Select(x => x.renderObject).ToList();
|
||||
OnRemoveObject(objects);
|
||||
}
|
||||
|
||||
internal void OnSelectObjects(string name, List<GameObject> selectedObjects)
|
||||
{
|
||||
var canvas_Popup = EventConnector.instance.GetCanvas<Canvas_Popup>();
|
||||
|
||||
@@ -235,30 +235,11 @@ namespace XED.Util
|
||||
}
|
||||
}
|
||||
}
|
||||
public void RemoveItem()
|
||||
{
|
||||
if (selectedRenderObjects.Count == 0) return;
|
||||
|
||||
ManagerHub.instance.Get<CustomAssetConnector>().OnRemoveObject(selectedRenderObjects);
|
||||
}
|
||||
public void CopyItem()
|
||||
{
|
||||
if (selectedRenderObjects.Count == 0)
|
||||
return;
|
||||
|
||||
ManagerHub.instance.Get<CustomAssetConnector>().OnCopyObject(selectedRenderObjects);
|
||||
}
|
||||
public void SaveItemsToCopy()
|
||||
{
|
||||
copyRenderObjects.Clear();
|
||||
copyRenderObjects.AddRange(selectedRenderObjects);
|
||||
}
|
||||
public void CopySavedItems()
|
||||
{
|
||||
if (copyRenderObjects.Count == 0)
|
||||
return;
|
||||
ManagerHub.instance.Get<CustomAssetConnector>().OnCopyObject(copyRenderObjects);
|
||||
}
|
||||
public void ResetGizmoTargetObjects()
|
||||
{
|
||||
rtgController.SetGizmoTargetObjects(selectedGameObjects);
|
||||
@@ -431,7 +412,7 @@ namespace XED.Util
|
||||
#if UNITY_EDITOR
|
||||
shortcutTable.Add(KeyCode.LeftShift, new Dictionary<KeyCode, Action>());
|
||||
shortcutTable[KeyCode.LeftShift].Add(KeyCode.C, SaveItemsToCopy);
|
||||
shortcutTable[KeyCode.LeftShift].Add(KeyCode.V, CopySavedItems);
|
||||
shortcutTable[KeyCode.LeftShift].Add(KeyCode.V, () => CommandInvoker.instance.Invoke(new CopyObjectCommand()));
|
||||
#else
|
||||
shortcutTable.Add(KeyCode.LeftControl, new Dictionary<KeyCode, Action>());
|
||||
shortcutTable[KeyCode.LeftControl].Add(KeyCode.C, SaveItemsToCopy);
|
||||
|
||||
@@ -30,11 +30,9 @@ namespace XED
|
||||
{
|
||||
var cameraManager = ManagerHub.instance.Get<CameraManager>();
|
||||
|
||||
Vector3 = viewAngle = new Vector3(45, 145, 0);
|
||||
|
||||
Vector3 viewAngle = new Vector3(45, 145, 0);
|
||||
|
||||
Camera.main.transform.rotation = Quaternion.Euler(viewAngle);
|
||||
|
||||
Camera.main.transform.position = target.position;
|
||||
Camera.main.transform.position += -Camera.main.transform.forward * cameraDistance;
|
||||
}
|
||||
|
||||
8
Assets/Scripts/Studio/Command/ObjectCommand.meta
Normal file
8
Assets/Scripts/Studio/Command/ObjectCommand.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0191b75d8fd469042a9f5920e1c54738
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -9,15 +9,12 @@ namespace XED.Command
|
||||
{
|
||||
public class CopyObjectCommand : IReversibleCommand
|
||||
{
|
||||
private List<ConnectedAsset> copySources;
|
||||
private List<ConnectedAsset> copyList;
|
||||
private CustomAssetConnector connector;
|
||||
|
||||
public CopyObjectCommand(List<ConnectedAsset> copySources, List<ConnectedAsset> copyList, CustomAssetConnector connector)
|
||||
public CopyObjectCommand()
|
||||
{
|
||||
this.copySources = copySources;
|
||||
this.copyList = copyList;
|
||||
this.connector = connector;
|
||||
|
||||
}
|
||||
|
||||
public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
|
||||
@@ -29,6 +26,23 @@ namespace XED.Command
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
var renderObjectHandler = ManagerHub.instance.Get<RenderObjectHandler>();
|
||||
connector = ManagerHub.instance.Get<CustomAssetConnector>();
|
||||
|
||||
if (renderObjectHandler.selectedRenderObjects.Count == 0)
|
||||
return;
|
||||
|
||||
List<ConnectedAsset> copySources = new List<ConnectedAsset>();
|
||||
copyList = new List<ConnectedAsset>();
|
||||
for (int i = 0; i < renderObjectHandler.selectedRenderObjects.Count; i++)
|
||||
{
|
||||
ConnectedAsset searchAsset = connector.connectedAssets.Find((x) => x.renderObject == renderObjectHandler.selectedRenderObjects[i]);
|
||||
copySources.Add(searchAsset);
|
||||
ConnectedAsset copyAsset = new ConnectedAsset();
|
||||
copyList.Add(copyAsset);
|
||||
connector.connectedAssets.Add(copyAsset);
|
||||
}
|
||||
|
||||
for (int i = 0; i < copyList.Count; i++)
|
||||
{
|
||||
ConnectedAsset copySource = copySources[i];
|
||||
@@ -0,0 +1,68 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using XED.Asset;
|
||||
using XED.Command;
|
||||
using XED.HierarchyTree;
|
||||
using XED.Manage;
|
||||
using XED.Util;
|
||||
|
||||
namespace XED
|
||||
{
|
||||
public class RemoveAllObjectCommand : IIrreversibleCommand
|
||||
{
|
||||
public RemoveAllObjectCommand()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
|
||||
|
||||
public bool CanExecute()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
var connector = ManagerHub.instance.Get<CustomAssetConnector>();
|
||||
|
||||
List<CustomAssetRenderObject> objects = connector.connectedAssets.Select(x => x.renderObject).ToList();
|
||||
|
||||
if (objects.Count == 0)
|
||||
return;
|
||||
|
||||
List<ConnectedAsset> removeList = new List<ConnectedAsset>();
|
||||
List<int> siblingIndex = new List<int>();
|
||||
|
||||
for (int i = 0; i < objects.Count; i++)
|
||||
{
|
||||
ConnectedAsset searchAsset = connector.connectedAssets.Find((x) => x.renderObject == objects[i]);
|
||||
removeList.Add(searchAsset);
|
||||
siblingIndex.Add(searchAsset.hierarchyItem.GetSiblingIndex());
|
||||
}
|
||||
|
||||
for (int i = 0; i < removeList.Count; i++)
|
||||
{
|
||||
ConnectedAsset connectedAsset = removeList[i];
|
||||
connector.componentScrollView.RemoveItem(connectedAsset.hierarchyItem);
|
||||
connectedAsset.assetData.RemoveTransform(connectedAsset.renderObject.transform);
|
||||
connectedAsset.renderObject.gameObject.SetActive(false);
|
||||
|
||||
List<HierarchyItem> childItems = connectedAsset.hierarchyItem.GetAll(true);
|
||||
for (int k = 0; k < childItems.Count; k++)
|
||||
{
|
||||
ConnectedAsset searchAsset = connector.connectedAssets.Find((x) => x.hierarchyItem == childItems[k]);
|
||||
searchAsset.assetData.RemoveTransform(searchAsset.renderObject.transform);
|
||||
searchAsset.renderObject.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
//connector.onRemoveObjects?.Invoke();
|
||||
ManagerHub.instance.Get<RenderObjectHandler>().DeselectAll();
|
||||
var canvas = EventConnector.instance.GetCanvas<Canvas_Popup>();
|
||||
canvas.panel_objectinfo.ResetObjectInfo();
|
||||
connector.componentScrollView.DeselectAll();
|
||||
EventConnector.instance.GetCanvas<Canvas_Popup>().panel_objectinfo.ResetObjectInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ff4d72d4e977c44881f0d235b93f816
|
||||
@@ -6,22 +6,17 @@ using XED.Util;
|
||||
|
||||
namespace XED.Command
|
||||
{
|
||||
public class RemoveObjectCommand : IReversibleCommand
|
||||
public class RemoveSelectObjectCommand : IReversibleCommand
|
||||
{
|
||||
private List<ConnectedAsset> removeList;
|
||||
private List<int> siblingIndex;
|
||||
private List<ConnectedAsset> removeList = new List<ConnectedAsset>();
|
||||
private List<int> siblingIndex = new List<int>();
|
||||
private CustomAssetConnector connector;
|
||||
|
||||
public RemoveObjectCommand(
|
||||
List<ConnectedAsset> removeList,
|
||||
List<int> siblingIndex,
|
||||
CustomAssetConnector connector
|
||||
)
|
||||
public RemoveSelectObjectCommand()
|
||||
{
|
||||
this.removeList = removeList;
|
||||
this.siblingIndex = siblingIndex;
|
||||
this.connector = connector;
|
||||
|
||||
}
|
||||
|
||||
public string id { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
|
||||
|
||||
public bool CanExecute()
|
||||
@@ -31,6 +26,19 @@ namespace XED.Command
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
var renderObjectHandler = ManagerHub.instance.Get<RenderObjectHandler>();
|
||||
connector = ManagerHub.instance.Get<CustomAssetConnector>();
|
||||
|
||||
if (renderObjectHandler.selectedRenderObjects.Count == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < renderObjectHandler.selectedRenderObjects.Count; i++)
|
||||
{
|
||||
ConnectedAsset searchAsset = connector.connectedAssets.Find((x) => x.renderObject == renderObjectHandler.selectedRenderObjects[i]);
|
||||
removeList.Add(searchAsset);
|
||||
siblingIndex.Add(searchAsset.hierarchyItem.GetSiblingIndex());
|
||||
}
|
||||
|
||||
for (int i = 0; i < removeList.Count; i++)
|
||||
{
|
||||
ConnectedAsset connectedAsset = removeList[i];
|
||||
@@ -50,8 +58,8 @@ namespace XED.Command
|
||||
ManagerHub.instance.Get<RenderObjectHandler>().DeselectAll();
|
||||
var canvas = EventConnector.instance.GetCanvas<Canvas_Popup>();
|
||||
canvas.panel_objectinfo.ResetObjectInfo();
|
||||
|
||||
connector.componentScrollView.DeselectAll();
|
||||
EventConnector.instance.GetCanvas<Canvas_Popup>().panel_objectinfo.ResetObjectInfo();
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
@@ -44,7 +44,7 @@ namespace XED.Command
|
||||
if (projectData == null)
|
||||
return;
|
||||
|
||||
connector.ClearObjects();
|
||||
CommandInvoker.instance.Invoke(new RemoveAllObjectCommand());
|
||||
|
||||
foreach (AssetData asset in assets)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace XED.Command
|
||||
projectManager.curProjectPath = string.Empty;
|
||||
projectManager.curProjectData = null;
|
||||
|
||||
connector.ClearObjects();
|
||||
CommandInvoker.instance.Invoke(new RemoveAllObjectCommand());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ namespace XED.UI
|
||||
panel_toolbar.onClickMove += () => CommandInvoker.instance.Invoke(new ActivateMoveGizmoCommand());
|
||||
panel_toolbar.onClickExpand += () => CommandInvoker.instance.Invoke(new ActivateScaleGizmoCommand());
|
||||
panel_toolbar.onClickRotate += () => CommandInvoker.instance.Invoke(new ActivateRotateGizmoCommand());
|
||||
panel_toolbar.onClickRemove += () => CommandInvoker.instance.Invoke(new RemoveObjectCommand());
|
||||
panel_toolbar.onClickCopy += renderObjectHandler.CopyItem;
|
||||
panel_toolbar.onClickRemove += () => CommandInvoker.instance.Invoke(new RemoveSelectObjectCommand());
|
||||
panel_toolbar.onClickCopy += () => CommandInvoker.instance.Invoke(new CopyObjectCommand());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user