コード例 #1
0
    private void Start()
    {
        patrolPath = GetComponentInChildren <WaypointContainer>();

        if (GetComponentInChildren <CharacterStats>())
        {
            CharacterStats enemy = GetComponentInChildren <CharacterStats>();
            enemy.OnDead += StartSpawnCoroutine;
            spawnedEnemy  = enemy.gameObject;

            if (patrollingEnemy)
            {
                Destroy(spawnedEnemy.GetComponent <SearchingState>());
                NPCController npcController = spawnedEnemy.GetComponent <NPCController>();

                float rand = Random.Range(minPatrolWaitTime, maxPatrolWaitTime);
                npcController.SetPatrolWaitTime(rand);
                npcController.SetPatrolPath(patrolPath);

                spawnedEnemy.AddComponent <PatrolState>();
                npcController.UpdateStateComponents();
            }

            spawnedEnemy.transform.parent = null;
        }
        else
        {
            Spawn();
        }
    }
コード例 #2
0
 void Awake()
 {
     gamecontroller    = GameObject.FindWithTag("GameController").GetComponent <GameController>();
     leaderboard       = GameObject.FindWithTag("GameController").GetComponent <Leaderboard>();
     waypointContainer = GameObject.FindGameObjectWithTag("WaypointContainer").GetComponent <WaypointContainer>();
     cardContainer     = GameObject.FindGameObjectWithTag("WaypointContainer").GetComponent <CardContainer>();
 }
コード例 #3
0
ファイル: MovePlayer.cs プロジェクト: Fabianofski/Boardgame
 void Awake()
 {
     playerStatsContainer = GetComponent <PlayerStatsContainer>();
     waypointContainer    = GameObject.FindWithTag("WaypointContainer").GetComponent <WaypointContainer>();
     gamecontroller       = GameObject.FindWithTag("GameController").GetComponent <GameController>();
     anim = GetComponent <Animator>();
 }
コード例 #4
0
    public WaypointConnection moveHelper(WaypointContainer startRoom, Waypoint destinationHelper, int count, WaypointContainer comeFrom)   //this method return which door(WaypointConnection) AI should move towards
    {
        WaypointConnection result = null;

        foreach (var conn in startRoom.WaypointConnections)
        {
            if (conn.ConnectedContainer == destinationHelper.MyContainer)
            {
                return(conn);
            }
            else
            {
                if (count < 5 && conn.ConnectedContainer != comeFrom)
                {
                    var temp = moveHelper(conn.ConnectedContainer, destinationHelper, count + 1, startRoom);
                    //result = temp != null ? conn : null;
                    if (temp == null)
                    {
                        result = null;
                    }
                    else
                    {
                        return(conn);
                    }
                }
            }
        }

        return(result);    //shuold never reach here
    }
コード例 #5
0
    void Start()
    {
        waypointContainer = GameObject.FindGameObjectWithTag("WaypointContainer").GetComponent <WaypointContainer>();
        gameController    = GameObject.FindWithTag("GameController").GetComponent <GameController>();


        foreach (GameObject x in gameController.Players)
        {
            targetOffsets.Add(x.GetComponent <SetPlayersStartingPos>());
        }
    }
コード例 #6
0
    // Use this for initialization
    void Start()
    {
        _circuit      = GameObject.FindObjectOfType <WaypointContainer>();
        _baseRotation = Quaternion.Euler(baseRotation);

        _positions = _circuit.waypoints.Select(wp => wp.transform.position).ToArray().Smooth(smoothIterations, true);
        _rotations = _circuit.waypoints.Select(wp => wp.transform.rotation).ToArray().Smooth(smoothIterations, true);

        _speed = _positions.Length / Mathf.Clamp(duration, 0.01f, 1000);
        Debug.LogFormat("Smoothed to {0} points", _positions.Length);
    }
