Example #1
0
        public override void DeserializeAssetData(NPCConversation conversation)
        {
            base.DeserializeAssetData(conversation);

            this.Audio = conversation.GetNodeData(this.ID).Audio;
            this.Icon  = conversation.GetNodeData(this.ID).Icon;

#if UNITY_EDITOR
            // If under V1.03, Load from database via GUID, so data is not lost for people who are upgrading
            if (conversation.Version < (int)eSaveVersion.V1_03)
            {
                if (this.Audio == null)
                {
                    if (!string.IsNullOrEmpty(AudioGUID))
                    {
                        string path = UnityEditor.AssetDatabase.GUIDToAssetPath(AudioGUID);
                        this.Audio = (AudioClip)UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(AudioClip));
                    }
                }

                if (this.Icon == null)
                {
                    if (!string.IsNullOrEmpty(IconGUID))
                    {
                        string path = UnityEditor.AssetDatabase.GUIDToAssetPath(IconGUID);
                        this.Icon = (Sprite)UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(Sprite));
                    }
                }
            }
#endif
        }
Example #2
0
        public override void SerializeAssetData(NPCConversation conversation)
        {
            base.SerializeAssetData(conversation);

            conversation.GetNodeData(this.ID).Audio = this.Audio;
            conversation.GetNodeData(this.ID).Icon  = this.Icon;
        }
        public override void PrepareForSerialization(NPCConversation conversation)
        {
            base.PrepareForSerialization(conversation);

            conversation.GetNodeData(this.ID).Audio = this.Audio;
            conversation.GetNodeData(this.ID).Icon  = this.Icon;
        }
Example #4
0
        //--------------------------------------
        // Public functions
        //--------------------------------------

        public void StartConversation(NPCConversation conversation)
        {
            m_conversation = conversation.Deserialize();
            if (OnConversationStarted != null)
            {
                OnConversationStarted.Invoke();
            }

            TurnOnUI();
            m_currentSpeech = m_conversation.Root;
            SetState(eState.TransitioningDialogueBoxOn);
        }
        public static bool OpenDialogue(int assetInstanceID, int line)
        {
            NPCConversation conversation = EditorUtility.InstanceIDToObject(assetInstanceID) as NPCConversation;

            if (conversation != null)
            {
                DialogueEditorWindow window = ShowWindow();
                window.LoadNewAsset(conversation);
                return(true);
            }
            return(false);
        }
Example #6
0
        public void StartConversationWithoutDeserialization(NPCConversation conversation)
        {
            m_conversation = conversation.RuntimeLoad();
            if (OnConversationStarted != null)
            {
                OnConversationStarted.Invoke();
            }

            TurnOnUI();
            ClearOptions();
            m_pendingDialogue = m_conversation.Root;
            SetState(eState.TransitioningDialogueBoxOn);
        }
        private void Save(bool manual = false)
        {
            if (CurrentAsset != null)
            {
                EditableConversation conversation = new EditableConversation();

                // Prepare each node for serialization
                for (int i = 0; i < uiNodes.Count; i++)
                {
                    uiNodes[i].Info.PrepareForSerialization(CurrentAsset);
                }

                // Now that each node has been prepared for serialization:
                // - Register the UIDs of their parents/children
                // - Add it to the conversation
                for (int i = 0; i < uiNodes.Count; i++)
                {
                    uiNodes[i].Info.RegisterUIDs();

                    if (uiNodes[i] is UISpeechNode)
                    {
                        conversation.SpeechNodes.Add((uiNodes[i] as UISpeechNode).SpeechNode);
                    }
                    else if (uiNodes[i] is UIOptionNode)
                    {
                        conversation.Options.Add((uiNodes[i] as UIOptionNode).OptionNode);
                    }
                }

                // Serialize
                CurrentAsset.Serialize(conversation);

                // Null / clear everything. We aren't pointing to it anymore.
                if (!manual)
                {
                    CurrentAsset = null;
                    while (uiNodes.Count != 0)
                    {
                        uiNodes.RemoveAt(0);
                    }
                    CurrentlySelectedNode = null;
                }

#if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
#endif
            }
        }
Example #8
0
        public virtual void DeserializeAssetData(NPCConversation conversation)
        {
            this.TMPFont = conversation.GetNodeData(this.ID).TMPFont;

#if UNITY_EDITOR
            // If under V1.03, Load from database via GUID, so data is not lost for people who are upgrading
            if (conversation.Version < (int)eSaveVersion.V1_03)
            {
                if (this.TMPFont == null)
                {
                    if (!string.IsNullOrEmpty(TMPFontGUID))
                    {
                        string path = UnityEditor.AssetDatabase.GUIDToAssetPath(TMPFontGUID);
                        this.TMPFont = (TMPro.TMP_FontAsset)UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(TMPro.TMP_FontAsset));
                    }
                }
            }
