コード例 #1
0
ファイル: DataContainer.cs プロジェクト: xayfuu/EnemyHitLog
 public DataContainer(string displayName, string truncatedDisplayName, string colorHex, DataContainerType dataContainerType)
 {
     DisplayName          = displayName;
     TruncatedDisplayName = truncatedDisplayName;
     ColorHex             = colorHex;
     DataContainerType    = dataContainerType;
 }
コード例 #2
0
        public ConfigContainerFactory SetLoader(DataContainerType containerType)
        {
            DefaultContainer = containerType;

            if (loader.ContainsKey(DefaultContainer))
            {
                return(this);
            }

            //---- 处理不同的配置加载逻辑 ----

            #if UNITY_EDITOR
            if (DefaultContainer == DataContainerType.EDITOR_UNITY_JSON)
            {
                loader.Add(DefaultContainer, new UnityJsonContainer());
            }
            if (DefaultContainer == DataContainerType.EDITOR_PROTOBUF)
            {
                loader.Add(DefaultContainer, new ProtobufContainer());
            }
            #endif

            //运行时Protobuf解析
            if (DefaultContainer == DataContainerType.RUNTIME_PROTOBUF)
            {
                loader.Add(DefaultContainer, new RuntimeProtobufContainer());
            }

            //---- 处理不同的配置加载逻辑 ----
            return(this);
        }
コード例 #3
0
    private void OnGUI()
    {
        _title           = new GUIStyle(GUI.skin.label);
        _title.alignment = TextAnchor.MiddleCenter;
        _title.fontSize  = 20;
        _title.fontStyle = FontStyle.Bold;

        _subTitle           = new GUIStyle(GUI.skin.label);
        _subTitle.fontSize  = 14;
        _subTitle.fontStyle = FontStyle.Bold;

        _description           = new GUIStyle(GUI.skin.label);
        _description.fontStyle = FontStyle.Italic;
        _description.wordWrap  = true;

        GUILayout.Space(20);

        GUILayout.BeginHorizontal("BOX");

        if (GUILayout.Button("Characters"))
        {
            _currentViewSelected = DataContainerType.Character;
            _toDelete            = false;
        }

        if (GUILayout.Button("Locations"))
        {
            _currentViewSelected = DataContainerType.Location;
            _toDelete            = false;
        }

        if (GUILayout.Button("Soundtrack"))
        {
            _currentViewSelected = DataContainerType.Soundtrack;
            _toDelete            = false;
        }

        if (GUILayout.Button("Setting"))
        {
            _currentViewSelected = DataContainerType.Setting;
            _toDelete            = false;
        }

        GUILayout.EndHorizontal();

        GUILayout.Space(5);

        EditorGUI.DrawRect(GUILayoutUtility.GetRect(100, 2), Color.black);

        EditorGUILayout.BeginVertical();
        _pos = EditorGUILayout.BeginScrollView(_pos, GUILayout.Width(position.width));

        DrawView();

        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();

        Repaint();
    }
コード例 #4
0
        public ConfigContainerFactory SetLoader(DataContainerType containerType)
        {
            if (loader.ContainsKey(containerType))
            {
                DefaultContainer = containerType;
                return(this);
            }

            //---- 处理不同的配置加载逻辑 ----
            if (containerType == DataContainerType.UNITY_JSON)
            {
                loader.Add(containerType, new UnityJsonContainer());
            }
            if (containerType == DataContainerType.PROTOBUF)
            {
                loader.Add(containerType, new ProtobufContainer());
            }



            //---- 处理不同的配置加载逻辑 ----
            return(this);
        }
コード例 #5
0
 public static ConfigContainerFactory GetInstance(DataContainerType containerType = DataContainerType.UNITY_JSON)
 {
     return((instance ?? (instance = new ConfigContainerFactory())).SetLoader(containerType));
 }
コード例 #6
0
ファイル: DataContainerManager.cs プロジェクト: BEXIS2/Core
        public DataAttribute CreateDataAttribute(string shortName, string name, string description, bool isMultiValue, bool isBuiltIn, string scope, MeasurementScale measurementScale, DataContainerType containerType, string entitySelectionPredicate,
            DataType dataType, Unit unit, Methodology methodology, Classifier classifier,
            ICollection<AggregateFunction> functions, ICollection<GlobalizationInfo> globalizationInfos, ICollection<Constraint> constraints,
            ICollection<ExtendedProperty> extendedProperies
            )
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(shortName));
            Contract.Requires(dataType != null && dataType.Id >= 0);
            Contract.Requires(unit != null && unit.Id >= 0);

            Contract.Ensures(Contract.Result<DataAttribute>() != null && Contract.Result<DataAttribute>().Id >= 0);
            DataAttribute e = new DataAttribute()
            {
                ShortName = shortName,
                Name = name,
                Description = description,
                IsMultiValue = isMultiValue,
                IsBuiltIn = isBuiltIn,
                Scope = scope,
                MeasurementScale = measurementScale,
                ContainerType = containerType,
                EntitySelectionPredicate = entitySelectionPredicate,
                DataType = dataType,
                Unit = unit,
                Methodology = methodology,
                AggregateFunctions = functions,
                GlobalizationInfos = globalizationInfos,
                Constraints = constraints,
                ExtendedProperties = extendedProperies,
            };
            if (classifier != null && classifier.Id > 0)
                e.Classification = classifier;
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<DataAttribute> repo = uow.GetRepository<DataAttribute>();
                repo.Put(e);
                uow.Commit();
            }
            return (e);
        }
コード例 #7
0
ファイル: DataContainerManager.cs プロジェクト: payamad/Core
        public DataAttribute CreateDataAttribute(string shortName, string name, string description, bool isMultiValue, bool isBuiltIn, string scope, MeasurementScale measurementScale, DataContainerType containerType, string entitySelectionPredicate,
                                                 DataType dataType, Unit unit, Methodology methodology, Classifier classifier,
                                                 ICollection <AggregateFunction> functions, ICollection <GlobalizationInfo> globalizationInfos, ICollection <Constraint> constraints,
                                                 ICollection <ExtendedProperty> extendedProperies
                                                 )
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(shortName));
            Contract.Requires(dataType != null && dataType.Id >= 0);
            Contract.Requires(unit != null && unit.Id >= 0);


            Contract.Ensures(Contract.Result <DataAttribute>() != null && Contract.Result <DataAttribute>().Id >= 0);
            DataAttribute e = new DataAttribute()
            {
                ShortName                = shortName,
                Name                     = name,
                Description              = description,
                IsMultiValue             = isMultiValue,
                IsBuiltIn                = isBuiltIn,
                Scope                    = scope,
                MeasurementScale         = measurementScale,
                ContainerType            = containerType,
                EntitySelectionPredicate = entitySelectionPredicate,
                DataType                 = dataType,
                Unit                     = unit,
                Methodology              = methodology,
                AggregateFunctions       = functions,
                GlobalizationInfos       = globalizationInfos,
                Constraints              = constraints,
                ExtendedProperties       = extendedProperies,
            };

            if (classifier != null && classifier.Id > 0)
            {
                e.Classification = classifier;
            }
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <DataAttribute> repo = uow.GetRepository <DataAttribute>();
                repo.Put(e);
                uow.Commit();
            }
            return(e);
        }
コード例 #8
0
 /// <summary>
 /// 如果可以不要new多个当前工厂,在PB加载下出现多个实例会报错的
 /// </summary>
 /// <param name="containerType">加载类型</param>
 public ConfigContainerFactory(DataContainerType containerType = DataContainerType.EDITOR_UNITY_JSON)
 {
     loader = new Dictionary <DataContainerType, IConfigContainer>();
     SetLoader(containerType);
 }
コード例 #9
0
 public DataContainer(DataContainerType Type, object Data)
 {
     this.Type = Type;
     this.Data = Data;
 }
コード例 #10
0
ファイル: IOHelper.cs プロジェクト: tomyqg/OneDAS-Core
        public static unsafe void Write <T>(long dataTargetId, T[] valueSet, DataContainerType dataContainerType)
        {
            Contract.Requires(valueSet != null, nameof(valueSet));

            long typeId = -1;

            int elementTypeSize;
            int byteLength;

            IntPtr   valueSetPointer;
            GCHandle gcHandle;
            Type     elementType;

            elementTypeSize = 0;
            byteLength      = 0;

            valueSetPointer = default;
            gcHandle        = default;
            elementType     = typeof(T);

            try
            {
                typeId = TypeConversionHelper.GetHdfTypeIdFromType(elementType);

                if (elementType == typeof(string))
                {
                    elementTypeSize = Marshal.SizeOf <IntPtr>();
                }
                else if (elementType == typeof(bool))
                {
                    elementTypeSize = Marshal.SizeOf <byte>();
                }
                else
                {
                    elementTypeSize = Marshal.SizeOf(elementType);
                }

                byteLength = elementTypeSize * valueSet.Count();

                if (elementType.IsPrimitive)
                {
                    gcHandle        = GCHandle.Alloc(valueSet, GCHandleType.Pinned);
                    valueSetPointer = gcHandle.AddrOfPinnedObject();
                }
                else if (elementType == typeof(string))
                {
                    IntPtr[] intPtrSet = valueSet.Cast <string>().Select(x => Marshal.StringToHGlobalAnsi(x)).ToArray();

                    valueSetPointer = Marshal.AllocHGlobal(byteLength);
                    Marshal.Copy(intPtrSet, 0, valueSetPointer, intPtrSet.Count());
                }
                else if (elementType.IsValueType && !elementType.IsPrimitive && !elementType.IsEnum)
                {
                    IntPtr sourcePtr;
                    int    counter;

                    counter         = 0;
                    valueSetPointer = Marshal.AllocHGlobal(byteLength);

                    valueSet.Cast <ValueType>().ToList().ForEach(x =>
                    {
                        Span <byte> source;
                        Span <byte> target;

                        sourcePtr = Marshal.AllocHGlobal(elementTypeSize);
                        Marshal.StructureToPtr(x, sourcePtr, false);

                        source = new Span <byte>(sourcePtr.ToPointer(), Marshal.SizeOf <T>());
                        target = new Span <byte>(IntPtr.Add(valueSetPointer, elementTypeSize * counter).ToPointer(), Marshal.SizeOf <T>());

                        source.CopyTo(target);

                        counter += 1;
                        Marshal.FreeHGlobal(sourcePtr);
                    });
                }
                else
                {
                    throw new NotSupportedException();
                }

                switch (dataContainerType)
                {
                case DataContainerType.Attribute:

                    if (H5A.write(dataTargetId, typeId, valueSetPointer) < 0)
                    {
                        throw new Exception(ErrorMessage.IOHelper_CouldNotWriteAttribute);
                    }

                    break;

                case DataContainerType.Dataset:

                    if (H5D.write(dataTargetId, typeId, H5S.ALL, H5S.ALL, H5P.DEFAULT, valueSetPointer) < 0)
                    {
                        throw new Exception(ErrorMessage.IOHelper_CouldNotWriteDataset);
                    }

                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            finally
            {
                if (gcHandle.IsAllocated)
                {
                    gcHandle.Free();
                }
                else
                {
                    Marshal.FreeHGlobal(valueSetPointer);
                }

                if (H5I.is_valid(typeId) > 0)
                {
                    H5T.close(typeId);
                }
            }
        }
コード例 #11
0
ファイル: IOHelper.cs プロジェクト: tomyqg/OneDAS-Core
        public static T[] Read <T>(long dataPortId, DataContainerType dataContainerType, long dataspaceId = -1)
        {
            long dataspaceId_file   = -1;
            long dataspaceId_memory = -1;
            long typeId             = -1;

            long elementCount;

            int elementTypeSize;
            int byteLength;

            IntPtr bufferPtr;
            Type   elementType;

            T[] returnValue;

            elementTypeSize = 0;
            byteLength      = 0;
            bufferPtr       = IntPtr.Zero;
            elementType     = typeof(T);
            returnValue     = null;

            try
            {
                if (dataspaceId > -1)
                {
                    dataspaceId = H5S.copy(dataspaceId);
                }

                switch (dataContainerType)
                {
                case DataContainerType.Attribute:

                    if (dataspaceId == -1)
                    {
                        dataspaceId = H5A.get_space(dataPortId);
                    }

                    break;

                case DataContainerType.Dataset:

                    if (dataspaceId == -1)
                    {
                        dataspaceId = H5D.get_space(dataPortId);
                    }

                    dataspaceId_file = dataspaceId;

                    break;

                default:
                    throw new NotSupportedException();
                }

                if (elementType == typeof(string))
                {
                    elementTypeSize = Marshal.SizeOf <IntPtr>();
                }
                else if (elementType == typeof(bool))
                {
                    elementTypeSize = Marshal.SizeOf <byte>();
                }
                else
                {
                    elementTypeSize = Marshal.SizeOf(elementType);
                }

                elementCount = H5S.get_select_npoints(dataspaceId);
                byteLength   = (int)elementCount * elementTypeSize;
                bufferPtr    = Marshal.AllocHGlobal(byteLength);
                typeId       = TypeConversionHelper.GetHdfTypeIdFromType(elementType);

                switch (dataContainerType)
                {
                case DataContainerType.Attribute:

                    if (H5A.read(dataPortId, typeId, bufferPtr) < 0)
                    {
                        throw new Exception(ErrorMessage.IOHelper_CouldNotReadAttribute);
                    }

                    break;

                case DataContainerType.Dataset:

                    dataspaceId_memory = H5S.create_simple(1, new ulong[] { (ulong)elementCount }, new ulong[] { (ulong)elementCount });

                    if (H5D.read(dataPortId, typeId, dataspaceId_memory, dataspaceId_file, H5P.DEFAULT, bufferPtr) < 0)
                    {
                        throw new Exception(ErrorMessage.IOHelper_CouldNotReadDataset);
                    }

                    break;

                default:
                    throw new NotSupportedException();
                }

                if (elementType.IsPrimitive)
                {
                    T[]      genericSet;
                    GCHandle gcHandle;
                    byte[]   byteSet;

                    genericSet = new T[(int)elementCount];
                    gcHandle   = GCHandle.Alloc(genericSet, GCHandleType.Pinned);
                    byteSet    = new byte[byteLength];

                    Marshal.Copy(bufferPtr, byteSet, 0, byteLength);
                    Marshal.Copy(byteSet, 0, gcHandle.AddrOfPinnedObject(), byteLength);

                    returnValue = genericSet;

                    gcHandle.Free();
                }
                else if (elementType == typeof(string))
                {
                    IntPtr[] intPtrSet;

                    intPtrSet = new IntPtr[(int)elementCount];

                    Marshal.Copy(bufferPtr, intPtrSet, 0, (int)elementCount);

                    returnValue = intPtrSet.Select(x =>
                    {
                        string result = Marshal.PtrToStringAnsi(x);
                        H5.free_memory(x);
                        return(result);
                    }).Cast <T>().ToArray();
                }
                else if (elementType.IsValueType && !elementType.IsPrimitive && !elementType.IsEnum)
                {
                    T[] structSet;
                    int offset;

                    structSet = new T[(int)elementCount];
                    offset    = 0;

                    Enumerable.Range(0, (int)elementCount).ToList().ForEach(x =>
                    {
                        structSet[x] = Marshal.PtrToStructure <T>(IntPtr.Add(bufferPtr, offset));
                        offset      += elementTypeSize;
                    });

                    returnValue = structSet;
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            finally
            {
                Marshal.FreeHGlobal(bufferPtr);

                if (H5I.is_valid(typeId) > 0)
                {
                    H5T.close(typeId);
                }
                if (H5I.is_valid(dataspaceId_memory) > 0)
                {
                    H5S.close(dataspaceId_memory);
                }
                if (H5I.is_valid(dataspaceId) > 0)
                {
                    H5S.close(dataspaceId);
                }
            }

            return(returnValue);
        }
コード例 #12
0
 public static void InitNodePopup(DataContainerType id)
 {
     _currentPop = (VNDatabasePopUpWindow)EditorWindow.GetWindow <VNDatabasePopUpWindow>();
     _currentPop.titleContent = new GUIContent("Paradox Engine Assistante");
     _currentPop._idToCreate  = id;
 }