Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CollisionEventContainer"/> struct.
 /// </summary>
 /// <param name="type">The type of event.</param>
 /// <param name="fixtureA">The fixture A.</param>
 /// <param name="fixtureB">The fixture B.</param>
 /// <param name="contact">The contact of the collision, if any.</param>
 public CollisionEventContainer(CollisionEventType type, Fixture fixtureA, Fixture fixtureB, Contact contact)
 {
     Type     = type;
     FixtureA = fixtureA;
     FixtureB = fixtureB;
     Contact  = contact;
 }
Exemplo n.º 2
0
    // Override Init to set up event handlers and start coroutines.
    public override void Init()
    {
        Script.UnhandledException += UnhandledException;
        if (RigidBody == null)
        {
            if (!ObjectPrivate.TryGetFirstComponent(out RigidBody))
            {
                // Since object scripts are initialized when the scene loads, no one will actually see this message.
                ScenePrivate.Chat.MessageAllUsers("There is no RigidBodyComponent attached to this object.");
                return;
            }
        }

        CurPos        = RigidBody.GetPosition();
        XWarehousePos = CurPos[0];
        YWarehousePos = CurPos[1];
        ZWarehousePos = CurPos[2];

        // Convert the supplied bools to the correct CollisionEventType to track
        CollisionEventType trackedEvents = 0;

        trackedEvents |= CollisionEventType.RigidBodyContact;

        StartCoroutine(CheckForCollisions, trackedEvents);
    }
Exemplo n.º 3
0
    public override void Init()
    {
        Script.UnhandledException += UnhandledException;
        if (RigidBody == null)
        {
            if (!ObjectPrivate.TryGetFirstComponent(out RigidBody))
            {
                // Since object scripts are initialized when the scene loads, no one will actually see this message.
                ScenePrivate.Chat.MessageAllUsers("There is no RigidBodyComponent attached to this object.");
                return;
            }
        }
        CurPos        = RigidBody.GetPosition();
        XWarehousePos = CurPos[0];
        //Log.Write(BeatBlockName + " initial X: " + XWarehousePos);
        YWarehousePos = CurPos[1];
        //Log.Write(BeatBlockName + " initial Y: " + YWarehousePos);
        ZWarehousePos = CurPos[2];
        //Log.Write(BeatBlockName + " initial Z: " + ZWarehousePos);
        CollisionEventType trackedEvents = 0;

        trackedEvents |= CollisionEventType.RigidBodyContact;
        //SubscribeToScriptEvent("Genre", getGenre);

        string myObject;

        myObject = ObjectPrivate.ObjectId.ToString();
        string BeatBlockConfigEvent       = "BeatBlockConfig" + myObject;
        string BeatBlockSampleConfigEvent = "BeatBlockSampleConfig" + myObject;

        BeatBlockConfigSub       = SubscribeToScriptEvent(BeatBlockConfigEvent, getBeatBlockcfg);
        BeatBlockSampleConfigSub = SubscribeToScriptEvent(BeatBlockSampleConfigEvent, getSamplescfg);
        StartCoroutine(CheckForCollisions, trackedEvents);
    }
    // Override Init to set up event handlers and start coroutines.
    public override void Init()
    {
        // When unhandled exceptions occur, they may be caught with this event handler.
        // Certain exceptions may not be recoverable at all and may cause the script to
        // immediately be removed.
        Script.UnhandledException += UnhandledException;

        // If the object had its components set in the editor they should now have the member initialized
        // The component can also be found dynamically
        if (RigidBody == null)
        {
            if (!ObjectPrivate.TryGetFirstComponent(out RigidBody))
            {
                // Since object scripts are initialized when the scene loads, no one will actually see this message.
                ScenePrivate.Chat.MessageAllUsers("There is no RigidBodyComponent attached to this object.");
                return;
            }
        }

        // Convert the supplied bools to the correct CollisionEventType to track
        CollisionEventType trackedEvents = 0;

        if (TrackAgentHits)
        {
            trackedEvents |= CollisionEventType.CharacterContact;
        }
        if (TrackObjectHits)
        {
            trackedEvents |= CollisionEventType.RigidBodyContact;
        }

        // StartCoroutine will queue CheckForCollisions to run
        // Arguments after the coroutine method are passed as arguments to the method.
        StartCoroutine(CheckForCollisions, trackedEvents);
    }
 public static IObservable <T> OnViewTrigger2DWith <T>(this GameObject t, CollisionEventType eventType)
     where T : ViewBase
 {
     return
         (t.OnTrigger2DObservable(eventType)
          .Where(p => p.gameObject.GetView <T>() != null)
          .Select(p => p.gameObject.GetView <T>()));
 }