#endif
        }
        protected void OnFocus()
        {
            // Get asset the user is selecting
            newlySelectedAsset = Selection.activeTransform;

            // If it's not null
            if (newlySelectedAsset != null)
            {
                // If its a conversation scriptable, load new asset
                if (newlySelectedAsset.GetComponent <NPCConversation>() != null)
                {
                    currentlySelectedAsset = newlySelectedAsset.GetComponent <NPCConversation>();

                    if (currentlySelectedAsset != CurrentAsset)
                    {
                        LoadNewAsset(currentlySelectedAsset);
                    }
                }
            }
        }
        protected void OnSelectionChange()
        {
            // Get asset the user is selecting
            newlySelectedAsset = Selection.activeTransform;

            // If it's not null
            if (newlySelectedAsset != null)
            {
                // If it's a different asset and our current asset isn't null, save our current asset
                if (currentlySelectedAsset != null && currentlySelectedAsset != newlySelectedAsset)
                {
                    Log("Saving conversation. Reason: Different asset selected");
                    Save();
                    currentlySelectedAsset = null;
                }

                // If its a conversation scriptable, load new asset
                currentlySelectedAsset = newlySelectedAsset.GetComponent <NPCConversation>();
                if (currentlySelectedAsset != null && currentlySelectedAsset != CurrentAsset)
                {
                    LoadNewAsset(currentlySelectedAsset);
                }
                else
                {
                    CurrentAsset = null;
                    Repaint();
                }
            }
            else
            {
                Log("Saving conversation. Reason: Conversation asset de-selected");
                Save();

                CurrentAsset           = null;
                currentlySelectedAsset = null;
                Repaint();
            }
        }
        //--------------------------------------
        // Load New Asset
        //--------------------------------------

        public void LoadNewAsset(NPCConversation asset)
        {
            CurrentAsset = asset;
            Log("Loading new asset: " + CurrentAsset.name);

            // Clear all current UI Nodes
            uiNodes.Clear();

            // Deseralize the asset and get the conversation root
            EditableConversation conversation = CurrentAsset.DeserializeForEditor();

            if (conversation == null)
            {
                conversation = new EditableConversation();
            }
            ConversationRoot = conversation.GetRootNode();

            // If it's null, create a root
            if (ConversationRoot == null)
            {
                ConversationRoot = new EditableSpeechNode();
                ConversationRoot.EditorInfo.xPos   = (Screen.width / 2) - (UISpeechNode.Width / 2);
                ConversationRoot.EditorInfo.yPos   = 0;
                ConversationRoot.EditorInfo.isRoot = true;
                conversation.SpeechNodes.Add(ConversationRoot);
            }

            // Get a list of every node in the conversation
            List <EditableConversationNode> allNodes = new List <EditableConversationNode>();

            for (int i = 0; i < conversation.SpeechNodes.Count; i++)
            {
                allNodes.Add(conversation.SpeechNodes[i]);
            }
            for (int i = 0; i < conversation.Options.Count; i++)
            {
                allNodes.Add(conversation.Options[i]);
            }

            // For every node:
            // Find the children and parents by UID
            for (int i = 0; i < allNodes.Count; i++)
            {
                // Remove duplicate parent UIDs
                HashSet <int> noDupes = new HashSet <int>(allNodes[i].parentUIDs);
                allNodes[i].parentUIDs.Clear();
                foreach (int j in noDupes)
                {
                    allNodes[i].parentUIDs.Add(j);
                }

                allNodes[i].parents = new List <EditableConversationNode>();
                for (int j = 0; j < allNodes[i].parentUIDs.Count; j++)
                {
                    allNodes[i].parents.Add(conversation.GetNodeByUID(allNodes[i].parentUIDs[j]));
                }

                if (allNodes[i] is EditableSpeechNode)
                {
                    // Speech options
                    int count = (allNodes[i] as EditableSpeechNode).OptionUIDs.Count;
                    (allNodes[i] as EditableSpeechNode).Options = new List <EditableOptionNode>();
                    for (int j = 0; j < count; j++)
                    {
                        (allNodes[i] as EditableSpeechNode).Options.Add(
                            conversation.GetOptionByUID((allNodes[i] as EditableSpeechNode).OptionUIDs[j]));
                    }

                    // Speech following speech
                    (allNodes[i] as EditableSpeechNode).Speech = conversation.
                                                                 GetSpeechByUID((allNodes[i] as EditableSpeechNode).SpeechUID);
                }
                else if (allNodes[i] is EditableOptionNode)
                {
                    (allNodes[i] as EditableOptionNode).Speech =
                        conversation.GetSpeechByUID((allNodes[i] as EditableOptionNode).SpeechUID);
                }
            }

            // For every node:
            // 1: Create a corresponding UI Node to represent it, and add it to the list
            // 2: Tell any of the nodes children that the node is the childs parent
            for (int i = 0; i < allNodes.Count; i++)
            {
                EditableConversationNode node = allNodes[i];

                if (node is EditableSpeechNode)
                {
                    // 1
                    UISpeechNode uiNode = new UISpeechNode(node,
                                                           new Vector2(node.EditorInfo.xPos, node.EditorInfo.yPos));

                    uiNodes.Add(uiNode);

                    // 2
                    EditableSpeechNode speech = node as EditableSpeechNode;
                    if (speech.Options != null)
                    {
                        for (int j = 0; j < speech.Options.Count; j++)
                        {
                            speech.Options[j].parents.Add(speech);
                        }
                    }

                    if (speech.Speech != null)
                    {
                        speech.Speech.parents.Add(speech);
                    }
                }
                else
                {
                    // 1
                    UIOptionNode uiNode = new UIOptionNode(node,
                                                           new Vector2(node.EditorInfo.xPos, node.EditorInfo.yPos));

                    uiNodes.Add(uiNode);

                    // 2
                    EditableOptionNode option = node as EditableOptionNode;
                    if (option.Speech != null)
                    {
                        option.Speech.parents.Add(option);
                    }
                }
            }

            Recenter();
            Repaint();
#if UNITY_EDITOR
            UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
#endif
        }
Example #12
0
 public virtual void SerializeAssetData(NPCConversation conversation)
 {
     conversation.GetNodeData(this.ID).TMPFont = this.TMPFont;
 }
 public virtual void PrepareForSerialization(NPCConversation conversation)
 {
     conversation.GetNodeData(this.ID).TMPFont = this.TMPFont;
 }