コード例 #1
0
        /// <summary>
        /// Copy all datas of components to target container
        /// </summary>
        /// <param name="container">target container</param>
        public void CopyTo(ref ComponentContainer container)
        {
            Component component;
            Type      type;

            // clone every component
            for (int i = 0; i < components.Count; i++)
            {
                component = components[i];
                type      = component.GetType();
                Component clone = (Component)Activator.CreateInstance(type);
                clone.SID     = container.owner.Manager.NewSID();
                clone.Manager = container.owner.Manager;
                container.owner.Manager.AddGameSource(clone);
                container.AddComponent(clone);

                // clone fields
                FieldInfo[] fInfos = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                for (int f = 0; f < fInfos.Length; f++)
                {
                    fInfos[f].SetValue(clone, fInfos[f].GetValue(component));
                }
                clone.transform = clone.gameObject.transform;

                // clone properties
                //PropertyInfo[] pInfos = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                //for (int p = 0; p < pInfos.Length; p++)
                //{
                //    if(pInfos[i].CanWrite)
                //        pInfos[p].SetValue(clone, pInfos[p].GetValue(component));
                //}
                // add component into clone
            }
        }
コード例 #2
0
 /// <summary>
 /// Add new component with type T
 /// </summary>
 /// <typeparam name="T">component type</typeparam>
 public T AddComponent <T>() where T : Component, new()
 {
     return(container.AddComponent <T>(Manager));
 }