Пример #1
0
        //private SlidesceneResource current_resource;

        public void RenderScene()
        {
            switch (sd.getType())
            {
            case GeneralScene.GeneralSceneSceneType.VIDEOSCENE:
                movie       = ResourceManager.Instance.getVideo(((Videoscene)sd).getResources()[0].getAssetPath(Videoscene.RESOURCE_TYPE_VIDEO));
                movieplayer = MovieState.LOADING;
                this.transform.FindChild("Background").localPosition = new Vector3(40, 30, 20);
                break;

            case GeneralScene.GeneralSceneSceneType.SCENE:

                loadParents();

                Scene rsd = (Scene)sd;
                foreach (ResourcesUni sr in rsd.getResources())
                {
                    if (ConditionChecker.check(sr.getConditions()))
                    {
                        Texture2D tmp = ResourceManager.Instance.getImage(sr.getAssetPath(Scene.RESOURCE_TYPE_BACKGROUND));

                        Transform background = this.transform.FindChild("Background");
                        background.GetComponent <Renderer>().material.mainTexture = tmp;
                        float scale = (tmp.width / (tmp.height / 600f)) / 800f;

                        this.transform.position         = new Vector3(40, 30, 20);
                        background.localPosition        = new Vector3(((80 * scale) - 80) / 2f, 0, 20);
                        background.transform.localScale = new Vector3(scale * 80, 60, 1);
                        break;
                    }
                }

                //###################### CHARACTERS ######################
                deleteChilds(Characters);
                foreach (ElementReference context in rsd.getCharacterReferences())
                {
                    instanceElement <NPC>(context);
                }

                //###################### OBJECTS ######################
                deleteChilds(Objects);
                foreach (ElementReference context in rsd.getItemReferences())
                {
                    instanceElement <Item>(context);
                }

                //###################### ATREZZOS ######################
                deleteChilds(Atrezzos);
                foreach (ElementReference context in rsd.getAtrezzoReferences())
                {
                    instanceElement <Atrezzo>(context);
                }

                //###################### ACTIVEAREAS ######################
                deleteChilds(ActiveAreas);

                foreach (ActiveArea ad in rsd.getActiveAreas())
                {
                    if (ConditionChecker.check(ad.getConditions()))
                    {
                        instanceRectangle <ActiveArea>(ad);
                    }
                }

                //###################### EXITS ######################
                deleteChilds(Exits);

                foreach (Exit exit in rsd.getExits())
                {
                    if (exit.isHasNotEffects() || ConditionChecker.check(exit.getConditions()))
                    {
                        instanceRectangle <Exit>(exit);
                    }
                }


                if (!Game.Instance.GameState.isFirstPerson())
                {
                    if (rsd.getTrajectory() == null)
                    {
                        break;
                    }

                    trajectory = new TrajectoryHandler(rsd.getTrajectory());
                    if (player_context == null)
                    {
                        //Vector2 pos = LineHandler.nodeToVector2 (lines [lines.Count-1].end);
                        Trajectory.Node pos = trajectory.getLastNode();
                        player_context = new ElementReference("Player", pos.getX(), pos.getY(), rsd.getPlayerLayer());
                        player_context.setScale(pos.getScale());
                    }
                    /*GameObject.Destroy(this.transform.FindChild ("Player"));*/

                    var player = GameObject.Instantiate(Player_Prefab).GetComponent <PlayerMB>();
                    player.transform.parent = Characters;
                    player.Element          = Game.Instance.GameState.getPlayer();
                    player.Context          = player_context;
                }

                break;

            case GeneralScene.GeneralSceneSceneType.SLIDESCENE:
                Slidescene ssd = (Slidescene)sd;
                foreach (ResourcesUni r in ssd.getResources())
                {
                    if (ConditionChecker.check(r.getConditions()))
                    {
                        this.slides = ResourceManager.Instance.getAnimation(r.getAssetPath(Slidescene.RESOURCE_TYPE_SLIDES));
                        this.transform.FindChild("Background").GetComponent <Renderer>().material.mainTexture = this.slides.frames[0].Image;
                        this.transform.position = new Vector3(40, 30, 20);
                        break;
                    }
                }
                break;
            }
        }
