Beispiel #1
0
        private void Update()
        {
            if ((Disabler != null && Disabler.activeSelf) || EventSystem.current.IsPointerOverGameObject())
            {
                hideMarker();
                hideOutline(ref _targetOutline);
                hideSphere();

                if (Target == null)
                {
                    hideOutline(ref _performerOutline);
                }
                else
                {
                    showOutline(ref _performerOutline, Target, SelectColor);
                }

                return;
            }

            var camera = _camera;

            if (camera == null)
            {
                camera = Camera.main;
            }
            if (camera == null)
            {
                return;
            }

            var mouse = Input.mousePosition;

            mouse.z = camera.nearClipPlane;

            var near = camera.ScreenToWorldPoint(mouse);

            mouse.z = camera.farClipPlane;
            var far = camera.ScreenToWorldPoint(mouse);

            var hit         = Util.GetClosestNonActorHit(near, far, 1);
            var targetActor = AIUtil.FindClosestActorIncludingDead(hit, 0.7f);

            var isMouseDown = Input.GetMouseButtonDown(0);

            if (Target == null)
            {
                if (targetActor != null && targetActor.Side == Side && targetActor.IsAlive)
                {
                    showOutline(ref _performerOutline, targetActor, PickColor);

                    if (isMouseDown)
                    {
                        Target      = targetActor;
                        isMouseDown = false;
                    }
                }
                else
                {
                    hideOutline(ref _performerOutline);
                }
            }
            else if (Target != null)
            {
                showOutline(ref _performerOutline, Target, SelectColor);
            }
            else
            {
                hideOutline(ref _performerOutline);
            }

            AIActions targetActions = null;

            if (Target != null)
            {
                targetActions = Target.GetComponent <AIActions>();
            }

            if (targetActions)
            {
                var target = hit;
                AIUtil.GetClosestStandablePosition(ref target);

                var isActor    = targetActor != null;
                var isSelf     = isActor && targetActor == Target;
                var isAlly     = isActor && targetActor.Side == Target.Side;
                var isEnemy    = isActor && targetActor.Side != Target.Side;
                var isDead     = isActor && !targetActor.IsAlive;
                var isLocation = Vector3.Distance(target, hit) < 0.5f;

                AIAction action           = null;
                var      isTargetingActor = false;

                if (_forcedAction != null)
                {
                    if (_forcedAction.CanTargetGround && isLocation)
                    {
                        action = _forcedAction;
                    }
                    else if ((!isDead || !_forcedAction.ShouldIgnoreDead) &&
                             ((isSelf && _forcedAction.CanTargetSelf) ||
                              (isAlly && _forcedAction.CanTargetAlly) ||
                              (isEnemy && _forcedAction.CanTargetEnemy)))
                    {
                        action           = _forcedAction;
                        isTargetingActor = true;
                    }
                }
                else
                {
                    for (int i = 0; i < targetActions.Actions.Length; i++)
                    {
                        var a = targetActions.Actions[i];

                        if (a.CanTargetGround && isLocation)
                        {
                            action = a;
                            break;
                        }
                        else if ((!isDead || !a.ShouldIgnoreDead) &&
                                 ((isSelf && a.CanTargetSelf) ||
                                  (isAlly && a.CanTargetAlly) ||
                                  (isEnemy && a.CanTargetEnemy)))
                        {
                            action           = a;
                            isTargetingActor = true;
                            break;
                        }
                    }
                }

                if (action != null)
                {
                    if (isTargetingActor)
                    {
                        if (isSelf)
                        {
                            hideOutline(ref _performerOutline);
                        }

                        showOutline(ref _targetOutline, targetActor, action.UIColor);
                        hideMarker();
                        hideSphere();
                    }
                    else
                    {
                        if (action.UIRadius > 0.001f)
                        {
                            showSphere(target, action.UIColor, action.UIRadius);
                            hideOutline(ref _targetOutline);
                            hideMarker();
                        }
                        else
                        {
                            showMarker(target, action.UIColor);
                            hideOutline(ref _targetOutline);
                            hideSphere();
                        }
                    }
                }

                if (isMouseDown)
                {
                    isMouseDown = false;

                    if (action != null)
                    {
                        if (action.CanTargetGround)
                        {
                            targetActions.Execute(action, target);
                        }
                        else
                        {
                            targetActions.Execute(action, targetActor);
                        }

                        if (_forcedAction != null)
                        {
                            _forcedAction = null;
                        }
                    }

                    Target = null;
                }
                else if (Input.GetMouseButtonDown(1))
                {
                    Target = null;
                }
            }
            else
            {
                hideOutline(ref _targetOutline);
                hideMarker();
                hideSphere();
            }
        }