예제 #1
0
    static bool CheckSelection(string tag)
    {
        if (Selection.activeTransform == null)
        {
            return(false);
        }

        Transform selected = Selection.activeTransform;

        if (tag.Contains("root"))
        {
            LevelRoot root = selected.GetComponent <LevelRoot>();
            if (root != null)
            {
                return(true);
            }
        }
        else if (tag.Contains("zone"))
        {
            Zone zone = selected.GetComponent <Zone>();
            if (zone != null)
            {
                return(true);
            }
        }

        return(false);
    }
예제 #2
0
    void Awake()
    {
        Asserts.Assert(null == instance);
        instance = this;

        rootTransform = gameObject.transform;
    }
예제 #3
0
        public void Save()
        {
            var data = new JObject();

            data["name"]       = Name;
            data["components"] = LevelRoot.SerializeComponents();
            data["entities"]   = LevelRoot.SerializeChildren();

            System.IO.File.WriteAllText(File, data.ToString(Formatting.Indented));
        }
예제 #4
0
    void PlayerDied(Entity player)
    {
        Killable entityComponent = player.GetEntityComponent <Killable>();
        bool     flag            = entityComponent != null && (entityComponent.CurrentHp > 0f || entityComponent.SilentDeath);

        this.mayChangeLevel = !flag;
        this.UnregEvents(player);
        base.enabled = true;
        this.timer   = this._deathTime;
        player.SaveState();
        if (!flag)
        {
            ProjectileFactory.Instance.DeactivateAll();
            if (this._doDeathOffset)
            {
                LevelRoom roomForPosition = LevelRoom.GetRoomForPosition(player.WorldTracePosition, null);
                this.levelCam.ReleaseRoom(this._releaseCamTime);
                player.RealTransform.position = player.WorldPosition + this._deathOffset;
                if (roomForPosition != null)
                {
                    this.levelRoot = roomForPosition.LevelRoot;
                    LevelRoom.SetCurrentActiveRoom(null, false);
                    if (this.levelRoot != null)
                    {
                        this.levelRoot.gameObject.SetActive(false);
                    }
                }
            }
            if (this.backCam != null)
            {
                this.fadeTimer     = this._bgFadeTime;
                this.fadeTimeScale = 1f / this.fadeTimer;
            }
            this.useRoomSpawn = false;
        }
        else
        {
            this.timer        = this._weakDeathTime;
            this.fadeTimer    = 0f;
            this.useRoomSpawn = true;
        }
        if (this.followCam != null)
        {
            this.followCam.SetFollowScale(new Vector3(0.9f, 0.25f, 0.9f));
        }
        this.noFadeOut = false;
        if (entityComponent != null && entityComponent.SilentDeath)
        {
            this.mayChangeLevel = true;
            this.useRoomSpawn   = false;
            this.noFadeOut      = true;
            this.timer          = 0f;
        }
    }
예제 #5
0
        public void clearAllLevelChildren()
        {
            for (int i = 0; i < LevelRoot.childCount; i++)
            {
                Destroy(LevelRoot.GetChild(i).gameObject);
            }

            for (int i = 0; i < TutorialRoot.childCount; i++)
            {
                Destroy(TutorialRoot.GetChild(i).gameObject);
            }
        }
예제 #6
0
        /// <summary>
        /// Regular gamemode uses a preset list of possible hold orders. This creates a bunch randomly.
        /// </summary>
        private List <TNH_PointSequence> GenerateRandomPointSequences(int count)
        {
            List <TNH_PointSequence> sequences = new List <TNH_PointSequence>();

            for (int ii = 0; ii < count; ii++)
            {
                TNH_PointSequence sequence = ScriptableObject.CreateInstance <TNH_PointSequence>();

                // Logic for forced spawn location.
                ForcedSpawn forcedSpawn = LevelRoot.GetComponentInChildren <ForcedSpawn>();
                if (forcedSpawn != null)
                {
                    sequence.StartSupplyPointIndex = _tnhManager.SupplyPoints.IndexOf(_tnhManager.SupplyPoints.First(x => x.gameObject == forcedSpawn.gameObject));
                }
                else
                {
                    sequence.StartSupplyPointIndex = Random.Range(0, _tnhManager.SupplyPoints.Count);
                }

                // If the mapper hasn't set a custom hold order
                if (LevelRoot.ExtraData == null || LevelRoot.ExtraData[0].Value == "")
                {
                    sequence.HoldPoints = new List <int>
                    {
                        Random.Range(0, _tnhManager.HoldPoints.Count),
                        Random.Range(0, _tnhManager.HoldPoints.Count),
                        Random.Range(0, _tnhManager.HoldPoints.Count),
                        Random.Range(0, _tnhManager.HoldPoints.Count),
                        Random.Range(0, _tnhManager.HoldPoints.Count)
                    }
                }
                ;
                else
                {
                    var namedOrder = LevelRoot.ExtraData[0].Value.Split(',');
                    sequence.HoldPoints = namedOrder.Select(x => _tnhManager.HoldPoints.FindIndex(y => y.name == x)).ToList();
                }

                // Fix sequence, because they may generate the same point after the current point, IE {1,4,4)
                // This would break things.
                for (int jj = 0; jj < sequence.HoldPoints.Count - 1; jj++)
                {
                    if (sequence.HoldPoints[jj] == sequence.HoldPoints[jj + 1])
                    {
                        sequence.HoldPoints[jj + 1] = (sequence.HoldPoints[jj + 1] + 1) % _tnhManager.HoldPoints.Count;
                    }
                }

                sequences.Add(sequence);
            }

            return(sequences);
        }
예제 #7
0
    // Use this for initialization
    void Start()
    {
        // get levels from Resources/level.xml
        TextAsset textAsset = (TextAsset)Resources.Load("levels");

        if (textAsset == null)
        {
            Debug.Log("ERROR: Cannot load levels.xml"); return;
        }

        StreamReader sr = new StreamReader(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(textAsset.text)), System.Text.Encoding.UTF8);

        XmlSerializer xmlSerializer = new XmlSerializer(typeof(LevelRoot));

        LevelRoot = (LevelRoot)xmlSerializer.Deserialize(sr);
    }
예제 #8
0
    /// <summary>
    /// 创建场景根物体
    /// </summary>
    static LevelRoot Create()
    {
        LevelRoot root = GameObject.FindObjectOfType <LevelRoot>();

        if (root != null)
        {
            return(root);
        }

        GameObject go = new GameObject();

        go.name     = "LevelRoot";
        go.isStatic = true;
        root        = go.AddComponent <LevelRoot>();

        return(root);
    }
예제 #9
0
        /// <summary>
        /// Base function for setting up the TNH Manager object to handle a custom level.
        /// </summary>
        public override void Resolve()
        {
            _tnhManager = ObjectReferences.ManagerDonor;

            // Hold points need to be set.
            _tnhManager.HoldPoints = LevelRoot.GetComponentsInChildren <TNH_HoldPoint>(true).ToList();

            // Supply points need to be set.
            _tnhManager.SupplyPoints = LevelRoot.GetComponentsInChildren <TNH_SupplyPoint>(true).ToList();

            // Possible Sequences need to be generated at random.
            if (LevelRoot.ExtraData == null || LevelRoot.ExtraData[0].Value == "")
            {
                _tnhManager.PossibleSequnces = GenerateRandomPointSequences(1);
            }

            // Safe Pos Matrix needs to be set. Diagonal for now.
            TNH_SafePositionMatrix maxMatrix = GenerateTestMatrix();

            _tnhManager.SafePosMatrix = maxMatrix;
        }
예제 #10
0
 void OnDestroy()
 {
     Asserts.Assert(this == instance);
     instance = null;
 }
예제 #11
0
    public void Init()
    {
        m_root = GameObject.FindObjectOfType <LevelRoot>();
        if (m_root == null)
        {
            Debug.LogError("There is no LevelRoot Object in the scene!");
            return;
        }

        if (m_zonelist == null || m_zonelist.Count == 0)
        {
            m_zonelist = new List <IDObject>();
            foreach (Zone zone in m_root.GetComponentsInChildren <Zone>())
            {
                m_zonelist.Add(zone);
            }
        }
        m_zonelist.Sort(new IDObjectComparer());


        mPlayerSpawnList = new Dictionary <int, List <IDObject> >();
        mEnemySpawnList  = new Dictionary <int, List <IDObject> >();
        mTransporterList = new Dictionary <int, List <IDObject> >();
        foreach (Zone zone in m_zonelist)
        {
            // 查找PlayerSpawn
            PlayerSpawn[]   playerspawns = zone.GetComponentsInChildren <PlayerSpawn>();
            List <IDObject> plist        = new List <IDObject>(playerspawns);
            plist.Sort(new IDObjectComparer());
            if (!mPlayerSpawnList.ContainsKey(zone.id))
            {
                mPlayerSpawnList.Add(zone.id, plist);
            }
            else
            {
                Debug.LogError("zone id key problem:" + zone.id);
            }
            foreach (PlayerSpawn spawn in playerspawns)
            {
                spawn.zone_id = zone.id;
            }

            // 查找EnemySpawn
            EnemySpawn[]    enemyspawns = zone.GetComponentsInChildren <EnemySpawn>();
            List <IDObject> elist       = new List <IDObject>(enemyspawns);
            elist.Sort(new IDObjectComparer());
            mEnemySpawnList.Add(zone.id, elist);
            foreach (EnemySpawn spawn in enemyspawns)
            {
                spawn.zone_id = zone.id;
            }

            // 查找LevelTransporter
            LevelTransporter[] transporters = zone.GetComponentsInChildren <LevelTransporter>();
            List <IDObject>    tlist        = new List <IDObject>(transporters);
            tlist.Sort(new IDObjectComparer());
            mTransporterList.Add(zone.id, tlist);
            foreach (LevelTransporter trans in transporters)
            {
                trans.zone_id       = zone.id; // 更改了数据
                trans.next_zone_id  = 0;       // 更改了数据
                trans.next_spawn_id = 0;       // 更改了数据
            }
        }
    }
예제 #12
0
    static void BuildMap()
    {
        LevelRoot root  = CreateLevelRoot();
        string    name  = EditorApplication.currentScene;
        int       index = name.LastIndexOf('/');

        name  = name.Substring(index + 1, name.Length - index - 1);
        index = name.IndexOf('.');
        name  = name.Substring(0, index);

        root.name = name;
        Transform[] children = root.GetComponentsInChildren <Transform>();

        int defaultlayer = GameObjectUtility.GetNavMeshLayerFromName("Default");

        //int olayer = GameObjectUtility.GetNavMeshLayerFromName("Not Walkable");

        foreach (Transform t in children)
        {
            if (t.name.StartsWith("gnav_")) // 地面
            {
                MeshRenderer r = t.GetComponent <MeshRenderer>();
                if (r != null)
                {
                    r.enabled = true;
                }
                t.gameObject.isStatic = true;
                //GameObjectUtility.SetNavMeshLayer(t.gameObject, defaultlayer);
                t.gameObject.layer = LayerMask.NameToLayer("ground");
                MeshCollider col = t.GetComponent <MeshCollider>();
                if (col == null)
                {
                    col           = t.gameObject.AddComponent <MeshCollider>();
                    col.isTrigger = false;
                }
            }
            else if (t.name.StartsWith("onav_")) // 墙
            {
                MeshRenderer r = t.GetComponent <MeshRenderer>();
                if (r != null)
                {
                    r.enabled = true;
                }
                t.gameObject.isStatic = true;
                //GameObjectUtility.SetNavMeshLayer(t.gameObject, olayer);
                MeshCollider col = t.GetComponent <MeshCollider>();
                if (col == null)
                {
                    col           = t.gameObject.AddComponent <MeshCollider>();
                    col.isTrigger = true;
                }
                t.gameObject.layer = LayerMask.NameToLayer("wall");
            }
            else if (t.name.StartsWith("cnav_")) // 摄像机
            {
                MeshRenderer r = t.GetComponent <MeshRenderer>();
                if (r != null)
                {
                    r.enabled = true;
                }
                t.gameObject.isStatic = true;
                GameObjectUtility.SetStaticEditorFlags(t.gameObject, ~StaticEditorFlags.NavigationStatic);
                MeshCollider col = t.GetComponent <MeshCollider>();
                if (col == null)
                {
                    col           = t.gameObject.AddComponent <MeshCollider>();
                    col.isTrigger = true;
                }
                //t.gameObject.layer = LayerMask.NameToLayer("camera");// 摄像机的层需要手工设置
            }
            else if (t.name.StartsWith("cnav2_")) // 摄像机
            {
                MeshRenderer r = t.GetComponent <MeshRenderer>();
                if (r != null)
                {
                    r.enabled = true;
                }
                t.gameObject.isStatic = true;
                GameObjectUtility.SetStaticEditorFlags(t.gameObject, ~StaticEditorFlags.NavigationStatic);
                MeshCollider col = t.GetComponent <MeshCollider>();
                if (col == null)
                {
                    col           = t.gameObject.AddComponent <MeshCollider>();
                    col.isTrigger = true;
                }
                t.gameObject.layer = LayerMask.NameToLayer("camera_side");
            }
            else
            {
                GameObjectUtility.SetStaticEditorFlags(t.gameObject, ~StaticEditorFlags.NavigationStatic);
            }
        }

        //NavMeshBuilder.ClearAllNavMeshes();
        //NavMeshBuilder.BuildNavMesh();

        foreach (Transform t in children)
        {
            if (t.name.StartsWith("gnav_"))
            {
                MeshRenderer r = t.GetComponent <MeshRenderer>();
                if (r != null)
                {
                    r.enabled = false;
                }
            }
            else if (t.name.StartsWith("onav_"))
            {
                MeshRenderer r = t.GetComponent <MeshRenderer>();
                if (r != null)
                {
                    r.enabled = false;
                }
            }
            else if (t.name.StartsWith("cnav_"))
            {
                MeshRenderer r = t.GetComponent <MeshRenderer>();
                if (r != null)
                {
                    r.enabled = false;
                }
            }
        }
    }