Skip to content

Commit a6f8311

Browse files
committed
ObjectDivider added
1 parent c0f2b36 commit a6f8311

File tree

11 files changed

+6139
-3
lines changed

11 files changed

+6139
-3
lines changed

EditorExpanded/Editor/Tools/CubeToPlanes/CubeToPlaneAction.cs

Lines changed: 288 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#pragma warning disable IDE1006
2+
using LevelEditorActions;
3+
using LevelEditorTools;
4+
using System.Collections.Generic;
5+
using UnityEngine;
6+
7+
namespace EditorExpanded.Editor.Tools
8+
{
9+
[EditorTool, KeyboardShortcut("SHIFT+P")]
10+
public class CubeToPlaneTool : InstantTool
11+
{
12+
internal static ToolInfo info_ => new ToolInfo("Cube to planes", "Turns cubes into planes.", ToolCategory.Edit, ToolButtonState.Button, true, 1427);
13+
public override ToolInfo Info_ => info_;
14+
15+
// Required by distance itself
16+
public static void Register()
17+
{
18+
if (!G.Sys.LevelEditor_.registeredToolsNamesToTypes_.ContainsKey(info_.Name_))
19+
G.Sys.LevelEditor_.RegisterTool(info_);
20+
}
21+
22+
public override bool Run()
23+
{
24+
25+
List<GameObject> trackNodeObjects = G.Sys.LevelEditor_.SelectedNonTrackNodeObjects_;
26+
List<GameObject> cubeObjects = new List<GameObject>();
27+
bool canPlanerizeAny = false;
28+
int cubeCount = 0;
29+
foreach (GameObject gameObject in trackNodeObjects)
30+
{
31+
if (gameObject.name.Equals("CubeGS"))
32+
{
33+
canPlanerizeAny = true;
34+
cubeCount++;
35+
cubeObjects.Add(gameObject);
36+
}
37+
}
38+
if (canPlanerizeAny)
39+
{
40+
//CubeToPlaneAction action = new CubeToPlaneAction(cubeObjects.ToArray());
41+
//Mod.Logger.Info("QUAT: "+ cubeObjects.ToArray()[0].GetComponent<Transform>().localRotation);
42+
CubeToPlaneAction action = new CubeToPlaneAction(cubeObjects.ToArray());
43+
action.TurnCubeIntoPlanes();
44+
action.FinishAndAddToLevelEditorActions();
45+
LevelEditorTool.PrintFormattedCountMessage("{0} object{1} were Planerized.", cubeCount);
46+
}
47+
else
48+
{
49+
LevelEditorTool.PrintErrorMessage("No Objects Were Planerized");
50+
}
51+
52+
return true;
53+
}
54+
}
55+
}

EditorExpanded/Editor/Tools/ObjHelper.cs

Lines changed: 580 additions & 0 deletions
Large diffs are not rendered by default.

EditorExpanded/Editor/Tools/ObjectDivide/DivideAction.cs

Lines changed: 1586 additions & 0 deletions
Large diffs are not rendered by default.

EditorExpanded/Editor/Tools/ObjectDivide/DividerTool.cs