Exemplo n.º 6
0
 public CollissionData(int start, int end, Touching allowedCollisions, CollisionEventType collisionEventType = CollisionEventType.NONE, Touching direction = Touching.ANY)
 {
     Start              = start;
     End                = end;
     AllowedCollisions  = allowedCollisions;
     CollisionEventType = collisionEventType;
     Direction          = direction;
 }
 public static IObservable <T> OnComponentTriggerWith <T>(this GameObject t, CollisionEventType eventType)
     where T : MonoBehaviour
 {
     return
         (t.OnTriggerObservable(eventType)
          .Where(p => p.gameObject.GetComponent <T>() != null)
          .Select(p => p.gameObject.GetComponent <T>()));
 }
Exemplo n.º 8
0
    private void CheckForCollisions(CollisionEventType trackedEvents)
    {
        while (true)
        {
            // This will block the coroutine until a collision happens
            CollisionData data = (CollisionData)WaitFor(RigidBody.Subscribe, trackedEvents, Sansar.Script.ComponentId.Invalid);
            if (data.EventType == CollisionEventType.CharacterContact)
            {
                //Log.Write("I hit an avatar");
            }
            else
            {
                //Log.Write("I hit an object");
                //Log.Write("CollisionEventType: " + data.EventType);
                goodhit = false;
                if (!hitDetected)
                {
                    //Log.Write("BeatBlock: BeatBlockName: " + BeatBlockName);
                    //Log.Write("Position: " + RigidBody.GetPosition());
                    pos  = GetXPosition(RigidBody.GetPosition().ToString4());
                    ypos = GetYPosition(RigidBody.GetPosition().ToString4());
                    if ((ypos == "-0") || (ypos == "0."))
                    {
                        goodhit = true;
                    }

                    if (goodhit)
                    {
                        SendBlockNames sendBlocks = new SendBlockNames();
                        sendBlocks.BlockNameArray = new List <string>();
                        sendBlocks.BlockNameArray.Add(BeatBlockName);
                        //sendBlocks.BlockNameArray.Add(pos);
                        sendBlocks.BlockNameArray.Add(newpos);
                        sendBlocks.BlockNameArray.Add(beats);
                        PostScriptEvent(ScriptId.AllScripts, "BeatBlock", sendBlocks);
                        BuildSampleLibrary();
                        Wait(TimeSpan.FromSeconds(1.5));
                        DisplayBeatBlock();
                        Wait(TimeSpan.FromSeconds(0.5));
                        //ReturnBeatBlock();
                        //Wait(TimeSpan.FromSeconds(1));
                        LightSplash();
                        SubscribeToScriptEvent("ReturnBeatBlock", getBin);
                        //Log.Write("Here");
                        hitDetected = true;
                    }
                    else
                    {
                        //ScenePrivate.Chat.MessageAllUsers("Drop the Beat Block in a Loop Bin");
                        //send it back
                        ReturnBeatBlock();
                    }
                }
            }
        }
    }
Exemplo n.º 9
0
 private void TriggerEvents(CollisionEventType type, Collision2D col)
 {
     foreach (var f in events)
     {
         if (f.eventType == type)
         {
             f.unityEvent.Invoke(col);
         }
     }
 }
Exemplo n.º 10
0
        private static List <CollissionData> GetColData()
        {
            List <CollissionData> data = new List <CollissionData>();

            var assembly = Assembly.GetExecutingAssembly();

            string path = $"{assembly.GetName().Name}.{CollissionFilePath}.{GlobalState.CURRENT_MAP_NAME}.col";

            using (Stream stream = assembly.GetManifestResourceStream(path))
            {
                if (stream == null)
                {
                    return(new List <CollissionData>());
                }

                using (StreamReader reader = new StreamReader(stream))
                {
                    while (!reader.EndOfStream)
                    {
                        string[] dataStrings = reader.ReadLine().Split('\t');

                        int                min        = -1;
                        int                max        = -1;
                        Touching           allowedCol = Touching.ANY;
                        CollisionEventType eventType  = CollisionEventType.NONE;
                        Touching           direction  = Touching.ANY;

                        if (Enum.TryParse(dataStrings[1], out allowedCol) &&
                            (dataStrings.Length == 2 || (Enum.TryParse(dataStrings[2], out eventType) &&
                                                         (dataStrings.Length <= 3 || Enum.TryParse(dataStrings[3], out direction)))))
                        {
                            if (dataStrings[0].Contains('-'))
                            {
                                string[] minMax = dataStrings[0].Split('-');

                                if (int.TryParse(minMax[0], out min) &&
                                    int.TryParse(minMax[1], out max))
                                {
                                    data.Add(new CollissionData(min, max, allowedCol, eventType, direction));
                                }
                            }
                            else
                            {
                                if (int.TryParse(dataStrings[0], out min))
                                {
                                    data.Add(new CollissionData(min, allowedCol, eventType, direction));
                                }
                            }
                        }
                    }
                }
            }

            return(data);
        }
