Exemplo n.º 1
0
    void Awake()
    {
        Instance    = this;
        trackLength = spline.CalculateLength();
        // bestReplayHandler = GameReplaySaver.INSTANCE.Load();
        // if (bestReplayHandler != null && !bestReplayHandler.IsEmpty()) {
        //  bestCar = Instantiate(carPrefab, Vector3.zero, Quaternion.identity);
        //  showReplay = true;
        // } else {
        //  // UIController.INSTANCE.DisableEnemyProgress();
        // }

        // var shapes = new List<List<Vector3>>();
        // for (int i = 0; i < 4; i++) {
        //  var vertecies = meshInformer.GetVertecies(i);
        //  shapes.Add(vertecies);
        // }

//		for (int i = 0; i < 4; i++) {
//			var mesh = MeshCreator.extrudeAlongPath(meshPath, trackWidth, shapes[i]);
//			var meshFilter = GameObject.Find("Track" + i).GetComponent<MeshFilter>();
//			meshFilter.mesh = mesh;
//			AssetDatabase.CreateAsset(meshFilter.mesh, "Assets/Objects/mesh" + i + ".asset");
//			AssetDatabase.SaveAssets();
//		}
    }
Exemplo n.º 2
0
    private void Generate()
    {
        data = new List <RoadEntityData>();
        var    isTutorial        = PlayerDataHolder.GetTutorial() == 0;
        var    length            = roadSpline.CalculateLength();
        double percentLength     = length / 100;
        var    percent           = percentLength / length;
        var    randomDist        = DistanceToPercent(Random.Range(minDistance, maxDistance));
        var    randomDistPercent = (int)(randomDist * 100);
        var    i = isTutorial ? tutorialEndPercent : startBarriersPercent;

        for (; i < 98; i += randomDistPercent)
        {
            if (randomDist > DistanceToPercent(maxDistance - 25))
            {
                // 70% chanse to spawn coins on long road sector
                var randomInt = Random.Range(0, 100);
                if (randomInt > 30)
                {
                    var moneyPercent = 0.0;
                    for (var j = 0; j < countOfRoads; j++)
                    {
                        moneyPercent = percent * (i + randomDistPercent / 2);
                        GenerateRingsOnRoad((float)moneyPercent, 0, 10, j);
                    }
                    var entityData = new RoadEntityData {
                        entityType = EntityType.Coins, percentAtRoad = (float)moneyPercent, height = 0, roadCount = countOfRoads
                    };
                    AddData(entityData);
                }
            }
            var splineOnPercent = roadSpline.Evaluate(percent * i);
            //if (levelHolder.InDeathLoops((float)(percent * i))) continue;
            var position = splineOnPercent.position;
            var rotation = splineOnPercent.rotation;
            GenerateEnemyOrBarrier(percent * i);
            randomDist        = DistanceToPercent(Random.Range(minDistance, maxDistance));
            randomDistPercent = (int)(randomDist * 100);
        }
    }
Exemplo n.º 3
0
    public SplineComputer CalculateMainRailway()
    {
        Debug.Log("<color=red>CalculateMainRailway</color>");
        mainRailway = allRailways[0];
        foreach (var railway in allRailways)
        {
            if (railway.CalculateLength() > mainRailway.CalculateLength())
            {
                mainRailway = railway;
            }
        }

        return(mainRailway);
    }
