コード例 #1
0
    /////////////////////////////////////////////////////////////////////////////

    //
    //Initializers
    //

    void Start()
    {
        List <IPausable> pausablesList = new List <IPausable>();

        //add IPausables in gameObject to pausablesList
        pausablesList.AddRange(GetComponents <IPausable>());

        //add pausableAnimators to pausablesList if there is any animator in gameObject
        Animator[] animators = GetComponentsInChildren <Animator>();
        if (animators != null)
        {
            int length = animators.Length;
            PausableAnimator[] pausableAnimators = new PausableAnimator[length];
            for (int i = 0; i < length; i++)
            {
                pausableAnimators[i] = new PausableAnimator(animators[i]);
            }

            pausablesList.AddRange(pausableAnimators);
        }

        //assign IPausables to pausables
        pausables = pausablesList.ToArray();

        Initialize();
    }
コード例 #2
0
    public static PausableData[] Setup(this PausableData[] pausableArray, GameObject gameObject)
    {
        List <PausableData> result = new List <PausableData>();

        //Need to manually add each derived type as a new one is added. Unsure if there's a better automated way to do this.

        //Rigidbody2D
        Rigidbody2D[] rigidbody2Ds = gameObject.GetComponentsInChildren <Rigidbody2D>();
        foreach (Rigidbody2D data in rigidbody2Ds)
        {
            PauseableRigidbody2D pausableRigidbody2D = new PauseableRigidbody2D();
            pausableRigidbody2D.Setup(data);
            result.Add(pausableRigidbody2D);
        }

        //Rigidbody
        Rigidbody[] rigidbodys = gameObject.GetComponentsInChildren <Rigidbody>();
        foreach (Rigidbody data in rigidbodys)
        {
            PauseableRigidbody pausableRigidbody = new PauseableRigidbody();
            pausableRigidbody.Setup(data);
            result.Add(pausableRigidbody);
        }

        //Animator
        Animator[] animators = gameObject.GetComponentsInChildren <Animator>();
        foreach (Animator data in animators)
        {
            PausableAnimator pausableAnimator = new PausableAnimator();
            pausableAnimator.Setup(data);
            result.Add(pausableAnimator);
        }

        //NavMeshAgent
        NavMeshAgent[] agents = gameObject.GetComponentsInChildren <NavMeshAgent>();
        foreach (NavMeshAgent data in agents)
        {
            PausableNavMeshAgent pausableNavMeshAgent = new PausableNavMeshAgent();
            pausableNavMeshAgent.Setup(data);
            result.Add(pausableNavMeshAgent);
        }

        return(result.ToArray());
    }