private void OnSceneGUI()
    {
        m_SerializedObject.Update();
        WaypointSystem waypointSystem = target as WaypointSystem;

        if (waypointSystem == null || waypointSystem.Graph == null)
        {
            return;
        }
        foreach (Edge <Vector3> edge in waypointSystem.Graph.Edges)
        {
            Handles.color = edge.EdgeColor;
            Handles.DrawAAPolyLine(edge.To.Value, edge.From.Value);
        }
        for (int i = 0; i < m_PropertyNodes.arraySize; i++)
        {
            SerializedProperty property = m_PropertyNodes.GetArrayElementAtIndex(i);
            property.vector3Value = Handles.PositionHandle(property.vector3Value, Quaternion.identity);
            waypointSystem.Graph.Nodes.ElementAt(i).Value = property.vector3Value;
            if (Event.current.type == EventType.Repaint)
            {
                Handles.color = waypointSystem.Graph.Nodes.ElementAt(i).NodeColor;
                Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                Handles.SphereHandleCap(0, waypointSystem.Graph.Nodes.ElementAt(i).Value, Quaternion.identity, 1.0f, EventType.Repaint);
            }
        }
        if (m_SerializedObject.ApplyModifiedProperties())
        {
            SceneView.RepaintAll();
        }
        if (waypointSystem != null)
        {
            EditorUtility.SetDirty(waypointSystem);
        }
    }
        public override void OnStart(Entity entity)
        {
            var targetWaypoint = entity.GetState <ActionBlackboardState>().TargetEntity;

            WaypointSystem.StartUsingWaypoint(targetWaypoint, entity);
            ActionStatus = ActionStatus.Succeeded;
        }
示例#3
0
 // Use this for initialization
 void Start()
 {
     ani = GetComponentInChildren <Animator> ();
     ws  = GetComponent <WaypointSystem> ();
     nma = GetComponent <UnityEngine.AI.NavMeshAgent> ();
     hc  = transform.parent.gameObject.GetComponent <HordeControler> ();
     StartCoroutine(checkPlayerPos());
 }
示例#4
0
        public void SetUp()
        {
            waypoints = new List <Waypoint>();
            var systemObj = new GameObject();

            waypointSystem = systemObj.AddComponent <WaypointSystem>();
            EditorSceneManager.MoveGameObjectToScene(systemObj, editorScene);
        }
示例#5
0
 //Override values from DungeonGenerator
 public void SetFromGeneration(Tile[] tiles, List <Room> rooms, WaypointSystem waypointSystem,
                               int width, int height)
 {
     this.tiles           = tiles;
     this.rooms           = rooms;
     this.waypointSystem  = waypointSystem;
     waypointsByRoomCache = waypointSystem.waypointsByRoom;
     WIDTH  = width;
     HEIGHT = height;
 }
示例#6
0
 private void Start()
 {
     player       = FindObjectOfType <PlayerController>();
     originalSize = marker.GetComponent <RectTransform>().sizeDelta;
     system       = this;
     if (!currentWaypoint)
     {
         currentWaypoint = waypoint;
     }
 }
 private void SetupObjects()
 {
     waypointSystem = new GameObject("Waypoint System").AddComponent <WaypointSystem>();
     if (generateNewDungeon)
     {
         waypointSystem.Init(dungeon);
     }
     else
     {
         waypointSystem.Init(dungeon, dungeon.waypointsByRoomCache);
     }
 }
    public override void OnInspectorGUI()
    {
        m_SerializedObject.Update();
        WaypointSystem waypointSystem = target as WaypointSystem;

        if (waypointSystem == null || waypointSystem.Graph == null)
        {
            return;
        }
        if (GUILayout.Button(k_ClearNodes))
        {
            ClearNodes(waypointSystem);
        }
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField($"Nodes: {waypointSystem.Graph.Nodes.Count}");
        EditorGUILayout.LabelField($"Edges: {waypointSystem.Graph.Edges.Count}");
        EditorGUILayout.EndHorizontal();
        if (GUILayout.Button(k_AddNode))
        {
            AddNode(waypointSystem);
        }
        if (GUILayout.Button(k_RemoveNode))
        {
            if (waypointSystem.Graph.Nodes.Count > 0)
            {
                RemoveNode(waypointSystem, waypointSystem.Graph.Nodes.Last());
            }
        }
        foreach (Node <Vector3> node in waypointSystem.Graph.Nodes)
        {
            EditorGUILayout.BeginHorizontal();
            node.Value     = EditorGUILayout.Vector3Field(k_Empty, node.Value);
            node.NodeColor = EditorGUILayout.ColorField(node.NodeColor);
            EditorGUILayout.EndHorizontal();
            foreach (Edge <Vector3> edge in waypointSystem.Graph.Edges.Where(edge => edge.From == node))
            {
                edge.EdgeColor = node.NodeColor;
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.IntField(edge.From.Index);
                EditorGUILayout.LabelField(k_Arrow);
                EditorGUILayout.IntField(edge.To.Index);
                EditorGUILayout.EndHorizontal();
            }
        }
        if (m_SerializedObject.ApplyModifiedProperties())
        {
            SceneView.RepaintAll();
        }
        if (waypointSystem != null)
        {
            EditorUtility.SetDirty(waypointSystem);
        }
    }
