Przeglądaj źródła

Urho3D Editor: Local offset for Spawn Editor

Vladimir 10 lat temu
rodzic
commit
48e62be7ca

+ 21 - 1
bin/Data/Scripts/Editor/EditorSpawn.as

@@ -1,5 +1,8 @@
 // Urho3D spawn editor
 
+LineEdit@ positionOffsetX;
+LineEdit@ positionOffsetY;
+LineEdit@ positionOffsetZ;
 LineEdit@ randomRotationX;
 LineEdit@ randomRotationY;
 LineEdit@ randomRotationZ;
@@ -10,6 +13,7 @@ LineEdit@ spawnRadiusEdit;
 LineEdit@ spawnCountEdit;
 
 Window@ spawnWindow;
+Vector3 positionOffset = Vector3(0, 0, 0);
 Vector3 randomRotation = Vector3(0, 0, 0);
 float randomScaleMin = 1;
 float randomScaleMax = 1;
@@ -36,6 +40,12 @@ void CreateSpawnEditor()
 
     HideSpawnEditor();
     SubscribeToEvent(spawnWindow.GetChild("CloseButton", true), "Released", "HideSpawnEditor");
+    positionOffsetX = spawnWindow.GetChild("PositionOffset.x", true);
+    positionOffsetY = spawnWindow.GetChild("PositionOffset.y", true);
+    positionOffsetZ = spawnWindow.GetChild("PositionOffset.z", true);
+    positionOffsetX.text = String(positionOffset.x);
+    positionOffsetY.text = String(positionOffset.y);
+    positionOffsetZ.text = String(positionOffset.z);
     randomRotationX = spawnWindow.GetChild("RandomRotation.x", true);
     randomRotationY = spawnWindow.GetChild("RandomRotation.y", true);
     randomRotationZ = spawnWindow.GetChild("RandomRotation.z", true);
@@ -60,6 +70,9 @@ void CreateSpawnEditor()
     spawnRadiusEdit.text = String(spawnRadius);
     spawnCountEdit.text = String(spawnCount);
 
+    SubscribeToEvent(positionOffsetX, "TextChanged", "EditPositionOffset");
+    SubscribeToEvent(positionOffsetY, "TextChanged", "EditPositionOffset");
+    SubscribeToEvent(positionOffsetZ, "TextChanged", "EditPositionOffset");
     SubscribeToEvent(randomRotationX, "TextChanged", "EditRandomRotation");
     SubscribeToEvent(randomRotationY, "TextChanged", "EditRandomRotation");
     SubscribeToEvent(randomRotationZ, "TextChanged", "EditRandomRotation");
@@ -99,6 +112,13 @@ void PickSpawnObject()
     SubscribeToEvent(uiFileSelector, "FileSelected", "PickSpawnObjectDone");
 }
 
+void EditPositionOffset(StringHash eventType, VariantMap& eventData)
+{
+    LineEdit@ edit = eventData["Element"].GetPtr();
+    positionOffset = Vector3(positionOffsetX.text.ToFloat(), positionOffsetY.text.ToFloat(), positionOffsetZ.text.ToFloat());
+    UpdateHierarchyItem(editorScene);
+}
+
 void EditRandomRotation(StringHash eventType, VariantMap& eventData)
 {
     LineEdit@ edit = eventData["Element"].GetPtr();
@@ -229,7 +249,7 @@ void PlaceObject(Vector3 spawnPosition, Vector3 normal)
 
     int number = RandomInt(0, spawnedObjectsNames.length);
     File@ file = cache.GetFile(spawnedObjectsNames[number]);
-    Node@ spawnedObject = InstantiateNodeFromFile(file, spawnPosition, spawnRotation, Random(randomScaleMin, randomScaleMax));
+    Node@ spawnedObject = InstantiateNodeFromFile(file, spawnPosition + (spawnRotation * positionOffset), spawnRotation, Random(randomScaleMin, randomScaleMax));
     if (spawnedObject is null)
     {
         spawnedObjectsNames[number] = spawnedObjectsNames[spawnedObjectsNames.length - 1];

+ 53 - 0
bin/Data/UI/EditorSpawnWindow.xml

@@ -55,6 +55,59 @@
 		</element>
 		<element type="BorderImage" internal="true" style="none">
 			<element internal="true" style="none">
+				<element style="ListRow">
+					<attribute name="Min Size" value="270 17" />
+					<attribute name="Layout Spacing" value="10" />
+					<element type="Text">
+						<attribute name="Top Left Color" value="0.85 0.85 0.85 1" />
+						<attribute name="Top Right Color" value="0.85 0.85 0.85 1" />
+						<attribute name="Bottom Left Color" value="0.85 0.85 0.85 1" />
+						<attribute name="Bottom Right Color" value="0.85 0.85 0.85 1" />
+						<attribute name="Text" value="Local offset" />
+					</element>
+					<element type="LineEdit">
+						<attribute name="Name" value="PositionOffset.x" />
+						<attribute name="Min Size" value="40 0" />
+						<attribute name="Max Size" value="40 2147483647" />
+						<element type="Text" internal="true" style="none">
+							<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+							<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+							<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+							<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+						</element>
+						<element type="BorderImage" internal="true" style="none">
+							<attribute name="Size" value="4 15" />
+						</element>
+					</element>
+					<element type="LineEdit">
+						<attribute name="Name" value="PositionOffset.y" />
+						<attribute name="Min Size" value="40 0" />
+						<attribute name="Max Size" value="40 2147483647" />
+						<element type="Text" internal="true" style="none">
+							<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+							<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+							<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+							<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+						</element>
+						<element type="BorderImage" internal="true" style="none">
+							<attribute name="Size" value="4 15" />
+						</element>
+					</element>
+					<element type="LineEdit">
+						<attribute name="Name" value="PositionOffset.z" />
+						<attribute name="Min Size" value="40 0" />
+						<attribute name="Max Size" value="40 2147483647" />
+						<element type="Text" internal="true" style="none">
+							<attribute name="Top Left Color" value="0.9 1 0.9 1" />
+							<attribute name="Top Right Color" value="0.9 1 0.9 1" />
+							<attribute name="Bottom Left Color" value="0.9 1 0.9 1" />
+							<attribute name="Bottom Right Color" value="0.9 1 0.9 1" />
+						</element>
+						<element type="BorderImage" internal="true" style="none">
+							<attribute name="Size" value="4 15" />
+						</element>
+					</element>
+				</element>
 				<element style="ListRow">
 					<attribute name="Min Size" value="270 17" />
 					<attribute name="Layout Spacing" value="10" />