static FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
    {
        // Recreate the event instance object
        FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);

        // Retrieve the user data
        IntPtr timelineInfoPtr;

        instance.getUserData(out timelineInfoPtr);

        // Get the object to store beat and marker details
        GCHandle     timelineHandle = GCHandle.FromIntPtr(timelineInfoPtr);
        TimelineInfo timelineInfo   = (TimelineInfo)timelineHandle.Target;

        switch (type)
        {
        case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT:
        {
            var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
            timelineInfo.currentMusicBar = parameter.bar;
        }
        break;

        case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER:
        {
            var parameter = (FMOD.Studio.TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_MARKER_PROPERTIES));
            timelineInfo.lastMarker = parameter.name;
        }
        break;
        }
        return(FMOD.RESULT.OK);
    }
Exemplo n.º 2
0
        public ArenaEngineAdapter(ArenaEngine arena)
        {
            Arena = arena;

            var timelines = new List <TimelineInfo>();
            int counter   = 0;

            foreach (var obj in arena.UpdatingObjects)
            {
                bool notFound = true;
                foreach (var tl in timelines)
                {
                    if (tl.Timeline.Name == obj.Name)
                    {
                        notFound = false;
                        break;
                    }
                }
                if (notFound)
                {
                    var tp = new TimelinePrototype(obj.Name, colors[counter++]);
                    var ti = new TimelineInfo
                    {
                        Timeline  = tp,
                        Functions = new BasicFunctionPair(() => Arena.Time,
                                                          () => Arena.GetObjects(obj.Name).Count())
                    };
                    timelines.Add(ti);
                }
            }

            Manager.AddGraph(timelines, "Time (s)", "Population");
        }
        /// <summary>
        /// Disconnect a peer from the timeline synchronizer
        /// </summary>
        /// <param name="peerIndex">Index number for the peer that connected.</param>
        public void DisconnectPeer(ushort peerIndex)
        {
            PeerInfo peerInfo;

            lock (_peerLock)
            {
                if (_peersByIndex.TryGetValue(peerIndex, out peerInfo))
                {
                    TimelineInfo[] connectedTimelines = new TimelineInfo[peerInfo.ConnectedTimelines.Count];
                    peerInfo.ConnectedTimelines.Values.CopyTo(connectedTimelines, 0);

                    foreach (var timelineInfo in connectedTimelines)
                    {
                        DisconnectPeerFromTimeline(peerInfo, timelineInfo);
                    }

                    _peersByIndex.Remove(peerIndex);

                    if (PeerDisconnected != null)
                    {
                        PeerDisconnected(peerIndex);
                    }
                }
            }
            return;
        }
Exemplo n.º 4
0
    static FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance instance, IntPtr parameterPtr)
    {
        // Retrieve the user data
        IntPtr timelineInfoPtr;

        FMOD.RESULT result = instance.getUserData(out timelineInfoPtr);
        if (result != FMOD.RESULT.OK)
        {
            UnityEngine.Debug.LogError("Timeline Callback error: " + result);
        }
        else if (timelineInfoPtr != IntPtr.Zero)
        {
            // Get the object to store beat and marker details
            GCHandle     timelineHandle = GCHandle.FromIntPtr(timelineInfoPtr);
            TimelineInfo timelineInfo   = (TimelineInfo)timelineHandle.Target;

            switch (type)
            {
            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT:
            {
                var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
                timelineInfo.currentMusicBeat = parameter.beat;
            }
            break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER:
            {
                var parameter = (FMOD.Studio.TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_MARKER_PROPERTIES));
                timelineInfo.lastMarker = parameter.name;
            }
            break;
            }
        }
        return(FMOD.RESULT.OK);
    }
    void Start()
    {
        markerOnEvent = new UnityEvent();
        barEvent      = new UnityEvent();
        markerOnEvent.AddListener(fireNote);
        instance = this;
        marker   = "";


        //FMOD shit
        timelineInfo = new TimelineInfo();

        // Explicitly create the delegate object and assign it to a member so it doesn't get freed
        // by the garbage collected while it's being used
        beatCallback = new FMOD.Studio.EVENT_CALLBACK(BeatEventCallback);

        musicInstance = FMODUnity.RuntimeManager.CreateInstance(LevelStateEvent);

        // Pin the class that will store the data modified during the callback
        timelineHandle = GCHandle.Alloc(timelineInfo, GCHandleType.Pinned);
        // Pass the object through the userdata of the instance
        musicInstance.setUserData(GCHandle.ToIntPtr(timelineHandle));

        musicInstance.setCallback(beatCallback, FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT | FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER);
        //Debug.Log("CALLBACK");

        musicInstance.start();

        //missInstance = FMODUnity.RuntimeManager.CreateInstance("event:/NoteMiss");

        //
    }