Exemplo n.º 4
0
            //Travel the spline segment while not exceeding the "max" percent
            //It also supports looping splines unlike the standard Travel methods found in SplineComputer and SplineUser
            double TravelClamped(double percent, float distance, Spline.Direction direction, double max, out float moved, bool loop)
            {
                moved = 0f;
                float  traveled = 0f;
                double result   = spline.Travel(percent, distance, out traveled, direction);

                moved += traveled;
                if (loop && moved < distance)
                {
                    if (direction == Spline.Direction.Forward && Mathf.Approximately((float)result, 1f))
                    {
                        result = spline.Travel(0.0, distance - moved, out traveled, direction);
                    }
                    else if (direction == Spline.Direction.Backward && Mathf.Approximately((float)result, 0f))
                    {
                        result = spline.Travel(1.0, distance - moved, out traveled, direction);
                    }
                    moved += traveled;
                }
                if (direction == Spline.Direction.Forward && percent <= max)
                {
                    if (result > max)
                    {
                        moved -= spline.CalculateLength(result, max);
                        result = max;
                    }
                }
                else if (direction == Spline.Direction.Backward && percent >= max)
                {
                    if (result < max)
                    {
                        moved -= spline.CalculateLength(max, result);
                        result = max;
                    }
                }
                return(result);
            }
Exemplo n.º 5
0
    void GenerateStair()
    {
        float stairSize = stairPrefab.transform.localScale.z * stairPrefab.GetComponent <BoxCollider>().size.z;

        float pathLenght = splineComputer.CalculateLength();

        float P = 0;

        SplineResult stairResult = splineComputer.Evaluate(0);

        GameObject obj = Instantiate(stairPrefab);

        obj.transform.position         = stairResult.position;
        obj.transform.rotation         = stairResult.rotation;
        obj.transform.localEulerAngles = new Vector3(0, obj.transform.localEulerAngles.y, obj.transform.localEulerAngles.z);


        Vector3 currentPos = obj.transform.position;

        while (P < 1)
        {
            P += 0.001f;

            stairResult = splineComputer.Evaluate(P);

            float distance = Vector3.Distance(stairResult.position, currentPos);

            if (distance >= stairSize)
            {
                obj = Instantiate(stairPrefab);

                obj.transform.position = stairResult.position;
                obj.transform.rotation = stairResult.rotation;


                obj.transform.localEulerAngles = new Vector3(0, obj.transform.localEulerAngles.y, obj.transform.localEulerAngles.z);

                currentPos = obj.transform.position;
            }
        }
    }
        void DrawTriggerGUI(int index, int groupIndex, SerializedProperty groupProperty)
        {
            bool               isSelected       = selected == index && selectedGroup == groupIndex;
            TriggerGroup       group            = spline.triggerGroups[groupIndex];
            SplineTrigger      trigger          = group.triggers[index];
            SerializedProperty triggersProperty = groupProperty.FindPropertyRelative("triggers");
            SerializedProperty triggerProperty  = triggersProperty.GetArrayElementAtIndex(index);
            SerializedProperty eventProperty    = triggerProperty.FindPropertyRelative("onCross");
            SerializedProperty positionProperty = triggerProperty.FindPropertyRelative("position");
            SerializedProperty colorProperty    = triggerProperty.FindPropertyRelative("color");
            SerializedProperty nameProperty     = triggerProperty.FindPropertyRelative("name");
            SerializedProperty enabledProperty  = triggerProperty.FindPropertyRelative("enabled");
            SerializedProperty workOnceProperty = triggerProperty.FindPropertyRelative("workOnce");
            SerializedProperty typeProperty     = triggerProperty.FindPropertyRelative("type");

            Color col = colorProperty.colorValue;

            if (isSelected)
            {
                col.a = 1f;
            }
            else
            {
                col.a = 0.6f;
            }
            GUI.backgroundColor = col;

            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUI.backgroundColor = Color.white;
            if (trigger == null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("NULL");
                if (GUILayout.Button("x"))
                {
                    ArrayUtility.RemoveAt(ref group.triggers, index);
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
                return;
            }


            if (isSelected && renameTrigger)
            {
                if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter))
                {
                    renameTrigger = false;
                    Repaint();
                }
                nameProperty.stringValue = EditorGUILayout.TextField(nameProperty.stringValue);
            }
            else
            {
                EditorGUILayout.LabelField(nameProperty.stringValue);
            }

            if (isSelected)
            {
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(enabledProperty);
                EditorGUILayout.PropertyField(colorProperty);

                EditorGUILayout.BeginHorizontal();
                positionProperty.floatValue = EditorGUILayout.Slider("Position", positionProperty.floatValue, 0f, 1f);
                if (GUILayout.Button("Set Distance", GUILayout.Width(85)))
                {
                    DistanceWindow w = EditorWindow.GetWindow <DistanceWindow>(true);
                    w.Init(OnSetDistance, spline.CalculateLength());
                    setDistanceGroup   = groupIndex;
                    setDistanceTrigger = index;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.PropertyField(typeProperty);
                EditorGUILayout.PropertyField(workOnceProperty);

                EditorGUILayout.PropertyField(eventProperty);
            }
            EditorGUILayout.EndVertical();

            Rect lastRect = GUILayoutUtility.GetLastRect();

            if (lastRect.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown)
            {
                if (Event.current.button == 0)
                {
                    Select(groupIndex, index);
                }
                else if (Event.current.button == 1)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Deselect"), false, delegate { Select(-1, -1); });
                    menu.AddItem(new GUIContent("Rename"), false, delegate { Select(groupIndex, index); renameTrigger = true; renameGroup = false; });
                    if (index > 0)
                    {
                        menu.AddItem(new GUIContent("Move Up"), false, delegate {
                            RecordUndo("Move Trigger Up");
                            SplineTrigger temp        = group.triggers[index - 1];
                            group.triggers[index - 1] = trigger;
                            group.triggers[index]     = temp;
                            selected--;
                            renameTrigger = false;
                        });
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Move Up"));
                    }
                    if (index < group.triggers.Length - 1)
                    {
                        menu.AddItem(new GUIContent("Move Down"), false, delegate {
                            RecordUndo("Move Trigger Down");
                            SplineTrigger temp        = group.triggers[index + 1];
                            group.triggers[index + 1] = trigger;
                            group.triggers[index]     = temp;
                            selected--;
                            renameTrigger = false;
                        });
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Move Down"));
                    }

                    menu.AddItem(new GUIContent("Duplicate"), false, delegate {
                        RecordUndo("Duplicate Trigger");
                        SplineTrigger newTrigger = new SplineTrigger(SplineTrigger.Type.Double);
                        newTrigger.color         = colorProperty.colorValue;
                        newTrigger.enabled       = enabledProperty.boolValue;
                        newTrigger.position      = positionProperty.floatValue;
                        newTrigger.type          = (SplineTrigger.Type)typeProperty.intValue;
                        newTrigger.name          = "Trigger " + (group.triggers.Length + 1);
                        ArrayUtility.Add(ref group.triggers, newTrigger);
                        Select(groupIndex, group.triggers.Length - 1);
                    });
                    menu.AddItem(new GUIContent("Delete"), false, delegate {
                        RecordUndo("Delete Trigger");
                        ArrayUtility.RemoveAt(ref group.triggers, index);
                        Select(-1, -1);
                    });
                    menu.ShowAsContext();
                }
            }
        }
