public void Fill(BackgroundPlane plane)
    {
        Plane = plane;

        MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>();

        meshFilter.sharedMesh = FezManager.Instance.BackgroundPlaneMesh;

        MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer>();
        object       tex          = FezManager.Instance.GetTextureOrOther("background planes/" + plane.TextureName);
        Texture2D    tex2D        = tex as Texture2D;
        Material     materialBase;

        if (plane.Doublesided || plane.Billboard)
        {
            if (plane.Fullbright)
            {
                materialBase = FezManager.Instance.BackgroundPlaneFullbrightMaterial;
            }
            else
            {
                materialBase = FezManager.Instance.BackgroundPlaneMaterial;
            }
        }
        else
        {
            if (plane.Fullbright)
            {
                materialBase = FezManager.Instance.BackgroundPlaneFullbrightOnesidedMaterial;
            }
            else
            {
                materialBase = FezManager.Instance.BackgroundPlaneOnesidedMaterial;
            }
        }

        if (tex is AnimatedTexture)
        {
            AnimatedTexture texAnim = (AnimatedTexture)tex;
            texAnim.Timing.Loop = plane.Loop;

            plane.Texture         = tex2D = texAnim.Texture;
            meshRenderer.material = Instantiate(tex2D.GenMaterial(materialBase));

            FezUnityAnimatedTexture animation = gameObject.AddComponent <FezUnityAnimatedTexture>();
            animation.Fill(texAnim);
        }
        else
        {
            plane.Texture         = tex2D;
            meshRenderer.material = Instantiate(tex2D.GenMaterial(materialBase));
        }

        meshRenderer.sharedMaterial.mainTexture.wrapMode = TextureWrapMode.Clamp; // Fixes bleeding edges in some background planes

        meshRenderer.sharedMaterial.SetVector("_PlaneScale", new Vector4(plane.Scale.x, plane.Scale.y, 0f, 0f));
        if (plane.TextureName == "dent_square")
        {
            meshRenderer.sharedMaterial.EnableKeyword("_PlaneClamp");
        }
    }
