Пример #1
0
    /*
     * Function: Setup
     *
     * -Sets up the GameObject this script is attached to. That is:
     *      -Adds controllers, components or child GameObjects to this GameObject, which are specific to each GObjectType
     *      -Initializes added controllers/components.
     */
    void Setup(GObjectType obj_type)
    {
        ActorController controller;
        GameObject      parts;

        switch (obj_type)
        {
        case GObjectType.Player:

            // add PlayerController
            controller = linked_gobject.renderedGameObject.AddComponent <PlayerController> ();
            addedComponents.Add(controller);

            // add bodypart structure hierarchy
            parts = Instantiate(GameRenderer.GRenderer.rObject.characterAnimStructure) as GameObject;
            addedGameObjects.Add(parts);

            parts.transform.parent = linked_gobject.renderedGameObject.transform;
            parts.GetComponent <CharBodyController> ().Init(linked_gobject);
            controller.linkActor((GActor)linked_gobject, parts.GetComponent <CharBodyController> ());
            break;

        case GObjectType.Character:

            // add CharacController
            controller = linked_gobject.renderedGameObject.AddComponent <CharacController> ();
            addedComponents.Add(controller);

            // add bodypart structure hierarchy
            parts = Instantiate(GameRenderer.GRenderer.rObject.characterAnimStructure) as GameObject;
            addedGameObjects.Add(parts);

            parts.transform.parent = linked_gobject.renderedGameObject.transform;
            parts.GetComponent <CharBodyController> ().Init(linked_gobject);
            controller.linkActor((GActor)linked_gobject, parts.GetComponent <CharBodyController> ());
            break;

        case GObjectType.Animal:

            // add AnimalController
            controller = linked_gobject.renderedGameObject.AddComponent <AnimalController> ();
            addedComponents.Add(controller);

            // add bodypart structure hierarchy
            parts = Instantiate(GameRenderer.GRenderer.rObject.animalAnimStructure) as GameObject;
            addedGameObjects.Add(parts);

            parts.transform.parent = linked_gobject.renderedGameObject.transform;
            parts.GetComponent <AnimalBodyController> ().Init(linked_gobject);
            controller.linkActor((GActor)linked_gobject, parts.GetComponent <AnimalBodyController> ());
            break;

        case GObjectType.Structure:

            // add GeneralObjectController
            StructureController ctrl = linked_gobject.renderedGameObject.AddComponent <StructureController> ();
            addedComponents.Add(ctrl);

            // add sprite renderer
            Component sprite_renderer = linked_gobject.renderedGameObject.AddComponent <SpriteRenderer> ();
            addedComponents.Add(sprite_renderer);

            ctrl.linkGObject(linked_gobject);
            ctrl.Init();                        // sets sprite
            break;
        }
    }