Ejemplo n.º 1
0
 internal static void Callback(CustomEventData customEventData)
 {
     if (customEventData.type == ASSIGNTRACKPARENT)
     {
         NoodleParentTrackEventData?noodleData = TryGetEventData <NoodleParentTrackEventData>(customEventData);
         if (noodleData != null)
         {
             IEnumerable <Track> tracks = noodleData.ChildrenTracks;
             Track parentTrack          = noodleData.ParentTrack;
             if (tracks != null && parentTrack != null)
             {
                 ParentObject.AssignTrack(tracks, parentTrack, noodleData.Position, noodleData.Rotation, noodleData.LocalRotation, noodleData.Scale);
             }
             else
             {
                 Logger.Log($"Missing _parentTrack or _childrenTracks!", IPA.Logging.Logger.Level.Error);
             }
         }
     }
 }
Ejemplo n.º 2
0
        internal static void Callback(CustomEventData customEventData)
        {
            if (customEventData.type == "AssignTrackParent")
            {
                Track parentTrack          = GetTrack(customEventData.data, "_parentTrack");
                IEnumerable <Track> tracks = GetTrackArray(customEventData.data, "_childrenTracks");

                IEnumerable <float> position  = ((List <object>)Trees.at(customEventData.data, POSITION))?.Select(n => Convert.ToSingle(n));
                Vector3?            posVector = null;
                if (position != null)
                {
                    posVector = new Vector3(position.ElementAt(0), position.ElementAt(1), position.ElementAt(2));
                }

                IEnumerable <float> rotation      = ((List <object>)Trees.at(customEventData.data, ROTATION))?.Select(n => Convert.ToSingle(n));
                Quaternion?         rotQuaternion = null;
                if (rotation != null)
                {
                    rotQuaternion = Quaternion.Euler(rotation.ElementAt(0), rotation.ElementAt(1), rotation.ElementAt(2));
                }

                IEnumerable <float> localrot           = ((List <object>)Trees.at(customEventData.data, LOCALROTATION))?.Select(n => Convert.ToSingle(n));
                Quaternion?         localRotQuaternion = null;
                if (localrot != null)
                {
                    localRotQuaternion = Quaternion.Euler(localrot.ElementAt(0), localrot.ElementAt(1), localrot.ElementAt(2));
                }

                IEnumerable <float> scale       = ((List <object>)Trees.at(customEventData.data, SCALE))?.Select(n => Convert.ToSingle(n));
                Vector3?            scaleVector = null;
                if (scale != null)
                {
                    scaleVector = new Vector3(scale.ElementAt(0), scale.ElementAt(1), scale.ElementAt(2));
                }

                if (tracks != null && parentTrack != null)
                {
                    ParentObject.AssignTrack(tracks, parentTrack, posVector, rotQuaternion, localRotQuaternion, scaleVector);
                }
            }
        }
Ejemplo n.º 3
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.º 4
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);
        }