Exemplo n.º 7
0
    public void InitScene()
    {
        currentPatternIndex         = 0;
        currentPatternSpawnedAmount = 0;

        stairControllers.Clear();


        float stairSize = StairPrefab.transform.localScale.z * StairPrefab.GetComponent <BoxCollider>().size.z - 0.1f;

        stairWidth = stairSize;
        float pathLenght = splineComputer.CalculateLength();

        float P = 0;

        SplineResult stairResult = splineComputer.Evaluate(0);

        int i = 0;

        GameObject obj = Instantiate(StairPrefab);

        obj.transform.position         = stairResult.position;
        obj.transform.rotation         = stairResult.rotation;
        obj.transform.localEulerAngles = new Vector3(0, obj.transform.localEulerAngles.y, obj.transform.localEulerAngles.z);

        StairController stairController = obj.GetComponent <StairController>();

        stairController.InitStair(i, GameManager.self.colorManager.GetStairColor(i));

        stairControllers.Add(stairController);

        Vector3 currentPos = obj.transform.position;


        while (P < 1)
        {
            P += 0.001f;

            stairResult = splineComputer.Evaluate(P);

            float distance = Vector3.Distance(stairResult.position, currentPos);

            if (distance >= stairSize)
            {
                obj = Instantiate(StairPrefab);

                obj.transform.position = stairResult.position;
                obj.transform.rotation = stairResult.rotation;


                obj.transform.localEulerAngles = new Vector3(0, obj.transform.localEulerAngles.y, obj.transform.localEulerAngles.z);

                currentPos = obj.transform.position;


                stairController = obj.GetComponent <StairController>();
                i += 1;
                stairController.InitStair(i, GameManager.self.colorManager.GetStairColor(i));

                stairControllers.Add(stairController);
            }
        }

        int lastIndex = stairControllers.Count - 1;

        FinishContainer.position = stairControllers[lastIndex].transform.position;
        stairControllers[lastIndex].isLastStair = true;

        StairsAmount = stairControllers.Count;

        for (int j = 0; j < stairControllers.Count; j++)
        {
            stairControllers[j].SetParameters(StairPatterns(j));
            stairControllers[j].DoMovement();
        }
    }
