コード例 #1
0
        private bool SetStyleValue <T>(StylePropertyId id, StyleEnum <T> inlineValue, StyleEnum <T> sharedValue) where T : struct, IConvertible
        {
            var sv       = new StyleValue();
            int intValue = UnsafeUtility.EnumToInt(inlineValue.value);

            if (TryGetStyleValue(id, ref sv))
            {
                if (sv.number == intValue && sv.keyword == inlineValue.keyword)
                {
                    return(false);
                }
            }
            else if (inlineValue.keyword == StyleKeyword.Null)
            {
                return(false);
            }

            sv.id      = id;
            sv.keyword = inlineValue.keyword;
            sv.number  = intValue;

            SetStyleValue(sv);

            if (inlineValue.keyword == StyleKeyword.Null)
            {
                sv.keyword = sharedValue.keyword;
                sv.number  = UnsafeUtility.EnumToInt(sharedValue.value);
            }

            ApplyStyleValue(sv);
            return(true);
        }
コード例 #2
0
ファイル: StyleEnum.cs プロジェクト: leek9d/UnityCsReference
 public override int GetHashCode()
 {
     unchecked
     {
         return((UnsafeUtility.EnumToInt(m_Value) * 397) ^ (int)m_Keyword);
     }
 }
コード例 #3
0
        /// <summary>
        /// Removes <typeparamref name="AudioSampleProvider"/> from the specified <typeparamref name="DSPNode"/>. If index is not passed or is -1 then it is removed from the last.
        /// </summary>
        /// <param name="node">The node to remove the <typeparamref name="AudioSampleProvider"/> from</param>
        /// <param name="item">The sample provider 'slot' that should have the sample provider removed from</param>
        /// <param name="index">The index into the array that the provider should be removed from. This is if the sample provider slot is an array.</param>
        /// <typeparam name="TParameters">Enum type of the parameters of the node</typeparam>
        /// <typeparam name="TProviders">Enum type of the sample providers of the node</typeparam>
        /// <typeparam name="TAudioKernel">The kernel type of the node</typeparam>
        /// <exception cref="ArgumentException">Unknown SampleProvider</exception>
        /// <exception cref="InvalidOperationException">Can only remove from variable-size array</exception>
        public void RemoveSampleProvider <TParameters, TProviders, TAudioKernel>(DSPNode node, TProviders item, int index = -1)
            where TParameters  : unmanaged, Enum
            where TProviders   : unmanaged, Enum
            where TAudioKernel : struct, IAudioKernel <TParameters, TProviders>
        {
            AssertSameGraphAsNode(node);

            AudioKernelExtensions.GetReflectionData <TAudioKernel, TParameters, TProviders>(out AudioKernelExtensions.SampleProviderDescriptionData sampleProviderDescriptionData);
            var itemIndex = UnsafeUtility.EnumToInt(item);

            // Can only remove from variable-size arrays.
            if (!sampleProviderDescriptionData.Descriptions[itemIndex].m_IsArray ||
                sampleProviderDescriptionData.Descriptions[itemIndex].m_Size >= 0)
            {
                throw new InvalidOperationException("Can only remove sample providers from variable-size array");
            }

            QueueCommand(new RemoveSampleProviderCommand
            {
                m_Type   = DSPCommandType.RemoveSampleProvider,
                m_Graph  = m_Graph,
                m_Handle = m_Handle,
                m_Node   = node.Handle,
                m_SampleProviderDescriptionData = sampleProviderDescriptionData,
                m_Item  = UnsafeUtility.EnumToInt(item),
                m_Index = index,
            });
        }
コード例 #4
0
        internal void InsertSampleProvider <TParameters, TProviders, TAudioKernel>(
            uint providerId, DSPNode node, TProviders item, int index = -1, bool destroyOnRemove = false)
            where TParameters  : unmanaged, Enum
            where TProviders   : unmanaged, Enum
            where TAudioKernel : struct, IAudioKernel <TParameters, TProviders>
        {
            AssertSameGraphAsNode(node);

            AudioKernelExtensions.GetReflectionData <TAudioKernel, TParameters, TProviders>(out AudioKernelExtensions.SampleProviderDescriptionData sampleProviderDescriptionData);
            var providerIndex = GetProviderIndex(item, sampleProviderDescriptionData);

            // Can only insert into variable-size arrays.
            if (!sampleProviderDescriptionData.Descriptions[providerIndex].m_IsArray ||
                sampleProviderDescriptionData.Descriptions[providerIndex].m_Size >= 0)
            {
                throw new InvalidOperationException("Can only insert into variable-size array.");
            }

            QueueCommand(new InsertSampleProviderCommand
            {
                m_Type   = DSPCommandType.InsertSampleProvider,
                m_Graph  = m_Graph,
                m_Handle = m_Handle,
                m_Node   = node.Handle,
                m_SampleProviderDescriptionData = sampleProviderDescriptionData,
                m_ProviderId      = providerId,
                m_Item            = UnsafeUtility.EnumToInt(item),
                m_Index           = index,
                m_DestroyOnRemove = destroyOnRemove,
            });
        }
コード例 #5
0
        internal void SetSampleProvider <TParameters, TProviders, TAudioKernel>(
            uint providerId, DSPNode node, TProviders item, int index = 0, bool destroyOnRemove = false)
            where TParameters  : unmanaged, Enum
            where TProviders   : unmanaged, Enum
            where TAudioKernel : struct, IAudioKernel <TParameters, TProviders>
        {
            AssertSameGraphAsNode(node);

            AudioKernelExtensions.GetReflectionData <TAudioKernel, TParameters, TProviders>(out AudioKernelExtensions.SampleProviderDescriptionData sampleProviderDescriptionData);
            var providerIndex = GetProviderIndex(item, sampleProviderDescriptionData);

            // Index validation for fixed-size array items can be performed here. For variable-array,
            // it can only be performed in the job threads, where the array size is known and stable.
            if (sampleProviderDescriptionData.Descriptions[providerIndex].m_IsArray &&
                sampleProviderDescriptionData.Descriptions[providerIndex].m_Size >= 0 &&
                (sampleProviderDescriptionData.Descriptions[providerIndex].m_Size < index || index < 0))
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            QueueCommand(new SetSampleProviderCommand
            {
                m_Type   = DSPCommandType.SetSampleProvider,
                m_Graph  = m_Graph,
                m_Handle = m_Handle,
                m_Node   = node.Handle,
                m_SampleProviderDescriptionData = sampleProviderDescriptionData,
                m_ProviderId      = providerId,
                m_Item            = UnsafeUtility.EnumToInt(item),
                m_Index           = index,
                m_DestroyOnRemove = destroyOnRemove,
            });
        }
コード例 #6
0
ファイル: ComponentEditor.cs プロジェクト: substence/UnityVS3
 static void PickStructType(StructModel structModel, Action <StructModel, StructType> action)
 {
     EditorUtility.DisplayCustomMenu(
         new Rect(Event.current.mousePosition, Vector2.one),
         s_StructTypeOptions,
         UnsafeUtility.EnumToInt(structModel.Type),
         (data, options, selected) =>
     {
         StructType type = (StructType)selected;
         action(structModel, type);
     },
         null);
 }
コード例 #7
0
    private unsafe static void TestUnsafeUtility()
    {
        // Allocate
        void *a = UnsafeUtility.Malloc(
            size: ARRAY_SIZE * UnsafeUtility.SizeOf <int>(),
            alignment: UnsafeUtility.AlignOf <byte>(),
            allocator: Allocator.Temp);
        void *b = UnsafeUtility.Malloc(
            size: ARRAY_SIZE * UnsafeUtility.SizeOf <int>(),
            alignment: UnsafeUtility.AlignOf <byte>(),
            allocator: Allocator.Temp);

        for (int i = 0; i < ARRAY_SIZE; i++)
        {
            ((int *)a)[i] = i;
        }

        Print5IntArray((int *)b);
        UnsafeUtility.MemCpy(destination: b, source: a, size: ARRAY_SIZE * UnsafeUtility.SizeOf <int>());
        Print5IntArray((int *)b);

        for (int i = 0; i < ARRAY_SIZE; i++)
        {
            UnsafeUtility.WriteArrayElement(
                destination: b,
                index: i,
                value: -i);
        }

        Print5IntFromVoidArray(b);

        // Free
        UnsafeUtility.Free(memory: a, allocator: Allocator.Temp);
        UnsafeUtility.Free(memory: b, allocator: Allocator.Temp);

        Debug.Log($"Vowel.I : {UnsafeUtility.EnumToInt(Vowel.I)}");

        Int4 int4 = new Int4();

        Debug.Log(int4);
        ModifyInt4ByAddressOfRef(ref int4);
        Debug.Log(int4);
    }
コード例 #8
0
        /// <summary>
        /// This API will sustain the previous parameter value until the dspclock time is reached
        /// </summary>
        /// <typeparam name="TParameters">Enum type of the parameters of the node</typeparam>
        /// <typeparam name="TProviders">Enum type of the sample providers of the node</typeparam>
        /// <typeparam name="TAudioKernel">The kernel type of the node</typeparam>
        /// <param name="node">The node that should have its parameter sustained</param>
        /// <param name="parameter">The parameter to sustain</param>
        /// <param name="dspClock">The time in which the parameter should be sustained until</param>
        /// <exception cref="ArgumentException">Throws exception when parameter is unknown</exception>
        public void SustainFloat <TParameters, TProviders, TAudioKernel>(DSPNode node, TParameters parameter, long dspClock)
            where TParameters  : unmanaged, Enum
            where TProviders   : unmanaged, Enum
            where TAudioKernel : struct, IAudioKernel <TParameters, TProviders>
        {
            AssertSameGraphAsNode(node);

            AudioKernelExtensions.GetReflectionData <TAudioKernel, TParameters, TProviders>(out void *jobReflectionData, out AudioKernelExtensions.ParameterDescriptionData parameterDescriptionData);
            QueueCommand(new SustainFloatCommand
            {
                m_Type                     = DSPCommandType.SustainFloat,
                m_Graph                    = m_Graph,
                m_Handle                   = m_Handle,
                m_Node                     = node.Handle,
                m_JobReflectionData        = jobReflectionData,
                m_ParameterDescriptionData = parameterDescriptionData,
                m_Parameter                = (uint)UnsafeUtility.EnumToInt(parameter),
                m_DSPClock                 = (ulong)dspClock,
            });
        }
コード例 #9
0
        /// <summary>
        /// Sets the value of a parameter on the specified node
        /// </summary>
        /// <param name="node">DSPNode in which the parameter value is set</param>
        /// <param name="parameter">Enum which specifies the parameter</param>
        /// <param name="value">Target value to be set</param>
        /// <param name="interpolationLength">The number of samples to reach the desired value</param>
        /// <typeparam name="TParameters">Enum type of the parameters of the node</typeparam>
        /// <typeparam name="TProviders">Enum type of the sample providers of the node</typeparam>
        /// <typeparam name="TAudioKernel">The kernel type of the node</typeparam>
        /// <exception cref="ArgumentException">Exception thrown when parameter is unknown</exception>
        public void SetFloat <TParameters, TProviders, TAudioKernel>(DSPNode node, TParameters parameter, float value, int interpolationLength = 0)
            where TParameters  : unmanaged, Enum
            where TProviders   : unmanaged, Enum
            where TAudioKernel : struct, IAudioKernel <TParameters, TProviders>
        {
            AssertSameGraphAsNode(node);

            AudioKernelExtensions.GetReflectionData <TAudioKernel, TParameters, TProviders>(out void *jobReflectionData, out AudioKernelExtensions.ParameterDescriptionData parameterDescriptionData);

            QueueCommand(new SetFloatCommand
            {
                m_Type   = DSPCommandType.SetFloat,
                m_Graph  = m_Graph,
                m_Handle = m_Handle,
                m_InterpolationLength = (uint)interpolationLength,
                m_JobReflectionData   = jobReflectionData,
                m_Node      = node.Handle,
                m_Parameter = (uint)UnsafeUtility.EnumToInt(parameter),
                m_ParameterDescriptionData = parameterDescriptionData,
                m_Value = value,
            });
        }
コード例 #10
0
        /// <summary>
        /// Gets the number of sample providers associated with a given enum value in a container.
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public int GetCount(TProviders p)
        {
            var itemIndex = UnsafeUtility.EnumToInt(p);

            if (itemIndex < 0 || itemIndex >= Count)
            {
                throw new IndexOutOfRangeException("itemIndex");
            }

            int globalIndex = SampleProviderIndices[itemIndex];

            // Happens if the 'itemIndex'th item is an empty array.
            if (globalIndex < 0)
            {
                return(0);
            }

            // Find the index of the next non-empty item.
            int nextItemIndex   = itemIndex + 1;
            int nextGlobalIndex = -1;

            for (; nextItemIndex < Count; ++nextItemIndex)
            {
                nextGlobalIndex = SampleProviderIndices[nextItemIndex];
                if (nextGlobalIndex >= 0)
                {
                    break;
                }
            }

            // All items after itemIndex are empty containers.
            if (nextGlobalIndex < 0)
            {
                return(SampleProvidersCount - globalIndex);
            }

            return(nextGlobalIndex - globalIndex);
        }
コード例 #11
0
 /// <param name="parameter">
 /// A specific enum value from the parameter enumeration specified in the
 /// audio job.
 /// <see cref="IAudioKernel{TParameters,TProviders}"/>
 /// </param>
 /// <param name="sampleOffset">
 /// The time to evaluate the parameter at.
 /// </param>
 /// <returns>The value of a parameter.</returns>
 public float GetFloat(P parameter, int sampleOffset)
 {
     return(GetFloat(UnsafeUtility.EnumToInt(parameter), sampleOffset));
 }
コード例 #12
0
        public Flags32(TEnum value)
        {
            CheckEnumSize();

            Flags = UnsafeUtility.EnumToInt(value);
        }
コード例 #13
0
 /// <summary>
 /// Gets the sample provider associated with a given enum value.
 /// </summary>
 /// <param name="p"></param>
 /// <param name="arrayIndex"></param>
 /// <returns>Returns a SampleProvider</returns>
 public SampleProvider GetSampleProvider(TProviders p, int arrayIndex = 0)
 {
     return(GetSampleProvider(UnsafeUtility.EnumToInt(p), arrayIndex));
 }