Lines changed: 3460 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using LevelEditorActions;
2+
using Serializers;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
namespace EditorExpanded.Editor.Tools
7+
{
8+
class MergeAction : SimplerAction
9+
{
10+
private ReferenceMap.Handle<GameObject> originalObjectHandle_;
11+
private ReferenceMap.Handle<GameObject> newObjectHandle_;
12+
private byte[] deletedObjectBytes_;
13+
private GroupAction groupAction_;
14+
15+
private bool nothingtodo = false;
16+
17+
public MergeAction(GameObject[] gameObjects)
18+
{
19+
ReferenceMap referenceMap = G.Sys.LevelEditor_.ReferenceMap_;
20+
21+
if (gameObjects.Length > 0)
22+
{
23+
//Group.InitData data = new Group.InitData(Vector3.zero, Quaternion.identity, Vector3.one, new Bounds());
24+
//this.groupAction_ = new GroupAction(gameObjects.ToArray(), data);
25+
this.groupAction_ = Group.CreateGroupAction(gameObjects.ToArray(), gameObjects.ToArray()[0]);
26+
Group group = this.groupAction_.GroupObjects();
27+
this.originalObjectHandle_ = referenceMap.GetHandle<GameObject>(group.gameObject);
28+
this.deletedObjectBytes_ = BinarySerializer.SaveGameObjectToBytes(group.gameObject, Resource.LoadPrefab("Group"), true);
29+
this.groupAction_.Undo();
30+
}
31+
else
32+
{
33+
nothingtodo = true;
34+
}
35+
36+
newObjectHandle_ = new ReferenceMap.Handle<GameObject>();
37+
38+
}
39+
public override string Description_ => "Merges objects.";
40+
41+
public override void Undo() => this.UnMergeObjects();
42+
43+
public override void Redo() => this.MergeObjects();
44+
45+
public void MergeObjects()
46+
{
47+
if (!nothingtodo)
48+
{
49+
50+
Group objectGroup = groupAction_.GroupObjects();
51+
GameObject groupObject = objectGroup.gameObject;
52+
53+
Vector3 groupPosition = groupObject.GetComponent<Transform>().localPosition;
54+
Quaternion groupRotation = groupObject.GetComponent<Transform>().localRotation;
55+
Vector3 groupSize = objectGroup.localBounds_.size;
56+
57+
GameObject[] originalobjs = groupAction_.UngroupObjects();
58+
LevelEditor levelEditor = G.Sys.LevelEditor_;
59+
60+
groupAction_.GroupObjects();
61+
levelEditor.DeleteGameObject(this.originalObjectHandle_.Get());
62+
List<LevelLayer> layersOfObjects = new List<LevelLayer>();
63+
LevelLayer origobjlayer = levelEditor.WorkingLevel_.GetLayerOfObject(originalobjs[0]);
64+
GameObject mergeObject = DuplicateObjectsAction.Duplicate(originalobjs[0]);
65+
levelEditor.AddGameObject(ref newObjectHandle_, mergeObject, origobjlayer);
66+
Vector3 mergeObjectPos = mergeObject.GetComponent<Transform>().position;
67+
Quaternion mergeObjectRot = mergeObject.GetComponent<Transform>().rotation;
68+
Vector3 mergeObjectScl = mergeObject.GetComponent<Transform>().localScale;
69+
//mergeObject.GetComponent<Transform>().rotation = Quaternion.identity;
70+
GroupAction groupAction_2 = Group.CreateGroupAction(new GameObject[] { mergeObject }, mergeObject);
71+
Group group = groupAction_2.GroupObjects();
72+
GameObject mergeObjectGroup = group.gameObject;
73+
mergeObjectGroup.GetComponent<Transform>().localRotation = mergeObjectRot;
74+
mergeObjectGroup.GetChild(0).GetComponent<Transform>().position = mergeObjectPos;
75+
mergeObjectGroup.GetChild(0).GetComponent<Transform>().rotation = mergeObjectRot;
76+
group.localBounds_ = Group.CalculateBoundsFromImmediateChildren(group);
77+
//Vector3 objsize = group.localBounds_.size;
78+
79+
Vector3 mergeObjectSize = group.localBounds_.size;
80+
81+
Vector3 newMergeObjectScale = new Vector3(groupSize.x / mergeObjectSize.x, groupSize.y / mergeObjectSize.y, groupSize.z / mergeObjectSize.z);
82+
83+
mergeObjectGroup.GetComponent<Transform>().localPosition = groupPosition;
84+
mergeObjectGroup.GetComponent<Transform>().localRotation = groupRotation;
85+
mergeObjectGroup.GetComponent<Transform>().localScale = newMergeObjectScale;
86+
87+
groupAction_2.UngroupObjects();
88+
}
89+
}
90+
public void UnMergeObjects()
91+
{
92+
if (!nothingtodo)
93+
{
94+
G.Sys.LevelEditor_.DeleteGameObject(this.newObjectHandle_.Get());
95+
96+
LevelEditor levelEditor = G.Sys.LevelEditor_;
97+
98+
GameObject newObj = Deserializer.LoadGameObjectFromBytes<BinaryDeserializer>(this.deletedObjectBytes_, levelEditor.ReferenceMap_.GetIDToObjectMap());
99+
if ((UnityEngine.Object)newObj == (UnityEngine.Object)null)
100+
{
101+
Debug.LogError((object)"Error loading deleted object");
102+
}
103+
else
104+
{
105+
levelEditor.AddGameObject(ref this.originalObjectHandle_, newObj, (LevelLayer)null);
106+
G.Sys.LevelEditor_.SelectObject(newObj);
107+
if (this.groupAction_ == null)
108+
return;
109+
this.groupAction_.groupObjectHandle_ = this.originalObjectHandle_;
110+
this.groupAction_.UngroupObjects();
111+
}
112+
}
113+
}
114+
115+
}
116+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma warning disable IDE1006
2+
using LevelEditorActions;
3+
using LevelEditorTools;
4+
using System.Collections.Generic;
5+
using UnityEngine;
6+
7+
namespace EditorExpanded.Editor.Tools
8+
{
9+
[EditorTool, KeyboardShortcut("SHIFT+K")]
10+
public class MergeTool : InstantTool
11+
{
12+
internal static ToolInfo info_ => new ToolInfo("Merge", "Merges objects. More accurately, it scales, rotates, and positions the first object you select to the same size, rotation, and position of the group bounds that would exist if you grouped the selected objects.", ToolCategory.Edit, ToolButtonState.Button, true, 1428);
13+
public override ToolInfo Info_ => info_;
14+
15+
// Required by distance itself
16+
public static void Register()
17+
{
18+
if (!G.Sys.LevelEditor_.registeredToolsNamesToTypes_.ContainsKey(info_.Name_))
19+
G.Sys.LevelEditor_.RegisterTool(info_);
20+
}
21+
22+
public override bool Run()
23+
{
24+
25+
List<GameObject> trackNodeObjects = G.Sys.LevelEditor_.SelectedNonTrackNodeObjects_;
26+
27+
if (trackNodeObjects.Count > 0)
28+
{
29+
//CubeToPlaneAction action = new CubeToPlaneAction(cubeObjects.ToArray());
30+
//Mod.Logger.Info("QUAT: "+ cubeObjects.ToArray()[0].GetComponent<Transform>().localRotation);
31+
MergeAction action = new MergeAction(trackNodeObjects.ToArray());
32+
action.MergeObjects();
33+
action.FinishAndAddToLevelEditorActions();
34+
LevelEditorTool.PrintFormattedCountMessage("{0} object{1} were Merged.", trackNodeObjects.Count);
35+
}
36+
else
37+
{
38+
LevelEditorTool.PrintErrorMessage("No Objects Were Merged");
39+
}
40+
41+
return true;
42+
}
43+
}
44+
}

EditorExpanded/Editor/Tools/TrackAttachToTrack/TrackToTrackButton.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections.Generic;
55
using UnityEngine;
66

7-
namespace EditorExpanded.Editor.Tools.TrackAttachToTrack
7+
namespace EditorExpanded.Editor.Tools
88
{
99
[EditorTool, KeyboardShortcut("CTRL+SHIFT+A")]
1010
public class TrackAttachToTrackTool : InstantTool

EditorExpanded/Editor/Tools/TrackAttachToTrack/TrackToTrackButtonS.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections.Generic;
55
using UnityEngine;
66

7-
namespace EditorExpanded.Editor.Tools.TrackAttachToTrack
7+
namespace EditorExpanded.Editor.Tools
88
{
99
[EditorTool, KeyboardShortcut("SHIFT+ALT+A")]
1010
public class TrackAttachToTrackToolS : InstantTool

EditorExpanded/EditorExpanded.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
<ItemGroup>
5858
<Compile Include="EditorTools.cs" />
5959
<Compile Include="EditorUtil.cs" />
60+
<Compile Include="Editor\Tools\CubeToPlanes\CubeToPlaneAction.cs" />
61+
<Compile Include="Editor\Tools\CubeToPlanes\CubeToPlaneTool.cs" />
62+
<Compile Include="Editor\Tools\ObjectDivide\DivideAction.cs" />
63+
<Compile Include="Editor\Tools\ObjectDivide\DividerTool.cs" />
64+
<Compile Include="Editor\Tools\ObjectMerge\MergeAction.cs" />
65+
<Compile Include="Editor\Tools\ObjectMerge\MergeTool.cs" />
66+
<Compile Include="Editor\Tools\ObjHelper.cs" />
6067
<Compile Include="Editor\Tools\Quickselect\Generated\Quickselect.cs">
6168
<AutoGen>True</AutoGen>
6269
<DesignTime>True</DesignTime>

0 commit comments

Comments
 (0)