Beispiel #2
0
    public void Fill(NpcInstance npc)
    {
        Animations.Clear();
        CurrentAction = NpcAction.None;

        NPC = npc;

        MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>();

        meshFilter.sharedMesh = FezManager.Instance.BackgroundPlaneMesh;

        meshRenderer = gameObject.AddComponent <MeshRenderer>();

        foreach (NpcAction action in Enum.GetValues(typeof(NpcAction)))
        {
            if (action == NpcAction.None ||
                action == NpcAction.Walk ||
                action == NpcAction.Idle ||
                action == NpcAction.Talk)
            {
                continue;
            }
            if (!NPC.Actions.ContainsKey(action) && FezManager.Instance.AssetExists("character animations/" + NPC.Name + "/" + action))
            {
                NPC.Actions.Add(action, new NpcActionContent()
                {
                    AnimationName = action.ToString()
                });
            }
        }

        foreach (KeyValuePair <NpcAction, NpcActionContent> pair in NPC.Actions)
        {
            NpcAction        action        = pair.Key;
            NpcActionContent actionContent = pair.Value;

            AnimatedTexture texAnim = FezManager.Instance.GetTextureOrOther("character animations/" + NPC.Name + "/" + actionContent.AnimationName) as AnimatedTexture;
            texAnim.Timing.Loop = true;
            texAnim.Timing.Loop =
                action != NpcAction.Idle2 &&
                action != NpcAction.Turn &&
                action != NpcAction.Burrow &&
                action != NpcAction.Hide &&
                action != NpcAction.ComeOut &&
                action != NpcAction.TakeOff &&
                action != NpcAction.Land;
            actionContent.Animation = texAnim;

            Texture2D tex2D = texAnim.Texture;
            meshRenderer.material = Instantiate(tex2D.GenMaterial(FezManager.Instance.BackgroundPlaneMaterial));
            meshRenderer.sharedMaterial.mainTexture.wrapMode = TextureWrapMode.Clamp;

            FezUnityAnimatedTexture animation = gameObject.AddComponent <FezUnityAnimatedTexture>();
            animation.Fill(texAnim);
            animation.enabled = false;

            Animations[action] = animation;
        }

        using (BinaryReader metadataReader = FezManager.Instance.ReadFromPack("character animations/" + NPC.Name + "/metadata")) {
            if (metadataReader != null)
            {
                npc.FillMetadata(FmbUtil.ReadObject(metadataReader) as NpcMetadata);
            }
        }

        CanIdle  = Animations.ContainsKey(NpcAction.Idle);
        CanIdle2 = Animations.ContainsKey(NpcAction.Idle2);
        CanIdle3 = Animations.ContainsKey(NpcAction.Idle3);
        CanWalk  = Animations.ContainsKey(NpcAction.Walk);
        CanTalk  = Animations.ContainsKey(NpcAction.Talk);
        CanTurn  = Animations.ContainsKey(NpcAction.Turn);

        CurrentAction = CanIdle ? NpcAction.Idle : NpcAction.Walk;

        if (!CanTalk)
        {
            return;
        }

        SpeechBubble = new GameObject("Speech Bubble");
        SpeechBubble.transform.parent        = transform;
        SpeechBubble.transform.localPosition = Vector3.up * transform.localScale.y * 0.5f + Vector3.forward * transform.localScale.z * 0.3f;
        SpeechBubble.transform.localScale    = new Vector3(
            0.01f / transform.localScale.x,
            0.01f / transform.localScale.y,
            1f
            );

        Canvas        bubbleCanvas    = SpeechBubble.AddComponent <Canvas>();
        RectTransform bubbleTransform = SpeechBubble.GetComponent <RectTransform>();

        bubbleTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200f);
        bubbleTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100f);

        SpeechBubbleCanvasGroup = SpeechBubble.AddComponent <CanvasGroup>();

        AddSpeechCorner(0f, 0f, "speechbubblese");
        AddSpeechCorner(0f, 1f, "speechbubblese");
        AddSpeechCorner(1f, 0f, "speechbubblese");
        AddSpeechCorner(1f, 1f, "speechbubblese");
        AddSpeechFill(0, "fullblack");
        AddSpeechFill(1, "fullblack");

        GameObject textObj = new GameObject("Text");

        textObj.transform.parent        = SpeechBubble.transform;
        textObj.transform.localPosition = Vector3.zero;
        textObj.transform.localScale    = new Vector3(0.25f, 0.25f, 1f);

        Text text = textObj.AddComponent <Text>();

        text.font = FezManager.Instance.SpeechFont;
        // text.fontSize = 50;
        text.fontSize         = 75;
        text.alignment        = TextAnchor.MiddleCenter;
        text.verticalOverflow = VerticalWrapMode.Overflow;
        text.text             = "";

        RectTransform textTransform = textObj.GetComponent <RectTransform>();

        // textTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200f);
        // textTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 243f);
        textTransform.anchorMin = new Vector2(0f, 0f);
        textTransform.anchorMax = new Vector2(1f, 1f);

        CurrentTextOpacity = 0f;
    }
    public void Fill(NpcInstance npc)
    {
        Animations.Clear();
        CurrentAction = NpcAction.None;

        NPC = npc;

        MeshFilter meshFilter = gameObject.AddComponent <MeshFilter>();

        meshFilter.sharedMesh = FezManager.Instance.BackgroundPlaneMesh;

        meshRenderer = gameObject.AddComponent <MeshRenderer>();

        foreach (NpcAction action in Enum.GetValues(typeof(NpcAction)))
        {
            if (action == NpcAction.None ||
                action == NpcAction.Walk ||
                action == NpcAction.Idle ||
                action == NpcAction.Talk)
            {
                continue;
            }
            if (!NPC.Actions.ContainsKey(action) && FezManager.Instance.AssetExists("character animations/" + NPC.Name + "/" + action))
            {
                NPC.Actions.Add(action, new NpcActionContent()
                {
                    AnimationName = action.ToString()
                });
            }
        }

        foreach (KeyValuePair <NpcAction, NpcActionContent> pair in NPC.Actions)
        {
            NpcAction        action        = pair.Key;
            NpcActionContent actionContent = pair.Value;

            AnimatedTexture texAnim = FezManager.Instance.GetTextureOrOther("character animations/" + NPC.Name + "/" + actionContent.AnimationName) as AnimatedTexture;
            texAnim.Timing.Loop = true;
            texAnim.Timing.Loop =
                action != NpcAction.Idle2 &&
                action != NpcAction.Turn &&
                action != NpcAction.Burrow &&
                action != NpcAction.Hide &&
                action != NpcAction.ComeOut &&
                action != NpcAction.TakeOff &&
                action != NpcAction.Land;
            actionContent.Animation = texAnim;

            Texture2D tex2D = texAnim.Texture;
            meshRenderer.material = Instantiate(tex2D.GenMaterial(FezManager.Instance.BackgroundPlaneMaterial));
            meshRenderer.sharedMaterial.mainTexture.wrapMode = TextureWrapMode.Clamp;

            FezUnityAnimatedTexture animation = gameObject.AddComponent <FezUnityAnimatedTexture>();
            animation.Fill(texAnim);
            animation.enabled = false;

            Animations[action] = animation;
        }

        BinaryReader metadataReader = FezManager.Instance.ReadFromPack("character animations/" + NPC.Name + "/metadata");

        if (metadataReader != null)
        {
            npc.FillMetadata(FmbUtil.ReadObject(metadataReader) as NpcMetadata);
        }

        CanIdle  = Animations.ContainsKey(NpcAction.Idle);
        CanIdle2 = Animations.ContainsKey(NpcAction.Idle2);
        CanIdle3 = Animations.ContainsKey(NpcAction.Idle3);
        CanWalk  = Animations.ContainsKey(NpcAction.Walk);
        CanTalk  = Animations.ContainsKey(NpcAction.Talk);
        CanTurn  = Animations.ContainsKey(NpcAction.Turn);

        CurrentAction = CanIdle ? NpcAction.Idle : NpcAction.Walk;
    }