Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        effect = target as MeshEffect;

        EditorGUI.BeginChangeCheck();

        DrawDefaultInspector();

        GUILayout.BeginHorizontal();
        if (NGUIEditorTools.DrawPrefixButton("Atlas"))
        {
            ComponentSelector.Show <UIAtlas>(OnSelectAtlas);
        }
        SerializedProperty atlas = NGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f));

        if (GUILayout.Button("Edit", GUILayout.Width(40f)))
        {
            if (atlas != null)
            {
                UIAtlas atl = atlas.objectReferenceValue as UIAtlas;
                NGUISettings.atlas = atl;
                NGUIEditorTools.Select(atl.gameObject);
            }
        }
        GUILayout.EndHorizontal();

        SerializedProperty sp = serializedObject.FindProperty("mSpriteName");

        NGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UIAtlas, sp.stringValue, SelectSprite, false);
    }
Exemplo n.º 2
0
 /// <summary>
 /// Updates the settings of the given effect to match the current style.
 /// The given <code>effect</code> will always match the class returned by
 /// <code>CreateEffect()</code>. Called just before Render();
 ///
 /// <para>To be overridden by subclasses!</para>
 /// </summary>
 public virtual void UpdateEffect(MeshEffect effect, RenderState state)
 {
     effect.Texture          = _texture;
     effect.TextureRepeat    = TextureRepeat;
     effect.TextureSmoothing = _textureSmoothing;
     effect.MvpMatrix3D      = state.MvpMatrix3D;
     effect.Alpha            = state.Alpha;
 }
Exemplo n.º 3
0
        public override void SetStyle(MeshStyle meshStyle       = null,
                                      bool mergeWithPredecessor = true)
        {
            base.SetStyle(meshStyle, mergeWithPredecessor);

            _effect?.Dispose();

            _effect           = Style.CreateEffect();
            _effect.OnRestore = SetVertexAndIndexDataChanged;
        }
Exemplo n.º 4
0
        private void Draw(
            CommandEncoder commandEncoder,
            MeshEffect meshEffect,
            EffectPipelineStateHandle pipelineStateHandle,
            IEnumerable <ModelMeshMaterialPass> materialPasses,
            RenderInstanceData instanceData)
        {
            commandEncoder.SetVertexBuffer(2, instanceData.WorldBuffer);

            if (Skinned)
            {
                meshEffect.SetSkinningBuffer(instanceData.SkinningBuffer);
                meshEffect.SetNumBones(NumBones);
            }

            meshEffect.SetSkinningEnabled(Skinned);

            meshEffect.SetMaterials(_materialsBuffer);
            meshEffect.SetTextures(_textures);

            commandEncoder.SetVertexBuffer(0, _vertexBuffer);

            foreach (var materialPass in materialPasses)
            {
                meshEffect.SetTextureIndices(materialPass.TextureIndicesBuffer);
                meshEffect.SetMaterialIndices(materialPass.MaterialIndicesBuffer);
                meshEffect.SetNumTextureStages(materialPass.NumTextureStages);

                commandEncoder.SetVertexBuffer(1, materialPass.TexCoordVertexBuffer);

                foreach (var meshPart in materialPass.MeshParts)
                {
                    if (meshPart.PipelineStateHandle != pipelineStateHandle)
                    {
                        continue;
                    }

                    meshEffect.SetPrimitiveOffset(meshPart.StartIndex / 3);
                    meshEffect.SetAlphaTest(meshPart.AlphaTest);
                    meshEffect.SetTexturing(meshPart.Texturing);

                    meshEffect.Apply(commandEncoder);

                    commandEncoder.DrawIndexedInstanced(
                        PrimitiveType.TriangleList,
                        meshPart.IndexCount,
                        instanceData.NumInstances,
                        _indexBuffer,
                        meshPart.StartIndex);
                }
            }
        }
Exemplo n.º 5
0
    public void Remove(Material mat, MeshEffect effect)
    {
        Dictionary <Material, HashSet <MeshEffect> > dict;

        if (dictionary.TryGetValue(effect.gameObject.layer, out dict))
        {
            HashSet <MeshEffect> set;
            if (dict.TryGetValue(mat, out set))
            {
                set.Remove(effect);
            }
        }

        needUpdateMesh = true;
    }
Exemplo n.º 6
0
        public MeshRenderer(
            GraphicsDevice graphicsDevice, GameSettingsComponent settings,
            ContentManager contentManager, Model scene)
        {
            _graphicsDevice = graphicsDevice;
            _settings       = settings;

            _scene           = scene;
            _sceneTransforms = new Matrix[_scene.Bones.Count];
            _scene.CopyAbsoluteBoneTransformsTo(_sceneTransforms);

            _cascadeSplits  = new float[4];
            _frustumCorners = new Vector3[8];

            _shadowMapEffect = new ShadowMapEffect(graphicsDevice, contentManager.Load <Effect>("effects/ShadowMap"));
            _meshEffect      = new MeshEffect(graphicsDevice, contentManager.Load <Effect>("effects/Mesh"));

            _boundingFrustum = new BoundingFrustum(Matrix.Identity);

            CreateShadowMaps();
        }
