Example #1
0
        private void findColliders(List <RigidBodyComponent> colliders, ObjectId id)
        {
            if (!ToggleCollisions)
            {
                return;
            }

            ObjectPrivate op = ScenePrivate.FindObject(id);

            if (op != null)
            {
                for (uint rbi = 0; rbi < op.GetComponentCount(ComponentType.RigidBodyComponent); ++rbi)
                {
                    if (op.TryGetComponent(rbi, out RigidBodyComponent rb))
                    {
                        if (rb != null)
                        {
                            if (colliders.Contains(rb))
                            {
                                return;
                            }
                            colliders.Add(rb);
                        }
                    }
                }
            }
        }
Example #2
0
        protected override void SimpleInit()
        {
            lights = new List <LightComponent>();

            uint lightCount = ObjectPrivate.GetComponentCount(ComponentType.LightComponent);

            for (uint i = 0; i < lightCount; i++)
            {
                LightComponent lc = (LightComponent)ObjectPrivate.GetComponent(ComponentType.LightComponent, i);
                if (lc.IsScriptable)
                {
                    lights.Add(lc);
                    break;
                }
            }

            if (lights.Count == 0)
            {
                Log.Write(LogLevel.Error, "SimpleLight::Init", "Object must have at least one scriptable light added at edit time for SimpleLight script to work.");
                return;
            }

            if (StartEnabled)
            {
                Subscribe(null);
            }

            SubscribeToAll(EnableEvent, Subscribe);
            SubscribeToAll(DisableEvent, Unsubscribe);

            // Potentially override the initial state of the light with A/B/C or an event specified for one of the modes.
            if (!string.IsNullOrWhiteSpace(InitialModeEventName))
            {
                if (InitialModeEventName.ToUpper() == "A" || ModeAEvent.Contains(InitialModeEventName))
                {
                    SetColorAndIntensityOfAllLights(ModeAColor, ModeAIntensity);
                }
                else if (InitialModeEventName.ToUpper() == "B" || ModeBEvent.Contains(InitialModeEventName))
                {
                    SetColorAndIntensityOfAllLights(ModeBColor, ModeBIntensity);
                }
                else if (InitialModeEventName.ToUpper() == "C" || ModeCEvent.Contains(InitialModeEventName))
                {
                    SetColorAndIntensityOfAllLights(ModeCColor, ModeCIntensity);
                }
            }
        }
Example #3
0
        protected override void SimpleInit()
        {
            rnd = new Random();

            lights = new List <LightComponent>();

            uint lightCount = ObjectPrivate.GetComponentCount(ComponentType.LightComponent);

            for (uint i = 0; i < lightCount; i++)
            {
                LightComponent lc = (LightComponent)ObjectPrivate.GetComponent(ComponentType.LightComponent, i);
                if (lc.IsScriptable)
                {
                    lights.Add(lc);
                    break;
                }
            }

            if (lights.Count == 0)
            {
                Log.Write(LogLevel.Error, "SimpleLightOnOff::Init", "Object must have at least one scriptable light added at edit time for SimpleLightOnOff script to work.");
                return;
            }

            initialColor     = lights[0].GetNormalizedColor();
            initialIntensity = lights[0].GetRelativeIntensity();

            randomMinIntensity = (MinRandomIntensity < MaxRandomIntensity ? MinRandomIntensity : MaxRandomIntensity);
            randomMaxIntensity = (MinRandomIntensity < MaxRandomIntensity ? MaxRandomIntensity : MinRandomIntensity);

            // Turn off the light if specified
            if (TurnOffAtStart)
            {
                SetColorAndIntensityOfAllLights(Sansar.Color.Black, 0.0f);
            }

            if (StartEnabled)
            {
                Subscribe(null);
            }

            SubscribeToAll(EnableEvent, Subscribe);
            SubscribeToAll(DisableEvent, Unsubscribe);
        }
        public override void Init()
        {
            for (uint i = 0; i < ObjectPrivate.GetComponentCount(ComponentType.MeshComponent); i++)
            {
                meshes.Add((MeshComponent)ObjectPrivate.GetComponent(ComponentType.MeshComponent, i));
            }

            animationComponent = (AnimationComponent)ObjectPrivate.GetComponent(ComponentType.AnimationComponent, 0);

            if ((anim_base = animationComponent.GetAnimation("EventHorizon")) == null)
            {
                Log.Write(LogLevel.Error, "Animation 'EventHorizon' (base animation) not found.");
            }

            if ((anim_open = animationComponent.GetAnimation("EventHorizon_Open")) == null)
            {
                Log.Write(LogLevel.Error, "Animation 'EventHorizon_Open' (opening animation) not found.");
            }

            if ((anim_close = animationComponent.GetAnimation("EventHorizon_Close")) == null)
            {
                Log.Write(LogLevel.Error, "Animation 'EventHorizon_Close' (closing animation) not found.");
            }

            if (anim_base == null || anim_open == null || anim_close == null)
            {
                return;
            }

            foreach (MeshComponent mesh in meshes)
            {
                mesh.SetIsVisible(false);
            }

            HorizonTeleporter.SetEnabled(false);
            HorizonTeleporter.Subscribe(TeleportAgent);

// DEBUG CODE
#if false
            ScenePrivate.Chat.Subscribe(0, Chat.User, OnChat);
        }
