private Sprite GetPortraitByActorName(string actorName, Actor actor) { // Also suppress logging for Lua return Actor[].Current_Portrait. var originalDebugLevel = DialogueDebug.level; DialogueDebug.level = DialogueDebug.DebugLevel.Warning; string imageName = DialogueLua.GetActorField(actorName, DialogueSystemFields.CurrentPortrait).asString; DialogueDebug.level = originalDebugLevel; if (string.IsNullOrEmpty(imageName)) { return((actor != null) ? actor.GetPortraitSprite(): null); } else if (imageName.StartsWith("pic=")) { if (actor == null) { return(null); } else { return(actor.GetPortraitSprite(Tools.StringToInt(imageName.Substring("pic=".Length)))); } } else { return(UITools.CreateSprite(DialogueManager.LoadAsset(imageName) as Texture2D)); } }
private Texture2D GetPortraitByActorName(string actorName) { // Also suppress logging for Lua return Actor[].Current_Portrait. var originalDebugLevel = DialogueDebug.Level; DialogueDebug.Level = DialogueDebug.DebugLevel.Warning; string textureName = DialogueLua.GetActorField(actorName, "Current Portrait").AsString; DialogueDebug.Level = originalDebugLevel; if (string.IsNullOrEmpty(textureName)) { return(null); } else if (textureName.StartsWith("pic=")) { Actor actor = database.GetActor(actorName); if (actor == null) { return(null); } else { return(actor.GetPortraitTexture(Tools.StringToInt(textureName.Substring("pic=".Length)))); } } else { return(DialogueManager.LoadAsset(textureName) as Texture2D); } }
/// <summary> /// Returns the actor's current portrait sprite. /// </summary> public Sprite GetPortraitSprite() { //--- Was: return UITools.GetSprite(portrait, spritePortrait); //--- Instead, check for override set by SetPortrait(): var originalDebugLevel = DialogueDebug.level; // Suppress logging for Lua return Actor[].Current_Portrait. DialogueDebug.level = DialogueDebug.DebugLevel.Warning; string imageName = DialogueLua.GetActorField(Name, DialogueSystemFields.CurrentPortrait).asString; DialogueDebug.level = originalDebugLevel; if (string.IsNullOrEmpty(imageName)) { return(GetPortraitSprite(1)); } else if (imageName.StartsWith("pic=")) { return(GetPortraitSprite(Tools.StringToInt(imageName.Substring("pic=".Length)))); } else { var sprite = GetPortraitSprite(imageName); return((sprite != null) ? sprite : UITools.CreateSprite(DialogueManager.LoadAsset(imageName) as Texture2D)); } }
/// <summary> /// Listens for the OnApplyPersistentData message and retrieves the current bark index. /// </summary> public void OnApplyPersistentData() { if (enabled) { barkHistory.index = DialogueLua.GetActorField(GetBarkerName(), "Bark_Index").AsInt; } }
/// <summary> /// Listens for the OnApplyPersistentData message and retrieves the current bark index. /// </summary> public void OnApplyPersistentData() { if (enabled && !string.IsNullOrEmpty(barkConversation)) { if (barkHistory == null) { barkHistory = new BarkHistory(barkOrder); } barkHistory.index = DialogueLua.GetActorField(GetBarkerName(), "Bark_Index").asInt; } }
/// <summary> /// Listens for the OnApplyPersistentData message and retrieves the current bark index. /// </summary> public void OnApplyPersistentData() { if (enabled) { if (barkHistory == null) { barkHistory = new BarkHistory(barkOrder); } barkHistory.index = DialogueLua.GetActorField(GetBarkerName(), "Bark_Index").asInt; } }
/// <summary> /// Listens for the OnApplyPersistentData message and retrieves the game object's position /// and rotation from the Lua Actor[] table. /// </summary> public void OnApplyPersistentData() { string spawnpointName = DialogueLua.GetActorField(actorName, "Spawnpoint").asString; if (!string.IsNullOrEmpty(spawnpointName)) { var spawnpoint = Tools.GameObjectHardFind(spawnpointName); if (spawnpoint == null) { if (DialogueDebug.logWarnings) { Debug.LogWarning("Dialogue System: Persistent Position Data found Actor[" + actorName + "].Spawnpoint value '" + spawnpointName + "' but can't find a GameObject with this name in the scene. Moving actor to saved position instead.", this); } } else { transform.position = spawnpoint.transform.position; transform.rotation = spawnpoint.transform.rotation; if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: Persistent Position Data spawning " + actorName + " at spawnpoint " + spawnpoint, this); } } DialogueLua.SetActorField(actorName, "Spawnpoint", string.Empty); if (spawnpoint != null) { return; } } var fieldName = recordCurrentLevel ? "Position_" + SanitizeLevelName(Tools.loadedLevelName) : "Position"; var positionString = DialogueLua.GetActorField(actorName, fieldName).asString; if (!string.IsNullOrEmpty(positionString)) { if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: Persistent Position Data restoring " + actorName + " to position " + positionString, this); } ApplyPositionString(positionString); } else { if (DialogueDebug.logInfo) { Debug.Log("Dialogue System: Persistent Position Data Actor[" + actorName + "]." + fieldName + " is blank. Not moving " + actorName, this); } } }
/// <summary> /// Listens for the OnApplyPersistentData message and retrieves the game object's position /// and rotation from the Lua Actor[] table. /// </summary> public void OnApplyPersistentData() { string s = string.Empty; if (restoreCurrentLevelPosition) { s = DialogueLua.GetActorField(actorName, "Position_" + Application.loadedLevelName).AsString; } if (string.IsNullOrEmpty(s) || string.Equals(s, "nil")) { s = DialogueLua.GetActorField(actorName, "Position").AsString; } if (!string.IsNullOrEmpty(s)) { ApplyPositionString(s); } }
/// <summary> /// Gets the name to use for this DialogueActor, including parsing if it contains a [lua] /// or [var] tag. /// </summary> /// <returns>The name to use, or <c>null</c> if not set.</returns> public string GetActorName() { var actorName = string.IsNullOrEmpty(actor) ? name : actor; var result = CharacterInfo.GetLocalizedDisplayNameInDatabase(DialogueLua.GetActorField(actorName, "Name").asString); if (!string.IsNullOrEmpty(result)) { actorName = result; } if (actorName.Contains("[lua") || actor.Contains("[var")) { return(FormattedText.Parse(actorName, DialogueManager.masterDatabase.emphasisSettings).text); } else { return(actorName); } }
public void AssignPortraitSprite(AssignSpriteDelegate assignSprite) { var originalDebugLevel = DialogueDebug.level; // Suppress logging for Lua return Actor[].Current_Portrait. DialogueDebug.level = DialogueDebug.DebugLevel.Warning; string imageName = DialogueLua.GetActorField(Name, DialogueSystemFields.CurrentPortrait).asString; DialogueDebug.level = originalDebugLevel; if (string.IsNullOrEmpty(imageName)) { assignSprite(GetPortraitSprite(1)); } else if (imageName.StartsWith("pic=")) { assignSprite(GetPortraitSprite(Tools.StringToInt(imageName.Substring("pic=".Length)))); } else { DialogueManager.LoadAsset(imageName, typeof(Texture2D), (asset) => { assignSprite(UITools.CreateSprite(asset as Texture2D)); }); } }