Exemplo n.º 6
0
    public void CastSkill(int skillIndex = -1)
    {
        var roleGameOE = RoleMgr.GetInstance().GetMainRole();
        var roleInfo   = roleGameOE.GetComponent <RoleInfo>();
        var skillID    = SkillManager.GetInstance().GetSkillIDByIndex(skillIndex);

        string assetPath      = ResPath.GetRoleSkillResPath(skillID);
        bool   isNormalAttack = skillIndex == -1;//普通攻击

        if (!isNormalAttack)
        {
            SkillManager.GetInstance().ResetCombo();//使用非普攻技能时就重置连击索引
        }
        var uid = SceneMgr.Instance.EntityManager.GetComponentData <UID>(roleGameOE.Entity);
        Action <TimelineInfo.Event> afterAdd = null;

        if (isNormalAttack)
        {
            //普攻的话增加连击索引
            afterAdd = (TimelineInfo.Event e) =>
            {
                if (e == TimelineInfo.Event.AfterAdd)
                {
                    SkillManager.GetInstance().IncreaseCombo();
                }
            };
        }
        var timelineInfo = new TimelineInfo {
            ResPath = assetPath, Owner = roleGameOE.Entity, StateChange = afterAdd
        };

        TimelineManager.GetInstance().AddTimeline(uid.Value, timelineInfo, SceneMgr.Instance.EntityManager);
    }
Exemplo n.º 7
0
        static FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance instance, IntPtr parameterPtr)
        {
            // Retrieve the user data
            IntPtr timelineInfoPtr;

            FMOD.RESULT result = instance.getUserData(out timelineInfoPtr);

            if (result != FMOD.RESULT.OK)
            {
                Debug.LogError("Timeline Callback error: " + result);
            }
            else if (timelineInfoPtr != IntPtr.Zero)
            {
                // Get the object to store beat and marker details
                GCHandle     timelineHandle = GCHandle.FromIntPtr(timelineInfoPtr);
                TimelineInfo timelineInfo   = (TimelineInfo)timelineHandle.Target;

                switch (type)
                {
                case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT:
                {
                    var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
                    //print("BEAT " + parameter.beat + " CALLBACK");
                    timelineInfo.currentMusicBar                = parameter.bar;
                    timelineInfo.currentMusicBeat               = parameter.beat;
                    timelineInfo.currentMusicTempo              = parameter.tempo;
                    timelineInfo.currentMusicPosition           = parameter.position;
                    timelineInfo.currentMusicTimeSignatureUpper = parameter.timesignatureupper;
                    timelineInfo.currentMusicTimeSignatureLower = parameter.timesignaturelower;
                    FmodMusicHandler.instance.onBeatDelegate();
                }
                break;

                case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER:
                {
                    var parameter = (FMOD.Studio.TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_MARKER_PROPERTIES));
                    timelineInfo.lastMarker = parameter.name;
                    //print(parameter.name + " MARKER CALLBACK");
                    if (FmodChordInterpreter.instance != null && FmodChordInterpreter.instance.IsFmodMarkerChordInformation(parameter.name))
                    {
                        FmodChordInterpreter.instance.ParseChordFromMarker(parameter.name);
                        if (FmodMusicHandler.instance.onChordMarkerDelegate != null)
                        {
                            FmodMusicHandler.instance.onChordMarkerDelegate(FmodChordInterpreter.instance.GetFmodChord());
                        }
                        //FmodChordInterpreter.instance.PrintCurrentChord();
                    }
                }
                break;

                case FMOD.Studio.EVENT_CALLBACK_TYPE.STARTED:
                {
                    //print("FMOD EVENT STARTED!");
                }
                break;
                }
            }
            return(FMOD.RESULT.OK);
        }
Exemplo n.º 8
0
 public void AssignBeatEvent(FMOD.Studio.EventInstance instance)
 {
     timelineInfo   = new TimelineInfo();
     timelineHandle = GCHandle.Alloc(timelineInfo, GCHandleType.Pinned);
     beatCallback   = new FMOD.Studio.EVENT_CALLBACK(BeatEventCallback);
     instance.setUserData(GCHandle.ToIntPtr(timelineHandle));
     instance.setCallback(beatCallback, FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT | FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER);
 }
