Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="go"></param>
        public GameObjectKun(GameObject go)
        {
            if (go == null)
            {
                return;
            }
            activeSelf = go.activeSelf;
            isStatic   = go.isStatic;
            layer      = go.layer;
            tag        = go.tag;
            instanceID = go.GetInstanceID();
            name       = go.name;

            var components = go.GetComponents(typeof(Component));

            componentKuns     = new ComponentKun[components.Length];
            componentKunTypes = new ComponentKun.ComponentKunType[components.Length];
            var i = 0;

            foreach (var component in components)
            {
                componentKunTypes[i] = ComponentKun.GetComponentKunType(component);
                var systemType = ComponentKun.GetComponetKunSyetemType(componentKunTypes[i]);
                componentKuns[i] = System.Activator.CreateInstance(systemType, new object[] { component }) as ComponentKun;
                i++;
            }
            dirty = false;
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameObject"></param>
        public void WriteBack(GameObject gameObject)
        {
            if (dirty)
            {
                gameObject.SetActive(activeSelf);
                gameObject.isStatic = isStatic;
                gameObject.layer    = layer;
                gameObject.tag      = tag;
                gameObject.name     = name;
            }

            // ComponentKun側がDirtyであるかいなかはComponentKun側に依存する
            for (var i = 0; i < componentKunTypes.Length; i++)
            {
                var componentKunType = componentKunTypes[i];
                if (componentKunType == ComponentKun.ComponentKunType.MissingMono)
                {
                    continue;
                }
                var systemType = ComponentKun.GetComponentSystemType(componentKunType);
                var component  = gameObject.GetComponent(systemType);

                //UnityChoseKun.Log(componentKunType);

                if (component == null)
                {
                    UnityChoseKun.LogWarning("component == null");
                    continue;
                }
                componentKuns[i].WriteBack(component);
                componentKuns[i].dirty = false;
            }

            dirty = false;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deserialize
        /// </summary>
        /// <param name="binaryReader">BinaryReader</param>
        public virtual void Deserialize(BinaryReader binaryReader)
        {
            m_activeSelf = binaryReader.ReadBoolean();
            m_isStatic   = binaryReader.ReadBoolean();
            m_layer      = binaryReader.ReadInt32();
            m_tag        = binaryReader.ReadString();
            m_instanceID = binaryReader.ReadInt32();
            m_name       = binaryReader.ReadString();

            var len = binaryReader.ReadInt32();

            if (len != -1)
            {
                m_componentKunTypes = new ComponentKun.ComponentKunType[len];
                for (var i = 0; i < len; i++)
                {
                    m_componentKunTypes[i] = (ComponentKun.ComponentKunType)binaryReader.ReadInt32();
                }
            }

            len = binaryReader.ReadInt32();
            if (len != -1)
            {
                m_componentKuns = new ComponentKun[len];
                for (var i = 0; i < len; i++)
                {
                    m_componentKuns[i] = ComponentKun.Instantiate(m_componentKunTypes[i]);
                    m_componentKuns[i].Deserialize(binaryReader);
                }
            }
        }
Exemplo n.º 4
0
        public T AddComponent <T>() where T : ComponentKun, new()
        {
            var componentKun = new T();


            componentKun.gameObjectKun = this;


            if (componentKuns == null)
            {
                componentKuns    = new ComponentKun[1];
                componentKuns[0] = componentKun;

                componentKunTypes    = new ComponentKun.ComponentKunType[1];
                componentKunTypes[0] = componentKun.componentKunType;
            }
            else
            {
                var list = new List <ComponentKun>(componentKuns);
                list.Add(componentKun);
                componentKuns = list.ToArray();

                var types = new List <ComponentKun.ComponentKunType>(componentKunTypes);
                types.Add(componentKun.componentKunType);
                componentKunTypes = types.ToArray();
            }


            return(componentKun);
        }
Exemplo n.º 5
0
        public override void SetComponentKun(ComponentKun componentKun)
        {
            rendererKun = componentKun as RendererKun;
            if (rendererKun.material != null)
            {
                materialView             = new MaterialView();
                materialView.materialKun = rendererKun.material;
            }

            if (rendererKun.materials != null)
            {
                materialViews = new MaterialView[rendererKun.materials.Length];
                for (var i = 0; i < materialViews.Length; i++)
                {
                    materialViews[i]             = new MaterialView();
                    materialViews[i].materialKun = rendererKun.materials[i];
                }
            }
        }
Exemplo n.º 6
0
 public override void SetComponentKun(ComponentKun componentKun)
 {
     cameraKun = (CameraKun)componentKun;
 }
Exemplo n.º 7
0
 /// <summary>
 /// ComponentKunを設定する
 /// </summary>
 /// <param name="componentKun">設定されるComponentKun</param>
 public virtual void SetComponentKun(ComponentKun componentKun)
 {
     this.componentKun = componentKun;
 }
Exemplo n.º 8
0
 public override void SetComponentKun(ComponentKun componentKun)
 {
     rigidbodyKun = componentKun as RigidbodyKun;
 }