コード例 #1
0
        private void OnNavigationNodeMoved(NavigationNodeEditorComponent l_movedNavigationNode)
        {
            SerializedNavigationNode l_updatedNode = NavigationGraphAsset.NavigationNodes[l_movedNavigationNode.GetSerializedNavigationNodeId()];

            l_updatedNode.LocalPosition = l_movedNavigationNode.transform.localPosition;
            NavigationGraphAsset.NavigationNodes[l_movedNavigationNode.GetSerializedNavigationNodeId()] = l_updatedNode;
            EditorUtility.SetDirty(NavigationGraphAsset);
        }
コード例 #2
0
        private void CalculateLinkTravelCosts()
        {
            if (NavigationGraphAsset != null)
            {
                for (int i = 0; i < NavigationGraphAsset.NavigationLinks.Count; i++)
                {
                    SerializedNavigationLink l_navigationLink      = NavigationGraphAsset.NavigationLinks[i];
                    SerializedNavigationNode l_startNodeSerialized = NavigationGraphAsset.NavigationNodes[l_navigationLink.StartNode];
                    SerializedNavigationNode l_endNodeSerialized   = NavigationGraphAsset.NavigationNodes[l_navigationLink.EndNode];
                    float l_travelCost = Vector3.Distance(l_startNodeSerialized.LocalPosition, l_endNodeSerialized.LocalPosition);
                    l_navigationLink.TravelCost             = l_travelCost;
                    NavigationGraphAsset.NavigationLinks[i] = l_navigationLink;
                }

                EditorUtility.SetDirty(NavigationGraphAsset);
            }
        }
コード例 #3
0
        public static NavigationNodeEditorComponent Instanciate(GameObject p_source, Transform p_parent, int p_serializedNavigationNodeId, SerializedNavigationNode p_serializedNavigationNode,
                                                                NavigationGraphEditorComponent p_navigationGraphEditorReference, Action <NavigationNodeEditorComponent> p_onPositionChangedCallback, Action <NavigationNodeEditorComponent, bool> p_onSelectionChangedCallback)
        {
            GameObject l_instanciatedGameObject = GameObject.Instantiate(p_source);
            NavigationNodeEditorComponent thiz  = l_instanciatedGameObject.AddComponent <NavigationNodeEditorComponent>();

            thiz.gameObject.transform.parent      = p_parent;
            thiz.m_lastFrameSelection             = BoolVariable.New(false, (p_value) => { p_onSelectionChangedCallback(thiz, p_value); }, (p_value) => { p_onSelectionChangedCallback(thiz, p_value); });
            thiz.m_serializedNavigationNodeId     = p_serializedNavigationNodeId;
            thiz.m_positionChangedCallback        = p_onPositionChangedCallback;
            thiz.transform.localPosition          = p_serializedNavigationNode.LocalPosition;
            thiz.m_lastFrameLocalPosition         = thiz.transform.localPosition;
            thiz.m_navigationGraphEditorReference = p_navigationGraphEditorReference;
            thiz.Tick();
            return(thiz);
        }
コード例 #4
0
        private void CreateGrid()
        {
            if (NavigationGraphAsset != null)
            {
                int currentKey = NavigationGraphAsset.NavigationNodes.Keys.Count == 0 ? 0 : (NavigationGraphAsset.NavigationNodes.Keys.ToList().Max() + 1);

                Dictionary <int, Dictionary <int, int> > l_XandZtoKeyLookupTable = new Dictionary <int, Dictionary <int, int> >();

                // Node creation
                for (int x = 0; x < XNumber; x++)
                {
                    if (!l_XandZtoKeyLookupTable.ContainsKey(x))
                    {
                        l_XandZtoKeyLookupTable[x] = new Dictionary <int, int>();
                    }

                    for (int z = 0; z < ZNumber; z++)
                    {
                        SerializedNavigationNode l_newNode = new SerializedNavigationNode();
                        l_newNode.LocalPosition = new Vector3(x, 0, z) * DistanceBetweenCells;
                        NavigationGraphAsset.NavigationNodes.Add(currentKey, l_newNode);
                        l_XandZtoKeyLookupTable[x][z] = currentKey;
                        currentKey += 1;
                    }
                }

                for (int x = 0; x < XNumber; x++)
                {
                    for (int z = 0; z < ZNumber; z++)
                    {
                        if (l_XandZtoKeyLookupTable.ContainsKey(x + 1))
                        {
                            NavigationGraphAsset.NavigationLinks.Add(new SerializedNavigationLink()
                            {
                                StartNode = l_XandZtoKeyLookupTable[x][z],
                                EndNode   = l_XandZtoKeyLookupTable[x + 1][z]
                            });
                            NavigationGraphAsset.NavigationLinks.Add(new SerializedNavigationLink()
                            {
                                StartNode = l_XandZtoKeyLookupTable[x + 1][z],
                                EndNode   = l_XandZtoKeyLookupTable[x][z]
                            });
                        }

                        if (l_XandZtoKeyLookupTable[x].ContainsKey(z - 1))
                        {
                            NavigationGraphAsset.NavigationLinks.Add(new SerializedNavigationLink()
                            {
                                StartNode = l_XandZtoKeyLookupTable[x][z],
                                EndNode   = l_XandZtoKeyLookupTable[x][z - 1]
                            });
                            NavigationGraphAsset.NavigationLinks.Add(new SerializedNavigationLink()
                            {
                                StartNode = l_XandZtoKeyLookupTable[x][z - 1],
                                EndNode   = l_XandZtoKeyLookupTable[x][z]
                            });
                        }
                    }
                }

                CalculateLinkTravelCosts();

                EditorUtility.SetDirty(NavigationGraphAsset);
            }
        }