Exemplo n.º 8
0
 void GetSplineLength()
 {
     length = Mathf.RoundToInt(spline.CalculateLength() * 100f) / 100f;
 }
Exemplo n.º 9
0
    void EndOfDraw()
    {
        if (spline == null)
        {
            return;
        }
        var prevLength = SplineLength;

        SplineLength = spline.CalculateLength();
        if (SplineLength < 0.01)
        {
            SplineLength = prevLength;
            return;
        }
        double  travel = spline.Travel(0, SplineLength / 2f);
        Vector3 middle = spline.EvaluatePosition(travel);



        if ((points[0].position.x < 0 && points[0].position.z >= -14f) && (points[pointCount - 1].position.x >= 1 && points[pointCount - 1].position.z <= -15))
        {
            Direction = "Right";
        }
        else if ((points[0].position.x > 0 && points[0].position.z >= -14f) && (points[pointCount - 1].position.x <= 1 && points[pointCount - 1].position.z <= -15))
        {
            Direction = "Left";
        }
        else
        {
            if (middle.x > 1f)
            {
                Direction = "Right";
            }
            else if (middle.x < -1f)
            {
                Direction = "Left";
            }
            else
            {
                Direction = "Forward";
            }
        }



        //Make disable all children of wingsPoint
        if (WingsPoint.transform.childCount != 0)
        {
            for (int i = 0; i < WingsPoint.transform.childCount; i++)
            {
                Destroy(WingsPoint.transform.GetChild(i).gameObject);
            }
        }


        Transform player = WingsPoint.GetComponentInParent <Transform>();


        GameObject transporter = (GameObject)Instantiate(DrawObjPref, closest, Quaternion.identity);

        if (createdDrawObj.GetComponent <MeshCollider>() == null)
        {
            createdDrawObj.AddComponent <MeshCollider>().convex = true;
        }
        else
        {
            createdDrawObj.GetComponent <MeshCollider>().convex = true;
        }
        createdDrawObj.AddComponent <WingCrashController>();
        createdDrawObj.transform.parent = transporter.transform;
        //createdDrawObj.transform.localPosition = Vector3.zero;

        transporter.transform.position = WingsPoint.transform.position;

        transporter.transform.rotation      = WingsPoint.GetComponentInParent <Transform>().rotation;
        transporter.transform.parent        = WingsPoint.transform;
        transporter.transform.localPosition = Vector3.zero;
        createdDrawObj.GetComponent <MeshRenderer>().enabled = true;
        isDrawComeFromOutside = true;


        Destroy(m_currentRenderer);
        Destroy(splineMesh);
        Destroy(spline);

        EventManager.FirstDrawExist.Invoke();
    }