Exemple #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateTickList()
        {
            if (SegmentInfo == null || SegmentInfo.TickInfoList == null)
            {
                return;
            }

            int newTickCount = SegmentInfo.TickInfoList.Count;

            if (Ticks.Count == newTickCount)
            {
                return;
            }

#if UNITY_EDITOR
            //ticks are often added within a prefab; this forces serialization of the "Ticks" list
            UnityEditor.EditorUtility.SetDirty(this);
#endif

            if (TickPrefab == null)
            {
                Debug.LogWarning("Cannot build ticks without a prefab reference.", this);
                return;
            }

            while (Ticks.Count < newTickCount)
            {
                HoverMesh tickMesh = RendererUtil.TryBuildPrefabRenderer <HoverMesh>(TickPrefab);
                tickMesh.name = "Tick" + Ticks.Count;
                tickMesh.transform.SetParent(gameObject.transform, false);
                Ticks.Add(tickMesh);
            }

            while (Ticks.Count > newTickCount)
            {
                int       lastTickIndex = Ticks.Count - 1;
                HoverMesh tick          = Ticks[lastTickIndex];

                Ticks.RemoveAt(lastTickIndex);

                if (Application.isPlaying)
                {
                    Destroy(tick.gameObject);
                }
                else
                {
                    tick.gameObject.SetActive(false);
                    tick.GetComponent <TreeUpdater>().enabled = false;
                    DestroyImmediate(tick.gameObject);
                }
            }

            GetComponent <TreeUpdater>().ImmediateReloadTreeChildren();
        }