Esempio n. 1
0
 public T GetComponent <T>() where T : Component
 {
     if (!m_components.ContainsKey(typeof(T).ToString()))
     {
         DebugManager.Debug(DebugType.Error, "There are no Component of :" + typeof(T).ToString());
         return(null);
     }
     return(m_components[typeof(T).ToString()] as T);
 }
Esempio n. 2
0
        internal override void OnConstruct(Game1 game)
        {
            content = game.Content;

            //构建资源管理表
            m_resourcesRoot = AppDomain.CurrentDomain.BaseDirectory + @"/Content.mgcb";
            if (!File.Exists(m_resourcesRoot))
            {
                DebugManager.Debug(DebugType.Error, "Please move the .mfcb file to the exe root path");
            }
            ReadResourcesList();
        }
Esempio n. 3
0
        /// <summary>
        /// 添加组件,当添加成功时返回组件,不能同时在一个物体上添加两个相同的组件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T AddComponent <T>() where T : Component, new()
        {
            T t = new T {
                gameObject = this
            };

            if (m_components.ContainsKey(typeof(T).ToString()))
            {
                DebugManager.Debug(DebugType.Error, "The gameobject :" + Name + " already has the component of : " + t.GetType().ToString());
                return(null);
            }
            m_components.Add(typeof(T).ToString(), t);
            scene.OnAwakeAction  += t.OnAwake;
            scene.OnUpdateAction += t.OnUpdate;
            return(t);
        }
Esempio n. 4
0
        public void ReadResourcesList()
        {
            using (StreamReader sr = new StreamReader(m_resourcesRoot))
            {
                while (!sr.EndOfStream)
                {
                    string s = sr.ReadLine();
                    if (s.Contains("#begin"))
                    {
                        s = s.Replace("#begin ", "");
                        string[] fname = s.Split('.');
                        switch (fname[1])
                        {
                        case "jpg":
                        case "png":
                        case "bmp":
                            if (m_textureDic.ContainsKey(fname[0]))
                            {
                                DebugManager.Debug(DebugType.Error, "Resources has exsited! Please cheack the name of : " + s);
                                return;
                            }
                            m_textureDic.Add(fname[0], null);
                            break;

                        case "wav":
                            if (m_soundDic.ContainsKey(fname[0]))
                            {
                                DebugManager.Debug(DebugType.Error, "Resources has exsited! Please cheack the name of : " + s);
                                return;
                            }
                            m_soundDic.Add(fname[0], null);
                            break;
                        }
                    }
                }
            }
        }