Exemplo n.º 7
0
    public void Add(Material mat, MeshEffect effect)
    {
        Dictionary <Material, HashSet <MeshEffect> > dict;

        if (!dictionary.TryGetValue(effect.gameObject.layer, out dict))
        {
            dict = new Dictionary <Material, HashSet <MeshEffect> >();
            dictionary.Add(effect.gameObject.layer, dict);
        }

        HashSet <MeshEffect> set;

        if (!dict.TryGetValue(mat, out set))
        {
            set = new HashSet <MeshEffect>();
            dict.Add(mat, set);
        }

        set.Add(effect);

        effect.renderer.enabled = false;

        needUpdateMesh = true;
    }
Exemplo n.º 8
0
        protected override void Start()
        {
            base.Start();

            _effect = ContentManager.GetEffect <MeshEffect>();
        }
Exemplo n.º 9
0
 void OnDestroy()
 {
     mThis = null;
 }
Exemplo n.º 10
0
 // Use this for initialization
 void Start()
 {
     mThis = this;
     mf    = gameObject.GetComponent <MeshFilter>();
 }
Exemplo n.º 11
0
        public void AddInstancedRenderItem(ModelMesh mesh, RenderableComponent renderable, MeshEffect effect)
        {
            if (!InstanceData.TryGetValue(mesh, out var instanceData))
            {
                InstanceData.Add(mesh, instanceData = new RenderInstanceData(mesh));

                mesh.BuildRenderList(this, instanceData, effect);
            }

            instanceData.InstancedRenderables.Add(new InstancedRenderable(renderable));
        }
Exemplo n.º 12
0
 public override void UpdateEffect(MeshEffect effect, RenderState state)
 {
     base.UpdateEffect(effect, state);
 }
Exemplo n.º 13
0
    protected virtual void onSkillEvent(int evt, string anim, ref bool needSync)
    {
        if (!mUnit.isState(UnitState.Anim))
        {
            return;
        }
        switch (evt)
        {
        case StopAnim:
            if (mAnimtor != null)
            {
                mAnimtor.enabled = false;
            }
            if (mAnim != null)
            {
                mAnim.Stop(anim);
            }
            needSync = true;
            break;

        case PlayAnim:
            if (mAnimtor != null)
            {
                mAnimtor.Play(anim);
            }
            if (mAnim != null)
            {
                mAnim.Play(anim, PlayMode.StopAll);
            }
            needSync = true;
            break;

        case StopRun:
            if (mAnimtor != null)
            {
                mAnimtor.SetBool("Run", false);
            }
            if (mAnim != null)
            {
                mAnim.Play("idle", PlayMode.StopAll);
            }
            break;

        case Run:
            if (mAnimtor != null)
            {
                mAnimtor.SetBool("Run", true);
            }
            if (mAnim != null)
            {
                mAnim.Play("run", PlayMode.StopAll);
            }

            //显示脚印
            jioTime += Time.deltaTime;
            if (jioTime > 0.5f && !mUnit.isServer)
            {
                jioTime -= 0.5f;
                MeshEffect.addQuad(mUnit.pos, mUnit.transform.eulerAngles.y, Vector2.one, 0);
            }
            break;

        case Jump:
            if (mAnimtor != null)
            {
                mAnimtor.SetTrigger("Jump");
            }
            if (mAnim != null)
            {
                mAnim.Play("jump", PlayMode.StopAll);
            }
            break;

        case Hit:
            if (mUnit.isState(UnitState.Break))
            {
                break;
            }
            if (mAnimtor != null)
            {
                mAnimtor.SetTrigger("Hit");
            }
            if (mAnim != null)
            {
                mAnim.Play("hit", PlayMode.StopAll);
            }
            needSync = true;
            break;

        case Die:
            if (mAnimtor != null)
            {
                mAnimtor.SetTrigger("Die");
            }
            if (mAnim != null)
            {
                mAnim.Play("die", PlayMode.StopAll);
            }
            needSync = true;
            break;
        }
    }
Exemplo n.º 14
0
        internal void BuildRenderList(RenderList renderList, RenderInstanceData instanceData, MeshEffect effect)
        {
            var uniquePipelineStates = MaterialPasses
                                       .SelectMany(x => x.MeshParts.Select(y => y.PipelineStateHandle))
                                       .Distinct()
                                       .ToList();

            foreach (var pipelineStateHandle in uniquePipelineStates)
            {
                var filteredMaterialPasses = MaterialPasses
                                             .Where(x => x.MeshParts.Any(y => y.PipelineStateHandle == pipelineStateHandle))
                                             .ToList();

                if (filteredMaterialPasses.Count > 0)
                {
                    renderList.AddRenderItem(new InstancedRenderItem(
                                                 instanceData,
                                                 effect,
                                                 pipelineStateHandle,
                                                 (commandEncoder, e, h, _) =>
                    {
                        Draw(
                            commandEncoder,
                            effect,
                            h,
                            filteredMaterialPasses,
                            instanceData);
                    }));
                }
            }
        }