Exemple #1
0
        /// <summary>
        /// Begins a traversing impulse at the provided origin.
        /// Will play on pads that are the origin, destination or 'in-between' them.
        /// Defaults to a simple 'hum' effect if you don't call WithEffect()
        /// Remember to call .Play() on the returned impulse.
        /// </summary>
        /// <param name="origin">The starting AreaFlag. Only provided a single AreaFlag pad.</param>
        /// <param name="destination">The ending location for the traversing impulse.</param>
        /// <returns>The Impulse that you can call .Play() on to play a create a HapticHandle referencing that Haptic</returns>
        public static Impulse BeginTraversingImpulse(AreaFlag origin, AreaFlag destination)
        {
            if (!origin.IsSingleArea() || !destination.IsSingleArea())
            {
                Debug.LogError("Invalid AreaFlag Provided: Origin is [" + origin.NumberOfAreas() + "] area(s) and Destination is [" + destination.NumberOfAreas() + "] area(s).\n\tImpulse Generator only supports single area flag values.\n");
                return(null);
            }
            CreateImpulse creation = delegate(float attenuation, float totalLength, HapticSequence seq)
            {
                HapticPattern emanation = new HapticPattern();
                var           stages    = _grapher.Dijkstras(origin, destination);

                float timeStep     = totalLength / stages.Count;
                float time         = 0.0f;
                float baseStrength = 1f;
                for (int i = 0; i < stages.Count; i++)
                {
                    if (i > 0)
                    {
                        baseStrength *= (attenuation);
                    }
                    //Debug.Log(timeStep + "\n" + baseStrength + "\n");
                    emanation.AddSequence(time, stages[i].Location, Mathf.Clamp(baseStrength, 0f, 1f), seq);
                    time += timeStep;
                }

                return(emanation.CreateHandle().Play());
            };

            return(new Impulse(creation));
        }
Exemple #2
0
        //public static NewGraphEngine _newGrapher = new NewGraphEngine();

        /// <summary>
        /// Begins an emanating impulse at the provided origin.
        /// Defaults to a simple 'hum' effect if you don't call WithEffect()
        /// Remember to call .Play() on the returned impulse.
        /// </summary>
        /// <param name="origin">The starting AreaFlag. Only provided a single AreaFlag pad.</param>
        /// <param name="depth">How many pads this will traverse before ending (will not reverb off 'end paths')</param>
        /// <returns>An Impulse object which can be given a HapticSequence, duration or Attenuation parameters
        /// Remember to call Play() on the returned object to begin the emanation
        /// <returns>The Impulse that you can call .Play() on to play a create a HapticHandle referencing that Haptic</returns>
        public static Impulse BeginEmanatingEffect(AreaFlag origin, int depth = 2)
        {
            if (!origin.IsSingleArea())
            {
                Debug.LogError("Invalid AreaFlag Provided: Origin is [" + origin.NumberOfAreas() + "] area(s).\n\tImpulse Generator only supports single area flag values.\n");
                return(null);
            }

            if (depth < 0)
            {
                Debug.LogError("Depth for emanation is negative: " + depth + "\n\tThis will be clamped to 0 under the hood, negative numbers will likely do nothing");
            }

            CreateImpulse creation = delegate(float attenuation, float totalLength, HapticSequence seq)
            {
                HapticPattern emanation = new HapticPattern();
                var           stages    = _grapher.BFS(origin, depth);
                //var stages = _newGrapher.BFS(origin, depth);
                float baseStrength = 1.0f;
                float timeStep     = totalLength / stages.Count;
                float time         = 0.0f;
                for (int i = 0; i < stages.Count; i++)
                {
                    AreaFlag area = AreaFlag.None;
                    foreach (var item in stages[i])
                    {
                        area |= item.Location;
                        //area |= item.ConvertToAreaFlag();
                    }
                    if (i > 0)
                    {
                        baseStrength *= (attenuation);
                    }

                    emanation.AddSequence(time, area, Mathf.Clamp(baseStrength, 0f, 1f), seq);
                    time += timeStep;
                }

                return(emanation.CreateHandle().Play());
            };

            return(new Impulse(creation));
        }
