예제 #1
0
        /// <summary>
        /// EditorからPlayerへの受信
        /// </summary>
        /// <param name="args"></param>
        void OnMessageEvent(MessageEventArgs args)
        {
            //UnityChoseKun.Log("UnityChoseKun::OnMessageEvent");
            if (args.data == null)
            {
                UnityChoseKun.LogError("args.data == null");
            }
            else
            {
                MemoryStream memory       = new MemoryStream(args.data);
                BinaryReader binaryReader = new BinaryReader(memory);

                try
                {
                    var messageID = (UnityChoseKun.MessageID)binaryReader.ReadInt32();
                    //UnityChoseKun.Log("message.id " + messageID);
                    var func = onMessageFuncDict[messageID];
                    func(binaryReader);
                }

                finally
                {
                    binaryReader.Close();
                    memory.Close();
                }
            }
        }
예제 #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;
        }
예제 #3
0
        /// <summary>
        /// ComponentKunTypeからComponentKunのSystem.Typeを取得する
        /// </summary>
        /// <params name="componentKunType">チェックするComponentKunType</params>
        /// <returns>ComponentKunのSystem.Type</returns>
        public static System.Type GetComponetKunSyetemType(ComponentKunType componentKunType)
        {
            if (!componentPairDict.ContainsKey(componentKunType))
            {
                UnityChoseKun.LogError("NotContainKey");
            }

            return(componentPairDict[componentKunType].componenKunType);
        }
예제 #4
0
        /// <summary>
        /// Objectデータをbyteの配列へ変換する
        /// </summary>
        /// <typeparam name="T">変換するObjectの型</typeparam>
        /// <param name="src">変換するObject</param>
        /// <param name="dst">byte型の配列</param>
        public static void ObjectToBytes <T>(T src, out byte[] dst)
#if SERIALIZATION_BINARFORMATTER
        {
            UnityChoseKun.Log("Start Serialize");
            var bf = new BinaryFormatter();
            var ms = new MemoryStream();

            try
            {
                bf.Serialize(ms, src);
                dst = ms.ToArray();
            }
            finally
            {
                ms.Close();
                UnityChoseKun.Log("End Serialize");
            }
        }
예제 #5
0
        /// <summary>
        /// メッセージの受信CB
        /// </summary>
        /// <param name="args">メッセージデータ</param>
        private void OnMessageEvent(UnityEngine.Networking.PlayerConnection.MessageEventArgs args)
        {
            MemoryStream memoryStream = new MemoryStream(args.data);
            BinaryReader binaryReader = new BinaryReader(memoryStream);

            var messageID = (UnityChoseKun.MessageID)binaryReader.ReadInt32();



            UnityChoseKun.Log("UnityChosekunEditorWindow.OnMessageEvent(playerID: " + args.playerId + ",message.id" + messageID + ")");
            if (onMessageFuncDict != null && onMessageFuncDict.ContainsKey(messageID) == true)
            {
                var func = onMessageFuncDict[messageID];
                func(binaryReader);
            }

            binaryReader.Close();
            memoryStream.Close();
        }
예제 #6
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;
            }

            // instanceIDが一致するComponetを探し出してWriteBackを実行する。
            // ※ComponentKun側がDirtyであるかいなかはGameObjectKunではなく各ComponentKun側に依存する
            var components = gameObject.GetComponents <Component>();

            for (var i = 0; i < componentKunTypes.Length; i++)
            {
                var componentKunType = componentKunTypes[i];
                if (componentKunType == ComponentKun.ComponentKunType.MissingMono)
                {
                    continue;
                }
                Component component = null;
                for (var j = 0; j < components.Length; j++)
                {
                    if (components[j] != null && components[j].GetInstanceID() == componentKuns[i].instanceID)
                    {
                        component = components[j];
                        break;
                    }
                }

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

            dirty = false;
        }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        public void GetAllTextureInScene()
        {
            #if UNITY_2019_1_OR_NEWER
            var scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
            if (scene != null)
            {
                var components = new List <Renderer>();
                foreach (var go in scene.GetRootGameObjects())
                {
                    GetSComponentsInChildren <Renderer>(go, components);
                }
                foreach (var renderer in components)
                {
                    if (renderer.materials != null)
                    {
                        for (var i = 0; i < renderer.materials.Length; i++)
                        {
                            var material = renderer.materials[i];
                            if (material != null)
                            {
                                var shader = material.shader;
                                if (shader != null)
                                {
                                    var cnt = shader.GetPropertyCount();
                                    //Debug.Log(shader.name + " cnt " + cnt);
                                    for (var j = 0; j < cnt; j++)
                                    {
                                        var type = shader.GetPropertyType(j);
                                        //Debug.Log(type);
                                        if (type != UnityEngine.Rendering.ShaderPropertyType.Texture)
                                        {
                                            continue;
                                        }
                                        var nameId  = shader.GetPropertyNameId(j);
                                        var texture = material.GetTexture(nameId);
                                        //Debug.Log("nameId:" + nameId);

                                        if (texture != null)
                                        {
                                            if (textureDict.ContainsKey(texture.GetInstanceID()))
                                            {
                                                continue;
                                            }
                                            textureDict.Add(texture.GetInstanceID(), texture);
                                        }
                                        else
                                        {
                                            //Debug.Log("texture == null");
                                        }
                                    }
                                }
                                else
                                {
                                    UnityChoseKun.LogWarning("shader == null");
                                }
                            }
                            else
                            {
                                UnityChoseKun.LogWarning("material == null");
                            }
                        }
                    }
                }
            }
            else
            {
                UnityChoseKun.LogWarning("scene == null");
            }
            #endif
        }