Example #5
0
        public void AnalyzeGateStructure()
        {
            uint meshComponentCount = ObjectPrivate.GetComponentCount(ComponentType.MeshComponent);
            Dictionary <string, MeshComponent> meshes = new Dictionary <string, MeshComponent>();

            for (uint i = 0; i < meshComponentCount; i++)
            {
                MeshComponent mc = (MeshComponent)ObjectPrivate.GetComponent(ComponentType.MeshComponent, i);
                if (!mc.IsScriptable)
                {
                    continue;
                }

                string name = thisModelTranslator.GetRealMeshName(mc.Name);
                meshes[name] = mc;
            }

            chevrons       = GatherLights(meshes, "Chevron");
            symbols        = GatherLights(meshes, "Symbol");
            symbolLitState = new bool[symbols.Count];
            FlushLights();

            Log.Write(LogLevel.Info, "Chevrons found:" + chevrons.Count + ", Symbols found: " + symbols.Count);
        }
Example #6
0
        protected override void SimpleInit()
        {
            lights = new List<LightComponent>();

            uint lightCount = ObjectPrivate.GetComponentCount(ComponentType.LightComponent);

            for (uint i = 0; i < lightCount; i++)
            {
                LightComponent lc = (LightComponent) ObjectPrivate.GetComponent(ComponentType.LightComponent, i);
                if (lc.IsScriptable)
                {
                    lights.Add(lc);
                    break;
                }
            }

            if (lights.Count == 0)
            {
                Log.Write(LogLevel.Error, "SimpleLight::Init", "Object must have at least one scriptable light added at edit time for SimpleLight script to work.");
                return;
            }

            InitialColors = new Sansar.Color[lights.Count];
            InitialIntensities = new float[lights.Count];
            for (int i=0; i<lights.Count;++i)
            {
                InitialColors[i] = lights[i].GetNormalizedColor();
                InitialIntensities[i] = lights[i].GetRelativeIntensity();
            }

            if (StartEnabled) Subscribe(null);

            SubscribeToAll(EnableEvent, Subscribe);
            SubscribeToAll(DisableEvent, Unsubscribe);

        }
Example #7
0
        protected override void SimpleInit()
        {
            if (LightComponents.Count > 0)
            {
                int removed = LightComponents.RemoveAll(light => light == null || !light.IsScriptable);
                if (removed > 0)
                {
                    Log.Write(LogLevel.Error, "Light::Init", $"{removed} lights were not set scriptable and will not be controllable by this script.");
                }
                if (LightComponents.Count == 0)
                {
                    Log.Write(LogLevel.Error, "Light::Init", "None of the selected Lights were scriptable.");
                    return;
                }
            }
            else
            {
                uint lightCount        = ObjectPrivate.GetComponentCount(ComponentType.LightComponent);
                bool foundUnscriptable = false;
                for (uint i = 0; i < lightCount; i++)
                {
                    LightComponent lc = (LightComponent)ObjectPrivate.GetComponent(ComponentType.LightComponent, i);
                    if (lc.IsScriptable)
                    {
                        LightComponents.Add(lc);
                    }
                    else if (!foundUnscriptable)
                    {
                        Log.Write(LogLevel.Error, "Light::Init", "Some lights on this object are not scriptable (first found: " + lc.Name + ")");
                        foundUnscriptable = true;
                    }
                }

                if (LightComponents.Count == 0)
                {
                    Log.Write(LogLevel.Error, "Light::Init", "No scriptable lights found on this object: " + ObjectPrivate.Name);
                    return;
                }
            }

            if (StartEnabled)
            {
                Subscribe(null);
            }

            SubscribeToAll(EnableEvent, Subscribe);
            SubscribeToAll(DisableEvent, Unsubscribe);

            // Potentially override the initial state of the light with A/B/C or an event specified for one of the modes.
            if (!string.IsNullOrWhiteSpace(InitialModeEventName))
            {
                if (InitialModeEventName.ToUpper() == "A" || ModeAEvent.Contains(InitialModeEventName))
                {
                    SetColorAndIntensityOfAllLights(ModeAColor, ModeAIntensity);
                }
                else if (InitialModeEventName.ToUpper() == "B" || ModeBEvent.Contains(InitialModeEventName))
                {
                    SetColorAndIntensityOfAllLights(ModeBColor, ModeBIntensity);
                }
                else if (InitialModeEventName.ToUpper() == "C" || ModeCEvent.Contains(InitialModeEventName))
                {
                    SetColorAndIntensityOfAllLights(ModeCColor, ModeCIntensity);
                }
            }
        }
Example #8
0
        protected override void SimpleInit()
        {
            rnd = new Random();

            if (LightComponents.Count > 0)
            {
                int removed = LightComponents.RemoveAll(light => light == null || !light.IsScriptable);
                if (removed > 0)
                {
                    Log.Write(LogLevel.Error, "LightOnOff::Init", $"{removed} lights were not set scriptable and will not be controllable by this script.");
                }
                if (LightComponents.Count == 0)
                {
                    Log.Write(LogLevel.Error, "LightOnOff::Init", "None of the selected Lights were scriptable.");
                    return;
                }
            }
            else
            {
                uint lightCount        = ObjectPrivate.GetComponentCount(ComponentType.LightComponent);
                bool foundUnscriptable = false;
                for (uint i = 0; i < lightCount; i++)
                {
                    LightComponent lc = (LightComponent)ObjectPrivate.GetComponent(ComponentType.LightComponent, i);
                    if (lc.IsScriptable)
                    {
                        LightComponents.Add(lc);
                    }
                    else if (!foundUnscriptable)
                    {
                        Log.Write(LogLevel.Error, "LightOnOff::Init", "Some lights on this object are not scriptable (first found: " + lc.Name + ")");
                        foundUnscriptable = true;
                    }
                }

                if (LightComponents.Count == 0)
                {
                    Log.Write(LogLevel.Error, "LightOnOff::Init", "No scriptable lights found on this object: " + ObjectPrivate.Name);
                    return;
                }
            }

            initialColor     = LightComponents[0].GetNormalizedColor();
            initialIntensity = LightComponents[0].GetRelativeIntensity();

            randomMinIntensity = (MinRandomIntensity < MaxRandomIntensity ? MinRandomIntensity : MaxRandomIntensity);
            randomMaxIntensity = (MinRandomIntensity < MaxRandomIntensity ? MaxRandomIntensity : MinRandomIntensity);

            // Turn off the light if specified
            if (TurnOffAtStart)
            {
                SetColorAndIntensityOfAllLights(Sansar.Color.Black, 0.0f);
            }

            if (StartEnabled)
            {
                Subscribe(null);
            }

            SubscribeToAll(EnableEvent, Subscribe);
            SubscribeToAll(DisableEvent, Unsubscribe);
        }
Example #9
0
        public override void Init()
        {
            Script.UnhandledException += Script_UnhandledException;

            foreach (var mesh in ShowMeshes)
            {
                if (mesh == null || !mesh.IsValid)
                {
                    continue;
                }

                if (mesh.IsScriptable)
                {
                    ScriptableShowMeshes.Add(mesh);
                    mesh.SetIsVisible(false);

                    findColliders(ShowColliders, mesh.ComponentId.ObjectId);
                }
                else
                {
                    Log.Write(LogLevel.Error, "The mesh " + mesh.Name + " is not scriptable and will not have it's visibility changed.");
                }
            }

            foreach (var mesh in HideMeshes)
            {
                if (mesh == null || !mesh.IsValid)
                {
                    continue;
                }

                if (mesh.IsScriptable)
                {
                    ScriptableHideMeshes.Add(mesh);
                    mesh.SetIsVisible(true);

                    findColliders(HideColliders, mesh.ComponentId.ObjectId);
                }
                else
                {
                    Log.Write(LogLevel.Error, "The mesh " + mesh.Name + " is not scriptable and will not have it's visibility changed.");
                }
            }

            if (ScriptableShowMeshes.Count == 0 && ScriptableHideMeshes.Count == 0)
            {
                for (uint index = 0; index < ObjectPrivate.GetComponentCount(MeshComponent.ComponentType); ++index)
                {
                    MeshComponent mesh = ObjectPrivate.GetComponent(MeshComponent.ComponentType, index) as MeshComponent;
                    if (mesh == null || !mesh.IsValid)
                    {
                        continue;
                    }
                    if (mesh.IsScriptable)
                    {
                        ScriptableShowMeshes.Add(mesh);
                    }
                }
            }

            if (ScriptableShowMeshes.Count == 0 && ScriptableHideMeshes.Count == 0)
            {
                Log.Write(LogLevel.Error, "No scriptable meshes set (and this object's meshes are not scriptable) on Quest Visibility script for object " + ObjectPrivate.Name);
                return;
            }

            InitVisibility();
        }