Exemplo n.º 9
0
    bool Process(TimelineInfo timelineInfo)
    {
        var  timelineState  = EntityManager.GetComponentData <TimelineState>(timelineInfo.Owner);
        bool isCanInterrupt = timelineState.InterruptStatus == TimelineState.InterruptState.Allow;

        if (!isCanInterrupt)
        {
            return(false);
        }
        ResourceManager.GetInstance().LoadAsset <PlayableAsset>(timelineInfo.ResPath, delegate(UnityEngine.Object[] objs)
        {
            if (objs == null || objs.Length <= 0)
            {
                return;
            }
            var entity         = timelineInfo.Owner;
            var playerDirector = EntityManager.GetComponentObject <PlayableDirector>(entity);
            playerDirector.Stop();
            playerDirector.playableAsset = objs[0] as PlayableAsset;
            var looksInfo = EntityManager.GetComponentData <LooksInfo>(entity);
            if (looksInfo.CurState != LooksInfo.State.Loaded)
            {
                return;
            }
            var looksEntity = looksInfo.LooksEntity;
            var animator    = EntityManager.GetComponentObject <Animator>(looksEntity);
            foreach (var at in playerDirector.playableAsset.outputs)
            {
                if (at.streamName.StartsWith("AnimationTrack") || at.streamName.StartsWith("Animation Track"))
                {
                    playerDirector.SetGenericBinding(at.sourceObject, animator);
                }
                else if (at.streamName.StartsWith("ParticleTrack"))
                {
                    var nameParts     = at.streamName.Split('_');
                    var hangPointName = "root";
                    if (nameParts.Length > 1)
                    {
                        hangPointName = nameParts[1];
                    }
                    // Debug.Log("hangPointName : "+hangPointName);
                    var ct             = at.sourceObject as ControlTrack;
                    var looksTrans     = EntityManager.GetComponentObject <Transform>(looksEntity);
                    var particleParent = looksTrans.Find(hangPointName);
                    foreach (var info in ct.GetClips())
                    {
                        // if (info.displayName.StartsWith("particle"))
                        // {
                        var cpa = info.asset as ControlPlayableAsset;
                        playerDirector.SetReferenceValue(cpa.sourceGameObject.exposedName, particleParent.gameObject);
                        // }
                    }
                }
            }
            playerDirector.Play();
        });
        return(true);
    }
Exemplo n.º 10
0
    static FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance instance, IntPtr parameterPtr)
    {
        //Debug.Log("callback");
        // Retrieve the user data
        IntPtr timelineInfoPtr;

        FMOD.RESULT result = instance.getUserData(out timelineInfoPtr);
        if (result != FMOD.RESULT.OK)
        {
            Debug.LogError("Timeline Callback error: " + result);
        }
        else if (timelineInfoPtr != IntPtr.Zero)
        {
            // Get the object to store beat and marker details
            GCHandle     timelineHandle = GCHandle.FromIntPtr(timelineInfoPtr);
            TimelineInfo timelineInfo   = (TimelineInfo)timelineHandle.Target;

            var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
            if (parameter.tempo != 0)
            {
                bpm = (int)parameter.tempo;
            }
            switch (type)
            {
            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT:
            {
                //var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
                timelineInfo.currentMusicBar = parameter.bar;
                bar = timelineInfo.currentMusicBar;
                //Debug.Log("bedug 1");

                timelineInfo.currentMusicBeat = parameter.beat;
                beat = timelineInfo.currentMusicBeat;
            }
            break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER:
            {
                var marker_param = (FMOD.Studio.TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_MARKER_PROPERTIES));
                timelineInfo.lastMarker = marker_param.name;
                marker = timelineInfo.lastMarker;

                //var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
                //timelineInfo.currentMusicBeat = parameter.beat;
                //beat = timelineInfo.currentMusicBeat;

                //markerEvent.Invoke();
                //Debug.Log("bedug 2");
            }
            break;
            }
        }
        return(FMOD.RESULT.OK);
    }
Exemplo n.º 11
0
 public TimelineData(TimelineInfo timeline)
     : this()
 {
     this.TimelineId   = timeline.TimelineId;
     this.Body         = timeline.Body;
     this.IsArchived   = timeline.IsArchived;
     this.CreatedBy    = new UserData(timeline.CreatedBy, timeline.CreatedByName, timeline.CreatedByEmail);
     this.CreatedDate  = timeline.CreatedDate;
     this.ModifiedBy   = new UserData(timeline.ModifiedBy, string.Empty, string.Empty);
     this.ModifiedDate = timeline.ModifiedDate;
 }
        public void AddSingleGraph(string name, Color color, BasicFunction xFunc, BasicFunction yFunc,
                                   string xAxis, string yAxis)
        {
            var info = new TimelineInfo(new TimelinePrototype(name, color),
                                        new BasicFunctionPair(xFunc, yFunc));

            AddGraph(new List <TimelineInfo>()
            {
                info
            }, xAxis, yAxis);
        }
