Example #1
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);
    }
Example #2
0
    private void getScreenPos(ScriptEventData gotScreenPos)
    {
        Log.Write("SCREEN EVENT RECIEVED");
        Log.Write("In getScreenPos");
        if (gotScreenPos.Data == null)
        {
            return;
        }
        SendScreenPos sendScreenPos = gotScreenPos.Data.AsInterface <SendScreenPos>();

        if (sendScreenPos == null)
        {
            Log.Write(LogLevel.Error, Script.ID.ToString(), "Unable to create interface, check logs for missing member(s)");
            return;
        }
        XScreenPos = float.Parse(sendScreenPos.SetScreenPos[0]);
        Log.Write("XScreenPos: " + XScreenPos);
        YScreenPos = float.Parse(sendScreenPos.SetScreenPos[1]);
        ZScreenPos = float.Parse(sendScreenPos.SetScreenPos[2]);
        XScreenRot = float.Parse(sendScreenPos.SetScreenPos[3]);
        YScreenRot = float.Parse(sendScreenPos.SetScreenPos[4]);
        ZScreenRot = float.Parse(sendScreenPos.SetScreenPos[5]);
        ScreenPos  = new Vector(XScreenPos, YScreenPos, ZScreenPos);
        Vector ScreenRot = new Vector(XScreenRot * pi / 180, YScreenRot * pi / 180, ZScreenRot * pi / 180);

        ScreenQuat = Quaternion.FromEulerAngles(ScreenRot).Normalized();
        CurQuat    = RigidBody.GetOrientation();
        CurPos     = RigidBody.GetPosition();
        SlideMass  = RigidBody.GetMass();
    }
Example #3
0
        // 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. This will also break out of any loops in coroutines!
            Script.UnhandledException += UnhandledException;

            // If the object had its components set in the editor they should now have the member initialized
            // [Editor support for Component types is not yet implemented]
            // 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.
                    Log.Write("There is no RigidBodyComponent attached to this object.");
                    return;
                }
            }

            // Initialize the Home position
            Home = RigidBody.GetPosition();

            // StartCoroutine will queue CheckForCollisions to run
            // Arguments after the coroutine method are passed as arguments to the method.
            StartCoroutine(CheckForCollisions);

            // Clamp our chaos to [0,1]
            StartCoroutine(Movement, Speed, Chaos.Clamp(0.0f, 1.0f));
        }
    // 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];
        //Log.Write(BeatBlockName + " initial X: " + XWarehousePos);
        YWarehousePos = CurPos[1];
        //Log.Write(BeatBlockName + " initial Y: " + YWarehousePos);
        ZWarehousePos = CurPos[2];
        //Log.Write(BeatBlockName + " initial Z: " + ZWarehousePos);

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

        trackedEvents |= CollisionEventType.RigidBodyContact;

        StartCoroutine(CheckForCollisions, trackedEvents);
    }
Example #5
0
    // Override Init to set up event handlers and start coroutines.
    public override void Init()
    {
        // If the object had its components set in the editor they should now have the member initialized
        // [Editor support for Component types is not yet implemented]
        // The component can also be found dynamically
        if (RigidBody == null)
        {
            if (!ObjectPrivate.TryGetFirstComponent(out RigidBody))
            {
                // This example will only work on a dynamic object with a rigidbody. Bail if there isn't one.
                return;
            }
        }

        // This small Action only adds the position to the list if one of the components is not zero.
        // To set <0,0,0> as a position, set the W field on the position to any non-zero value.
        Action <Sansar.Vector> AddItem = position =>
        {
            if (position.X != 0 || position.Y != 0 || position.Z != 0 || position.W != 0)
            {
                Positions.Add(position + RigidBody.GetPosition());
            }
        };

        AddItem(new Sansar.Vector(0, 0, 0, 1));
        AddItem(Relative_Position_1);
        AddItem(Relative_Position_2);
        AddItem(Relative_Position_3);
        AddItem(Relative_Position_4);
        AddItem(Relative_Position_5);
        AddItem(Relative_Position_6);
        AddItem(Relative_Position_7);

        // Check that we got at least 2 good positions before doing anything.
        if (Positions.Count < 2)
        {
            Log.Write(Sansar.Script.LogLevel.Warning, "Not enough points set for dynamic object script. Set at least 1 position in the properties panel.");
            return;
        }

        // If there is a position set for On_Collide_TP_Dest then set up a collision coroutine to TP anyone that collides with the object.
        // To set <0,0,0> as the TP destination, set the W field on the position to any non-zero value.
        if (On_Collide_TP_Dest.X != 0 || On_Collide_TP_Dest.Y != 0 || On_Collide_TP_Dest.Z != 0 || On_Collide_TP_Dest.W != 0)
        {
            StartCoroutine(CollisionsCoroutine);
        }

        // Start up a coroutine to handle moving from position to position.
        StartCoroutine(Movement);
    }
Example #6
0
    // Override Init to set up event handlers and start coroutines.
    public override void Init()
    {
        // Sensible default setting values
        if (OpenAngleDegrees == 0)
        {
            OpenAngleDegrees = 90;
        }
        if (Channel == 0)
        {
            Channel = 1000;
        }
        if (SecondsToOpen == 0)
        {
            SecondsToOpen = 1;
        }
        if (SecondsBeforeClose == 0)
        {
            SecondsBeforeClose = 5;
        }

        // Parse the pipe-delimited sensor names into a clean list
        if (SensorNames != null)
        {
            foreach (string Name in SensorNames.Split(','))
            {
                if (Name.Trim() == "")
                {
                    continue;
                }
                SensorNameList.Add(Name.Trim());
            }
        }

        // Find the door we'll manipulate.
        if (DoorBody == null)
        {
            ObjectPrivate.TryGetFirstComponent(out DoorBody);
        }

        // Compute some basics
        OpenAngle         = OpenAngleDegrees / Mathf.DegreesPerRadian;
        ClosedOrientation = DoorBody.GetOrientation();
        HingeOffset       = new Vector(HingeOffsetX, HingeOffsetY, 0, 0).Rotate(ref ClosedOrientation);
        ClosedPosition    = DoorBody.GetPosition() + HingeOffset;

        // Only subscribe to collision events if the experience creator requested it
        if (OpenOnCollision)
        {
            DoorBody.Subscribe(CollisionEventType.CharacterContact, Collide);
        }

        // Only listen for chat if the experience creator wants outside sensors to trip this
        if (SensorNames != null)
        {
            ScenePrivate.Chat.Subscribe(Channel, null, ChatMessage);
        }

        // Start a continuous loop updating the door's position and orientation
        StartCoroutine(UpdateLoop);
    }
Example #7
0
    public override void Init()
    {
        if (!ObjectPrivate.TryGetFirstComponent <AnimationComponent>(out animComponent))
        {
            Log.Write(LogLevel.Error, "NPCAnimation.Init", "Object must have an animation added at edit time for NPCAnimation to work");
            return;
        }

        if (!ObjectPrivate.TryGetFirstComponent <RigidBodyComponent>(out rigidBodyComponent))
        {
            Log.Write(LogLevel.Error, "NPCAnimation.Init", "Object must have a rigid body added at edit time for NPCAnimation to work");
            return;
        }

        InitialPosition = rigidBodyComponent.GetPosition();
        Log.Write("Initial Position: " + InitialPosition);
        CurrentPosition = InitialPosition;

        animations = animComponent.GetAnimations();
        if (animations == null)
        {
            Log.Write("This animation component contains a single animation");
        }
        else
        {
            int i = 0;

            Log.Write("This animation component contains multiple animations");
            //hasMultipleAnimations = true;

            foreach (Animation animation in animations)
            {
                Log.Write($"[{i++}] {animation.GetName()} with {animation.GetFrameCount()} frames");
                animationList.Add(animation);
            }
        }

        animation = animComponent.DefaultAnimation;
        animation.JumpToFrame(0);
        initialAnimationParameters = animation.GetParameters();

        if (EnableEvent != "")
        {
            Log.Write("Enable Event was not null: " + EnableEvent);
            SubscribeToAll(EnableEvent, Subscribe);
        }
        else
        {
            Subscribe(null);  //executes it by passing null data
        }

        //if (DisableEvent != "")
        //{
        //    SubscribeToAll(DisableEvent, Unsubscribe);
        //}
    }
