Exemplo n.º 1
0
        /// <summary>
        /// Caches the collider and hides it
        /// and configures all the necessary information from it
        /// </summary>
        void OnEnable()
        {
            _targetter = (Targetter)target;
            _serializedAttachedCollider = serializedObject.FindProperty("attachedCollider");
            _attachedCollider           = (Collider)_serializedAttachedCollider.objectReferenceValue;

            if (_attachedCollider == null)
            {
                _attachedCollider = _targetter.GetComponent <Collider>();
                if (_attachedCollider == null)
                {
                    switch (_colliderConfiguration)
                    {
                    case TowerCollider.Sphere:
                        _attachedCollider = _targetter.gameObject.AddComponent <SphereCollider>();
                        break;

                    case TowerCollider.Capsule:
                        _attachedCollider = _targetter.gameObject.AddComponent <CapsuleCollider>();
                        break;
                    }

                    _serializedAttachedCollider.objectReferenceValue = _attachedCollider;
                }
            }

            if (_attachedCollider is SphereCollider)
            {
                _colliderConfiguration = TowerCollider.Sphere;
            }
            else if (_attachedCollider is CapsuleCollider)
            {
                _colliderConfiguration = TowerCollider.Capsule;
            }

            // to ensure the collider is referenced by the serialized object
            if (_serializedAttachedCollider.objectReferenceValue == null)
            {
                _serializedAttachedCollider.objectReferenceValue = _attachedCollider;
            }

            GetValues();
            _attachedCollider.isTrigger = true;
            _attachedCollider.hideFlags = HideFlags.HideInInspector;
        }
Exemplo n.º 2
0
        /// <summary>
        /// draws the default inspector
        /// and then draws configuration for colliders
        /// </summary>
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            // To make the inspector a little bit neater
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Targetter Collider Configuration", EditorStyles.boldLabel);

            _colliderConfiguration =
                (TowerCollider)EditorGUILayout.EnumPopup("Targetter Collider", _colliderConfiguration);
            AttachCollider();
            _colliderRadius = EditorGUILayout.FloatField("Radius", _colliderRadius);
            if (_colliderConfiguration == TowerCollider.Capsule)
            {
                _extraVerticalRange = EditorGUILayout.FloatField("Vertical Range", _extraVerticalRange);
            }

            SetValues();
            EditorUtility.SetDirty(_targetter);
            EditorUtility.SetDirty(_attachedCollider);
            serializedObject.ApplyModifiedProperties();
        }