Exemplo n.º 13
0
        // Start is called before the first frame update
        public override void OnStart()
        {
            timelineInfo = new TimelineInfo();
            beatCallback = new FMOD.Studio.EVENT_CALLBACK(BeatEventCallback);

            // Pin the class that will store the data modified during the callback
            timelineHandle = GCHandle.Alloc(timelineInfo, GCHandleType.Pinned);

            if (startMusicOnAwake)
            {
                StartCoroutine(DelayedMusicStart());
            }
        }
Exemplo n.º 14
0
    FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance instance, IntPtr parameterPtr)
    {
        IntPtr timelineInfoPtr;

        FMOD.RESULT result = instance.getUserData(out timelineInfoPtr);
        if (result != FMOD.RESULT.OK)
        {
            Debug.LogError("Timeline Callback error: " + result);
        }
        else if (timelineInfoPtr != IntPtr.Zero)
        {
            GCHandle     timelineHandle = GCHandle.FromIntPtr(timelineInfoPtr);
            TimelineInfo timelineInfo   = (TimelineInfo)timelineHandle.Target;

            switch (type)
            {
            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT:
            {
                var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
                timelineInfo.currentBeat = parameter.beat;
                timelineInfo.bpm         = parameter.tempo;
                if (OnBeat != null)
                {
                    OnBeat();
                }
            }
            break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER:
            {
                var parameter = (FMOD.Studio.TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_MARKER_PROPERTIES));
                if (OnMarker != null)
                {
                    OnMarker();
                }
                timelineInfo.lastMarker         = parameter.name;
                timelineInfo.lastMarkerPosition = parameter.position / 1000f;
            }
            break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.STOPPED:
            {
                print("stopped");
            }
            break;
            }
        }
        return(FMOD.RESULT.OK);
    }
        public void Add3DGraph(string name, BasicFunction funcX, VectorFunc funcY, string xAxis, string yAxis)
        {
            var xVec = new TimelineInfo(new TimelinePrototype("x " + name, Color.Red),
                                        new BasicFunctionPair(funcX, () => funcY().X));

            var yVec = new TimelineInfo(new TimelinePrototype("y " + name, Color.Green),
                                        new BasicFunctionPair(funcX, () => funcY().Y));

            var zVec = new TimelineInfo(new TimelinePrototype("z " + name, Color.Blue),
                                        new BasicFunctionPair(funcX, () => funcY().Z));

            AddGraph(new List <TimelineInfo> {
                xVec, yVec, zVec
            }, xAxis, yAxis);
        }
Exemplo n.º 16
0
    private void Awake()
    {
        _instance = this;

        //本地加载
        _soundDictionary = new Dictionary <string, AudioClip>();
        AudioClip[] audioArray = Resources.LoadAll <AudioClip>("Audio/SE");
        audioSources      = GetComponents <AudioSource>();
        audioSourceEffect = audioSources[1];

        audioSourceBgMusic = audioSources[0];

        audioSourceEffect_Z = audioSources[2];
        audioSourceEffect_X = audioSources[3];
        audioSourceEffect_M = audioSources[4];

        //存放到字典

        foreach (AudioClip item in audioArray)
        {
            _soundDictionary.Add(item.name, item);
        }

        audioSourceEffect_Z.clip = _soundDictionary["Bassdrum"];
        audioSourceEffect_X.clip = _soundDictionary["Snare"];
        audioSourceEffect_M.clip = _soundDictionary["Hihat"];


        //fmod init
        samplerate = 44100;


//        RuntimeManager.LowlevelSystem.getSoftwareFormat(out samplerate,out sPEAKERMODE,out rawspeaker);


        //fmod callback相关
        timelineInfo = new TimelineInfo();

        // Explicitly create the delegate object and assign it to a member so it doesn't get freed
        // by the garbage collected while it's being used
        beatCallback = new FMOD.Studio.EVENT_CALLBACK(BeatEventCallback);


        // Pin the class that will store the data modified during the callback
        timelineHandle = GCHandle.Alloc(timelineInfo, GCHandleType.Pinned);
        // Pass the object through the userdata of the instance
        //callback
    }
Exemplo n.º 17
0
 void Start()
 {
     SceneLoader.Instance.CameraBlack();
     Time.timeScale = 0;
     if (timelineInfo == null)
     {
         NetworkManager.Instance.GetTimelineInfo(info =>
         {
             Debug.Log("received!");
             timelineInfo = info;
             Init();
         });
     }
     else
     {
         Init();
     }
 }
