private static DialogGUIImage makePictureOfAKerbal(int width, int height, bool isGoodNews) { if (instructor == null) { GameObject genesPrefab = AssetBase.GetPrefab("Instructor_Gene"); var instantiatedGene = UnityEngine.Object.Instantiate(genesPrefab); instructor = instantiatedGene.GetComponent <KerbalInstructor>(); // Remove the lights for Gene/Wernher Light mainlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "mainlight").FirstOrDefault(); if (mainlight != null) { UnityEngine.Object.Destroy(mainlight); } Light backlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "backlight").FirstOrDefault(); if (backlight != null) { UnityEngine.Object.Destroy(backlight); } instructor.gameObject.transform.Translate(25f, 0.0f, 0.0f); // Add a light GameObject lightGameObject = new GameObject("Dialog Box Light"); Light lightComp = lightGameObject.AddComponent <Light>(); lightComp.color = new Color(0.4f, 0.4f, 0.4f); lightGameObject.transform.position = instructor.instructorCamera.transform.position; instructor.SetupAnimations(); } var instructorTexture = new RenderTexture(width, height, 8); instructor.instructorCamera.targetTexture = instructorTexture; instructor.instructorCamera.ResetAspect(); var initialHappyAnimations = new List <CharacterAnimationState>() { instructor.anim_true_thumbsUp, instructor.anim_true_thumbUp, instructor.anim_true_nodA, instructor.anim_true_nodB, instructor.anim_true_smileA, instructor.anim_true_smileB, }; var initialGrumpyAnimations = new List <CharacterAnimationState>() { instructor.anim_false_disagreeA, instructor.anim_false_disagreeB, instructor.anim_false_disagreeC, }; var vampingAnimations = new List <CharacterAnimationState>() { instructor.anim_idle_lookAround, instructor.anim_idle_sigh, instructor.anim_idle_wonder, instructor.anim_true_nodA, instructor.anim_true_nodB, instructor.anim_true_smileA, instructor.anim_true_smileB, }; // Give a short delay before playing the animation float nextAnimTime = Time.fixedTime + 0.3f; bool doneFirstYet = false; var random = new System.Random(); var guiImage = new DialogGUIImage(new Vector2(width, height), new Vector2(0, 0), Color.gray, instructorTexture); guiImage.OnUpdate = () => { // Play the animation if (nextAnimTime <= Time.fixedTime) { CharacterAnimationState nowPlaying; if (!doneFirstYet) { List <CharacterAnimationState> animationSet = isGoodNews ? initialHappyAnimations : initialGrumpyAnimations; nowPlaying = animationSet[random.Next(animationSet.Count)]; instructor.PlayEmote(nowPlaying); doneFirstYet = true; } else { nowPlaying = vampingAnimations[random.Next(vampingAnimations.Count)]; instructor.PlayEmote(nowPlaying, instructor.anim_idle, playSound: false); } nextAnimTime = Time.fixedTime + nowPlaying.clip.length + 1.0f; } }; return(guiImage); }
public override void OnGUI() { if (instructor == null) { instructor = ((GameObject)UnityEngine.Object.Instantiate(AssetBase.GetPrefab(name))).GetComponent <KerbalInstructor>(); instructorTexture = new RenderTexture(128, 128, 8); instructor.instructorCamera.targetTexture = instructorTexture; instructor.instructorCamera.ResetAspect(); // Remove the lights for Gene/Wernher Light mainlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "mainlight").FirstOrDefault(); if (mainlight != null) { UnityEngine.Object.Destroy(mainlight); } Light backlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "backlight").FirstOrDefault(); if (backlight != null) { UnityEngine.Object.Destroy(backlight); } offset += 25f; instructor.gameObject.transform.Translate(offset, 0.0f, 0.0f); // Add a light lightGameObject = new GameObject("Dialog Box Light"); Light lightComp = lightGameObject.AddComponent <Light>(); lightComp.color = new Color(0.4f, 0.4f, 0.4f); lightGameObject.transform.position = instructor.instructorCamera.transform.position; if (string.IsNullOrEmpty(characterName)) { characterName = Localizer.GetStringByTag(instructor.CharacterName); } instructor.SetupAnimations(); if (animation != null) { switch (animation.Value) { case Animation.idle: animState = instructor.anim_idle; break; case Animation.idle_lookAround: animState = instructor.anim_idle_lookAround; break; case Animation.idle_sigh: animState = instructor.anim_idle_sigh; break; case Animation.idle_wonder: animState = instructor.anim_idle_wonder; break; case Animation.true_thumbUp: animState = instructor.anim_true_thumbUp; break; case Animation.true_thumbsUp: animState = instructor.anim_true_thumbsUp; break; case Animation.true_nodA: animState = instructor.anim_true_nodA; break; case Animation.true_nodB: animState = instructor.anim_true_nodB; break; case Animation.true_smileA: animState = instructor.anim_true_smileA; break; case Animation.true_smileB: animState = instructor.anim_true_smileB; break; case Animation.false_disappointed: animState = instructor.anim_false_disappointed; break; case Animation.false_disagreeA: animState = instructor.anim_false_disagreeA; break; case Animation.false_disagreeB: animState = instructor.anim_false_disagreeB; break; case Animation.false_disagreeC: animState = instructor.anim_false_disagreeC; break; case Animation.false_sadA: animState = instructor.anim_false_sadA; break; } // Give a short delay before playing the animation nextAnimTime = Time.fixedTime + 0.3f; } } // Play the animation if (nextAnimTime <= Time.fixedTime) { instructor.PlayEmote(animState); animState.audioClip = null; nextAnimTime = Time.fixedTime + animState.clip.length; } GUILayout.BeginVertical(GUILayout.Width(128)); GUILayout.Box("", GUILayout.Width(128), GUILayout.Height(128)); if (Event.current.type == EventType.Repaint) { Rect rect = GUILayoutUtility.GetLastRect(); rect = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 2f); Graphics.DrawTexture(rect, instructorTexture, new Rect(0.0f, 0.0f, 1f, 1f), 124, 124, 124, 124, Color.white, PortraitRenderMaterial); } DisplayName(128); GUILayout.EndVertical(); }
public override void OnGUI() { if (instructor == null) { instructor = ((GameObject)UnityEngine.Object.Instantiate(AssetBase.GetPrefab(name))).GetComponent<KerbalInstructor>(); instructorTexture = new RenderTexture(128, 128, 8); instructor.instructorCamera.targetTexture = instructorTexture; instructor.instructorCamera.ResetAspect(); // Remove the lights for Gene/Wernher Light mainlight = instructor.GetComponentsInChildren<Light>(true).Where(l => l.name == "mainlight").FirstOrDefault(); if (mainlight != null) { UnityEngine.Object.Destroy(mainlight); } Light backlight = instructor.GetComponentsInChildren<Light>(true).Where(l => l.name == "backlight").FirstOrDefault(); if (backlight != null) { UnityEngine.Object.Destroy(backlight); } offset += 25f; instructor.gameObject.transform.Translate(offset, 0.0f, 0.0f); // Add a light lightGameObject = new GameObject("Dialog Box Light"); Light lightComp = lightGameObject.AddComponent<Light>(); lightComp.color = new Color(0.4f, 0.4f, 0.4f); lightGameObject.transform.position = instructor.instructorCamera.transform.position; if (string.IsNullOrEmpty(characterName)) { characterName = instructor.CharacterName; } instructor.SetupAnimations(); if (animation != null) { switch (animation.Value) { case Animation.idle: animState = instructor.anim_idle; break; case Animation.idle_lookAround: animState = instructor.anim_idle_lookAround; break; case Animation.idle_sigh: animState = instructor.anim_idle_sigh; break; case Animation.idle_wonder: animState = instructor.anim_idle_wonder; break; case Animation.true_thumbUp: animState = instructor.anim_true_thumbUp; break; case Animation.true_thumbsUp: animState = instructor.anim_true_thumbsUp; break; case Animation.true_nodA: animState = instructor.anim_true_nodA; break; case Animation.true_nodB: animState = instructor.anim_true_nodB; break; case Animation.true_smileA: animState = instructor.anim_true_smileA; break; case Animation.true_smileB: animState = instructor.anim_true_smileB; break; case Animation.false_disappointed: animState = instructor.anim_false_disappointed; break; case Animation.false_disagreeA: animState = instructor.anim_false_disagreeA; break; case Animation.false_disagreeB: animState = instructor.anim_false_disagreeB; break; case Animation.false_disagreeC: animState = instructor.anim_false_disagreeC; break; case Animation.false_sadA: animState = instructor.anim_false_sadA; break; } // Give a short delay before playing the animation nextAnimTime = Time.fixedTime + 0.3f; } } // Play the animation if (nextAnimTime <= Time.fixedTime) { instructor.PlayEmote(animState); animState.audioClip = null; nextAnimTime = Time.fixedTime + animState.clip.length; } GUILayout.BeginVertical(GUILayout.Width(128)); GUILayout.Box("", GUILayout.Width(128), GUILayout.Height(128)); if (Event.current.type == EventType.Repaint) { Rect rect = GUILayoutUtility.GetLastRect(); rect = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 2f); Graphics.DrawTexture(rect, instructorTexture, new Rect(0.0f, 0.0f, 1f, 1f), 124, 124, 124, 124, Color.white, PortraitRenderMaterial); } DisplayName(128); GUILayout.EndVertical(); }