Exemplo n.º 11
0
        internal void SetTileProperties(int tileMin, Touching allowCollisions, CollisionEventType collisionEventType, Touching direction, int tileMax = 0)
        {
            if (tileMax == 0)
            {
                tileMax = tileMin;
            }

            for (int i = tileMin; i <= tileMax; i++)
            {
                Tile tile = _tileObjects[i];

                tile.allowCollisions    = allowCollisions;
                tile.collisionEventType = collisionEventType;
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Bind a Unity Collision event to a ViewModel command.
 /// </summary>
 /// <param name="t">The view that owns the binding</param>
 /// <param name="eventType">The collision event to bind to.</param>
 /// <returns>The collision binding class that allows chaining extra options.</returns>
 public static IObservable <Collision> OnCollisionObservable(this GameObject t, CollisionEventType eventType)
 {
     if (eventType == CollisionEventType.Enter)
     {
         return(t.EnsureComponent <ObservableCollisionEnterBehaviour>().OnCollisionEnterAsObservable());
     }
     else if (eventType == CollisionEventType.Exit)
     {
         return(t.EnsureComponent <ObservableCollisionExitBehaviour>().OnCollisionExitAsObservable());
     }
     else
     {
         return(t.EnsureComponent <ObservableCollisionStayBehaviour>().OnCollisionStayAsObservable());
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// Bind a Unity Collision event to a ViewModel command.
 /// </summary>
 /// <param name="t">The view that owns the binding</param>
 /// <param name="eventType">The collision event to bind to.</param>
 /// <returns>The collision binding class that allows chaining extra options.</returns>
 public static IObservable <Collider2D> OnTrigger2DObservable(this GameObject t, CollisionEventType eventType)
 {
     if (eventType == CollisionEventType.Enter)
     {
         return(t.EnsureComponent <ObservableTriggerEnter2DBehaviour>().OnTriggerEnter2DAsObservable());
     }
     else if (eventType == CollisionEventType.Exit)
     {
         return(t.EnsureComponent <ObservableTriggerExit2DBehaviour>().OnTriggerExit2DAsObservable());
     }
     else
     {
         return(t.EnsureComponent <ObservableTriggerStay2DBehaviour>().OnTriggerStay2DAsObservable());
     }
 }
Exemplo n.º 14
0
 private void CheckForCollisions(CollisionEventType trackedEvents)
 {
     while (true)
     {
         // This will block the coroutine until a collision happens
         CollisionData data = (CollisionData)WaitFor(RigidBody.Subscribe, trackedEvents, Sansar.Script.ComponentId.Invalid);
         if (data.EventType == CollisionEventType.CharacterContact)
         {
             ScenePrivate.Chat.MessageAllUsers("I hit an avatar!");
         }
         else
         {
             ScenePrivate.Chat.MessageAllUsers("I hit an object!");
         }
     }
 }
Exemplo n.º 15
0
    private void CheckForCollisions(CollisionEventType trackedEvents)
    {
        while (true)
        {
            // This will block the coroutine until a collision happens
            CollisionData data = (CollisionData)WaitFor(RigidBody.Subscribe, trackedEvents, Sansar.Script.ComponentId.Invalid);
            if (data.EventType == CollisionEventType.CharacterContact)
            {
                //Log.Write("I hit an avatar");
            }
            else
            {
                //Log.Write("I hit an object");
                //Log.Write("CollisionEventType: " + data.EventType);
                goodhit = false;
                if (!hitDetected)
                {
                    //Log.Write("VolumeBlock");
                    //Log.Write("Position: " + RigidBody.GetPosition());
                    pos  = GetXPosition(RigidBody.GetPosition().ToString4());
                    ypos = GetYPosition(RigidBody.GetPosition().ToString4());
                    if ((ypos == "-0") || (ypos == "0."))
                    {
                        goodhit = true;
                    }

                    SendBlockNames sendBlocks = new SendBlockNames();
                    sendBlocks.BlockNameArray = new List <string>();
                    sendBlocks.BlockNameArray.Add("volume");
                    sendBlocks.BlockNameArray.Add(pos);
                    sendBlocks.BlockNameArray.Add(change);
                    if (goodhit)
                    {
                        PostScriptEvent(ScriptId.AllScripts, "VolumeBlock", sendBlocks);
                        Wait(TimeSpan.FromSeconds(2));
                        ReturnBeatBlock();
                    }
                    else
                    {
                        ScenePrivate.Chat.MessageAllUsers("Drop the Beat Block in a Loop Bin");
                        ReturnBeatBlock();
                    }
                }
            }
        }
    }
Exemplo n.º 16
0
        private void Subscribe(ScriptEventData sed)
        {
            if (Unsubscribes == null)
            {
                Unsubscribes  = SubscribeToAll(LocalEvent, LocalTeleport);
                Unsubscribes += SubscribeToAll(RemoteEvent, RemoteTeleport);

                if (UseObjectForLocal || UseObjectForRemote)
                {
                    try
                    {
                        RigidBodyComponent rigidBody = null;
                        if (ObjectPrivate.TryGetFirstComponent(out rigidBody))
                        {
                            CollisionEventType collisionEvent = rigidBody.IsTriggerVolume() ? CollisionEventType.Trigger : CollisionEventType.CharacterContact;

                            if (UseObjectForRemote)
                            {
                                Unsubscribes += rigidBody.Subscribe(collisionEvent, (CollisionData data) =>
                                {
                                    AgentPrivate agent = ScenePrivate.FindAgent(data.HitComponentId.ObjectId);
                                    if (agent != null)
                                    {
                                        RemoteTeleport(agent.AgentInfo.SessionId);
                                    }
                                }).Unsubscribe;
                            }
                            if (UseObjectForLocal)
                            {
                                Unsubscribes += rigidBody.Subscribe(collisionEvent, (CollisionData data) =>
                                {
                                    AgentPrivate agent = ScenePrivate.FindAgent(data.HitComponentId.ObjectId);
                                    if (agent != null)
                                    {
                                        LocalTeleport(agent.AgentInfo.SessionId);
                                    }
                                }).Unsubscribe;
                            }
                        }
                    }
                    catch (NullReferenceException nre) { SimpleLog(LogLevel.Info, "NullReferenceException setting up collision events: " + nre.Message); }
                    catch (Exception e) { SimpleLog(LogLevel.Error, "Exception setting up collision event user: " + e.Message); }
                }
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Adds a binding to a collision, when the collusion occurs the call back will be invoked.
 /// </summary>
 /// <param name="t"></param>
 /// <param name="eventType"></param>
 /// <param name="action"></param>
 /// <returns></returns>
 public static IDisposable BindCollision(this ViewBase t, CollisionEventType eventType, Action <Collision> action)
 {
     return(t.AddBinding(OnCollisionObservable(t.gameObject, eventType).Subscribe(action)));
 }
Exemplo n.º 18
0
 public static IObservable <T> OnViewCollisionWith <T>(this GameObject t, CollisionEventType eventType) where T : ViewBase
 {
     return(OnCollisionObservable(t, eventType).Where(p => p.GetView <T>() != null).Select(p => p.GetView <T>()));
 }
Exemplo n.º 19
0
 public static IObservable <ViewBase> OnViewCollision(this GameObject t, CollisionEventType eventType)
 {
     return(OnCollisionObservable(t, eventType).Select(p => p.GetView()).Where(p => p != null));
 }
Exemplo n.º 20
0
 public static IDisposable BindViewCollisionWith <T>(this ViewBase t, CollisionEventType eventType, Action <T> collision) where T : ViewBase
 {
     return(t.AddBinding(OnViewCollisionWith <T>(t.gameObject, eventType).Subscribe(collision)));
 }
Exemplo n.º 21
0
 public static IObservable <Collision2DBindingData <T> > OnComponentCollision2DWith <T>(this GameObject t, CollisionEventType eventType) where T : MonoBehaviour
 {
     return(t.OnCollision2DObservable(eventType).Where(p => p.gameObject.GetComponent <T>() != null).Select(p => new Collision2DBindingData <T>()
     {
         Component = p.gameObject.GetComponent <T>(),
         Collision = p
     }));
 }
Exemplo n.º 22
0
    private void CheckForCollisions(CollisionEventType trackedEvents)
    {
        while (true)
        {
            // This will block the coroutine until a collision happens
            CollisionData data = (CollisionData)WaitFor(RigidBody.Subscribe, trackedEvents, Sansar.Script.ComponentId.Invalid);
            if (data.EventType == CollisionEventType.CharacterContact)
            {
                //Log.Write("I hit an avatar");
            }
            else
            {
                //Log.Write("I hit an object");
                //Log.Write("CollisionEventType: " + data.EventType);
                goodhit = false;
                if (!hitDetected)
                {
                    //Log.Write("BPMBlock");
                    //Log.Write("BPMBlock: Position: " + RigidBody.GetPosition());
                    pos  = GetXPosition(RigidBody.GetPosition().ToString4());
                    ypos = GetYPosition(RigidBody.GetPosition().ToString4());
                    if ((ypos == "-0") || (ypos == "0."))
                    {
                        goodhit = true;
                    }

                    SendBPM sendBPM = new SendBPM();
                    sendBPM.BPMArray = new List <string>();
                    sendBPM.BPMArray.Add("bpm");
                    sendBPM.BPMArray.Add(pos);
                    sendBPM.BPMArray.Add(bpm);
                    SendBlockNames sendBlocks = new SendBlockNames();
                    sendBlocks.BlockNameArray = new List <string>();
                    sendBlocks.BlockNameArray.Add(BeatBlockName);
                    sendBlocks.BlockNameArray.Add("0");
                    sendBlocks.BlockNameArray.Add(beats);
                    SendSamples sendSamples = new SendSamples();
                    sendSamples.SampleLibrary = new List <SoundResource>();
                    if (Sample1 != null)
                    {
                        //Log.Write("BPMBlock: sample being sent from BPM: " + Sample1.GetName());
                        sendSamples.SampleLibrary.Add(Sample1);
                    }

                    if (goodhit)
                    {
                        //Log.Write("BPMBlock: goodhit");
                        PostScriptEvent(ScriptId.AllScripts, "BPMBlock", sendBPM);
                        PostScriptEvent(ScriptId.AllScripts, "BeatBlock", sendBlocks);
                        PostScriptEvent(ScriptId.AllScripts, "BeatBlockSample", sendSamples);
                        Wait(TimeSpan.FromSeconds(1.5));
                        DisplayBPMBlock();
                        Wait(TimeSpan.FromSeconds(1.0));
                        SubscribeToScriptEvent("ReturnBeatBlock", getBin);
                        subscribe   = true;
                        hitDetected = true;
                    }
                    else
                    {
                        //ScenePrivate.Chat.MessageAllUsers("Drop the BPM Block in a Loop Bin");
                        ReturnBPMBlock();
                    }
                }
            }
        }
    }
Exemplo n.º 23
0
 /// <summary>
 /// Gets called when a collision with a 3D trigger happens.
 /// </summary>
 /// <param name="type">Collision type.</param>
 /// <param name="collider">Collision information.</param>
 protected virtual void OnTrigger3D(CollisionEventType type, Collider collider)
 {
     //
 }
 public static IDisposable BindComponentTrigger2DWith <T>(this ViewBase t, CollisionEventType eventType,
                                                          Action <T> collision) where T : MonoBehaviour
 {
     return(t.AddBinding(OnComponentTriggerWith2D <T>(t.gameObject, eventType).Subscribe(collision)));
 }
Exemplo n.º 25
0
 public static bool MatchesMask(this CollisionEventType type, CollisionEventType mask)
 {
     return((type & mask) != 0);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Gets called if a 3D collision event happend.
 /// </summary>
 /// <param name="type">Collision type.</param>
 /// <param name="collision">Collsion information.</param>
 protected virtual void OnCollide3D(CollisionEventType type, Collision collision)
 {
     //
 }
Exemplo n.º 27
0
 /// <summary>
 /// Bind a Unity Collision event to a ViewModel command.
 /// </summary>
 /// <param name="t"></param>
 /// <param name="evenyType"></param>
 /// <returns></returns>
 public static IObservable <Collision> OnCollisionObservable(this GameObject t, CollisionEventType evenyType)
 {
     if (evenyType == CollisionEventType.Enter)
     {
         return(t.OnCollisionEnterAsObservable());
     }
     else if (evenyType == CollisionEventType.Exit)
     {
         return(t.OnCollisionExitAsObservable());
     }
     else
     {
         return(t.OnCollisionStayAsObservable());
     }
 }