Exemplo n.º 18
0
    // Start is called before the first frame update
    void Start()
    {
        timelineInfo = new TimelineInfo();
        // Explicitly create the delegate object and assign it to a member so it doesn't get freed
        // by the garbage collected while it's being used
        beatCallback = new FMOD.Studio.EVENT_CALLBACK(BeatEventCallback);
        musicEvent   = FMODUnity.RuntimeManager.CreateInstance(musicPath);

        // Pin the class that will store the data modified during the callback
        timelineHandle = GCHandle.Alloc(timelineInfo, GCHandleType.Pinned);
        // Pass the object through the userdata of the instance
        musicEvent.setUserData(GCHandle.ToIntPtr(timelineHandle));

        musicEvent.setCallback(beatCallback, FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT | FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER);
        musicEvent.start();

        gm = GameObject.Find("GameManager").GetComponent <GameManager>();
    }
Exemplo n.º 19
0
        /// <summary>
        /// Connect a peer to a timeline. For internal use only.
        /// </summary>
        /// <param name="peerInfo">The peer which wants to connect to a timeline.</param>
        /// <param name="remoteTimelineIndex">The index used by the peer to refer to the timeline.</param>
        /// <param name="timelineId">The unique ID of the timeline.</param>
        void ConnectPeerToTimeline(PeerInfo peerInfo, ushort remoteTimelineIndex, byte[] timelineId)
        {
            // Check if timeline exists first. If not, create it.
            TimelineInfo timelineInfo;

            if (_timelinesById.ContainsKey(timelineId))
            {
                timelineInfo = _timelinesById[timelineId];
                if (TimelineUpdated != null)
                {
                    TimelineUpdated(timelineInfo.ConnectedPeers.Count + 1, timelineId);
                }
            }
            else
            {
                timelineInfo    = new TimelineInfo();
                timelineInfo.ID = timelineId;
                _timelinesById.Add(timelineId, timelineInfo);

                if (TimelineCreated != null)
                {
                    TimelineCreated(timelineId);
                }
            }

            timelineInfo.ConnectedPeers[peerInfo]            = remoteTimelineIndex;
            peerInfo.ConnectedTimelines[remoteTimelineIndex] = timelineInfo;

            // Send cached messages if there are any

            foreach (TimelineMessage cachedMessage in timelineInfo.CachedEntries)
            {
                TimelineMessage relayMessage = CreateSetCachedMessageFromTemplate(
                    cachedMessage, remoteTimelineIndex);

                peerInfo.OutgoingMessages.Enqueue(relayMessage);
            }

            if (TimelineConnected != null)
            {
                TimelineConnected(peerInfo.Index, remoteTimelineIndex, timelineId);
            }
        }
Exemplo n.º 20
0
        public int CreateTimeline(
            string timelineName,
            string chartName,
            Color color,
            TimelineSampleSourceDelegate source = null,
            float?verticalScale = null,
            float?sampleHistory = null)
        {
            var chart = this.charts.GetOrInit(chartName);

            // Vertical scale.
            var verticalScaleToUse = verticalScale ?? this.defaultVerticalScale;

            chart.Config.VerticalScale   = verticalScaleToUse;
            chart.Config.VerticalMarkers = chart.Config.VerticalScale / 2f;

            // Sample history time.
            var sampleHistoryTime = sampleHistory ?? this.defaultSampleHistoryTime;

            chart.SampleHistoryTime        = sampleHistoryTime;
            chart.Config.HorizontalScale   = chart.SampleHistoryTime;
            chart.Config.HorizontalMarkers = chart.Config.HorizontalScale / 4f;

            var newId    = this.GetNextTimelineId();
            var timeline = new TimelineInfo(newId, timelineName)
            {
                SampleSource = source,
                Color        = color,
                Chart        = chart
            };

            chart.Timelines[newId]       = timeline;
            this.timelineChartMap[newId] = chart;

            this.Log(string.Format("Created timeline {0}", timeline), this.loggingEnabled);

            // Initialise the samples with zeros to make chart drawing simpler.
//            var numSamples = chart.GetSampleHistorySize();
//	        for (var i=0; i < numSamples; i++)
//	            timeline.Samples.Enqueue(0f);

            return(newId);
        }
Exemplo n.º 21
0
        private void LogTimelineSample(TimelineInfo timeline, float sampleValue)
        {
            if (timeline.Samples.Any())
            {
                var next = timeline.Samples.Peek();
                while (next != null && next.Timestamp < Time.time - timeline.Chart.SampleHistoryTime)
                {
                    timeline.Samples.Dequeue();
                    next = timeline.Samples.Peek();
                }
            }

            var sample = new TimelineSample(Time.time, sampleValue);

            timeline.Samples.Enqueue(sample);

            // Flag that the timeline has received a sample for this period.
            timeline.IsLatestSampleReceived = true;
        }
