Пример #1
0
    public T SetBehaviour <T>() where T : NPCBehaviourBase
    {
        if (ActiveBehaviour as T != null)
        {
            return(_ActiveBehaviour as T);
        }

        if (_ActiveBehaviour != null)
        {
            Destroy(_ActiveBehaviour);
            _ActiveBehaviour = null;
        }

        T behaviour = gameObject.AddComponent <T>();

        _ActiveBehaviour            = behaviour;
        _ActiveBehaviour.controller = this;
        _ActiveBehaviour.rb         = rb;
        _ActiveBehaviour.Init(_seed);
        return(behaviour);
    }
Пример #2
0
    internal NPCBehaviourBase SetBehaviour(Type t)
    {
        if (ActiveBehaviour != null && ActiveBehaviour.GetType().IsAssignableFrom(t))
        {
            return(_ActiveBehaviour);
        }

        if (_ActiveBehaviour != null)
        {
            Destroy(_ActiveBehaviour);
            _ActiveBehaviour = null;
        }

        NPCBehaviourBase behaviour = (NPCBehaviourBase)gameObject.AddComponent(t);

        _ActiveBehaviour            = behaviour;
        _ActiveBehaviour.controller = this;
        _ActiveBehaviour.rb         = rb;
        _ActiveBehaviour.Init(_seed);
        return(behaviour);
    }