コード例 #7
0
 public override void Initialize()
 {
     base.Initialize();
     waitTimer              = 0;
     waiting                = false;
     patrolPath             = npcController.GetPatrolPath();
     agent.speed            = npcController.GetWalkSpeed();
     agent.stoppingDistance = 1;
     waitTime               = npcController.GetPatrolWaitTime();
     nextWaypointPosition   = patrolPath.transform.GetChild(nextWaypointIndex).position;
     agent.SetDestination(nextWaypointPosition);
 }
コード例 #8
0
ファイル: Cockpit.cs プロジェクト: EusthEnoptEron/Splash-Dash
    private void Awake()
    {
        base.Awake();

        rigidbody = GetComponent <Rigidbody>();

        // Start constrained
        rigidbody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
        // get the car controller
        m_Car    = GetComponent <CarController>();
        _circuit = GameObject.FindGameObjectWithTag("Circuit").GetComponent <WaypointContainer>();

        currentWaypoint = _circuit.waypoints.Last();
        nextWaypoint    = _circuit.GetNextWaypoint(currentWaypoint);
    }
コード例 #9
0
    void Awake()
    {
        FindObjectOfType <CharacterContainer>().SpawnPlayers(start.position);
        Destroy(FindObjectOfType <CharacterContainer>().gameObject);

        Players           = GameObject.FindGameObjectsWithTag("Player");
        MovePlayerScripts = new MovePlayer[Players.Length];
        waypointContainer = GameObject.FindGameObjectWithTag("WaypointContainer").GetComponent <WaypointContainer>();
        PlayerPassesTurn  = new bool[Players.Length];
        PlayerReachedEnd  = new bool[Players.Length];

        for (int i = 0; i < Players.Length; i++)
        {
            MovePlayerScripts[i] = Players[i].GetComponent <MovePlayer>();
        }
    }
コード例 #10
0
        private int land(Coord a, Coord b, Coord c, Coord d, int idx)
        {
            int waycount, i, j, k;
            WaypointContainer landcurve = new WaypointContainer();
            Coord             cc        = new Coord();

            waycount = 0;

            landcurve.Add(new Waypoint()
            {
                x = d.X, y = d.Y
            });
            landcurve.Add(new Waypoint()
            {
                x = c.X, y = c.Y
            });

            i = makecurve(b, 5000, 120, 10, 0, landcurve);

            waycount = waycount + i;

            _waypoints[idx].x     = a.X;
            _waypoints[idx].y     = a.Y;
            _waypoints[idx + 1].x = b.X;
            _waypoints[idx + 1].y = b.Y;

            cc.X = landcurve[i - 1].x;
            cc.Y = landcurve[i - 1].y;
            j    = makecurve(cc, 5000, 120, 10, idx);

            waycount = waycount + j;

            cc.X = landcurve[i - 1].x;
            cc.Y = landcurve[i - 1].y;
            k    = makestraight(cc, 50000, 50000, 50, j);

            waycount = waycount + k - j;

            //waycpy(landcurve, i-1, k-1, true, l_WP); //ñëèâàåì äâà ìàññèâà òî÷åê
            _waypoints.AddRange(landcurve);

            return(waycount);
        }
コード例 #11
0
 // Use this for initialization
 void Start()
 {
     _car     = RaceController.Locate().MyCar;
     _circuit = GameObject.FindGameObjectWithTag("Circuit").GetComponent <WaypointContainer>();
 }
コード例 #12
0
 public void SetPatrolPath(WaypointContainer path)
 {
     patrolPath = path;
 }