示例#9
0
        public void TearDown()
        {
            foreach (var waypoint in waypoints)
            {
                GameObject.DestroyImmediate(waypoint.gameObject);
            }

            waypoints.Clear();

            GameObject.DestroyImmediate(waypointSystem.gameObject);
            waypointSystem = null;
        }
    private void AddNode(WaypointSystem waypointSystem, Vector3 position = default, Color color = default, bool reappear = false)
    {
        Node <Vector3> lastNode  = new Node <Vector3>();
        Node <Vector3> firstNode = new Node <Vector3>();
        int            nodeCount = waypointSystem.Graph.Nodes.Count;

        if (nodeCount > 0)
        {
            lastNode  = waypointSystem.Graph.Nodes.Last();
            firstNode = waypointSystem.Graph.Nodes.First();
            foreach (Edge <Vector3> edge in waypointSystem.Graph.Edges.Where(edge => edge.From == lastNode))
            {
                RemoveEdge(waypointSystem, edge);
                break;
            }
        }
        if (reappear)
        {
            waypointSystem.Graph.Nodes.Add(new Node <Vector3> {
                Value = position, NodeColor = color, Index = nodeCount
            });
        }
        else
        {
            waypointSystem.Graph.Nodes.Add(new Node <Vector3> {
                Value = Vector3.Lerp(firstNode.Value, lastNode.Value, 0.5f), NodeColor = Color.white, Index = nodeCount
            });
        }
        m_Nodes.Add(waypointSystem.Graph.Nodes.Last().Value);
        if (nodeCount + 1 > 1)
        {
            waypointSystem.Graph.Edges.Add(new Edge <Vector3>()
            {
                EdgeColor = lastNode.NodeColor,
                From      = lastNode,
                To        = waypointSystem.Graph.Nodes.Last()
            });
        }
        if (nodeCount + 1 > 2)
        {
            waypointSystem.Graph.Edges.Add(new Edge <Vector3>()
            {
                EdgeColor = waypointSystem.Graph.Nodes.Last().NodeColor,
                From      = waypointSystem.Graph.Nodes.Last(),
                To        = waypointSystem.Graph.Nodes.First()
            });
        }
    }
