Пример #1
0
    public void UpdateHeightTEST() //this is the old one, with obly 1 cube selector
    {
        currentHeight = Mathf.Clamp(currentHeight, 0, StageBuilder.MAX_HEIGHT);

        float      newHei           = transform.position.y;
        Vector3    fromTopPosition  = new Vector3(transform.position.x, StageBuilder.MAX_HEIGHT, transform.position.z);
        Vector3    toBottomPosition = new Vector3(transform.position.x, 0, transform.position.z);
        Vector3    direction        = toBottomPosition - fromTopPosition;
        RaycastHit hit;

        if (Physics.Raycast(fromTopPosition, direction, out hit))
        {
            if (hit.transform.gameObject.GetComponent <StageObject>() != null)
            {
                //height will be the highest block in that tile plus that block's height, same if it's an object
                StageObject obt = hit.transform.gameObject.GetComponent <StageObject>();
                newHei = obt.GridPosition.Height + obt.GetCurrentItemHeight();
            }
            else if (hit.transform.gameObject.GetComponent <StageBlock>() != null)
            {
                StageBlock block = hit.transform.gameObject.GetComponent <StageBlock>();
                newHei = block.GridPosition.Height + block.GetCurrengBlockHeight();
            }
            else
            {
                newHei = 0;
            }
        }

        currentHeight      = newHei;
        transform.position = new Vector3(transform.position.x, currentHeight, transform.position.z);
    }
Пример #2
0
    public void Clean()
    {
        if (groundBlocks.Count > 0)
        {
            for (int i = groundBlocks.Count - 1; i >= 0; i--)
            {
                StageBlock item = groundBlocks[i];
                groundBlocks.Remove(item);
                item.DeleteItem();
            }
        }
        //objects
        if (StageObjects.Count > 0)
        {
            for (int i = StageObjects.Count - 1; i >= 0; i--)
            {
                StageObject item = StageObjects[i];
                StageObjects.Remove(item);
                item.DeleteItem();
            }
        }
        //for (int i = Decorations.Count - 1; i >= 0; i--)
        //{
        //    StageDecoration item = Decorations[i];
        //    Decorations.Remove(item);
        //    item.DeleteItem();
        //}

        PlayerSpawns.Clear();
        EnemySpawns.Clear();
    }
Пример #3
0
    //ブロックの色を変える
    void ApplyBlockStatus(StageBlock stageBlock)
    {
        switch (stageBlock.status)
        {
        case BlockStatus.Hole:
            if (stageBlock.gameObject.activeSelf)
            {
                stageBlock.gameObject.SetActive(false);
            }
            break;

        case BlockStatus.White:
            if (!stageBlock.gameObject.activeSelf)
            {
                stageBlock.gameObject.SetActive(true);
            }
            LeanTween.color(stageBlock.gameObject, Color.white, 0.0f);
            break;

        case BlockStatus.Black:
            if (!stageBlock.gameObject.activeSelf)
            {
                stageBlock.gameObject.SetActive(true);
            }
            LeanTween.color(stageBlock.gameObject, Color.black, 0.0f);
            break;
        }
    }
Пример #4
0
 void Resize()
 {
     Undo.RecordObjects(targets, "Resize");
     foreach (var t in targets)
     {
         StageBlock lStageBlock = t as StageBlock;
         lStageBlock.Resize();
     }
 }
Пример #5
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        for (var i = 0; i < targets.Length; i++)
        {
            block = targets[i] as StageBlock;
            block.SnapCoords();
            block.ForceScale();
            block.ForceRotation();
        }
    }