Пример #2
0
    //private SlidesceneResource current_resource;

    public void renderScene()
    {
        ElementReference auxEleRef;

        switch (sd.getType())
        {
        case GeneralScene.GeneralSceneSceneType.VIDEOSCENE:
            StartCoroutine(loadMovie());
            this.transform.FindChild("Background").localPosition = new Vector3(40, 30, 20);
            break;

        case GeneralScene.GeneralSceneSceneType.SCENE:
            Scene rsd = (Scene)sd;
            foreach (ResourcesUni sr in rsd.getResources())
            {
                if (ConditionChecker.check(sr.getConditions()))
                {
                    Texture2DHolder th  = new Texture2DHolder(sr.getAssetPath(Scene.RESOURCE_TYPE_BACKGROUND));
                    Texture2D       tmp = th.Texture;

                    Transform background = this.transform.FindChild("Background");
                    background.GetComponent <Renderer> ().material.mainTexture = tmp;
                    float scale = (tmp.width / (tmp.height / 600f)) / 800f;

                    this.transform.position         = new Vector3(40, 30, 20);
                    background.localPosition        = new Vector3(((80 * scale) - 80) / 2f, 0, 20);
                    background.transform.localScale = new Vector3(scale * 80, 60, 1);
                    break;
                }
            }

            Transform characters = this.transform.FindChild("Characters");
            foreach (Transform child in characters)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (ElementReference cr in rsd.getCharacterReferences())
            {
                if (ConditionChecker.check(cr.getConditions()))
                {
                    GameObject ret   = GameObject.Instantiate(Character_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <CharacterMB> ().context  = cr;
                    ret.GetComponent <CharacterMB> ().charData = Game.Instance.getCharacter(cr.getTargetId());
                    trans.SetParent(characters);
                }
            }

            Transform objects = this.transform.FindChild("Objects");
            foreach (Transform child in objects)
            {
                GameObject.Destroy(child.gameObject);
            }

            List <ElementReference> items = rsd.getItemReferences();

            ElementReference tmpElement;
            foreach (ElementReference ir in rsd.getItemReferences())
            {
                if (ConditionChecker.check(ir.getConditions()))
                {
                    if (!contexts.ContainsKey(ir))
                    {
                        tmpElement = new ElementReference(ir.getTargetId(), ir.getX(), ir.getY());
                        tmpElement.setScale(ir.getScale());
                        contexts.Add(ir, tmpElement);
                    }

                    GameObject ret   = GameObject.Instantiate(Object_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <ObjectMB> ().context = contexts[ir];
                    ret.GetComponent <ObjectMB> ().objData = Game.Instance.getObject(ir.getTargetId());
                    trans.SetParent(objects);
                }
            }

            Transform atrezzos = this.transform.FindChild("Atrezzos");
            foreach (Transform child in atrezzos)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (ElementReference ir in rsd.getAtrezzoReferences())
            {
                if (ConditionChecker.check(ir.getConditions()))
                {
                    GameObject ret   = GameObject.Instantiate(Atrezzo_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <AtrezzoMB> ().context = ir;
                    ret.GetComponent <AtrezzoMB> ().atrData = Game.Instance.getAtrezzo(ir.getTargetId());
                    trans.SetParent(atrezzos);
                }
            }

            Transform activeareas = this.transform.FindChild("ActiveAreas");
            foreach (Transform child in activeareas)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (ActiveArea ad in rsd.getActiveAreas())
            {
                if (ConditionChecker.check(ad.getConditions()))
                {
                    GameObject ret   = GameObject.Instantiate(ActiveArea_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <ActiveAreaMB> ().aaData = ad;
                    trans.localScale = new Vector3(ad.getWidth() / 10f, ad.getHeight() / 10f, 1);
                    Vector2 tmppos = new Vector2(ad.getX(), ad.getY()) / 10 + (new Vector2(trans.localScale.x, trans.localScale.y)) / 2;

                    trans.localPosition = new Vector2(tmppos.x, 60 - tmppos.y);
                    trans.SetParent(activeareas);
                }
            }

            Transform exits = this.transform.FindChild("Exits");
            foreach (Transform child in exits)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (Exit ed in rsd.getExits())
            {
                if (ed.isHasNotEffects() || ConditionChecker.check(ed.getConditions()))
                {
                    GameObject ret   = GameObject.Instantiate(Exit_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <ExitMB> ().exitData = ed;
                    trans.localScale = new Vector3(ed.getWidth() / 10f, ed.getHeight() / 10f, 1);
                    Vector2 tmppos = new Vector2(ed.getX(), ed.getY()) / 10 + (new Vector2(trans.localScale.x, trans.localScale.y)) / 2;

                    trans.localPosition = new Vector2(tmppos.x, 60 - tmppos.y);
                    trans.SetParent(exits);
                }
            }

            if (!Game.Instance.isFirstPerson())
            {
                lines = new List <LineHandler> ();
                foreach (Trajectory.Side side in rsd.getTrajectory().getSides())
                {
                    lines.Add(new LineHandler(rsd.getTrajectory().getNodeForId(side.getIDStart())
                                              , rsd.getTrajectory().getNodeForId(side.getIDEnd())
                                              , side));
                }
                updateNeighbours();

                if (player_context == null)
                {
                    //Vector2 pos = LineHandler.nodeToVector2 (lines [lines.Count-1].end);
                    Trajectory.Node pos = lines [lines.Count - 1].end;
                    player_context = new ElementReference("Player", pos.getX(), pos.getY(), rsd.getPlayerLayer());
                    player_context.setScale(pos.getScale());
                }
                /*GameObject.Destroy(this.transform.FindChild ("Player"));*/

                player = GameObject.Instantiate(Player_Prefab).GetComponent <PlayerMB>();
                player.transform.parent = characters;
                player.playerData       = Game.Instance.getPlayer();
                player.context          = player_context;
            }

            break;

        case GeneralScene.GeneralSceneSceneType.SLIDESCENE:
            Slidescene ssd = (Slidescene)sd;
            foreach (ResourcesUni r in ssd.getResources())
            {
                if (ConditionChecker.check(r.getConditions()))
                {
                    this.slides = new eAnim(r.getAssetPath(Slidescene.RESOURCE_TYPE_SLIDES));
                    this.transform.FindChild("Background").GetComponent <Renderer> ().material.mainTexture = this.slides.frames[0].Image;
                    this.transform.position = new Vector3(40, 30, 20);
                    break;
                }
            }
            break;
        }
    }