예제 #1
0
    protected virtual void Awake()
    {
        Animator = GetComponentInChildren <Animator>();
        Debug.AssertFormat(Animator, "Animator not found in Character's children");
        Debug.AssertFormat(Context.StateTransitionRules, "No character state transition rules found");

        AnimationEventHandler = Animator.gameObject.GetComponent <AnimationEventHandler>();

        // Create state machine and register all states
        StateMachine = new StateMachine(this, StateId.Idle);
        StateMachine.RegisterState <IdleState>(StateId.Idle);
        StateMachine.RegisterState <AimState>(StateId.Aim);
        StateMachine.RegisterState <ReloadState>(StateId.Reload);
        StateMachine.RegisterState <ShootState>(StateId.Shoot);
        StateMachine.RegisterState <ThrowState>(StateId.Throw);

        EquipmentManager = new EquipmentManager(AttachmentSlots);
        EquipmentManager.OnEquipmentChanged += OnEquippedHandler;

        // Add the default items to the inventory
        foreach (ItemCountPair itemCountPair in _defaultItems)
        {
            for (int i = 0; i < itemCountPair.count; i++)
            {
                EquipmentManager.AddToInventory(new InventoryItem(itemCountPair.context, null));
            }
        }
    }