예제 #1
0
 public void AttachInput(string sceneName, string inputMethod, string parameter, float executionDelay, SignalProcessor localProcessor)
 {
     var l = new OutputEventListener() {
         targetProcessorName = sceneName,
         method = inputMethod,
         param = parameter,
         delay = executionDelay
     };
     l.FindTargetProcessors(localProcessor);
     registeredListeners.Add(l);
 }
        public void Prepare(SignalProcessor processor)
        {
            if (processor == null) {
                Debug.Log("Passed SignalProcessor was null or empty...");
                return;
            }
            this.processor = processor;

            this.outputs = new string[processor.Outputs.Count];
            for (int i = 0; i < processor.Outputs.Count; ++i) {
                this.outputs[i] = processor.Outputs[i].Name;
            }
            this.dataCache.Clear();
        }
예제 #3
0
        private Dictionary<string, string[]> inputMapping; // must be arrays because they are used from the unity GUI which does not work on lists

        #endregion Fields

        #region Constructors

        public SignalDataCache(SignalProcessor localProcessor, OutputEventListener listener)
        {
            // Generates data.
            // This is a more or lesss expensive task which is why the results are stored for later re-use.
            listener.matchedProcessors.Clear();
             // expensive but it's not used THAT often
            Dictionary<string, List<string>> inputMap = new Dictionary<string, List<string>>();
            if (!string.IsNullOrEmpty(listener.targetProcessorName)) { // check if target processor name is okay
                // Here come some exceptions. We can reference !self as target which means target is local processor
                if (listener.targetProcessorName == "!self") {
                    listener.matchedProcessors.Add(localProcessor);
                }
                else {
                    var hits = UnityEngine.Object.FindObjectsOfType<SignalProcessor>();
                    for (int i = 0; i < hits.Length; ++i) {
                        if (!hits[i].name.StartsWith(listener.targetProcessorName, StringComparison.Ordinal)) {
                            continue;
                        }
                        listener.matchedProcessors.Add(hits[i]);
                        if (hits[i].InputFuncs.Count == 0) {
                            UnityEngine.Debug.LogError("No inputfunc components on processor " + hits[i].name);
                        }
                        foreach (var kvp in hits[i].InputFuncs) {
                            if (!inputMap.ContainsKey(kvp.Key)) {
                                inputMap.Add(kvp.Key, new List<string>());
                            }
                            for (int j = 0; j < kvp.Value.Count; ++j) {
                                inputMap[kvp.Key].Add(kvp.Value[j].Name);
                            }
                        }
                    }
                }

            }

            this.inputMapping = new Dictionary<string, string[]>(inputMap.Count);
            componentList = new string[inputMap.Count];
            int k = 0;
            // This is a bit of a waste but apparently it has to happen, after all.
            // Unitys popup elements don't support lists
            foreach (var kvp in inputMap) {
                inputMapping.Add(kvp.Key, kvp.Value.ToArray());
                componentList[k] = kvp.Key;
                ++k;
            }
        }
        /// <summary>
        /// Called after savegame loading, to restore the entity reference.
        /// </summary>
        public void FindTargetProcessors(SignalProcessor localProcessor)
        {
            this.matchedProcessors = new List<SignalProcessor>();
            if (string.IsNullOrEmpty(this.targetProcessorName)) {
                return;
            }
            if (this.targetProcessorName == "!self") {
                this.matchedProcessors.Add(localProcessor);
            }
            else {
                // TODO: Check what kind of performance hit this thing has when instantiating loads of objects and how to mitigate
                // without writing a custom tracker. Seems rather redundant
                var hits = UnityEngine.Object.FindObjectsOfType<SignalProcessor>();
                for (int i = 0; i < hits.Length; ++i) {
                    if (!hits[i].name.StartsWith(this.targetProcessorName, StringComparison.InvariantCulture)) {
                        continue;
                    }
                    this.matchedProcessors.Add(hits[i]);
                }
            }

            //matchedProcessors.AddRange(SignalProcessorTracker.Instance.GetByName(this.processorName));
        }
예제 #5
0
 public void AttachInput(SignalProcessor localProcessor)
 {
     this.AttachInput(null, null, null, 0.0f, localProcessor);
 }
 public void GenerateCacheData(SignalProcessor localProcessor, OutputEventListener l)
 {
     cache = new SignalDataCache(localProcessor, l);
 }
 /// <summary>
 /// Manually untrack a handler.
 /// This can be called in a handlers OnDestroy() method.
 /// If the handler was already destroyed, is null or is untracked, nothing will happen.
 /// </summary>
 /// <param name="handler"></param>
 public void Untrack(SignalProcessor handler)
 {
     if (handler != null && trackedHandlers.Contains(handler)) {
         trackedHandlers.Remove(handler);
     }
     if (handler != null && preTrackedHandlers.Contains(handler)) {
         preTrackedHandlers.Remove(handler);
     }
 }
 /// <summary>
 /// Starts tracking a signal handler.
 /// </summary>
 /// <param name="handler"></param>
 public void Track(SignalProcessor handler)
 {
     if (!trackedHandlers.Contains(handler)) {
         this.trackedHandlers.Add(handler);
         if (preTrackedHandlers.Contains(handler)) {
             preTrackedHandlers.Remove(handler);
         }
     }
 }
 /// <summary>
 /// Starts pre-tracking a signal handler.
 /// Once properly tracked a handler is auto-removed from the pre-tracking list.
 /// </summary>
 /// <param name="handler"></param>
 public void PreTrack(SignalProcessor handler)
 {
     this.preTrackedHandlers.Add(handler);
 }