예제 #1
0
        void OnDisable()
        {
            //Debug.Log("OnDisable()");

            neutrinoEffectModel_ = null;
            neutrinoEffect_      = null;
            renderBuffer_        = null;
            neutrinoInited_      = false;

                        #if UNITY_EDITOR
            EditorApplication.update -= Update;
                        #endif
        }
예제 #2
0
        private void initNeutrino()
        {
            //Debug.Log("initNeutrino()");

            neutrinoEffectModel_ = createModel();

            Mesh mesh = new Mesh();

            gameObject.GetComponent <MeshFilter>().mesh = mesh;
            renderBuffer_ = new NeutrinoRenderBuffer(mesh);

            neutrinoEffect_ = new Neutrino.Effect(neutrinoEffectModel_, renderBuffer_,
                                                  simulateInWorldSpace ?
                                                  Neutrino._math.vec3_(gameObject.transform.position.x / gameObject.transform.localScale.x,
                                                                       gameObject.transform.position.y / gameObject.transform.localScale.y,
                                                                       gameObject.transform.position.z / gameObject.transform.localScale.z) :
                                                  Neutrino._math.vec3_(0, 0, 0),
                                                  simulateInWorldSpace ?
                                                  Neutrino._math.quat_(transform.rotation.w, transform.rotation.x, transform.rotation.y, transform.rotation.z) :
                                                  Neutrino._math.quat_(1, 0, 0, 0));

            deserializeToEffect();

            // preparing materials
            {
                string[]      textures     = neutrinoEffectModel_.textures();
                RenderStyle[] renderStyles = neutrinoEffectModel_.renderStyles();

                materials_ = new Material[renderStyles.Length];

                for (int i = 0; i < renderStyles.Length; ++i)
                {
                    Material material;

                    switch (neutrinoEffectModel_.materials()[renderStyles[i].material_])
                    {
                    default:
                        material = new Material(NeutrinoContext.Instance.shaderNormal());
                        break;

                    case Neutrino.RenderMaterial.Add:
                        material = new Material(NeutrinoContext.Instance.shaderAdd());
                        break;

                    case Neutrino.RenderMaterial.Multiply:
                        material = new Material(NeutrinoContext.Instance.shaderMultiply());
                        break;
                    }

                    string filename = Path.GetFileNameWithoutExtension(
                        textures[renderStyles[i].textureIndex_[0]]);

                    if (string.IsNullOrEmpty(filename))
                    {
                        Debug.LogError("Texture file name is empty or incorrect " +
                                       textures[renderStyles[i].textureIndex_[0]]);
                        return;
                    }

                    Texture texture = Resources.Load(filename) as Texture;
                    if (texture == null)
                    {
                        Debug.LogError("Unable to load texture from Resources: " + filename);
                        return;
                    }

                    material.name = filename;
                    material.SetTexture("_MainTex", texture);

                    materials_[i] = material;
                }
            }

            neutrinoInited_ = true;

                        #if UNITY_EDITOR
            lastFrameTime_ = Time.realtimeSinceStartup;
                        #else
            lastFrameTime_ = Time.time;
                        #endif

                        #if UNITY_EDITOR
            EditorApplication.update += Update;
                        #endif
        }