示例#1
0
    void SpawnNewObstacleSet(float refY)
    {
        int  setID     = Random.Range(0, obstacleSets.Count);
        bool isReverse = false;

        if (Random.Range(0, 2) == 0)
        {
            isReverse = true;
        }
        Debug.Log("Spawning Set " + setID);
        ObstacleSet oSet = obstacleSets[setID];

        foreach (ObstacleData oData in oSet.obstacles)
        {
            float revX = oData.x;
            if (isReverse)
            {
                revX = rocket.gameObject.GetComponent <RocketManager3> ().worldXMax + rocket.gameObject.GetComponent <RocketManager3> ().worldXMin - oData.x;
            }
            GameObject spawnedObs = (GameObject)Instantiate(ObstacleLookUp[oData.type].gameObject, new Vector3(revX, oData.y + refY + lengthBetweenSets, 0), Quaternion.identity);
            if (isReverse)
            {
                spawnedObs.transform.localScale = new Vector3(-spawnedObs.transform.localScale.x, spawnedObs.transform.localScale.y, spawnedObs.transform.localScale.z);
            }
            spawnedObs.transform.SetParent(transform);
            spawnedObs.AddComponent <Lifetime> ();
            lastY = Mathf.Max(lastY, oData.y + refY + lengthBetweenSets);
        }
    }
示例#2
0
    public void SpawnRandomSet(float weight)
    {
        if (obstacles.Count > 0)
        {
            if (max_rarity == 0)
            {
                max_rarity = 0;
                foreach (ObstacleSet ob in obstacles)
                {
                    max_rarity += ob.rarity;
                }
            }

            ObstacleSet selected = null;
            float       rand     = Random.Range(0, max_rarity);
            int         count    = -1;
            while (rand > 0)
            {
                count++;
                rand    -= obstacles[count].rarity;
                selected = obstacles[count];
            }

            GameObject new_obstacles = Instantiate(selected.obstacles);

            new_obstacles.transform.SetParent(transform, false);
        }
    }
示例#3
0
    void Initialize(List <Vector3> Path)
    {
        PlayerPrefs.SetInt("Points", 0);
        PlayerPrefs.SetInt("Collision", 0);
        float D = CalculateDistance(Path);

        PlayerPrefs.SetString("StartTime", System.DateTime.Now.ToString());
        FilePath = Application.dataPath + "/Resources/Records/" + PlayerPrefs.GetInt("UserID").ToString() + "-" + Round + ".txt";
        PlayerPrefs.SetString("FilePath", FilePath);
        if (!File.Exists(FilePath))
        {
            //Directory.CreateDirectory(Application.dataPath + "/Resources/Records/" + PlayerPrefs.GetInt("UserID").ToString() + "/" + TaskID + ".txt");
            File.WriteAllText(FilePath, "TaskID: " + Round.ToString() + " \n" + "StartTime: " + PlayerPrefs.GetString("StartTime")
                              + PlayerPrefs.GetString("SetString") + " \n" + "Distance: " + D + " \n");
        }

        WaypointIndex = 0; // for headUp and plane
        PathForPlane  = new List <Vector3>(Path);

        //set all things invisible
        GameObject[] Arrows = GameObject.FindGameObjectsWithTag("Arrows");
        foreach (GameObject a in Arrows)
        {
            Destroy(a);
        }
        Plane.SetActive(false);
        HeadUp.SetActive(false);
        NextRound.SetActive(false);
        DisplayNext = false;

        //invisit all waypoints
        GameObject[] WayPointSets = GameObject.FindGameObjectsWithTag("WayPointSet");
        foreach (GameObject WayPointSet in  WayPointSets)
        {
            WayPointSet.SetActive(false);
        }

        //invisit all obstacles
        GameObject[] ObstacleSets = GameObject.FindGameObjectsWithTag("ObstacleSet");
        foreach (GameObject ObstacleSet in ObstacleSets)
        {
            ObstacleSet.SetActive(false);
        }

        //user at starting point, diamond at destination
        Diamond.transform.position = Path.Last();
        Diamond.SetActive(true);
        Player.transform.position = Path[0];
        Plane.transform.position  = Path[0];

        ShowWayPoint(Round);
        ShowObstacle(Round);
    }
