コード例 #1
0
        public override void Execute(ActorAI actor)
        {
            currentAIState = AIState.Combat;

            AIController aiController = actor.ActorController;

            if (aiController.GetAIControllerMode() != AIController.ControllerMode.Combat)
            {
                aiController.SetAIControllerMode(AIController.ControllerMode.Combat);
            }

            if (!aiController.OpponentTargetDestinationIsKnown)
            {
                aiController.FindTargetOpponnentMapDestination(actor);
            }

            if (aiController.OpponentTargetDestinationIsKnown)
            {
                aiController.AIMoveTarget = AIController.MoveTarget.Opponent;
                actor.ActorController.Move(actor);

                if (aiController.HasReachedOpponentTargetDestination(actor))
                {
                    aiController.OpponentTargetDestinationIsKnown = false;
                }
            }
            if (actor.Brain.ExistShootableOpponent())
            {
                aiController.Shoot(actor.Brain.CurrentOpponentType);
            }
        }
コード例 #2
0
    public void SaveGraph(ActorAI destObject)
    {
        if (!Edges.Any() && !Nodes.Any())
        {
            return;
        }
        bool newContainer = false;

        AIGraphContainer inst;

        if (!destObject.editorGraphContainer)
        {
            inst         = ScriptableObject.CreateInstance <AIGraphContainer>();
            newContainer = true;
        }
        else
        {
            inst = destObject.editorGraphContainer;
            inst.RefreshFields();
        }
        SaveEdges(inst);

        List <AINodePortData> npd;

        //destObject.stateTransitions.Add(null, Nodes.Find(x => x.EntryPoint).outputContainer.ElementAt)
        //foreach(var stateNode in Nodes)
        for (int i = 0; i < Nodes.Count; i++)
        {
            var stateNode = Nodes[i];
            npd = new List <AINodePortData>();
            foreach (var elem in stateNode.ports)
            {
                //Debug.Log(elem.Value);
                npd.Add(new AINodePortData
                {
                    cond      = elem.Key,
                    destState = elem.Value
                });
            }

            inst.nodeData.Add(new ActorStateNodeData
            {
                GUID          = stateNode.GUID,
                relevantState = stateNode.relevantState,
                position      = stateNode.GetPosition().position,
                title         = stateNode.nodeName,
                ports         = npd,
            });
        }

        if (newContainer)
        {
            AssetDatabase.RemoveObjectFromAsset(destObject.editorGraphContainer);
            AssetDatabase.AddObjectToAsset(inst, AssetDatabase.GetAssetPath(destObject));
            destObject.editorGraphContainer = inst;
            AssetDatabase.SaveAssets();
        }
        _containerCache = inst;
        UpdateVars(_targetGraphView);
    }
コード例 #3
0
ファイル: ActorAI.cs プロジェクト: zagganoth/Procedural2020
    public static bool OpenEditor(int instanceId, int line)
    {
        ActorAI obj = EditorUtility.InstanceIDToObject(instanceId) as ActorAI;

        if (obj != null)
        {
            AIGraph.OpenDialogueGraphWindow(obj);
            return(true);
        }
        return(false);
    }
コード例 #4
0
        public override void Execute(ActorAI actor)
        {
            currentAIState = AIState.DeathCircle;
            AIController aiController = actor.ActorController;

            if (aiController.GetAIControllerMode() != AIController.ControllerMode.DeathCircle)
            {
                aiController.SetAIControllerMode(AIController.ControllerMode.DeathCircle);
            }

            aiController.SetDeathCircleFleeDestination(actor);
            if (aiController.MapDestinationIsKnown)
            {
                aiController.AIMoveTarget = AIController.MoveTarget.Map;
                actor.ActorController.Move(actor);
            }
        }
コード例 #5
0
 public override void Process(ActorAI actorAI)
 {
     if (actorAI.PlayerDistance <= AttackDistance)
     {
         actorAI.ActorMovement.LookAt(actorAI.PlayerDirection);
         actorAI.ActorMovement.StopMovement();
         TimeUntilNextAttack -= Time.deltaTime;
         if (actorAI.CanAttack && TimeUntilNextAttack <= 0f)
         {
             actorAI.ActorWeapon.Attack();
             actorAI.CanAttack   = false;
             TimeUntilNextAttack = AttackRate;
         }
     }
     else
     {
         actorAI.ActorMovement.Move(actorAI.PlayerDirection, true);
     }
 }
コード例 #6
0
 public void LoadGraph(ActorAI sourceObject)
 {
     if (_targetGraphView == null)
     {
         //Debug.Log("No Graph view!");
         return;
     }
     if (_containerCache == sourceObject.editorGraphContainer)
     {
         return;
     }
     _containerCache = sourceObject.editorGraphContainer;
     if (!_containerCache)
     {
         return;
     }
     ClearGraph();
     CreateNodes();
     UpdateVars(_targetGraphView);
     ConnectNodes();
 }