コード例 #13
0
        private int makecurve(Coord target, int seg_length, int max_angle, int max_segments, int idx, WaypointContainer waypoints)
        {
            Coord  c;
            Coord  v;
            Coord  v1;
            Coord  v2;
            double d;

            v = new Coord();

            v.X = waypoints[idx + 1].x - waypoints[idx].x;
            v.Y = waypoints[idx + 1].y - waypoints[idx].y;
            v   = setmag(v, seg_length);

            for (int i = idx; i < max_segments; i++)
            {
                c   = new Coord();
                c.X = target.X - waypoints[i + 1].x;
                c.Y = target.Y - waypoints[i + 1].y;

                if (angle(v, c) < max_angle)
                {
                    v.X = target.X - waypoints[i + 1].x;
                    v.Y = target.Y - waypoints[i + 1].y;
                    v   = setmag(v, seg_length);

                    //SetLength(m_WP, i+3);
                    waypoints.Add(new Waypoint()
                    {
                        x = waypoints[i + 1].x + v.X, y = waypoints[i + 1].y + v.Y
                    });

                    return(i + 3); //Success
                }

                d = distance(waypoints[i + 1].x, waypoints[i + 1].y, target.X, target.Y);

                if (d < seg_length)
                {
                    //SetLength(m_WP, i+3);
                    waypoints.Add(new Waypoint()
                    {
                        x = target.X, y = target.Y
                    });
                    return(i + 3); //Success
                }

                v1 = rotate(v, max_angle);
                v2 = rotate(v, -max_angle);

                c.X = target.X - waypoints[i + 1].x;
                c.Y = target.Y - waypoints[i + 1].y;

                if (angle(v1, c) < angle(v2, c))
                {
                    v = v1;
                }
                else
                {
                    v = v2;
                }

                //SetLength(m_WP, i+3);
                waypoints.Add(new Waypoint()
                {
                    x = _waypoints[i + 1].x + v.X, y = _waypoints[i + 1].y + v.Y
                });
            }

            return(max_segments);
        }
コード例 #14
0
 public Route()
 {
     _waypoints = new WaypointContainer();
 }
    //protected virtual void OnSceneGUI()
    //{
    //    if (Event.current.type == EventType.Repaint)
    //    {
    //        Transform transform = ((WaypointContainer)target).transform;
    //    //    Handles.color = Handles.xAxisColor;
    //    //    Handles.CircleHandleCap(
    //    //        0,
    //    //        transform.position + new Vector3(3f, 0f, 0f),
    //    //        transform.rotation * Quaternion.LookRotation(Vector3.right),
    //    //        size,
    //    //        EventType.Repaint
    //    //    );
    //    }
    //}

    public override void OnInspectorGUI()
    {
        if (selectedObject == null)
        {
            selectedObject = (WaypointContainer)target;
        }

        if (m_editMode)
        {
            //serializedObject.Update();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("nodeList"));
            //openedList = EditorGUI.DropdownButton(new Rect(10, 0, 100, 50), GUIContent.none, FocusType.Passive);
            serializedObject.ApplyModifiedProperties();
        }

        nodeColor = EditorGUILayout.ColorField("Node Color", nodeColor);

        if (GUILayout.Button("Generate Pathfinding"))
        {
            if (selectedObject.nodeList.Count == selectedObject.transform.childCount)
            {
                Debug.Log("Update");

                selectedObject.nodeList.Clear();
            }

            m_editMode       = true;
            hasCompletedList = false;

            serializedObject.Update();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("nodeList"));
            serializedObject.ApplyModifiedProperties();

            for (int i = 0; i < selectedObject.transform.childCount; i++)
            {
                Waypoint selectedChild = selectedObject.transform.GetChild(i).gameObject.GetComponent <Waypoint>();

                if (selectedObject.nodeList.Contains(selectedChild))
                {
                    Debug.Log("Need To Replace");
                }
                else
                {
                    selectedChild.nodeColor = nodeColor;
                    selectedObject.nodeList.Add(selectedChild);
                }
            }

            Debug.Log("Calling");
            UpdateConnectors();

            if (!hasScannedBefore)
            {
                // Recalculate all graphs
                AstarPath.active.Scan();
                hasScannedBefore = true;
            }
        }

        if (GUILayout.Button("Reset Node Data"))
        {
            m_editMode       = false;
            hasCompletedList = false;

            for (int i = 0; i < selectedObject.nodeList.Count; i++)
            {
                Waypoint selectedNode = null;

                selectedNode = selectedObject.nodeList[i];
                selectedNode.connectedTo.Clear();
                //selectedNode.SetConnections();
            }

            selectedObject.nodeList.Clear();

            serializedObject.Update();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("nodeList"));
            serializedObject.ApplyModifiedProperties();

            hasScannedBefore = false;
        }
    }