コード例 #1
0
        public void Update()
        {
            if (!agent.HasPath())
            {
                return;
            }

            var corners = agent.GetPathCorners();
            var requiredHighlighterCount = corners.Length - 1;

            while (requiredHighlighterCount > enabledHighlighterCount && enabledHighlighterCount < pathHighlighters.Count)
            {
                pathHighlighters[enabledHighlighterCount].SetActive(true);
                enabledHighlighterCount++;
            }

            while (requiredHighlighterCount > pathHighlighters.Count)
            {
                pathHighlighters.Add(
                    HighlightLine.CreateLine(
                        Vector3.zero,
                        Vector3.zero,
                        parent
                        )
                    );

                enabledHighlighterCount++;
            }

            for (var i = 1; i < corners.Length; i++)
            {
                HighlightLine.UpdateLine(
                    pathHighlighters[i - 1],
                    corners[i - 1],
                    corners[i]
                    );
            }

            while (enabledHighlighterCount > requiredHighlighterCount)
            {
                pathHighlighters[enabledHighlighterCount - 1].SetActive(false);
                enabledHighlighterCount--;
            }
        }
コード例 #2
0
        void Start()
        {
            UIState.Building.OnChange += newBuilding =>
            {
                ClearHighlighters();

                if ((focusedBuilding = newBuilding) != null)
                {
                    HighlighterObject.enabled              = true;
                    HighlighterObject.transform.position   = focusedBuilding.transform.position;
                    HighlighterObject.transform.rotation   = focusedBuilding.transform.rotation;
                    HighlighterObject.transform.localScale = focusedBuilding.GetComponent <BoxCollider>().size;

                    var weights       = SimulationController.Instance.BuildingManager.GetBuildingWeights(focusedBuilding.DataAlias);
                    var buildingInfos = SimulationController.Instance.BuildingManager.GetBuildingInfos();

                    for (var i = 0; i < buildingInfos.Length; i++)
                    {
                        var buildingInfo = buildingInfos[i];

                        if (buildingInfo.Building != focusedBuilding)
                        {
                            highlighters.Add(
                                HighlightLine.CreateLine(
                                    focusedBuilding.transform.position,
                                    buildingInfo.Building.transform.position,
                                    transform,
                                    weights[buildingInfo.Id] * 10f
                                    )
                                );
                        }
                    }
                }
                else
                {
                    HighlighterObject.enabled = false;
                }
            };
        }