Example #8
0
 void OnCollision(CollisionData data)
 {
     Log.Write(LogLevel.Info, $"Choppable Struck by: {data.HitObject.ObjectId}");
     if (data.HitObject.ObjectId != Axe.ObjectIdReflected())
     {
         return;
     }
     Sansar.Vector pos = RigidBody.GetPosition();
     WaitFor(RigidBody.SetPosition, new Sansar.Vector(0, 2, 0));
     foreach (INamedRigidThing p in Pieces)
     {
         p.SetPosition(pos);
     }
     Log.Write(LogLevel.Info, $"Done setting stuff to ({pos.X}, {pos.Y}, {pos.Z})");
 }
    public override void Init()
    {
        Script.UnhandledException += UnhandledException; // Catch errors and keep running unless fatal

        //SubscribeToScriptEvent("CollisionData", getCollisionData);

        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();
        Log.Write("CurPos: " + CurPos);
        CurCollisionCenter = RigidBody.GetColliderCenter();
        Log.Write("CurCollisionCenter: " + CurCollisionCenter);
        CurCollisionExtents = RigidBody.GetColliderExtents();
        Log.Write("CurCollisionExtents: " + CurCollisionExtents);
        SubscribeToScriptEvent("VRControllerInfo", getVRControllerInfo);
    }
    public override void Init()
    {
        Script.UnhandledException += UnhandledException; // Catch errors and keep running unless fatal

        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();
        Log.Write("CurPos: " + CurPos);
        ZRotation = RigidBody.GetOrientation().GetEulerAngles().Z * 57.2958;
        Log.Write("Zrotation: " + ZRotation);

        int cntr = 0;

        if (ControlSurface1.Length > 0)
        {
            LoadControlSurfaces(ControlSurface1, cntr);
            cntr++;
        }
        if (ControlSurface2.Length > 0)
        {
            LoadControlSurfaces(ControlSurface2, cntr);
            cntr++;
        }
        if (ControlSurface3.Length > 0)
        {
            LoadControlSurfaces(ControlSurface3, cntr);
            cntr++;
        }
        if (ControlSurface4.Length > 0)
        {
            LoadControlSurfaces(ControlSurface4, cntr);
            cntr++;
        }
        if (ControlSurface5.Length > 0)
        {
            LoadControlSurfaces(ControlSurface5, cntr);
            cntr++;
        }
        if (ControlSurface6.Length > 0)
        {
            LoadControlSurfaces(ControlSurface6, cntr);
            cntr++;
        }
        if (ControlSurface7.Length > 0)
        {
            LoadControlSurfaces(ControlSurface7, cntr);
            cntr++;
        }
        if (ControlSurface8.Length > 0)
        {
            LoadControlSurfaces(ControlSurface8, cntr);
            cntr++;
        }
        if (ControlSurface9.Length > 0)
        {
            LoadControlSurfaces(ControlSurface9, cntr);
            cntr++;
        }
        if (ControlSurface10.Length > 0)
        {
            LoadControlSurfaces(ControlSurface10, cntr);
            cntr++;
        }
        if (ControlSurface11.Length > 0)
        {
            LoadControlSurfaces(ControlSurface11, cntr);
            cntr++;
        }
        if (ControlSurface12.Length > 0)
        {
            LoadControlSurfaces(ControlSurface12, cntr);
            cntr++;
        }
        if (ControlSurface13.Length > 0)
        {
            LoadControlSurfaces(ControlSurface13, cntr);
            cntr++;
        }
        if (ControlSurface14.Length > 0)
        {
            LoadControlSurfaces(ControlSurface14, cntr);
            cntr++;
        }
        if (ControlSurface15.Length > 0)
        {
            LoadControlSurfaces(ControlSurface15, cntr);
            cntr++;
        }
        if (ControlSurface16.Length > 0)
        {
            LoadControlSurfaces(ControlSurface16, cntr);
            cntr++;
        }
        if (ControlSurface17.Length > 0)
        {
            LoadControlSurfaces(ControlSurface17, cntr);
            cntr++;
        }
        if (ControlSurface18.Length > 0)
        {
            LoadControlSurfaces(ControlSurface18, cntr);
            cntr++;
        }
        if (ControlSurface19.Length > 0)
        {
            LoadControlSurfaces(ControlSurface19, cntr);
            cntr++;
        }
        if (ControlSurface20.Length > 0)
        {
            LoadControlSurfaces(ControlSurface20, cntr);
            cntr++;
        }
        if (ControlSurface21.Length > 0)
        {
            LoadControlSurfaces(ControlSurface21, cntr);
            cntr++;
        }
        if (ControlSurface22.Length > 0)
        {
            LoadControlSurfaces(ControlSurface22, cntr);
            cntr++;
        }
        if (ControlSurface23.Length > 0)
        {
            LoadControlSurfaces(ControlSurface23, cntr);
            cntr++;
        }
        if (ControlSurface24.Length > 0)
        {
            LoadControlSurfaces(ControlSurface24, cntr);
            cntr++;
        }
        if (ControlSurface25.Length > 0)
        {
            LoadControlSurfaces(ControlSurface25, cntr);
            cntr++;
        }
        if (ControlSurface26.Length > 0)
        {
            LoadControlSurfaces(ControlSurface26, cntr);
            cntr++;
        }
        if (ControlSurface27.Length > 0)
        {
            LoadControlSurfaces(ControlSurface27, cntr);
            cntr++;
        }
        if (ControlSurface28.Length > 0)
        {
            LoadControlSurfaces(ControlSurface28, cntr);
            cntr++;
        }
        if (ControlSurface29.Length > 0)
        {
            LoadControlSurfaces(ControlSurface29, cntr);
            cntr++;
        }
        if (ControlSurface30.Length > 0)
        {
            LoadControlSurfaces(ControlSurface30, cntr);
            cntr++;
        }
        NumOfControlSurfaces = cntr;
        ComplexInteractionHandler();
    }
        Vector GetPositionOfCOM()
        {
            Quaternion rot = RigidBody.GetOrientation();

            return(RigidBody.GetPosition() + RotationPivot.Rotate(ref rot));
        }
    private void InitializeComplexInteraction(ScriptEventData data)
    {
        CurPos = RigidBody.GetPosition();
        Log.Write("CurPos: " + CurPos);
        ZRotation = RigidBody.GetOrientation().GetEulerAngles().Z * 57.2958;
        Log.Write("Zrotation: " + ZRotation);

        int cntr = 0;

        if (ControlSurface1.Length > 0)
        {
            LoadControlSurfaces(ControlSurface1, cntr);
            cntr++;
        }
        if (ControlSurface2.Length > 0)
        {
            LoadControlSurfaces(ControlSurface2, cntr);
            cntr++;
        }
        if (ControlSurface3.Length > 0)
        {
            LoadControlSurfaces(ControlSurface3, cntr);
            cntr++;
        }
        if (ControlSurface4.Length > 0)
        {
            LoadControlSurfaces(ControlSurface4, cntr);
            cntr++;
        }
        if (ControlSurface5.Length > 0)
        {
            LoadControlSurfaces(ControlSurface5, cntr);
            cntr++;
        }
        if (ControlSurface6.Length > 0)
        {
            LoadControlSurfaces(ControlSurface6, cntr);
            cntr++;
        }
        if (ControlSurface7.Length > 0)
        {
            LoadControlSurfaces(ControlSurface7, cntr);
            cntr++;
        }
        if (ControlSurface8.Length > 0)
        {
            LoadControlSurfaces(ControlSurface8, cntr);
            cntr++;
        }
        if (ControlSurface9.Length > 0)
        {
            LoadControlSurfaces(ControlSurface9, cntr);
            cntr++;
        }
        if (ControlSurface10.Length > 0)
        {
            LoadControlSurfaces(ControlSurface10, cntr);
            cntr++;
        }
        if (ControlSurface11.Length > 0)
        {
            LoadControlSurfaces(ControlSurface11, cntr);
            cntr++;
        }
        if (ControlSurface12.Length > 0)
        {
            LoadControlSurfaces(ControlSurface12, cntr);
            cntr++;
        }
        if (ControlSurface13.Length > 0)
        {
            LoadControlSurfaces(ControlSurface13, cntr);
            cntr++;
        }
        if (ControlSurface14.Length > 0)
        {
            LoadControlSurfaces(ControlSurface14, cntr);
            cntr++;
        }
        if (ControlSurface15.Length > 0)
        {
            LoadControlSurfaces(ControlSurface15, cntr);
            cntr++;
        }
        if (ControlSurface16.Length > 0)
        {
            LoadControlSurfaces(ControlSurface16, cntr);
            cntr++;
        }
        if (ControlSurface17.Length > 0)
        {
            LoadControlSurfaces(ControlSurface17, cntr);
            cntr++;
        }
        NumOfControlSurfaces = cntr;
        ComplexInteractionHandler();
    }
Example #13
0
 Vector GetPositionOfCOM()
 {
     return(RigidBody.GetPosition() + RotationPivot.Rotate(RigidBody.GetOrientation()));
 }