コード例 #7
0
    //private SerializedObject _serializedObject;
    //[MenuItem("Graph/AI Graph")]
    public static void OpenDialogueGraphWindow(ActorAI AI)
    {
        AIGraph window = GetWindow <AIGraph>();

        window.titleContent = new GUIContent("AI Graph");
        window.destAI       = AI;
        window._serializer  = AIGraphSerializer.GetInstance(window._graphView);
        window._serializer.LoadGraph(AI);
        //window._serializedObject = new SerializedObject(AI);

        /*foreach(ActorStateNode n in window._graphView.nodes.ToList())
         * {
         *  var a = n.Q<Port>();
         *  var b = a.contentContainer.Q<ObjectField>();
         *  SerializedObject c;
         *  if(b != null) c = new SerializedObject(b.value);
         *  else { Debug.Log(a.contentContainer.Q<VisualElement>()); }
         *  a.contentContainer.Add(new Foldout());
         *  //a.contentContainer.Add(new IMGUIContainer());
         * }*/
    }
コード例 #8
0
        public override void Execute(ActorAI actor)
        {
            currentAIState = AIState.Explore;
            AIController aiController = actor.ActorController;

            if (aiController.GetAIControllerMode() != AIController.ControllerMode.Explore)
            {
                aiController.SetAIControllerMode(AIController.ControllerMode.Explore);
            }

            if (!aiController.MapDestinationIsKnown)
            {
                aiController.GenerateRandomDestination(actor);
            }

            aiController.AIMoveTarget = AIController.MoveTarget.Map;
            actor.ActorController.Move(actor);

            if (aiController.HasReachedMapDestination(actor))
            {
                aiController.MapDestinationIsKnown = false;
            }
        }
コード例 #9
0
        public void SwitchState(ActorAI actor, AIState newState)
        {
            switch (newState)
            {
            case AIState.Dead:
                actor.ChangeState(new DeadState());
                break;

            case AIState.Explore:
                actor.ChangeState(new ExploreState());
                break;

            case AIState.Loot:
                actor.ChangeState(new LootState());
                break;

            case AIState.Hunt:
                actor.ChangeState(new HuntState());
                break;

            case AIState.Combat:
                actor.ChangeState(new CombatState());
                break;

            case AIState.Flee:
                actor.ChangeState(new FleeState());
                break;

            case AIState.DeathCircle:
                actor.ChangeState(new DeathCircleState());
                break;

            default:
                break;
            }
        }
コード例 #10
0
 public void Start()
 {
     actorAI  = GetComponent <ActorAI>();
     waySpawn = FindObjectOfType <WaySpawn>();
     anim     = GetComponent <ActorAnimation>();
 }
コード例 #11
0
 public abstract void Process(ActorAI actorAI);
コード例 #12
0
ファイル: Actor.cs プロジェクト: mengtest/skilldemo
 protected void InitAI()
 {
     mActorAI = new ActorAI(this);
     mActorAI.Start();
 }
コード例 #13
0
 public override void Execute(ActorAI actor)
 {
     currentAIState = AIState.Dead;
 }
コード例 #14
0
    public void Update()
    {
        if (!isLocalPlayer)   // networking related: this makes only local player controlled by this script
        {
            return;
        }
        getInput(); // get the input only once per frame

        // process click
        if (leftMouseClicked)
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(mousePos);
            Physics.Raycast(ray, out hit, 2.0f);
            Collider collider = hit.collider;
            if (collider != null)
            {
                ActorAI npc = collider.GetComponent <ActorAI>();
                if (npc != null)
                {
                    npc.doInteract();
                }
            }
        }

        // do translational movement
        PlayerTranslation.RunState runState = PlayerTranslation.RunState.Running;
        if (isSprinting)   // sprinting overrides others
        {
            runState = PlayerTranslation.RunState.Sprinting;
        }
        else if (isWalking)
        {
            runState = PlayerTranslation.RunState.Walking;
        }
        else if (zInput == 0 && xInput == 0)     // not moving
        {
            runState = PlayerTranslation.RunState.Still;
        }
        playerTranslation.SetRunState(runState);
        playerTranslation.SetMovementDirection(new Vector2(xInput, zInput));
        if (jumpInput)
        {
            playerTranslation.Jump();
        }

        bool suicide = Input.GetKeyDown(KeyCode.K); // kill ; TODO: remove this, its just a dumb testing feature

        switch (Input.inputString)                  //get keyboard input, probably not a good idea to use strings here...Garbage collection problems with regards to local string usage are known to happen
        {                                           //the garbage collection memory problem arises from local alloction of memory, and not freeing it up efficiently
        case "p":
            animator.SetTrigger("Pain");            //the animator controller will detect the trigger pain and play the pain animation
            break;

        /*case "a":
         *  animator.SetInteger("Death", 1);//the animator controller will detect death=1 and play DeathA
         *  break;
         * case "b":
         *  animator.SetInteger("Death", 2);//the animator controller will detect death=2 and play DeathB
         *  break;
         * case "c":
         *  animator.SetInteger("Death", 3);//the animator controller will detect death=3 and play DeathC
         *  break; */
        case "n":
            animator.SetBool("NonCombat", true);    //the animator controller will detect this non combat bool, and go into a non combat state "in" this weaponstate
            break;

        default:
            break;
        }
        Vector3 velocity = playerTranslation.GetCurrentVelocity();

        if (velocity.magnitude > 0.1f)
        {
            animator.SetBool("Idling", false);
        }
        else
        {
            animator.SetBool("Idling", true);
        }

        if (leftMouseClicked)
        {
            animator.SetTrigger("Use");
        }
    }
コード例 #15
0
 public AIDecisionManager(ActorAI actor, AIBrain brain)
 {
     this.brain = brain;
     this.actor = actor;
 }
コード例 #16
0
 public abstract void Execute(ActorAI actor);