Exemple #1
0
    /// <summary>
    /// Проверить, соответствует ли текущее сюжетное действие объекту, над которым это действие совершается
    /// </summary>
    public void CheckGameObjectActions(StoryAction sAction, int actionIndex)
    {
        if (actionNamesIndexes.Count < actionIndex)
        {
            return;
        }

        else if (actionNamesIndexes.Count == actionIndex)
        {
            ChangeActionIndexesCount(1);
        }

        GameObject actionObject = sAction.gameObj;

        if (actionObject == null)
        {
            actionNamesIndexes[actionIndex] = -1;
            actionID1Indexes[actionIndex]   = -1;
            actionID2Indexes[actionIndex]   = -1;
        }
        else
        {
            IHaveStory storyObject = actionObject.GetComponent <IHaveStory>();
            if (storyObject == null)
            {
                actionNamesIndexes[actionIndex] = -1;
                actionID1Indexes[actionIndex]   = -1;
                actionID2Indexes[actionIndex]   = -1;
            }
            else
            {
                if (storyObject.actionNames().Contains(sAction.actionName))
                {
                    actionNamesIndexes.Add(storyObject.actionNames().IndexOf(sAction.actionName));
                    List <string> id1List = storyObject.actionIDs1()[sAction.actionName], id2List = storyObject.actionIDs2()[sAction.actionName];
                    if (id1List.Contains(sAction.id1))
                    {
                        actionID1Indexes[actionIndex] = id1List.IndexOf(sAction.id1);
                    }
                    else if (id1List.Count > 0)
                    {
                        actionID1Indexes[actionIndex] = -1;
                        sAction.id1 = string.Empty;
                    }

                    if (id2List.Contains(sAction.id2))
                    {
                        actionID2Indexes[actionIndex] = id2List.IndexOf(sAction.id2);
                    }
                    else if (id2List.Count > 0)
                    {
                        actionID2Indexes[actionIndex] = -1;
                        sAction.id2 = string.Empty;
                    }
                }
                else
                {
                    actionNamesIndexes[actionIndex] = -1;
                    actionID1Indexes[actionIndex]   = -1;
                    actionID2Indexes[actionIndex]   = -1;
                    sAction.actionName = string.Empty;
                    sAction.id1        = string.Empty;
                    sAction.id2        = string.Empty;
                }
            }
        }
    }
Exemple #2
0
    public override void OnInspectorGUI()
    {
        story.storyName = EditorGUILayout.TextField("story name", story.storyName);

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

        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.id            = 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.id    = 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.id    = conditionIDs[newIndex];
            }
        }
        _condition.id = EditorGUILayout.TextField("id", _condition.id);

        _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>());
        }
    }