示例#11
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "MultiRotor")
     {
         controls       = other.GetComponentInParent <Controls>();
         waypointSystem = controls.waypointSystem;
         if (controls.targetWaypoint.name == this.name)
         {
             Debug.Log(other.name);
             controls.waypointnb++;
             if (controls.waypointnb > waypointSystem.waypoints.Length - 1) // retour au debut
             {
                 controls.waypointnb = 0;
             }
             controls.targetWaypoint = waypointSystem.waypoints[controls.waypointnb];
         }
     }
 }
    private void OnEnable()
    {
        Tools.hidden                = true;
        m_SerializedObject          = new SerializedObject(this);
        m_PropertyNodes             = m_SerializedObject.FindProperty(k_Nodes);
        Selection.selectionChanged += Repaint;
        WaypointSystem waypointSystem = target as WaypointSystem;

        if (waypointSystem == null || waypointSystem.Graph == null)
        {
            return;
        }
        for (int i = 0; i < PlayerPrefs.GetInt(k_Length); i++)
        {
            Vector3 position = new Vector3(PlayerPrefs.GetFloat($"{i}x", 0.0f), PlayerPrefs.GetFloat($"{i}y", 0.0f), PlayerPrefs.GetFloat($"{i}z", 0.0f));
            Color   color    = new Color(PlayerPrefs.GetFloat($"{i}r", 1.0f), PlayerPrefs.GetFloat($"{i}g", 1.0f), PlayerPrefs.GetFloat($"{i}b", 1.0f), PlayerPrefs.GetFloat($"{i}a", 1.0f));
            AddNode(waypointSystem, position, color, true);
        }
    }
        public override void OnStart(Entity entity)
        {
            var inventoryItem  = entity.GetState <InventoryState>().Child;
            var waypointEntity = entity.GetState <ActionBlackboardState>().TargetEntity;

            if (inventoryItem != null && waypointEntity != null)
            {
                var waypointUserState = waypointEntity.GetState <UserState>();
                if (waypointUserState.IsFree())
                {
                    EventSystem.ParentingRequestEvent.Invoke(new ParentingRequest {
                        EntityFrom = entity, EntityTo = waypointEntity, Mover = inventoryItem
                    });
                    WaypointSystem.StartUsingWaypoint(waypointEntity, inventoryItem);
                    ActionStatus = ActionStatus.Succeeded;
                    return;
                }
            }
            ActionStatus = ActionStatus.Failed;
        }
    private void OnDisable()
    {
        WaypointSystem waypointSystem = target as WaypointSystem;

        if (waypointSystem == null || waypointSystem.Graph == null)
        {
            return;
        }
        PlayerPrefs.SetInt(k_Length, waypointSystem.Graph.Nodes.Count);
        foreach (Node <Vector3> node in waypointSystem.Graph.Nodes)
        {
            PlayerPrefs.SetFloat($"{node.Index}x", node.Value.x);
            PlayerPrefs.SetFloat($"{node.Index}y", node.Value.y);
            PlayerPrefs.SetFloat($"{node.Index}z", node.Value.z);
            PlayerPrefs.SetFloat($"{node.Index}r", node.NodeColor.r);
            PlayerPrefs.SetFloat($"{node.Index}g", node.NodeColor.g);
            PlayerPrefs.SetFloat($"{node.Index}b", node.NodeColor.b);
            PlayerPrefs.SetFloat($"{node.Index}a", node.NodeColor.a);
        }
        Selection.selectionChanged -= Repaint;
        Tools.hidden = false;
        ClearNodes(waypointSystem);
    }
 private void RemoveNode(WaypointSystem waypointSystem, Node <Vector3> node)
 {
     foreach (Edge <Vector3> edge in waypointSystem.Graph.Edges.Where(edge => edge.From == node))
     {
         RemoveEdge(waypointSystem, edge);
         break;
     }
     foreach (Edge <Vector3> edge in waypointSystem.Graph.Edges.Where(edge => edge.To == node))
     {
         RemoveEdge(waypointSystem, edge);
         break;
     }
     waypointSystem.Graph.Nodes.Remove(node);
     m_Nodes.Remove(node.Value);
     if (waypointSystem.Graph.Nodes.Count > 2)
     {
         waypointSystem.Graph.Edges.Add(new Edge <Vector3>()
         {
             EdgeColor = waypointSystem.Graph.Nodes.Last().NodeColor,
             From      = waypointSystem.Graph.Nodes.Last(),
             To        = waypointSystem.Graph.Nodes.First()
         });
     }
 }
 private void RemoveEdge(WaypointSystem waypointSystem, Edge <Vector3> edge)
 {
     waypointSystem.Graph.Edges.Remove(edge);
 }
 private void ClearEdges(WaypointSystem waypointSystem)
 {
     waypointSystem.Graph.Edges.Clear();
 }
    /// <summary>
    /// Inicia a máquina de estados.
    /// </summary>
    public TurretStateMachine(Transform pMyTransform)
    {
        this._idTurret = ++TURRET_ID;
        this._currentState = FiniteStateMachineType.IDLE;
        //SetNewState(FiniteStateMachineType.PATROL);

        this._distanceLimitToChasing = DISTANCELIMITTOCHASE;
        this._distanceLimitToEvade = DISTANCELIMITTOEVADE;
        this._idleTime = Random.Range(MINVALUEIDLE, MAXVALUEIDLE);
        this._patrolTIme = Random.Range(MINVALUEPATROL, MAXVALUEPATROL);

        this._myTransform = pMyTransform;
        this._tracer = new TurretTracer(this._myTransform.FindChild("Cabeca").FindChild("Camera"));
        this._target = GameObject.FindGameObjectWithTag("Player").transform;

        this._waypointSystem = new WaypointSystem(this._myTransform, this._target);
        this._navigationMesh = new TurretNavigationMesh(this._myTransform, this._myTransform.GetComponent<NavMeshAgent>());
    }
示例#19
0
 // Use this for initialization
 void Start()
 {
     _playerfound = transform.parent.GetComponent <WaypointSystem>();
 }
示例#20
0
 void Start()
 {
     waypointSystem     = FindObjectOfType <WaypointSystem>();
     transform.position = waypointSystem.Waypoints[0];
     currentPathIndex   = 0;
 }
