//copy values from the prefab component to the runtime component, since we're don't want to create the entire object
 public virtual void Initialize(RoomSpecificElevatorAnimatorController prefab)
 {
     instance = this;
     this.runtimeController = prefab.runtimeController;
     if (RoomSpecificAnimator != null)
     {
         RoomSpecificAnimator.runtimeAnimatorController = runtimeController;
         RoomSpecificAnimator.Rebind();
     }
 }
Exemplo n.º 2
0
    RoomSpecificElevatorAnimatorController CreateRoomSpecificAnimatorController(RoomDefinition room)
    {
        //no matter what's null, destroy the current controller
        RoomSpecificElevatorAnimatorController contr = null;

        if (roomSpecificAnimatorControllerTarget != null)
        {
            contr = roomSpecificAnimatorControllerTarget.GetComponent <RoomSpecificElevatorAnimatorController>();
        }

        //if null room, error out
        if (room == null)
        {
            UnityEngine.Debug.LogError("Null room definition");
            return(default(RoomSpecificElevatorAnimatorController));
        }
        //if not room anim controller, error out
        if (room.roomSpecificElevatorAnimController == null)
        {
            UnityEngine.Debug.LogError("No room specific elevator animator controller");
            return(default(RoomSpecificElevatorAnimatorController));
        }
        else
        {
            //if the controller already exists and is of the same type as the current room, just return it
            if (contr != null && contr.GetType() == room.roomSpecificElevatorAnimController.GetType())
            {
                return(contr);
            }
        }

        //destroy the old controller
        if (contr != null)
        {
            Component.Destroy(contr);
        }

        if (roomSpecificAnimatorControllerTarget != null)
        {
            roomSpecificAnimatorControllerTarget.GetOrAddComponent <Animator>();

            //add a new controller component of the proper type
            contr = roomSpecificAnimatorControllerTarget.gameObject.AddComponent(room.roomSpecificElevatorAnimController.GetType()) as RoomSpecificElevatorAnimatorController;
            //initialize the controller with the prefab values, since we didn't instantiate from prefab exactly, but rather just created a new component
            contr.Initialize(room.roomSpecificElevatorAnimController);

            return(contr);
        }
        else
        {
            return(null);
        }
    }
 public override void Initialize(RoomSpecificElevatorAnimatorController prefab)
 {
     base.Initialize(prefab);
     instance = this;
 }