Created
June 29, 2015 17:06
-
-
Save tsubaki/4bda5bc574e7ac1d5ce2 to your computer and use it in GitHub Desktop.
This file contains 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; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
public class DisappearAttachedFieldAttribute : PropertyAttribute{} | |
#if UNITY_EDITOR | |
[CustomPropertyDrawer( typeof ( DisappearAttachedFieldAttribute ) )] | |
public class DisappearAttachedField : PropertyDrawer | |
{ | |
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) | |
{ | |
if (property.propertyType == SerializedPropertyType.ObjectReference) { | |
if( property.objectReferenceValue == null ){ | |
EditorGUI.PropertyField(position, property, label, true); | |
} | |
} | |
} | |
public override float GetPropertyHeight (SerializedProperty property, GUIContent label) | |
{ | |
if (property.objectReferenceValue != null) { | |
return 0; | |
} | |
return base.GetPropertyHeight (property, label); | |
} | |
} | |
#endif |
This file contains 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; | |
[RequireComponent(typeof(Rigidbody))] | |
[RequireComponent(typeof(SphereCollider))] | |
public class GetRigidbody : MonoBehaviour { | |
[SerializeField, DisappearAttachedField] | |
protected Rigidbody rigidbody = null; | |
[SerializeField, DisappearAttachedField] | |
protected Transform transform = null; | |
[SerializeField, DisappearAttachedField] | |
protected Collider collider = null; | |
[SerializeField, DisappearAttachedField] | |
protected Renderer renderer = null; | |
// Use this for initialization | |
void Reset () { | |
rigidbody = GetComponent<Rigidbody>(); | |
transform = GetComponent<Transform>(); | |
collider = GetComponent<Collider>(); | |
renderer = GetComponent<Renderer>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment