Example #1
0
 protected override void OnStart()
 {
     if (!areasEnabled)
     {
         return;
     }
     cam = GetPerso <StdCam>();
     SetRule("Default");
 }
Example #2
0
        public void ClearLevel(bool createPlane = false, string spawnPerso = "")
        {
            GameObject ray = null, cam = null, test = null;

            foreach (Transform t in GameObject.Find("Dynamic World").transform)
            {
                if (t.name.Contains("YLT_RaymanModel"))
                {
                    ray = t.gameObject;
                }
                else if (t.name.Contains("StdCam"))
                {
                    cam = t.gameObject;
                }
                else if (spawnPerso != "" && t.name.Contains(spawnPerso))
                {
                    test = t.gameObject;
                }
                else
                {
                    Destroy(t.gameObject);
                }
            }
            //ray.transform.position = wldPos;
            wldPos = ray.transform.position;
            if (test != null)
            {
                test.transform.position = wldPos + new Vector3(0, 0, 10);
            }
            GameObject.Find("Father Sector").SetActive(false);
            anyCollision = true;

            if (createPlane)
            {
                ResManager.Inst("Test/Plane").transform.position = wldPos;
            }
        }
Example #3
0
        public void Load()
        {
            // Set physics clock nice and high and enable the ambience/SFX environment effects
            Time.fixedDeltaTime = 1f / 144;
            FindObjectOfType <EnvHandler>().Enable();


            // Do a few things if Empty Level is ticked
            if (emptyLevel)
            {
                ClearLevel(true, emptyLevelPersoTest);
            }


            // Remove colliders on everything but actual world collision
            GameObject root = null;

            if (!isRom)
            {
                root = GameObject.Find("Actual World");
            }
            else
            {
                foreach (var r in SceneManager.GetActiveScene().GetRootGameObjects())
                {
                    if (r.name.Contains("Hierarchy Root"))
                    {
                        root = r;
                    }
                }
            }

            if (root != null)
            {
                foreach (var col in root.GetComponentsInChildren <Collider>())
                {
                    var comp = col.GetComponent <CollideComponent>();
                    var so   = comp?.GetComponentInParent <SuperObjectComponent>();
                    if (comp == null || (comp.type != CollideType.None && comp.type != CollideType.ZDR))
                    {
                        Destroy(col);
                    }
                    else if (so != null && so.flagPreview.Contains("NoRayTracing"))
                    {
                        comp.gameObject.layer = 2;
                    }
                }
            }

            // Find Waypoint graphs
            if (controller.graphManager.transform.childCount > 0)
            {
                foreach (Transform gr in controller.graphManager.transform.GetChild(0))
                {
                    gr.gameObject.AddComponent <WaypointGraph>();
                }
            }

            // Find isolate Waypoints
            foreach (Transform w in GameObject.Find("Isolate WayPoints").transform)
            {
                w.gameObject.AddComponent <Waypoint>();
            }


            var gameMode = Settings.Mode.Rayman2PC;

#if UNITY_EDITOR
            gameMode = UnitySettings.GameMode;
#endif

            // Make sure spawnable persos are far-out
            foreach (Transform p in GameObject.Find("Spawnable persos").transform)
            {
                p.transform.position = PersoController.nullPos;
            }


            // Perso script loading for different games - applied with (Model > Family) priority
            switch (gameMode)
            {
            case Settings.Mode.Rayman2PC:
            case Settings.Mode.Rayman2DC:
            case Settings.Mode.Rayman3PC:
                // The OGs work the best
                foreach (var pb in FindObjectsOfType <PersoBehaviour>())
                {
                    Type matchModel = null, matchFamily = null;
                    foreach (var s in persoScripts)
                    {
                        if (s.Name == pb.perso.nameModel)
                        {
                            matchModel = s;
                        }
                        if (s.Name == pb.perso.nameFamily)
                        {
                            matchFamily = s;
                        }
                    }
                    if (matchModel != null)
                    {
                        persos.Add((PersoController)pb.gameObject.AddComponent(matchModel));
                    }
                    else if (matchFamily != null)
                    {
                        persos.Add((PersoController)pb.gameObject.AddComponent(matchFamily));
                    }
                }
                break;

            case Settings.Mode.Rayman2N64:
                isRom = true;
                // ROM method with gameObject name splitting, since idk how names are getting there in the first place
                foreach (var pb in FindObjectsOfType <ROMPersoBehaviour>())
                {
                    var names = pb.name.Replace("[", "").Split(new string[] { "] ", " | " }, StringSplitOptions.None);
                    if (names.Length != 3)
                    {
                        continue;
                    }
                    Type matchModel = null, matchFamily = null;
                    foreach (var s in persoScripts)
                    {
                        if (s.Name == names[1])
                        {
                            matchModel = s;
                        }
                        if (s.Name == names[0])
                        {
                            matchFamily = s;
                        }
                    }
                    PersoController pc = null;
                    if (matchModel != null)
                    {
                        persos.Add(pc = (PersoController)pb.gameObject.AddComponent(matchModel));
                    }
                    else if (matchFamily != null)
                    {
                        persos.Add(pc = (PersoController)pb.gameObject.AddComponent(matchFamily));
                    }
                    if (pc != null && names.Length >= 3)
                    {
                        pc.persoFamily = names[0];
                        pc.persoModel  = names[1];
                        pc.persoName   = names[2];
                    }
                }
                // Camera is currently applied arbitrarily
                cam = FindObjectOfType <ROMPersoBehaviour>().gameObject.AddComponent <StdCam>();
                break;

            case Settings.Mode.Rayman2PS2:
                // Names don't exist. Rayman is always last in the perso list and StdCam is applied arbitrarily
                var world = GameObject.Find("Dynamic World").transform;
                rayman = world.GetChild(world.childCount - 1).gameObject.AddComponent <YLT_RaymanModel>();
                cam    = FindObjectOfType <PersoBehaviour>().gameObject.AddComponent <StdCam>();
                break;
            }

            // HD Shaders?
            if (HDShaders)
            {
                GameObject.Find("HD").SetActive(HDShaders);
                foreach (var l in controller.lightManager.GetComponentsInChildren <LightBehaviour>())
                {
                    var light = l.gameObject.AddComponent <Light>();
                    light.shadows   = LightShadows.None;
                    light.intensity = 2;
                    light.color     = l.color;
                    light.range     = 20;
                }
                foreach (var sec in controller.sectorManager.sectors)
                {
                    foreach (var mr in sec.GetComponentsInChildren <MeshRenderer>())
                    {
                        if (mr.material.name == "mat_gouraud (Instance)")
                        {
                            var tex = mr.material.GetTexture("_Tex0");
                            mr.material             = new Material(Shader.Find("Standard"));
                            mr.material.mainTexture = tex;
                            mr.receiveShadows       = true;
                            mr.material.SetFloat("_Glossiness", 0.1f);
                        }
                    }
                }
            }

            // Done loading
            onLoad.Invoke(this, EventArgs.Empty);
            loaded = true;
        }