Пример #1
0
    public Character Initialize <T>(UInt32 id, string name_) where T : Actor, new()
    {
        if (!isInitialized)
        {
            isInitialized = true;
            name          = name_;
            tag           = "Character";
            Actor         = new T();
            ID            = id;
            Instances[ID] = this;
            Animator      = GetComponent <Animator>();
            Collider      = GetComponent <Collider>();
            Rigidbody     = gameObject.AddComponent <Rigidbody>();
            ActionManager = gameObject.AddComponent <ActionManager>();

            ActionManager.Action(ActionType.Normal);

            statusCanvas = Instantiate(ObjectManager.StatusCanvas).GetComponent <StatusCanvas>().Initialize(this);

            HP.Pairwise().Subscribe(hp =>
            {
                if (hp.Previous <= 0 && hp.Current > 0)
                {
                    IsAlive.Value = true;
                }

                if (hp.Previous > 0 && hp.Current <= 0)
                {
                    IsAlive.Value = false;
                }
            });

            IsAlive.Subscribe(isAlive =>
            {
                if (isAlive)
                {
                    Animator.SetTrigger("Normal");
                }
                else
                {
                    Animator.SetTrigger("Death");
                }

                Collider.enabled = CanAct.Value = isAlive;
            });
        }

        return(this);
    }