Exemplo n.º 22
0
        void DisconnectPeerFromTimeline(PeerInfo peerInfo, TimelineInfo timelineInfo)
        {
            // Disconnect peer from timeline.
            // Check if timeline is no longer connected to any peers. If so, remove timeline.

            ushort remoteTimelineIndex;

            if (timelineInfo.ConnectedPeers.TryGetValue(peerInfo, out remoteTimelineIndex))
            {
                peerInfo.ConnectedTimelines.Remove(remoteTimelineIndex);
                timelineInfo.ConnectedPeers.Remove(peerInfo);

                if (TimelineDisconnected != null)
                {
                    TimelineDisconnected(peerInfo.Index, remoteTimelineIndex, timelineInfo.ID);
                }
            }
            else
            {
                return;
            }

            if (timelineInfo.ConnectedPeers.Count == 0)
            {
                _timelinesById.Remove(timelineInfo.ID);

                if (TimelineDestroyed != null)
                {
                    TimelineDestroyed(timelineInfo.ID);
                }
            }
            else
            {
                if (TimelineUpdated != null)
                {
                    TimelineUpdated(timelineInfo.ConnectedPeers.Count, timelineInfo.ID);
                }
            }
        }
Exemplo n.º 23
0
    //THE SINGLETON HAS APPEARED: This allows for everything to access this SINGLE INSTANCE of the script and access its variables
    //The drawback is that if this script ever gets destroyed, it's gonna mean everything that relies on the information provided
    //by this script is gonna break.
    //public static FMODVibeTracker vt;

    /*
     * void Awake()
     * {
     *     vt = this;
     * }
     */
    // Start is called before the first frame update
    void Start()
    {
        timelineInfo = new TimelineInfo();

        //Explicitly create the delegate object and assign it to a member so it doesn't get freed
        //by the garbage collected while it's being used
        beatCallback = new FMOD.Studio.EVENT_CALLBACK(BeatEventCallback);

        musicInstance = FMODUnity.RuntimeManager.CreateInstance(music);

        //Pin the class that will store the data modified during the callback
        timelineHandle = GCHandle.Alloc(timelineInfo, GCHandleType.Pinned);
        //Pass the object through the userdata of the instance
        musicInstance.setUserData(GCHandle.ToIntPtr(timelineHandle));

        musicInstance.setCallback(beatCallback, FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT | FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER);
        musicInstance.start();

        musicInstance.getDescription(out descriptionCallback);
        descriptionCallback.getLength(out int length);

        timelineInfo.songLength = length;
    }
Exemplo n.º 24
0
    //private static
    public void GetTimelineInfo(Action <TimelineInfo> callback)
    {
        Call("api/timeline", Method.GET).Then(response =>
        {
            /*var jToken = JToken.Parse(response.text);
             * var timeline = new TimelineInfo();
             * List<Category> categories = new List<Category>();
             * foreach (var item in jToken.Children())
             * {
             *  var cat = new Category();
             *  cat = item.ToObject<Category>();
             *  categories.Add(cat);
             * }
             * timeline.Categories = categories;*/
            var categories   = JsonConvert.DeserializeObject <List <Category> >(response.text);
            var timelineInfo = new TimelineInfo
            {
                Categories = categories
            };

            callback(timelineInfo);
        });
    }
Exemplo n.º 25
0
    static FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
    {
        FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
        // Retrieve the user data
        IntPtr timelineInfoPtr;

        FMOD.RESULT result = instance.getUserData(out timelineInfoPtr);
        if (result != FMOD.RESULT.OK)
        {
            Debug.LogError("Timeline Callback error: " + result);
        }

        else if (timelineInfoPtr != IntPtr.Zero)
        {
            // Get the object to store beat and marker details
            GCHandle     timelineHandle = GCHandle.FromIntPtr(timelineInfoPtr);
            TimelineInfo timelineInfo   = (TimelineInfo)timelineHandle.Target;

            switch (type)
            {
            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT:
            {
                var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
                timelineInfo.currentMusicBeat = parameter.beat;
                beat       = timelineInfo.currentMusicBeat;
                bpm        = parameter.tempo;
                secPerBeat = 60f / bpm;

                // Event firing for on beat events.
                if (OnBeat != null)
                {
                    OnBeat();
                }

                // Event firing for every other beat.
                if (beat % 2 != 0)
                {
                    if (OnOtherBeat != null)
                    {
                        OnOtherBeat();
                    }
                }
            }
            break;

            case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER:
            {
                var parameter = (FMOD.Studio.TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_MARKER_PROPERTIES));
                timelineInfo.lastMarker = parameter.name;
                marker = timelineInfo.lastMarker;


                markerTimeLinePosition = timelinePosition;

                if (marker.Equals("ENDGAME"))
                {
                    GameManager.EndMinigame();
                }

                // Event firing for OnMarker events.
                OnMarker?.Invoke();
            }
            break;
            }
        }
        return(FMOD.RESULT.OK);
    }