示例#4
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI ();
        serializedObject.Update();
        ObstacleSetManager myTarget = (ObstacleSetManager)target;

        EditorGUI.BeginChangeCheck();
        SerializedProperty rock = serializedObject.FindProperty("rocket");

        EditorGUILayout.PropertyField(rock, true);
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
        GUILayout.Label("Kullanilacak butun engellerin prefab'leri buraya referanslanmak zorunda.\n Ayni zamanda her engel turune farkli bir tag koymaniz gerekiyor.");
        EditorGUI.BeginChangeCheck();
        SerializedProperty obst = serializedObject.FindProperty("obstacles");

        EditorGUILayout.PropertyField(obst, true);

        /*if (GUILayout.Button ("Create New Prefab Slot"))
         * {
         *      Undo.RecordObject (myTarget,"Undo Creating New Prefab Slot");
         *      myTarget.obstacles(ScriptableObject.CreateInstance<ObstacleSet> ());
         *      EditorUtility.SetDirty(target);
         * }*/
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }

        GUILayout.Label("Burdan setleri sahneye geri alip editleyip tekrar uzerine yazabilirsiniz.");
        EditorGUI.BeginChangeCheck();
        if (myTarget.obstacleSets == null)
        {
            myTarget.obstacleSets = new List <ObstacleSet> ();
        }
        int i = 0;

        foreach (ObstacleSet obs in myTarget.obstacleSets)
        {
            i++;
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Set " + i);
            if (GUILayout.Button("SAVE"))
            {
                Undo.RecordObject(myTarget, "Undo Saving Over Set " + i);                 // DOESNT WORK?
                Debug.Log("Deleting " + obs.obstacles.Count + " obstacles in Set " + i);
                obs.obstacles.Clear();
                foreach (Transform childTr in myTarget.gameObject.transform)
                {
                    ObstacleData OD = ScriptableObject.CreateInstance <ObstacleData> ();
                    Debug.Log("Saving a " + childTr.tag + " on Set " + i);
                    OD.SetValues(childTr.tag, childTr.position.x, childTr.position.y);
                    obs.obstacles.Add(OD);
                }
                EditorUtility.SetDirty(target);
            }
            if (GUILayout.Button("LOAD"))
            {
                Undo.RecordObject(myTarget.gameObject, "Undo Clearing Scene Obstacles");
                GameObject[] objectsToDestroy = new GameObject[myTarget.gameObject.transform.childCount];
                int          j = 0;
                foreach (Transform childTr in myTarget.gameObject.transform)
                {
                    objectsToDestroy[j] = childTr.gameObject;
                    j++;
                }
                foreach (GameObject obj in objectsToDestroy)
                {
                    Undo.DestroyObjectImmediate(obj);
                }
                Undo.RecordObject(myTarget.gameObject, "Undo Loading Obstacles To Scene");
                foreach (ObstacleData oData in obs.obstacles)
                {
                    GameObject OB = (GameObject)Instantiate(FindObstacleWithTag(myTarget.obstacles, oData.type).gameObject, new Vector3(oData.x, oData.y, 0), Quaternion.identity);
                    OB.transform.SetParent(myTarget.transform);
                }
                EditorUtility.SetDirty(target);
            }

            if (GUILayout.Button("DELETE"))
            {
                Undo.RecordObject(myTarget, "Undo Deleting Set " + i);
                myTarget.obstacleSets.Remove(obs);
                EditorUtility.SetDirty(target);
                break;
            }
            EditorGUILayout.EndHorizontal();
        }

        if (GUILayout.Button("Create New Set"))
        {
            Undo.RecordObject(myTarget, "Undo Creating New Set");
            ObstacleSet OS = ScriptableObject.CreateInstance <ObstacleSet> ();
            OS.obstacles = new List <ObstacleData> ();
            myTarget.obstacleSets.Add(OS);
            EditorUtility.SetDirty(target);
        }
        if (GUILayout.Button("Clear Obstacles From Scene"))
        {
            Undo.RecordObject(myTarget.gameObject, "Undo Clearing Scene Obstacles");
            GameObject[] objectsToDestroy = new GameObject[myTarget.gameObject.transform.childCount];
            int          j = 0;
            foreach (Transform childTr in myTarget.gameObject.transform)
            {
                objectsToDestroy[j] = childTr.gameObject;
                j++;
            }
            foreach (GameObject obj in objectsToDestroy)
            {
                Undo.DestroyObjectImmediate(obj);
            }
            EditorUtility.SetDirty(target);             //???? ONLY SCENE STUFF
        }

        if (EditorGUI.EndChangeCheck())
        {
            EditorUtility.SetDirty(target);
        }


        EditorGUI.BeginChangeCheck();
        SerializedProperty lengthProp = serializedObject.FindProperty("lengthBetweenSets");

        EditorGUILayout.PropertyField(lengthProp, true);

        /*if (GUILayout.Button ("Create New Prefab Slot"))
         * {
         *      Undo.RecordObject (myTarget,"Undo Creating New Prefab Slot");
         *      myTarget.obstacles(ScriptableObject.CreateInstance<ObstacleSet> ());
         *      EditorUtility.SetDirty(target);
         * }*/
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
    }