示例#21
0
 private void OnEnable()
 {
     waypoint = target as WaypointSystem;
 }
示例#22
0
 private void OnEnable()
 {
     enemy    = target as Enemy;
     waypoint = enemy.GetWaypointSystem();
 }
示例#23
0
 void Start()
 {
     waypoints = FindObjectOfType <WaypointSystem>();
     index     = 0;
     GetNextWaypoint();
 }
 private void OnEnable()
 {
     m_system = target as WaypointSystem;
     SceneView.duringSceneGui += DisplayHandles;
 }
 private void ClearNodes(WaypointSystem waypointSystem)
 {
     waypointSystem.Graph.Nodes.Clear();
     ClearEdges(waypointSystem);
     m_Nodes.Clear();
 }
        private static void OnScene(SceneView sceneview)
        {
            void BeginCentered(bool area)
            {
                if (area)
                {
                    Handles.BeginGUI();
                }
                if (area)
                {
                    GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
                }
                if (area)
                {
                    GUILayout.Space(WaypointSettings.GetInstance().UiPosition == UIPosition.Top ? 5 : Screen.height - 100);
                }
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
            }

            void EndCentered(bool area)
            {
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                if (area)
                {
                    GUILayout.EndArea();
                }
                if (area)
                {
                    Handles.EndGUI();
                }
            }

            if (Selection.activeObject != null)
            {
                if (Selection.activeObject.GetType() != typeof(GameObject))
                {
                    return;
                }

                var activeObject = Selection.activeGameObject;
                //non generic method is faster http://chaoscultgames.com/2014/03/unity3d-mythbusting-performance/
                _wp  = (Waypoint)activeObject.GetComponent(typeof(Waypoint));
                _wps = (Runtime.WaypointSystem)activeObject.GetComponent(typeof(Runtime.WaypointSystem));
            }

            //if no system or waypoint is selection
            if (_wp == null && _wps == null)
            {
                BeginCentered(true);
                if (GUILayout.Button("Create new waypoint sytem"))
                {
                    //Get a point where to spawn the system
                    Camera  sceneCam = SceneView.currentDrawingSceneView.camera;
                    Vector3 spawnPos = sceneCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 10f));
                    Runtime.WaypointSystem.Create(spawnPos);
                }
                EndCentered(true);
                return;
            }

            //if the system is selected
            if (_wps)
            {
                if (_wps.transform.childCount == 0)
                {
                    _wps.AddNewWayPoint();
                    Selection.activeObject = _wp.gameObject;
                }

                _wp = _wps.StartingWaypoint;
            }

            var wpsParent = _wp.GetComponentInParent <WaypointSystem>();

            HandleWaypointDeletion();

            BeginCentered(true);
            if (GUILayout.Button("Insert (end)"))
            {
                wpsParent.AddNewWayPoint();
            }

            if (GUILayout.Button("Insert (after)"))
            {
                var si = _wp.transform.GetSiblingIndex() + 1;
                wpsParent.AddNewWayPoint(si);
            }

            if (GUILayout.Button("Delete all"))
            {
                wpsParent.DeleteWaypoints();
            }

            if (GUILayout.Button("Delete selected"))
            {
                var si = _wp.transform.GetSiblingIndex();
                wpsParent.DeleteWaypoint(si);
            }

            if (GUILayout.Button("Delete system"))
            {
                wpsParent.DestroySystem();
            }

            EndCentered(false);
            BeginCentered(false);

            if (wpsParent.LoopType == LoopType.Loop)
            {
                if (GUILayout.Button("Loop"))
                {
                    wpsParent.SetLoopType(LoopType.PingPong);
                }
            }
            else if (wpsParent.LoopType == LoopType.PingPong)
            {
                if (GUILayout.Button("PingPong"))
                {
                    wpsParent.SetLoopType(LoopType.OneWay);
                }
            }
            else
            {
                if (GUILayout.Button("One-way"))
                {
                    wpsParent.SetLoopType(LoopType.Loop);
                }
            }

            if (GUILayout.Button("Reset waypoints to system default"))
            {
                wpsParent.ResetWaypointToDefaultsFromSystem();
            }

            if (GUILayout.Button("Reset system to default"))
            {
                wpsParent.ResetSystemToDefault();
            }

            EndCentered(true);
        }
示例#27
0
文件: Enemy.cs 项目: Knusan/Pruject
 // Use this for initialization
 void Start()
 {
     WaypointSystem Script = MyPath.GetComponent<WaypointSystem>();
     waypointSystem = Script;
     BeginPath (0);
 }
示例#28
0
 private void OnEnable()
 {
     waypointSystem = (WaypointSystem)target;
 }