Ejemplo n.º 1
0
        internal static void AssignTrack(IEnumerable <Track> tracks, Track parentTrack, Vector3?startPos, Quaternion?startRot, Quaternion?startLocalRot, Vector3?startScale)
        {
            if (tracks.Contains(parentTrack))
            {
                throw new System.InvalidOperationException("How could a track contain itself?");
            }

            if (Controller == null)
            {
                GameObject gameObject = new GameObject("ParentController");
                Controller = gameObject.AddComponent <ParentController>();
            }

            GameObject   parentGameObject = new GameObject("ParentObject");
            ParentObject instance         = parentGameObject.AddComponent <ParentObject>();

            instance._origin = parentGameObject.transform;
            instance._track  = parentTrack;

            Transform transform = instance.transform;

            if (startPos.HasValue)
            {
                instance._startPos      = startPos.Value;
                transform.localPosition = instance._startPos * NoteLinesDistance;
            }

            if (startRot.HasValue)
            {
                instance._startRot      = startRot.Value;
                instance._startLocalRot = instance._startRot;
                transform.localPosition = instance._startRot * transform.localPosition;
                transform.localRotation = instance._startRot;
            }

            if (startLocalRot.HasValue)
            {
                instance._startLocalRot  = instance._startRot * startLocalRot.Value;
                transform.localRotation *= instance._startLocalRot;
            }

            if (startScale.HasValue)
            {
                instance._startScale = startScale.Value;
                transform.localScale = instance._startScale;
            }

            parentTrack.AddGameObject(parentGameObject);

            foreach (Track track in tracks)
            {
                foreach (ParentObject parentObject in Controller.ParentObjects)
                {
                    track.OnGameObjectAdded   -= parentObject.OnTrackGameObjectAdded;
                    track.OnGameObjectRemoved -= parentObject.OnTrackGameObjectRemoved;
                    parentObject.ChildrenTracks.Remove(track);
                }

                foreach (GameObject gameObject in track.GameObjects)
                {
                    instance.ParentToObject(gameObject.transform);
                }

                instance.ChildrenTracks.Add(track);

                track.OnGameObjectAdded   += instance.OnTrackGameObjectAdded;
                track.OnGameObjectRemoved += instance.OnTrackGameObjectRemoved;
            }

            Controller.ParentObjects.Add(instance);
        }
Ejemplo n.º 2
0
        internal static void AssignTrack(IEnumerable <Track> tracks, Track parentTrack, Vector3?startPos, Quaternion?startRot, Quaternion?startLocalRot, Vector3?startScale)
        {
            if (Controller == null)
            {
                GameObject gameObject = new GameObject("ParentController");
                Controller = gameObject.AddComponent <ParentController>();
            }

            GameObject   parentGameObject = new GameObject("ParentObject");
            ParentObject instance         = parentGameObject.AddComponent <ParentObject>();

            instance._origin = parentGameObject.transform;
            instance._track  = parentTrack;

            Transform transform = instance.transform;

            if (startPos.HasValue)
            {
                instance._startPos      = startPos.Value;
                transform.localPosition = instance._startPos * NoteLinesDistance;
            }

            if (startRot.HasValue)
            {
                instance._startRot      = startRot.Value;
                instance._startLocalRot = instance._startRot;
                transform.localPosition = instance._startRot * transform.localPosition;
                transform.localRotation = instance._startRot;
            }

            if (startLocalRot.HasValue)
            {
                instance._startLocalRot  = instance._startRot * startLocalRot.Value;
                transform.localRotation *= instance._startLocalRot;
            }

            if (startScale.HasValue)
            {
                instance._startScale = startScale.Value;
                transform.localScale = instance._startScale;
            }

            foreach (ParentObject parentObject in Controller.ParentObjects)
            {
                if (parentObject.ChildrenTracks.Contains(parentTrack))
                {
                    parentObject.ParentToObject(transform);
                }
                else
                {
                    ResetTransformParent(transform);
                }
            }

            foreach (Track track in tracks)
            {
                foreach (ParentObject parentObject in Controller.ParentObjects)
                {
                    parentObject.ChildrenTracks.Remove(track);

                    if (parentObject._track == track)
                    {
                        instance.ParentToObject(parentObject.transform);
                    }
                }

                foreach (ObstacleController obstacleController in ObstaclePool.activeItems)
                {
                    if (obstacleController?.obstacleData != null)
                    {
                        NoodleObstacleData noodleData = (NoodleObstacleData)NoodleObjectDatas[obstacleController.obstacleData];
                        Track obstacleTrack           = noodleData.Track;
                        if (obstacleTrack == track)
                        {
                            instance.ParentToObject(obstacleController.transform);
                        }
                    }
                }

                instance.ChildrenTracks.Add(track);
            }

            Controller.ParentObjects.Add(instance);
        }