Example #1
0
 protected void LoadContent()
 {
     foreach (NpcAction action in this.Npc.Actions.Keys)
     {
         NpcActionContent npcActionContent = this.Npc.Actions[action];
         npcActionContent.Animation             = this.LoadAnimation(npcActionContent.AnimationName);
         npcActionContent.Animation.Timing.Loop = NpcActionExtensions.Loops(action);
         if (npcActionContent.SoundName != null)
         {
             npcActionContent.Sound = this.LoadSound(npcActionContent.SoundName);
         }
         else if (this.Npc.Metadata.SoundActions.Contains(action))
         {
             npcActionContent.Sound = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/" + this.Npc.Metadata.SoundPath);
         }
     }
     foreach (NpcActionContent npcActionContent in Enumerable.Select <SpeechLine, NpcActionContent>(Enumerable.Where <SpeechLine>((IEnumerable <SpeechLine>) this.Npc.Speech, (Func <SpeechLine, bool>)(x => x.OverrideContent != null)), (Func <SpeechLine, NpcActionContent>)(x => x.OverrideContent)))
     {
         if (npcActionContent.AnimationName != null)
         {
             npcActionContent.Animation = this.LoadAnimation(npcActionContent.AnimationName);
         }
         if (npcActionContent.SoundName != null)
         {
             npcActionContent.Sound = this.LoadSound(npcActionContent.SoundName);
         }
     }
     if (!this.CanTakeOff)
     {
         return;
     }
     this.flySound = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Wildlife/BirdFly");
 }
Example #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;
    }