Exemple #3
0
        /// <summary>
        /// This function replaces existing elements so we can change the suit definition more easily at runtime (say the player's arm is added or destroyed)
        /// </summary>
        /// <param name="SingleFlagToModify"></param>
        /// <param name="SingleHolder"></param>
        /// <param name="newCollider"></param>
        /// <returns></returns>
        public bool ModifyValidRegions(AreaFlag SingleFlagToModify, GameObject SingleHolder, HardlightCollider newCollider)
        {
            bool Succeeded = false;

            if (!SingleFlagToModify.IsSingleArea())
            {
                Debug.LogError("Attempted to modify the valid regions of the Hardlight Suit by providing a complex AreaFlag.\n\tThis function does not yet support complex area flags. Call it individually for each flag if you need to do this.");

                return(false);
            }

            if (SingleHolder == null || newCollider == null || SingleFlagToModify == AreaFlag.None)
            {
                Debug.LogError("Attempted to modify the valid regions of the Hardlight Suit to provide invalid elements (either the collider or the holder) or to provide an AreaFlag of None (" + SingleFlagToModify.ToString() + ")");
                return(false);
            }

            bool ReplacedExistingElement = false;

            var               indexOfFlag = -1;
            GameObject        oldHolder   = null;
            HardlightCollider oldCollider = null;

            //If we have the area flag already
            if (Definition.DefinedAreas.Contains(SingleFlagToModify))
            {
                ReplacedExistingElement = true;

                //Find which index it is (index is the access key to all three lists)
                indexOfFlag = Definition.DefinedAreas.IndexOf(SingleFlagToModify);

                //Store the old holder and old collider
                oldHolder   = Definition.ZoneHolders[indexOfFlag];
                oldCollider = Definition.SceneReferences[indexOfFlag];

                oldHolder.SetActive(false);

                //No longer have this location as disabled
                DisabledRegions.EnableArea(SingleFlagToModify);

                //Replace the old elements
                Definition.ZoneHolders[indexOfFlag]     = SingleHolder;
                Definition.SceneReferences[indexOfFlag] = newCollider;
                Succeeded = true;
            }
            //Flag does not yet exist in the dictionary (it was empty so it was deleted)
            else
            {
                //Store the index of the new element we're adding.
                indexOfFlag = DefinedAreas.Count;
                Definition.DefinedAreas.Add(SingleFlagToModify);

                //Add the new elements
                Definition.ZoneHolders.Add(SingleHolder);
                Definition.SceneReferences.Add(newCollider);

                //This location is now enabled.
                DisabledRegions.EnableArea(SingleFlagToModify);

                Succeeded = true;
            }

            if (ReplacedExistingElement)
            {
                //Do something about the old elements?
                //What if we want to revert?
            }

            return(Succeeded);
        }
Exemple #4
0
        private void TestAreaFlagExtensions()
        {
            //This section digs into some of the AreaFlagExtension methods.

            string   Report = "[AreaFlag Tests]\n" + "\t[Number of Areas/Single Area Tests]\n\n";
            AreaFlag flag   = AreaFlag.Mid_Ab_Left;

            Report += "How many flags in Mid Ab Left [1]:" + flag.NumberOfAreas() + " - is single area? [T] " + flag.IsSingleArea() + "\n";

            flag    = AreaFlag.Back_Both;
            Report += "How many flags in Mid Ab Left [2]: " + flag.NumberOfAreas() + " - is single area? [F] " + flag.IsSingleArea() + "\n";

            flag    = (AreaFlag.All_Areas).RemoveArea(AreaFlag.Back_Both);
            Report += "How many flags in All but Back Both [14]: " + flag.NumberOfAreas() + " - is single area? [T] " + flag.IsSingleArea() + "\n";

            flag    = AreaFlag.Right_All;
            Report += "How many flags in Right All [8]: " + flag.NumberOfAreas() + " - is single area? [T] " + flag.IsSingleArea() + "\n\n";

            flag    = AreaFlag.All_Areas;
            Report += "AreaFlag HasFlag Tests:\nDoes All_Areas contain Lower Left Ab? (T): " + flag.HasFlag(AreaFlag.Lower_Ab_Left) +
                      "\nDoes All_Areas contain Right_All? (T):  " + flag.HasFlag(AreaFlag.Right_All) +
                      "\nDoes Right_All contain Back_Both? (F): " + AreaFlag.Right_All.HasFlag(AreaFlag.Back_Both) + "\n";

            Debug.Log(Report);
        }