Last active
March 25, 2019 15:06
-
-
Save eddie-knight/67abdbe9a60bab776d93ee30d1c0545d to your computer and use it in GitHub Desktop.
Revisions
-
Eddie Knight revised this gist
Mar 25, 2019 . 1 changed file with 33 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,9 +16,6 @@ public class CloneGameObject : ScriptableWizard public bool randomizeYRotation; private List<GameObject> allClones; System.Random random = new System.Random(); @@ -30,8 +27,6 @@ static void CloneGameObjectWizard() void OnWizardCreate() { cloneAll(); } @@ -57,35 +52,49 @@ void cloneColumns(int rowCounter, int layerCounter) { for (int columnCounter = 0; columnCounter < xCount; columnCounter++) { // Prepare all values for cloning GameObject objectToClone = setObjectToClone(); Vector3 clonePosition = setTransform(columnCounter, rowCounter, layerCounter); Transform cloneParent = setParent(columnCounter, rowCounter, layerCounter); Quaternion cloneRotation = setRotation(objectToClone); // Clone GameObject newObject = Instantiate(objectToClone, clonePosition, cloneRotation, cloneParent); newObject.name = objectToClone.name + "-" + columnCounter + "-" + rowCounter + "-" + layerCounter; // Move to parent container if object uses randomYRotation parent if (randomizeYRotation) cloneParent.transform.parent = parentObjectForClones.transform; } } GameObject setObjectToClone() { int coinToss = random.Next(2); // if no second object, only use first // if second object provided, check coinToss to select if (secondObjectToClone == null || coinToss == 1) return firstObjectToClone; return secondObjectToClone; } Transform setParent(int columnCounter, int rowCounter, int layerCounter) { if (randomizeYRotation) { // Create a new parent to enable rotation on the center of cloned object GameObject rotationObject = new GameObject("clone-" + columnCounter + "-" + rowCounter + "-" + layerCounter); return rotationObject.transform; } return parentObjectForClones.transform; } Quaternion setRotation(GameObject objectToClone) { // Rotation value should match original object's rotation Quaternion rotation = new Quaternion(); rotation.Set(objectToClone.transform.rotation.x, objectToClone.transform.rotation.y, @@ -97,10 +106,12 @@ Quaternion setRotation() return rotation; } Vector3 setTransform(int columnCounter, int rowCounter, int layerCounter) { Vector3 clonePosition; clonePosition.x = parentObjectForClones.transform.position.x + (XAxisSpacing * columnCounter); clonePosition.y = parentObjectForClones.transform.position.y + (YAxisSpacing * rowCounter); clonePosition.z = parentObjectForClones.transform.position.z + (ZAxisSpacing * layerCounter); return clonePosition; } } -
Eddie Knight revised this gist
Mar 25, 2019 . 1 changed file with 32 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,8 @@ public class CloneGameObject : ScriptableWizard { public GameObject firstObjectToClone; public GameObject secondObjectToClone; public GameObject parentObjectForClones; public int xCount = 1; public int yCount = 1; @@ -16,6 +17,10 @@ public class CloneGameObject : ScriptableWizard private List<GameObject> allClones; private Vector3 clonePosition; private GameObject objectToClone; private GameObject rotationObject; System.Random random = new System.Random(); [MenuItem("Tools/Clone Game Object")] static void CloneGameObjectWizard() @@ -25,6 +30,8 @@ static void CloneGameObjectWizard() void OnWizardCreate() { if(secondObjectToClone == null) secondObjectToClone = firstObjectToClone; cloneAll(); } @@ -50,11 +57,33 @@ void cloneColumns(int rowCounter, int layerCounter) { for (int columnCounter = 0; columnCounter < xCount; columnCounter++) { setObjectToClone(); setTransform(columnCounter, rowCounter, layerCounter); checkRandomRotation(columnCounter, rowCounter, layerCounter); Instantiate(objectToClone, clonePosition, setRotation(), rotationObject.transform); } } void setObjectToClone() { int test = random.Next(2); if (test == 1) objectToClone = firstObjectToClone; else objectToClone = secondObjectToClone; } void checkRandomRotation(int columnCounter, int rowCounter, int layerCounter) { if (randomizeYRotation) { rotationObject = new GameObject("clone-" + columnCounter + "-" + rowCounter + "-" + layerCounter); rotationObject.transform.parent = parentObjectForClones.transform; } else rotationObject = parentObjectForClones; } Quaternion setRotation() { Quaternion rotation = new Quaternion(); -
Eddie Knight revised this gist
Mar 24, 2019 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,6 +54,7 @@ void cloneColumns(int rowCounter, int layerCounter) Instantiate(objectToClone, clonePosition, setRotation(), parentObjectForClones.transform); } } Quaternion setRotation() { Quaternion rotation = new Quaternion(); @@ -64,8 +65,6 @@ Quaternion setRotation() if (randomizeYRotation) rotation.y = Random.rotation.y; return rotation; } -
Eddie Knight revised this gist
Mar 24, 2019 . 1 changed file with 21 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,10 +2,6 @@ using System.Collections.Generic; using UnityEditor; public class CloneGameObject : ScriptableWizard { public GameObject objectToClone; @@ -16,9 +12,10 @@ public class CloneGameObject : ScriptableWizard public float XAxisSpacing = 1; public float YAxisSpacing = 1; public float ZAxisSpacing = 1; public bool randomizeYRotation; private List<GameObject> allClones; private Vector3 clonePosition; [MenuItem("Tools/Clone Game Object")] static void CloneGameObjectWizard() @@ -27,7 +24,7 @@ static void CloneGameObjectWizard() } void OnWizardCreate() { cloneAll(); } @@ -54,14 +51,28 @@ void cloneColumns(int rowCounter, int layerCounter) for (int columnCounter = 0; columnCounter < xCount; columnCounter++) { setTransform(columnCounter, rowCounter, layerCounter); Instantiate(objectToClone, clonePosition, setRotation(), parentObjectForClones.transform); } } Quaternion setRotation() { Quaternion rotation = new Quaternion(); rotation.Set(objectToClone.transform.rotation.x, objectToClone.transform.rotation.y, objectToClone.transform.rotation.z, objectToClone.transform.rotation.w); if (randomizeYRotation) rotation.y = Random.rotation.y; Debug.Log(rotation.y); Debug.Log(rotation); return rotation; } void setTransform(int columnCounter, int rowCounter, int layerCounter) { clonePosition.x = parentObjectForClones.transform.position.x + (XAxisSpacing * columnCounter); clonePosition.y = parentObjectForClones.transform.position.y + (YAxisSpacing * rowCounter); clonePosition.z = parentObjectForClones.transform.position.z + (ZAxisSpacing * layerCounter); } } -
Eddie Knight created this gist
Mar 23, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ using UnityEngine; using System.Collections.Generic; using UnityEditor; // Clones object a specified number of times // into a specified number of rows // and a specified number of row layers, // a specified distance apart public class CloneGameObject : ScriptableWizard { public GameObject objectToClone; public GameObject parentObjectForClones; public int xCount = 1; public int yCount = 1; public int zCount = 1; public float XAxisSpacing = 1; public float YAxisSpacing = 1; public float ZAxisSpacing = 1; private List<GameObject> allClones; private Vector3 cloneTransform; [MenuItem("Tools/Clone Game Object")] static void CloneGameObjectWizard() { ScriptableWizard.DisplayWizard<CloneGameObject>("Clone Game Object", "Clone Now"); } void OnWizardCreate() { cloneAll(); } // Helper Functions void cloneAll() { for(int layerCounter = 0; layerCounter < zCount; layerCounter++) { cloneRowsOfColumns(layerCounter); } } void cloneRowsOfColumns(int layerCounter) { for (int rowCounter = 0; rowCounter < yCount; rowCounter++) { cloneColumns(rowCounter, layerCounter); } } void cloneColumns(int rowCounter, int layerCounter) { for (int columnCounter = 0; columnCounter < xCount; columnCounter++) { setTransform(columnCounter, rowCounter, layerCounter); Instantiate(objectToClone, cloneTransform, objectToClone.transform.rotation, parentObjectForClones.transform); } } void setTransform(int columnCounter, int rowCounter, int layerCounter) { cloneTransform.x = parentObjectForClones.transform.position.x + (XAxisSpacing * columnCounter); cloneTransform.y = parentObjectForClones.transform.position.y + (YAxisSpacing * rowCounter); cloneTransform.z = parentObjectForClones.transform.position.z + (ZAxisSpacing * layerCounter); } }