Exemplo n.º 26
0
    bool Process(TimelineInfo timelineInfo)
    {
        var  timelineState  = EntityManager.GetComponentData <TimelineState>(timelineInfo.Owner);
        bool isCanInterrupt = timelineState.InterruptStatus == TimelineState.InterruptState.Allow;

        if (!isCanInterrupt)
        {
            return(false);
        }
        ResourceManager.GetInstance().LoadAsset <PlayableAsset>(timelineInfo.ResPath, delegate(UnityEngine.Object[] objs)
        {
            if (objs == null || objs.Length <= 0)
            {
                return;
            }
            var entity         = timelineInfo.Owner;
            var playerDirector = EntityManager.GetComponentObject <PlayableDirector>(entity);
            playerDirector.Stop();
            playerDirector.playableAsset = objs[0] as PlayableAsset;
            var looksInfo = EntityManager.GetComponentData <LooksInfo>(entity);
            if (looksInfo.CurState != LooksInfo.State.Loaded)
            {
                return;
            }
            var looksEntity = looksInfo.LooksEntity;
            var animator    = EntityManager.GetComponentObject <Animator>(looksEntity);
            foreach (var at in playerDirector.playableAsset.outputs)
            {
                if (at.sourceObject.GetType() == typeof(AnimationTrack))
                {
                    playerDirector.SetGenericBinding(at.sourceObject, animator);
                }
                else if (at.sourceObject.GetType() == typeof(CinemachineTrack))
                {
                    CinemachineBrain mainCamBrian = SceneMgr.Instance.MainCameraTrans.GetComponent <Cinemachine.CinemachineBrain>();//将主摄像机传入
                    playerDirector.SetGenericBinding(at.sourceObject, mainCamBrian);
                    CinemachineTrack cinemachineTrack = (CinemachineTrack)at.sourceObject;
                    int idx = 0;
                    try
                    {
                        foreach (var c in cinemachineTrack.GetClips())
                        {
                            CinemachineShot shot = (CinemachineShot)c.asset;
                            // playerDirector.SetReferenceValue(shot.VirtualCamera.exposedName, vCams[idx++]);
                        }
                    }
                    catch (Exception)
                    {
                        Debug.LogError("Clip Num InEqual Cam Num");
                    }
                }
                else if (at.streamName.StartsWith("ParticleTrack"))
                {
                    var nameParts     = at.streamName.Split('_');
                    var hangPointName = "root";
                    if (nameParts.Length > 1)
                    {
                        hangPointName = nameParts[1];
                    }
                    var ct             = at.sourceObject as ControlTrack;
                    var looksTrans     = EntityManager.GetComponentObject <Transform>(looksEntity);
                    var particleParent = looksTrans.Find(hangPointName);
                    foreach (var info in ct.GetClips())
                    {
                        var cpa = info.asset as ControlPlayableAsset;
                        playerDirector.SetReferenceValue(cpa.sourceGameObject.exposedName, particleParent.gameObject);
                    }
                }
                // Debug.Log("timelineInfo.Param != null : "+(timelineInfo.Param != null).ToString());
                if (timelineInfo.Param != null)
                {
                    var nameParts = at.streamName.Split('_');
                    // Debug.Log("nameParts : "+nameParts[0]);
                    if (timelineInfo.Param.ContainsKey(nameParts[0]))
                    {
                        var ta = at.sourceObject as TrackAsset;
                        foreach (var info in ta.GetClips())
                        {
                            // var cpa = info.asset as ScriptPlayable<>;
                            var cpa = info.asset as ParamPlayableAsset;
                            Debug.Log("cpa != null : " + (cpa != null).ToString());
                            if (cpa != null)
                            {
                                cpa.Param = timelineInfo.Param[nameParts[0]];
                            }
                            else
                            {
                                Debug.LogError("error : trying to set param with no param playable asset name : " + at.streamName);
                            }
                        }
                    }
                }
            }
            playerDirector.Play();
        });
        return(true);
    }
