12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #if UNITY_4_6 || UNITY_4_7
- using UnityEngine;
- namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityCircleCollider2D
- {
- [TaskCategory("Unity/CircleCollider2D")]
- [TaskDescription("Sets the center of the CircleCollider2D. Returns Success.")]
- public class SetCenter : Action
- {
- [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
- public SharedGameObject targetGameObject;
- [Tooltip("The center of the CircleCollider2D")]
- public SharedVector2 center;
- private CircleCollider2D circleCollider2D;
- private GameObject prevGameObject;
- public override void OnStart()
- {
- var currentGameObject = GetDefaultGameObject(targetGameObject.Value);
- if (currentGameObject != prevGameObject) {
- circleCollider2D = currentGameObject.GetComponent<CircleCollider2D>();
- prevGameObject = currentGameObject;
- }
- }
- public override TaskStatus OnUpdate()
- {
- if (circleCollider2D == null) {
- Debug.LogWarning("CircleCollider2D is null");
- return TaskStatus.Failure;
- }
- circleCollider2D.center = center.Value;
- return TaskStatus.Success;
- }
- public override void OnReset()
- {
- targetGameObject = null;
- center = Vector2.zero;
- }
- }
- }
- #endif
|