Пример #1
0
    public void SpawnLevel()
    {
        currentLevel += 1;
        int        scaleMod = 1;
        GameObject nextLevelModel;

        UpdateSpawnChances();
        if (specialLevels.ContainsKey(currentLevel) && specialLevels[currentLevel].GetComponent <InfiniteLevel>().CanSpawn())
        {
            nextLevelModel = specialLevels[currentLevel];
        }
        else
        {
            if (Random.Range(0, 2) == 0)
            {
                scaleMod = -1;
            }

            nextLevelModel = possibleLevels[PickLevelToSpawn()];
        }

        InfiniteLevelGoal boundEnd    = null;
        Vector3           endPrevious = Vector3.zero;
        int minDepth = int.MaxValue;

        for (int levelIdx = 0; levelIdx < levels.Count; ++levelIdx)
        {
            for (int endIdx = 0; endIdx < levels[levelIdx].ends.Count; ++endIdx)
            {
                int currentDepth = levels[levelIdx].GetDepth();
                if (currentDepth < minDepth && levels[levelIdx].ends[endIdx].boundStart == null)
                {
                    minDepth    = currentDepth;
                    boundEnd    = levels[levelIdx].ends[endIdx];
                    endPrevious = levels[levelIdx].ends[endIdx].transform.position;
                }
            }
        }

        InfiniteLevel level  = nextLevelModel.GetComponent <InfiniteLevel>();
        Vector3       newPos = endPrevious - level.start.transform.localPosition;

        GameObject newLevel = Instantiate(nextLevelModel, newPos, Quaternion.identity);

        newLevel.GetComponentInChildren <InfiniteLevel>().levelNumber = currentLevel;
        newLevel.transform.SetParent(levelsRoot);
        newLevel.name = nextLevelModel.name + currentLevel;
        newLevel.transform.position  = newPos;
        boundEnd.boundStart          = newLevel.GetComponentInChildren <InfiniteLevelStart>();
        boundEnd.boundStart.boundEnd = boundEnd;
        if (scaleMod != 1)
        {
            newLevel.transform.localScale = new Vector3(scaleMod * newLevel.transform.localScale.x, newLevel.transform.localScale.y, newLevel.transform.localScale.z);
        }
    }
Пример #2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        CheckInitialize(property, label);


        var foldoutRect = position;

        foldoutRect.width -= 2 * 50;
        foldoutRect.height = 17f;
        EditorGUI.BeginChangeCheck();
        _foldout = EditorGUI.Foldout(foldoutRect, _foldout, label, true);
        if (EditorGUI.EndChangeCheck())
        {
            EditorPrefs.SetBool(label.text, _foldout);
        }

        float yPos = 17f;

        if (_foldout)
        {
            EditorGUI.LabelField(new Rect(new Vector2(position.position.x, position.position.y + yPos), new Vector2(position.size.x, 17f)), "Count: " + _dict.Count);
            yPos += 17f;
            EditorGUI.BeginChangeCheck();
            int        newIdx = EditorGUI.IntField(new Rect(new Vector2(position.position.x, position.position.y + yPos), new Vector2(position.size.x / 2, 17f)), _nextObject.Key);
            GameObject newObj = EditorGUI.ObjectField(new Rect(new Vector2(position.position.x + position.size.x / 2, position.position.y + yPos), new Vector2(position.size.x / 2, 17f)), _nextObject.Value, typeof(GameObject), false) as GameObject;
            if (EditorGUI.EndChangeCheck())
            {
                _nextObject = new KeyValuePair <int, GameObject>(newIdx, newObj);
                ValueChanged(property);
            }

            yPos += 20f;
            if (GUI.Button(new Rect(new Vector2(position.position.x + position.size.x * 0.1f, position.position.y + yPos), new Vector2(position.size.x * 0.8f, 17f)), "Add"))
            {
                if (_dict.ContainsKey(_nextObject.Key) == false)
                {
                    _dict.Add(_nextObject.Key, _nextObject.Value);
                    _orderedKeys.Add(_nextObject.Key);
                    ValueChanged(property);
                }
                else
                {
                    Debug.LogWarning("This dictionary already contains a value for key " + _nextObject.Key);
                }
                return;
            }
            yPos += 6;

            if (Event.current.keyCode == KeyCode.Return && changedKey.Key >= 0)
            {
                if (_orderedKeys.Contains(changedKey.Value))
                {
                    Debug.LogWarning("This dictionary already contains a value for key " + changedKey.Value);
                }
                else
                {
                    int oldValue = _orderedKeys[changedKey.Key];
                    _orderedKeys[changedKey.Key] = changedKey.Value;
                    _dict.Add(changedKey.Value, _dict[oldValue]);
                    _dict.Remove(oldValue);
                    changedKey = new KeyValuePair <int, int>(-1, -1);
                    ValueChanged(property);
                }
                return;
            }

            for (int keyOrder = 0; keyOrder < _orderedKeys.Count; ++keyOrder)
            {
                int        key = _orderedKeys[keyOrder];
                GameObject val = _dict[key];
                yPos += 18f;
                if (GUI.Button(new Rect(new Vector2(position.position.x, position.position.y + yPos), new Vector2(17f, 17f)), "-"))
                {
                    _dict.Remove(key);
                    _orderedKeys.RemoveAt(keyOrder);
                    ValueChanged(property);
                    return;
                }
                int newKey = EditorGUI.IntField(new Rect(new Vector2(position.position.x + 18f, position.position.y + yPos), new Vector2(position.size.x / 2 - 9f, 17f)), key);

                if (newKey != key)
                {
                    changedKey = new KeyValuePair <int, int>(keyOrder, newKey);
                }

                EditorGUI.BeginChangeCheck();
                GameObject newObject = EditorGUI.ObjectField(new Rect(new Vector2(position.position.x + position.size.x / 2 + 9f, position.position.y + yPos), new Vector2(position.size.x / 2 - 9f, 17f)), val, typeof(GameObject), false) as GameObject;
                if (EditorGUI.EndChangeCheck())
                {
                    _dict[key] = newObject;
                    ValueChanged(property);
                    return;
                }
            }
        }
    }