Пример #6
0
    /// <summary>
    /// updates the height in that tile using a raycast from maximum height to the selector's height
    /// </summary>
    /// <param name="newHeight"></param>
    public void UpdateHeight()
    {
        currentHeight = Mathf.Clamp(currentHeight, 0, StageBuilder.MAX_HEIGHT);
        float          highestHei  = 0;
        List <Vector3> activeCubes = GetActiveCubes();

        for (int i = 0; i < activeCubes.Count; i++)
        {
            float      newHei           = transform.position.y;
            Vector3    fromTopPosition  = new Vector3(activeCubes[i].x, StageBuilder.MAX_HEIGHT, activeCubes[i].z);
            Vector3    toBottomPosition = new Vector3(activeCubes[i].x, 0, activeCubes[i].z);
            Vector3    direction        = toBottomPosition - fromTopPosition;
            RaycastHit hit;

            if (Physics.Raycast(fromTopPosition, direction, out hit))
            {
                if (hit.transform.gameObject.GetComponent <StageObject>() != null)
                {
                    //height will be the highest block in that tile plus that block's height, same if it's an object
                    StageObject obt = hit.transform.gameObject.GetComponent <StageObject>();
                    newHei = obt.GridPosition.Height + obt.GetCurrentItemHeight();
                }
                else if (hit.transform.gameObject.GetComponent <StageBlock>() != null)
                {
                    StageBlock block = hit.transform.GetComponent <StageBlock>();
                    newHei = block.GridPosition.Height + block.GetCurrengBlockHeight();
                }
                else
                {
                    newHei = 0;
                }

                highestHei = newHei > highestHei ? newHei : highestHei;
            }

            currentHeight = highestHei;                                                           //newHei;
        }
        transform.position = new Vector3(transform.position.x, highestHei, transform.position.z); //currentHeight
    }