Exemplo n.º 27
0
        /// <summary>
        /// Process a message from one of the peers
        /// </summary>
        /// <param name="peerIndex">Index number for the peer.</param>
        /// <param name="message">The message to be processed.</param>
        public void ProcessIncomingMessage(ushort peerIndex, TimelineMessage message)
        {
            lock (_peerLock)
            {
                lock (_timelineLock)
                {
                    PeerInfo peerInfo = null;

                    if (!_peersByIndex.TryGetValue(peerIndex, out peerInfo))
                    {
                        return;
                    }

                    peerInfo.BytesToTLS += message.Data.Length;

                    // Be sure to arrange the message types in descending order of frequency.
                    // For example, sets are most frequent, so they are checked first.

                    if (message.MessageType == TimelineMessageType.RelayAbsolute)
                    {
                        BinaryReader reader = new BinaryReader(new MemoryStream(message.Data));
                        // We only need to read the timeline index, since we are only relaying, not receiving.
                        ushort timelineIndex = reader.ReadUInt16();
                        reader.Close();

                        // Get the timeline this message was intended for.
                        TimelineInfo timelineInfo = null;

                        if (!peerInfo.ConnectedTimelines.TryGetValue(timelineIndex, out timelineInfo))
                        {
                            return;
                        }

                        // Add message to cache queue
                        timelineInfo.CachedEntries.Add(message);

                        if (TimelineSet != null)
                        {
                            TimelineSet(timelineIndex, timelineInfo.ID);
                        }

                        while (timelineInfo.CachedEntries.Count > timelineInfo.EntryCacheSize)
                        {
                            timelineInfo.CachedEntries.RemoveAt(0);
                        }

                        // Loop through all the subscribers except for the sender...
                        foreach (var otherPeer in timelineInfo.ConnectedPeers)
                        {
                            if (peerInfo == otherPeer.Key)
                            {
                                continue;
                            }

                            // Create a new message to relay.
                            TimelineMessage relayMessage = CreateRelayMessageFromTemplate(message, otherPeer.Value);
                            otherPeer.Key.OutgoingMessages.Enqueue(relayMessage);
                        }
                    }
                    else if (message.MessageType == TimelineMessageType.ClockSyncPong)
                    {
                        BinaryReader reader         = new BinaryReader(new MemoryStream(message.Data));
                        double       localPingTime  = reader.ReadDouble();
                        double       remotePongTime = reader.ReadDouble();
                        double       localPongTime  = (localPingTime + _now) / 2;
                        reader.Close();

                        ClockSyncData newData = new ClockSyncData()
                        {
                            RTT    = (float)(_now - localPingTime),
                            Offset = (float)(localPongTime - remotePongTime)
                        };

                        AddClockSyncData(peerInfo, newData);
                        float correction = GetClockSyncCorrection(peerInfo);

                        TimelineMessage correctionMessage = new TimelineMessage(TimelineMessageType.ClockSyncCorrection,
                                                                                BitConverter.GetBytes(correction), DeliveryMode.Unreliable);

                        peerInfo.OutgoingMessages.Enqueue(correctionMessage);
                        peerInfo.Pinging = false;
                    }
                    else if (message.MessageType == TimelineMessageType.ConnectTimeline)
                    {
                        // Message format:
                        // 2 bytes (ushort) remote timeline index
                        // byte array (byte[]) timeline id

                        BinaryReader reader = new BinaryReader(new MemoryStream(message.Data));
                        ushort       remoteTimelineIndex = reader.ReadUInt16();
                        byte[]       timelineId          = reader.ReadBytes(message.Data.Length - sizeof(ushort));
                        reader.Close();

                        ConnectPeerToTimeline(peerInfo, remoteTimelineIndex, timelineId);
                    }
                    else if (message.MessageType == TimelineMessageType.DisconnectTimeline)
                    {
                        // Call disconnect method
                        BinaryReader reader = new BinaryReader(new MemoryStream(message.Data));
                        ushort       remoteTimelineIndex = reader.ReadUInt16();
                        reader.Close();

                        TimelineInfo timelineInfo;

                        if (peerInfo.ConnectedTimelines.TryGetValue(remoteTimelineIndex, out timelineInfo))
                        {
                            DisconnectPeerFromTimeline(peerInfo, timelineInfo);
                        }
                    }
                    else if (message.MessageType == TimelineMessageType.CacheSize)
                    {
                        BinaryReader reader = new BinaryReader(new MemoryStream(message.Data));
                        ushort       remoteTimelineIndex = reader.ReadUInt16();
                        ushort       cacheSize           = reader.ReadUInt16();
                        reader.Close();

                        TimelineInfo timelineInfo;

                        if (peerInfo.ConnectedTimelines.TryGetValue(remoteTimelineIndex, out timelineInfo))
                        {
                            timelineInfo.EntryCacheSize = cacheSize;

                            while (timelineInfo.CachedEntries.Count > cacheSize)
                            {
                                timelineInfo.CachedEntries.RemoveAt(0);
                            }
                        }
                    }
                }
            }
        }