Ejemplo n.º 1
0
 public void OnDestroy()
 {
     actionNamesIndexes = new List <int>();
     actionID1Indexes   = new List <int>();
     actionID2Indexes   = new List <int>();
     story = null;
     init  = null;
 }
Ejemplo n.º 2
0
    public void LoadHistory(StoryInfo sInfo, QuestInfo qInfo)
    {
        if (sInfo != null)
        {
            storyList = new List <Story>();
            foreach (string _storyName in sInfo.stories)
            {
                StoryInitializer init = FindInitializer(_storyName);
                if (init != null)
                {
                    storyList.Add(init.story);
                }
            }

            foreach (string _storyName in sInfo.completedStories)
            {
                StoryInitializer init = FindInitializer(_storyName);
                if (init != null)
                {
                    init.completed = true;
                }
            }
        }

        if (qInfo != null)
        {
            activeQuests = new List <Quest>();
            foreach (string questName in qInfo.quests)
            {
                Quest _quest = null;
                if ((_quest = SpecialFunctions.statistics.GetQuest(questName)) != null)
                {
                    activeQuests.Add(new Quest(_quest));
                }
                SpecialFunctions.gameUI.ConsiderQuests(activeQuests.ConvertAll <string>(x => x.questLine[x.stage]));
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Убрать игровой объект из участия в событии, вызываемом классом Story
    /// </summary>
    public void DeInitializeScript(Story _story)
    {
        StoryInitializer init = FindInitializer(_story);
        GameObject       obj  = init.eventReason;

        if (obj == null)
        {
            return;
        }

        //В первую очередь, отпишимся от журнальных объектов
        if (storyDeInitBase.ContainsKey(_story.storyCondition.storyConditionName))
        {
            string s = _story.storyCondition.storyConditionName;
            storyDeInitBase[s].Invoke(_story, obj);
        }

        foreach (StoryAction _action in _story.storyActions)
        {
            _action.storyAction = null;
        }

        _story.storyCondition.storyCondition = null;
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Подписка всех событий происходит здесь. Сделав правильную подписку, мы реализуем историю игры
    /// </summary>
    public void InitializeScript(Story _story)
    {
        GameObject storyTarget = null;

        StoryInitializer init = FindInitializer(_story);

        if (init == null)
        {
            return;
        }

        storyTarget = init.eventReason;

        if (storyTarget == null)
        {
            return;
        }

        //В первую очередь, подпишемся на сюжетные объекты объекты
        if (storyInitBase.ContainsKey(_story.storyCondition.storyConditionName))
        {
            string s = _story.storyCondition.storyConditionName;
            storyInitBase[s].Invoke(_story, storyTarget);
        }

        for (int i = 0; i < _story.storyActions.Count; i++)
        {
            if (i >= init.eventObjects.Count)
            {
                break;
            }
            StoryAction _action = _story.storyActions[i];

            GameObject obj = init.eventObjects[i];
            if (obj == null)
            {
                continue;
            }
            if (obj.GetComponent <GameHistory>() != null)
            {
                if (storyActionBase.ContainsKey(_action.actionName))
                {
                    string s = _action.actionName;
                    _action.storyAction = storyActionBase[s].Invoke;
                }
            }
            else if (obj.GetComponent <NPCController>() != null)
            {
                NPCController npc = obj.GetComponent <NPCController>();
                if (npc.StoryActionBase.ContainsKey(_action.actionName))
                {
                    string s = _action.actionName;
                    _action.storyAction = npc.StoryActionBase[s].Invoke;
                }
            }
            else if (obj.GetComponent <CharacterController>() != null)
            {
                CharacterController character = obj.GetComponent <CharacterController>();
                if (character.StoryActionBase.ContainsKey(_action.actionName))
                {
                    string s = _action.actionName;
                    _action.storyAction = character.StoryActionBase[s].Invoke;
                }
            }
        }

        if (storyConditionBase.ContainsKey(_story.storyCondition.conditionName))
        {
            string s = _story.storyCondition.conditionName;
            _story.storyCondition.storyCondition = storyConditionBase[s].Invoke;
        }
        else
        {
            _story.storyCondition.storyCondition = Empty;
        }
    }
Ejemplo n.º 5
0
    IHaveStory currentConditionObject = null;//Объект, который является инициатором сюжетного события

    public void OnEnable()
    {
        if (story == null)
        {
            story = (Story)target;
        }

        List <StoryInitializer> initList = null;

        if (GameObject.FindGameObjectWithTag("gameController") != null)
        {
            history = SpecialFunctions.history;
            if (history != null)
            {
                initList = history.InitList;
            }
        }

        if (story.storyActions == null)
        {
            story.storyActions = new List <StoryAction>();
            actionNamesIndexes = new List <int>();
            actionID1Indexes   = new List <int>();
            actionID2Indexes   = new List <int>();
        }
        if (story.presequences == null)
        {
            story.presequences = new List <Story>();
        }
        if (story.consequences == null)
        {
            story.consequences = new List <Story>();
        }
        if (story.nonConsequences == null)
        {
            story.nonConsequences = new List <Story>();;
        }
        if (story.storyCondition == null)
        {
            story.storyCondition = new StoryCondition();
        }

        sceneName = SceneManager.GetActiveScene().name;

        if (story.sceneName == SceneManager.GetActiveScene().name)
        {
            if (initList != null)
            {
                init = history.FindInitializer(story);
                if (init == null)
                {
                    init              = new StoryInitializer();
                    init.story        = story;
                    init.eventObjects = new List <GameObject>();
                    initList.Add(init);
                }
                if (init.eventObjects.Count != story.storyActions.Count)
                {
                    int m = init.eventObjects.Count;
                    for (int i = m; i < story.storyActions.Count; i++)
                    {
                        init.eventObjects.Add(null);
                    }
                    for (int i = m - 1; i >= story.storyActions.Count; i--)
                    {
                        init.eventObjects.RemoveAt(i);
                    }
                }
            }
        }

        #region reinitialize

        if (actionNamesIndexes.Count != story.storyActions.Count)
        {
            actionNamesIndexes = new List <int>();
            actionID1Indexes   = new List <int>();
            actionID2Indexes   = new List <int>();

            for (int i = 0; i < story.storyActions.Count; i++)
            {
                CheckGameObjectActions(story.storyActions[i], i);
            }
        }

        CheckGameObjectCondition(story.storyCondition);

        #endregion //reinitialize
    }
Ejemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        story.storyName = EditorGUILayout.TextField("story name", story.storyName);

        string newSceneName = EditorGUILayout.TextField("scene name", story.sceneName);

        if (newSceneName != story.sceneName)
        {
            story.sceneName = newSceneName;
            if (story.sceneName == sceneName)
            {
                if (history != null)
                {
                    init = history.FindInitializer(story);
                    if (init == null)
                    {
                        init              = new StoryInitializer();
                        init.story        = story;
                        init.eventObjects = new List <GameObject>();
                        history.initList.Add(init);
                    }
                    if (init.eventObjects.Count != story.storyActions.Count)
                    {
                        int m = init.eventObjects.Count;
                        for (int i = m; i < story.storyActions.Count; i++)
                        {
                            init.eventObjects.Add(null);
                        }
                        for (int i = m - 1; i >= story.storyActions.Count; i--)
                        {
                            init.eventObjects.RemoveAt(i);
                        }
                    }
                }
            }
        }


        EditorGUILayout.Space();

        #region storyActions

        EditorGUILayout.HelpBox("story actions", MessageType.Info);

        actionSize = story.storyActions.Count;
        actionSize = EditorGUILayout.IntField("action size", actionSize);
        if (actionSize != story.storyActions.Count)
        {
            int m = story.storyActions.Count;
            for (int i = m; i < actionSize; i++)
            {
                story.storyActions.Add(new StoryAction());
                CheckGameObjectActions(story.storyActions[i], i);
            }
            for (int i = m - 1; i >= actionSize; i--)
            {
                story.storyActions.RemoveAt(i);
                ChangeActionIndexesCount(-1);
            }
        }

        if (init != null? init.eventObjects.Count != story.storyActions.Count:false)
        {
            int m = init.eventObjects.Count;
            for (int i = m; i < story.storyActions.Count; i++)
            {
                init.eventObjects.Add(null);
            }
            for (int i = m - 1; i >= story.storyActions.Count; i--)
            {
                init.eventObjects.RemoveAt(i);
            }
        }

        for (int i = 0; i < story.storyActions.Count; i++)
        {
            StoryAction _action = story.storyActions[i];
            _action.storyActionName = EditorGUILayout.TextField("story action name", _action.storyActionName);

            GameObject actionObject = _action.gameObj;
            IHaveStory storyObject  = null;

            if (actionObject != null)
            {
                storyObject = actionObject.GetComponent <IHaveStory>();
            }

            if (storyObject != null)
            {
                int newActionIndex = EditorGUILayout.Popup(actionNamesIndexes[i], storyObject.actionNames().ToArray());
                if (newActionIndex != actionNamesIndexes[i])
                {
                    actionNamesIndexes[i] = newActionIndex;
                    _action.actionName    = storyObject.actionNames()[newActionIndex];

                    actionID1Indexes[i] = -1;
                    actionID2Indexes[i] = -1;
                    _action.id1         = string.Empty;
                    _action.id2         = string.Empty;
                }
            }
            _action.actionName = EditorGUILayout.TextField("action name", _action.actionName);

            if (storyObject != null? storyObject.actionIDs1().ContainsKey(_action.actionName):false)
            {
                List <string> IDs = storyObject.actionIDs1()[_action.actionName];
                if (IDs.Count > 0)
                {
                    int newIDIndex = EditorGUILayout.Popup(actionID1Indexes[i], IDs.ToArray());
                    if (newIDIndex != actionID1Indexes[i])
                    {
                        actionID1Indexes[i] = newIDIndex;
                        _action.id1         = IDs[newIDIndex];
                    }
                }
            }
            _action.id1 = EditorGUILayout.TextField("id1", _action.id1);

            if (storyObject != null ? storyObject.actionIDs2().ContainsKey(_action.actionName) : false)
            {
                List <string> IDs = storyObject.actionIDs2()[_action.actionName];
                if (IDs.Count > 0)
                {
                    int newIDIndex = EditorGUILayout.Popup(actionID2Indexes[i], IDs.ToArray());
                    if (newIDIndex != actionID2Indexes[i])
                    {
                        actionID2Indexes[i] = newIDIndex;
                        _action.id2         = IDs[newIDIndex];
                    }
                }
            }
            _action.id2 = EditorGUILayout.TextField("id2", _action.id2);

            _action.argument = EditorGUILayout.IntField("argument", _action.argument);

            GameObject newObj = (GameObject)EditorGUILayout.ObjectField("action object", _action.gameObj, typeof(GameObject), true);//с каким игровым объектом произвести действие
            if (newObj != null ? newObj != _action.gameObj : _action.gameObj != null)
            {
                _action.gameObj = newObj;
                CheckGameObjectActions(_action, i);

                if ((sceneName == story.sceneName) && (_action.gameObj != null))
                {
                    if (init != null)
                    {
                        init.eventObjects[story.storyActions.IndexOf(_action)] = _action.gameObj;
                    }
                }
            }

            if (GUILayout.Button("Delete"))
            {
                if (sceneName == story.sceneName)
                {
                    if (init != null)
                    {
                        init.eventObjects.RemoveAt(story.storyActions.IndexOf(_action));
                    }
                }
                story.storyActions.Remove(_action);
                actionNamesIndexes.RemoveAt(i);
                actionID1Indexes.RemoveAt(i);
                actionID2Indexes.RemoveAt(i);
            }

            EditorGUILayout.Space();
        }

        #endregion //storyActions

        EditorGUILayout.Space();

        #region presequences

        EditorGUILayout.HelpBox("presequences", MessageType.Info);
        EditorGUILayout.Space();

        presequencesSize = story.presequences.Count;
        presequencesSize = EditorGUILayout.IntField("presequences size", presequencesSize);
        if (presequencesSize != story.presequences.Count)
        {
            int m = story.presequences.Count;
            for (int i = m; i < presequencesSize; i++)
            {
                story.presequences.Add(null);
            }
            for (int i = m - 1; i >= presequencesSize; i--)
            {
                story.storyActions.RemoveAt(i);
            }
        }

        for (int i = 0; i < story.presequences.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            {
                story.presequences[i] = (Story)EditorGUILayout.ObjectField(story.presequences[i], typeof(Story));
                Story _presequence = story.presequences[i];
                if (_presequence != null)
                {
                    if (!_presequence.consequences.Contains(story))
                    {
                        _presequence.consequences.Add(story);
                    }
                    if (story.presequences.FindAll(x => (story.presequences.IndexOf(x) != i)).Contains(_presequence))
                    {
                        _presequence          = null;
                        story.presequences[i] = null;
                    }
                }
                if (GUILayout.Button("Delete"))
                {
                    if (_presequence != null)
                    {
                        DeletePresequence(story, _presequence);
                    }
                    else
                    {
                        story.presequences.RemoveAt(i);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();

        #endregion //presequences

        #region consequences

        EditorGUILayout.HelpBox("consequences", MessageType.Info);
        EditorGUILayout.Space();

        consequencesSize = story.consequences.Count;
        consequencesSize = EditorGUILayout.IntField("consequences size", consequencesSize);
        if (consequencesSize != story.consequences.Count)
        {
            int m = story.consequences.Count;
            for (int i = m; i < consequencesSize; i++)
            {
                story.consequences.Add(null);
            }
            for (int i = m - 1; i >= consequencesSize; i--)
            {
                story.consequences.RemoveAt(i);
            }
        }

        for (int i = 0; i < story.consequences.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            {
                story.consequences[i] = (Story)EditorGUILayout.ObjectField(story.consequences[i], typeof(Story));
                Story _consequence = story.consequences[i];
                if (_consequence != null)
                {
                    if (story.nonConsequences.Contains(_consequence))
                    {
                        story.nonConsequences.Remove(_consequence);
                    }
                    if (!_consequence.presequences.Contains(story))
                    {
                        _consequence.presequences.Add(story);
                    }
                    if (story.consequences.FindAll(x => (story.consequences.IndexOf(x) != i)).Contains(_consequence))
                    {
                        story.consequences[i] = null;
                        _consequence          = null;
                    }
                }
                if (GUILayout.Button("Delete"))
                {
                    if (_consequence != null)
                    {
                        DeleteConsequence(story, _consequence);
                    }
                    else
                    {
                        story.consequences.RemoveAt(i);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.Space();

        #endregion //consequences

        #region nonsequences

        EditorGUILayout.HelpBox("nonsequences", MessageType.Info);
        EditorGUILayout.Space();

        nonsequencesSize = story.nonConsequences.Count;
        nonsequencesSize = EditorGUILayout.IntField("nonConsequences size", nonsequencesSize);
        if (nonsequencesSize != story.nonConsequences.Count)
        {
            int m = story.nonConsequences.Count;
            for (int i = m; i < nonsequencesSize; i++)
            {
                story.nonConsequences.Add(null);
            }
            for (int i = m - 1; i >= nonsequencesSize; i--)
            {
                story.nonConsequences.RemoveAt(i);
            }
        }

        for (int i = 0; i < story.nonConsequences.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            {
                story.nonConsequences[i] = (Story)EditorGUILayout.ObjectField(story.nonConsequences[i], typeof(Story));
                Story _nonsequence = story.nonConsequences[i];
                if (_nonsequence != null)
                {
                    if (story.consequences.Contains(_nonsequence))
                    {
                        DeleteConsequence(story, _nonsequence);
                    }
                    if (story.nonConsequences.FindAll(x => (story.nonConsequences.IndexOf(x) != i)).Contains(_nonsequence))
                    {
                        story.nonConsequences[i] = null;
                        _nonsequence             = null;
                    }
                }
                if (GUILayout.Button("Delete"))
                {
                    story.nonConsequences.RemoveAt(i);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.Space();

        #endregion //nonsequences

        #region storyCondition

        EditorGUILayout.HelpBox("story condition", MessageType.Info);
        EditorGUILayout.Space();

        StoryCondition _condition = story.storyCondition;


        if (_condition.obj != null)
        {
            int newIndex = EditorGUILayout.Popup(initNameIndex, initNames.ToArray());
            if (newIndex != initNameIndex)
            {
                initNameIndex = newIndex;
                _condition.storyConditionName = initNames[newIndex];

                _condition.conditionName = string.Empty;
                _condition.id1           = string.Empty;
                conditionIDIndex         = -1;
                conditionNameIndex       = -1;
            }
        }
        _condition.storyConditionName = EditorGUILayout.TextField("story condition name", _condition.storyConditionName);

        if (_condition.obj != null)
        {
            int newIndex = EditorGUILayout.Popup(conditionNameIndex, conditionNames.ToArray());
            if (newIndex != conditionNameIndex)
            {
                conditionNameIndex       = newIndex;
                _condition.conditionName = conditionNames[newIndex];

                _condition.id1   = string.Empty;
                conditionIDIndex = -1;

                List <string> conditionTypes = SpecialFunctions.history.storyTypes;
                for (int i = 0; i < conditionTypes.Count; i++)
                {
                    Type conditionType = Type.GetType(conditionTypes[i]);
                    var  component     = _condition.obj.GetComponent(conditionType);
                    if (component != null && (component is IHaveStory))
                    {
                        IHaveStory storyObject = (IHaveStory)component;
                        if (storyObject.conditionIDs().ContainsKey(_condition.conditionName))
                        {
                            conditionIDs           = storyObject.conditionIDs()[_condition.conditionName];
                            currentConditionObject = storyObject;
                            break;
                        }
                    }
                }
            }
        }
        _condition.conditionName = EditorGUILayout.TextField("condition name", _condition.conditionName);

        if (_condition.obj != null && currentConditionObject != null)
        {
            int newIndex = EditorGUILayout.Popup(conditionIDIndex, conditionIDs.ToArray());
            if (newIndex != conditionIDIndex && conditionIDs.Count > 0)
            {
                conditionIDIndex = newIndex;
                _condition.id1   = conditionIDs[newIndex];
            }
        }
        _condition.id1 = EditorGUILayout.TextField("id", _condition.id1);

        if (_condition.obj != null && currentConditionObject != null)
        {
            int newIndex = EditorGUILayout.Popup(conditionID2Index, conditionIDs2.ToArray());
            if (newIndex != conditionID2Index)
            {
                conditionID2Index = newIndex;
                _condition.id2    = conditionIDs2[newIndex];
            }
        }
        _condition.id2 = EditorGUILayout.TextField("id2", _condition.id2);

        _condition.argument = EditorGUILayout.IntField("argument", _condition.argument);

        GameObject newObj1 = (GameObject)EditorGUILayout.ObjectField("condition object", _condition.obj, typeof(GameObject), true);
        if (newObj1 != null ? newObj1 != _condition.obj : _condition.obj != null)
        {
            _condition.obj = newObj1;
            CheckGameObjectCondition(_condition);

            if ((sceneName == story.sceneName) && (_condition.obj != null))
            {
                if (init != null)
                {
                    init.eventReason = _condition.obj;
                }
            }
        }
        #endregion//storyCondition

        story.SetDirty();
        if (history != null)
        {
            EditorUtility.SetDirty(SpecialFunctions.gameController.GetComponent <GameHistory>());
        }
    }