Skip to content

Instantly share code, notes, and snippets.

@ProGM
Last active April 25, 2023 07:45

Revisions

  1. ProGM revised this gist Dec 7, 2016. No changes.
  2. ProGM revised this gist Oct 19, 2016. No changes.
  3. ProGM revised this gist Oct 18, 2016. 1 changed file with 25 additions and 13 deletions.
    38 changes: 25 additions & 13 deletions DraggablePoint.cs
    Original file line number Diff line number Diff line change
    @@ -10,18 +10,30 @@ public class DraggablePoint : PropertyAttribute {}
    #if UNITY_EDITOR
    [CustomEditor(typeof(MonoBehaviour), true)]
    public class DraggablePointDrawer : Editor {
    public void OnSceneGUI () {
    var property = serializedObject.GetIterator ();
    while (property.Next (true)) {
    if (property.propertyType == SerializedPropertyType.Vector3) {
    var draggablePoints = serializedObject.targetObject.GetType ().GetField (property.name).GetCustomAttributes (typeof(DraggablePoint), false);
    if (draggablePoints.Length > 0) {
    Handles.Label(property.vector3Value, property.name);
    property.vector3Value = Handles.PositionHandle (property.vector3Value, Quaternion.identity);
    serializedObject.ApplyModifiedProperties ();
    }
    }
    }
    }

    readonly GUIStyle style = new GUIStyle();

    void OnEnable(){
    style.fontStyle = FontStyle.Bold;
    style.normal.textColor = Color.white;
    }

    public void OnSceneGUI () {
    var property = serializedObject.GetIterator ();
    while (property.Next (true)) {
    if (property.propertyType == SerializedPropertyType.Vector3) {
    var field = serializedObject.targetObject.GetType ().GetField (property.name);
    if (field == null) {
    continue;
    }
    var draggablePoints = field.GetCustomAttributes (typeof(DraggablePoint), false);
    if (draggablePoints.Length > 0) {
    Handles.Label(property.vector3Value, property.name);
    property.vector3Value = Handles.PositionHandle (property.vector3Value, Quaternion.identity);
    serializedObject.ApplyModifiedProperties ();
    }
    }
    }
    }
    }
    #endif
  4. ProGM revised this gist Oct 9, 2016. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions ExampleBehavior.cs
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,7 @@
    using System.Collections;

    public class ExampleBehavior : MonoBehaviour {

    [DraggablePoint] public Vector3 SpawnPosition;
    [DraggablePoint] public Vector3 SpawnPosition;
    public GameObject SpawnableObject;

    public void Spawn() {
  5. ProGM created this gist Oct 9, 2016.
    27 changes: 27 additions & 0 deletions DraggablePoint.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    using System;
    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif

    public class DraggablePoint : PropertyAttribute {}


    #if UNITY_EDITOR
    [CustomEditor(typeof(MonoBehaviour), true)]
    public class DraggablePointDrawer : Editor {
    public void OnSceneGUI () {
    var property = serializedObject.GetIterator ();
    while (property.Next (true)) {
    if (property.propertyType == SerializedPropertyType.Vector3) {
    var draggablePoints = serializedObject.targetObject.GetType ().GetField (property.name).GetCustomAttributes (typeof(DraggablePoint), false);
    if (draggablePoints.Length > 0) {
    Handles.Label(property.vector3Value, property.name);
    property.vector3Value = Handles.PositionHandle (property.vector3Value, Quaternion.identity);
    serializedObject.ApplyModifiedProperties ();
    }
    }
    }
    }
    }
    #endif
    12 changes: 12 additions & 0 deletions ExampleBehavior.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    using UnityEngine;
    using System.Collections;

    public class ExampleBehavior : MonoBehaviour {

    [DraggablePoint] public Vector3 SpawnPosition;
    public GameObject SpawnableObject;

    public void Spawn() {
    Instantiate(SpawnableObject, SpawnPosition, Quaternion.identity);
    }
    }