Пример #7
0
        private void PrintLinks(ref StageBlock stageBlock)
        {
            DebugLog.WriteLine("  |- Stage [{0}]", stageBlock.Shader.GetType().Name);
            for (int resourceTypeIndex = 0; resourceTypeIndex < stageBlock.Slots.Length; resourceTypeIndex++)
            {
                var resourceType = (EffectResourceType)resourceTypeIndex;
                var slotRangePerResourceType = stageBlock.Slots[resourceTypeIndex];
                if (slotRangePerResourceType == null)
                {
                    continue;
                }

                DebugLog.WriteLine("     |- ResourceType [{0}]", resourceType);
                foreach (var slotLinkSet in slotRangePerResourceType)
                {
                    DebugLog.WriteLine("        |- SlotRange Slot [{0}] Count [{1}] (IsDirect: {2})", slotLinkSet.SlotIndex, slotLinkSet.SlotCount, slotLinkSet.IsDirectSlot);
                    foreach (var slotLink in slotLinkSet.Links)
                    {
                        DebugLog.WriteLine("           |- Resource [{0}] Index [{1}] Count[{2}]", slotLink.GlobalIndex, slotLink.SlotIndex, slotLink.SlotCount);
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Optimizes the slot links.
        /// </summary>
        /// <param name="stageBlock">The stage block.</param>
        private void PrepareSlotLinks(ref StageBlock stageBlock)
        {
            // Allocate slots only when needed
            stageBlock.Slots = new List<SlotLinkSet>[1 + (int)EffectResourceType.UnorderedAccessView];

            // Retrieve Constant buffer resource index as It has been updated by the reordering of resources
            for (int i = 0; i < stageBlock.ConstantBufferLinks.Length; i++)
            {
                stageBlock.ConstantBufferLinks[i].ResourceIndex = stageBlock.ConstantBufferLinks[i].Parameter.Offset;
            }

            // Compute default slot links link
            foreach (var parameter in stageBlock.Parameters)
            {

                var slots = stageBlock.Slots[(int)parameter.ResourceType];
                if (slots == null)
                {
                    slots = new List<SlotLinkSet>();
                    stageBlock.Slots[(int)parameter.ResourceType] = slots;
                }

                var parameterRaw = (EffectData.ResourceParameter)parameter.ParameterDescription;

                var range = new SlotLinkSet() { SlotCount = parameterRaw.Count, SlotIndex = parameterRaw.Slot };
                slots.Add(range);
                range.Links.Add(new SlotLink(parameter.Offset, 0, parameterRaw.Count));
            }

            if (EnableDebug)
            {
                DebugLog.WriteLine("*** Before OptimizeSlotLinks ****");
                PrintLinks(ref stageBlock);
            }

            // Optimize all slots
            foreach (var slotRangePerResourceType in stageBlock.Slots)
            {
                if (slotRangePerResourceType == null)
                    continue;

                var previousRange = slotRangePerResourceType[0];

                for (int i = 1; i < slotRangePerResourceType.Count; i++)
                {
                    var currentRange = slotRangePerResourceType[i];
                    int endIndex = previousRange.SlotIndex + previousRange.SlotCount;

                    var delta = (currentRange.SlotIndex - endIndex);

                    // If there is at maximum a 1 
                    if (delta <= 1)
                    {
                        foreach (var slotLink in currentRange.Links)
                        {
                            var previousLink = previousRange.Links[previousRange.Links.Count - 1];
                            // Merge consecutive individual slot link
                            if ((previousLink.GlobalIndex + previousLink.SlotCount) == slotLink.GlobalIndex && (previousLink.SlotIndex + previousLink.SlotCount) == (currentRange.SlotIndex + slotLink.SlotIndex))
                            {
                                previousLink.SlotCount += slotLink.SlotCount;
                                previousRange.Links[previousRange.Links.Count - 1] = previousLink;
                            }
                            else
                            {
                                previousRange.Links.Add(new SlotLink(slotLink.GlobalIndex, (slotLink.SlotIndex + previousRange.SlotCount + delta), slotLink.SlotCount));
                            }
                        }

                        // Update the total slot count
                        previousRange.SlotCount += delta + currentRange.SlotCount;

                        slotRangePerResourceType.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        previousRange = currentRange;
                    }
                }
            }

            if (EnableDebug)
            {
                DebugLog.WriteLine("*** After OptimizeSlotLinks ****");
                PrintLinks(ref stageBlock);
            }
        }
Пример #9
0
        /// <summary>
        /// Initializes the stage block.
        /// </summary>
        /// <param name="stageBlock">The stage block.</param>
        /// <param name="logger">The logger.</param>
        private void InitStageBlock(StageBlock stageBlock, Logger logger)
        {
            // If null shader, then skip init
            if (stageBlock.Index < 0)
            {
                return;
            }

            stageBlock.Shader = Effect.Pool.GetOrCompileShader(stageBlock.Type, stageBlock.Index);
            var shaderRaw = Effect.Pool.EffectData.Shaders[stageBlock.Index];

            // Cache the input signature
            if (shaderRaw.Type == EffectShaderType.Vertex)
            {
                inputSignatureManager = graphicsDevice.GetOrCreateInputSignatureManager(shaderRaw.InputSignature.Bytecode, shaderRaw.InputSignature.Hashcode);
            }

            for (int i = 0; i < shaderRaw.ConstantBuffers.Count; i++)
            {
                var constantBufferRaw = shaderRaw.ConstantBuffers[i];

                // Constant buffers with a null size are skipped
                if (constantBufferRaw.Size == 0)
                    continue;

                var constantBuffer = Effect.GetOrCreateConstantBuffer(Effect.GraphicsDevice, constantBufferRaw);
                // IF constant buffer is null, it means that there is a conflict
                if (constantBuffer == null)
                {
                    logger.Error("Constant buffer [{0}] cannot have multiple size or different content declaration inside the same effect pool", constantBufferRaw.Name);
                    continue;
                }
                
                // Test if this constant buffer is not already part of the effect
                if (Effect.ConstantBuffers[constantBufferRaw.Name] == null)
                {
                    // Add the declared constant buffer to the effect shader.
                    Effect.ConstantBuffers.Add(constantBuffer);

                    // Declare all parameter from constant buffer at the effect level.
                    foreach (var parameter in constantBuffer.Parameters)
                    {
                        var previousParameter = Effect.Parameters[parameter.Name];
                        if (previousParameter == null)
                        {
                            // Add an effect parameter linked to the approriate constant buffer at the effect level.
                            Effect.Parameters.Add(new EffectParameter((EffectData.ValueTypeParameter) parameter.ParameterDescription, constantBuffer));
                        }
                        else if (parameter.ParameterDescription != previousParameter.ParameterDescription || parameter.buffer != previousParameter.buffer)
                        {
                            // If registered parameters is different
                            logger.Error("Parameter [{0}] defined in Constant buffer [{0}] is already defined by another constant buffer with the definition [{2}]", parameter, constantBuffer.Name, previousParameter);
                        }
                    }
                }
            }

            var constantBufferLinks = new List<ConstantBufferLink>();

            // Declare all resource parameters at the effect level.
            foreach (var parameterRaw in shaderRaw.ResourceParameters)
            {
                EffectParameter parameter;
                var previousParameter = Effect.Parameters[parameterRaw.Name];

                // Skip enmpty constant buffers.
                if (parameterRaw.Type == EffectParameterType.ConstantBuffer && Effect.ConstantBuffers[parameterRaw.Name] == null)
                {
                    continue;
                }

                int resourceIndex = Effect.ResourceLinker.Count;

                if (previousParameter == null)
                {
                    parameter = new EffectParameter(parameterRaw, EffectResourceTypeHelper.ConvertFromParameterType(parameterRaw.Type), Effect.ResourceLinker.Count, Effect.ResourceLinker);
                    Effect.Parameters.Add(parameter);

                    Effect.ResourceLinker.Count += parameterRaw.Count;
                }
                else
                {
                    resourceIndex = ((EffectData.ResourceParameter) previousParameter.ParameterDescription).Slot;

                    if (CompareResourceParameter(parameterRaw, (EffectData.ResourceParameter) previousParameter.ParameterDescription))
                    {
                        // If registered parameters is different
                        logger.Error("Resource Parameter [{0}] is already defined with a different definition [{1}]", parameterRaw, previousParameter.ParameterDescription);
                    }
                    parameter = previousParameter;
                }

                // For constant buffers, we need to store explicit link
                if (parameter.ResourceType == EffectResourceType.ConstantBuffer)
                {
                    constantBufferLinks.Add(new ConstantBufferLink(Effect.ConstantBuffers[parameter.Name], parameter));
                }

                if (stageBlock.Parameters == null)
                {
                     stageBlock.Parameters = new List<EffectParameter>();
                }

                stageBlock.Parameters.Add(parameter);
            }

            stageBlock.ConstantBufferLinks = constantBufferLinks.ToArray();
        }
Пример #10
0
        /// <summary>
        /// Initializes this pass.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <exception cref="System.InvalidOperationException"></exception>
        internal void Initialize(Logger logger)
        {
            // Gets the output merger stage.
            pipeline.OutputMergerStage = ((Direct3D11.DeviceContext) Effect.GraphicsDevice).OutputMerger;

            for (int i = 0; i < StageCount; i++)
            {
                var shaderType = (EffectShaderType) i;
                var link = pass.Pipeline[shaderType];
                if (link == null)
                    continue;

                if (link.IsImport)
                {
                    throw new InvalidOperationException(string.Format("Unable to resolve imported shader [{0}] for stage [{1}]", link.ImportName, shaderType));
                }

                var stageBlock = new StageBlock(shaderType);
                pipeline.Stages[i] = stageBlock;

                stageBlock.Index = link.Index;
                stageBlock.ShaderStage = Effect.GraphicsDevice.ShaderStages[i];

                InitStageBlock(stageBlock, logger);
            }
        }
Пример #11
0
        /// <summary>
        /// Optimizes the slot links.
        /// </summary>
        /// <param name="stageBlock">The stage block.</param>
        private void OptimizeSlotLinks(ref StageBlock stageBlock)
        {
            if (stageBlock.Slots == null)
                return;

            // Optimize all slots
            foreach (var slotRangePerResourceType in stageBlock.Slots)
            {
                if (slotRangePerResourceType == null)
                    continue;

                var previousRange = slotRangePerResourceType[0];

                for (int i = 1; i < slotRangePerResourceType.Count; i++)
                {
                    var currentRange = slotRangePerResourceType[i];
                    int endIndex = previousRange.SlotIndex + previousRange.SlotCount;

                    var delta = (currentRange.SlotIndex - endIndex);

                    // If there is at maximum a 1 
                    if (delta <= 1)
                    {
                        foreach (var slotLink in currentRange.Links)
                        {
                            var previousLink = previousRange.Links[previousRange.Links.Count - 1];
                            // Merge consecutive individual slot link
                            if ((previousLink.GlobalIndex + previousLink.SlotCount) == slotLink.GlobalIndex && (previousLink.SlotIndex + previousLink.SlotCount) == (currentRange.SlotIndex + slotLink.SlotIndex))
                            {
                                previousLink.SlotCount += slotLink.SlotCount;
                                previousRange.Links[previousRange.Links.Count - 1] = previousLink;
                            }
                            else
                            {
                                previousRange.Links.Add(new SlotLink(slotLink.GlobalIndex, (slotLink.SlotIndex + previousRange.SlotCount + delta), slotLink.SlotCount));
                            }
                        }

                        // Update the total slot count
                        previousRange.SlotCount += delta + currentRange.SlotCount;

                        slotRangePerResourceType.RemoveAt(i);
                        i--;
                    }
                    else
                    {
                        previousRange = currentRange;
                    }
                }
            }
        }
Пример #12
0
 public void AddStageBlock(StageBlock block)
 {
     groundBlocks.Add(block);
 }