- Home /
Inspector public with movable pivot in editor window.
Can I create something like Vector3 public in inspector that has movable pivot in editor? Whithout attaching any game object.
I concur! It would be amazingly useful to enable a gizmo for any public Vector3 or Vector2.
If your question has been answered I'd appreciate if you marked it as such, or please explain if the code posted isn't working for you and I can try to help!
Scribe
Answer by Scribe · Apr 04, 2014 at 03:43 AM
Well this took me a little while to figure out but this seems to work, just copy it into a file: V3visulization.cs and have it somewhere in your assets folder (doesn't need to be in an 'Editor' folder), the rest should work for Vector3's (I haven't bothered with Vector2's, they shouldn't be hard to add yourself with this start):
using UnityEditor;
using System.Reflection;
using UnityEngine;
[InitializeOnLoad]
class V3visulization{
static V3visulization(){
SceneView.onSceneGUIDelegate += OnSceneGUI;
}
static void OnSceneGUI(SceneView scnView){
GameObject selObj;
Vector3 v3;
MonoBehaviour[] scripts;
selObj = Selection.activeGameObject;
if(selObj != null){
scripts = selObj.GetComponents<MonoBehaviour>();
for(int i = 0; i < scripts.Length; i++){
MonoBehaviour data = scripts[i];
FieldInfo[] fields = data.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
for(int j = 0; j < fields.Length; j++){
if(fields[j].GetValue(scripts[i]).GetType() == typeof(Vector3)){
v3 = (Vector3)fields[j].GetValue(scripts[i]);
v3 = Handles.PositionHandle(v3, Quaternion.identity);
fields[j].SetValue(scripts[i], v3);
}
}
}
}
}
}
Hope that helps you!
Scribe
Great, thank you!:) but I need real transforms like gameobject transform in inspector with moving and rotation gismos