Created
July 10, 2019 15:31
-
-
Save pr00thmatic/31eb781741cbffc91887a8f66423367b to your computer and use it in GitHub Desktop.
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 characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class Practice : MonoBehaviour { | |
public float radius = 3; | |
public GameObject prototype; | |
public List<GameObject> r; | |
public List<GameObject> Search () { | |
for (int i=0; i<radius; i++) { | |
GameObject created = Instantiate(prototype); | |
created.transform.position = | |
new Vector3(i, 0, 0) + transform.position; | |
r.Add(created); | |
} | |
return r; | |
} | |
} |
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 characters
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using System.Collections; | |
using System.Collections.Generic; | |
[CustomEditor(typeof(Practice))] | |
public class PracticeEditor : Editor { | |
Practice Target { get => (Practice) target; } | |
// void OnEnable () { | |
// Target.Search(); | |
// } | |
// void OnDisable () { | |
// Debug.Log("unselected!"); | |
// } | |
public override void OnInspectorGUI () { | |
DrawDefaultInspector(); | |
bool wasPressed = GUILayout.Button("Create!"); | |
Undo.RecordObject(Target, "list created"); | |
if (wasPressed) { | |
List<GameObject> created = Target.Search(); | |
Undo.RecordObject(Target, "changed radius"); | |
Target.radius++; | |
foreach (GameObject c in created) { | |
Undo.RegisterCreatedObjectUndo(c, "!!!"); | |
} | |
} | |
} | |
void OnSceneGUI () { | |
if (Target.r == null || Target.r.Count == 0) return; | |
foreach (GameObject block in Target.r) { | |
if (block.name == "INDESTRUCTIBLE") continue; | |
bool wasPressed = | |
Handles.Button(block.transform.position | |
+ block.transform.forward * 0.5f | |
+ block.transform.right * 0.5f, | |
Quaternion.Euler(90,0,0), | |
0.25f, 0.25f, | |
Handles.RectangleHandleCap); | |
if (wasPressed) { | |
Undo.RecordObject(Target, "destroyed block"); | |
Target.r.Remove(block); | |
Undo.DestroyObjectImmediate(block); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment