예제 #1
0
        public async Task <IActionResult> PostGUIDEntity([FromRoute] string id, GUIDEntity gUIDEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            GUIDEntity entity = new GUIDEntity();

            int expiryTime;

            Int32.TryParse(_distributedCache.GetString("ExpiryTime"), out expiryTime);

            entity.GuidValue = id.ToUpper();
            entity.User      = gUIDEntity.User;

            if (expiryTime > gUIDEntity.Expire.Value)
            {
                gUIDEntity.Expire = expiryTime;
            }

            entity.Expire = gUIDEntity.Expire;

            _context.GuidEntities.Add(entity);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGUIDEntity", new { id = entity.GuidValue }, entity));
        }
예제 #2
0
        public override void OnInspectorGUI()
        {
            _entityTarget           = target as GUIDEntity;
            _propertySerializedGUID = serializedObject.FindProperty(PROPERTY_NAME_SERIALIZED_GUID);

            serializedObject.Update();
            OnInspectorGUIObjectField();
            EditorGUILayout.Space();


            serializedObject.ApplyModifiedProperties();
        }
예제 #3
0
        public async Task <IActionResult> PostGUIDEntity(GUIDEntity gUIDEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            int expiryTime;

            Int32.TryParse(_distributedCache.GetString("ExpiryTime"), out expiryTime);
            gUIDEntity.GuidValue = Guid.NewGuid().ToString("N").ToUpper();
            gUIDEntity.Expire    = expiryTime;

            _context.GuidEntities.Add(gUIDEntity);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGUIDEntity", new { id = gUIDEntity.GuidValue }, gUIDEntity));
        }
예제 #4
0
        public async Task <IActionResult> PutGUIDEntity([FromRoute] string id, GUIDEntity pgUIDEntity)
        {
            GUIDEntity gUIDEntity = new GUIDEntity();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (pgUIDEntity == null)
            {
                return(BadRequest());
            }

            if (id != string.Empty)
            {
                gUIDEntity = await _context.GuidEntities.FindAsync(id);

                if (gUIDEntity != null)
                {
                    gUIDEntity.Expire = pgUIDEntity.Expire;

                    _context.Entry(gUIDEntity).State = EntityState.Modified;
                }
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GUIDEntityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetGUIDEntity", new { id = gUIDEntity.GuidValue }, gUIDEntity));
        }
예제 #5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            guidProp  = property.FindPropertyRelative("serializedGuid");
            nameProp  = property.FindPropertyRelative("cachedName");
            sceneProp = property.FindPropertyRelative("cachedScene");

            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            position.height = EditorGUIUtility.singleLineHeight;

            // Draw prefix label, returning the new rect we can draw in
            var guidCompPosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            System.Guid currentGuid;
            GameObject  currentGO = null;

            // working with array properties is a bit unwieldy
            // you have to get the property at each index manually
            byte[] byteArray = new byte[16];
            int    arraySize = guidProp.arraySize;

            for (int i = 0; i < arraySize; ++i)
            {
                var byteProp = guidProp.GetArrayElementAtIndex(i);
                byteArray[i] = (byte)byteProp.intValue;
            }

            currentGuid = new System.Guid(byteArray);
            currentGO   = GUIDManager.ResolveGuid(currentGuid);
            GUIDEntity currentGuidComponent = currentGO != null?currentGO.GetComponent <GUIDEntity>() : null;

            GUIDEntity component = null;

            if (currentGuid != System.Guid.Empty && currentGuidComponent == null)
            {
                // if our reference is set, but the target isn't loaded, we display the target and the scene it is in, and provide a way to clear the reference
                float buttonWidth = 55.0f;

                guidCompPosition.xMax -= buttonWidth;

                bool guiEnabled = GUI.enabled;
                GUI.enabled = false;
                EditorGUI.LabelField(guidCompPosition, new GUIContent(nameProp.stringValue, "Target GameObject is not currently loaded."), EditorStyles.objectField);
                GUI.enabled = guiEnabled;

                Rect clearButtonRect = new Rect(guidCompPosition);
                clearButtonRect.xMin  = guidCompPosition.xMax;
                clearButtonRect.xMax += buttonWidth;

                if (GUI.Button(clearButtonRect, clearButtonGUI, EditorStyles.miniButton))
                {
                    ClearPreviousGuid();
                }
            }
            else
            {
                // if our object is loaded, we can simply use an object field directly
                component = EditorGUI.ObjectField(guidCompPosition, currentGuidComponent, typeof(GUIDEntity), true) as GUIDEntity;
            }

            if (currentGuidComponent != null && component == null)
            {
                ClearPreviousGuid();
            }

            // if we have a valid reference, draw the scene name of the scene it lives in so users can find it
            if (component != null)
            {
                nameProp.stringValue = component.name;
                string scenePath = component.gameObject.scene.path;
                sceneProp.objectReferenceValue = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePath);

                // only update the GUID Prop if something changed. This fixes multi-edit on GUID References
                if (component != currentGuidComponent)
                {
                    byteArray = component.GetGuid().ToByteArray();
                    arraySize = guidProp.arraySize;
                    for (int i = 0; i < arraySize; ++i)
                    {
                        var byteProp = guidProp.GetArrayElementAtIndex(i);
                        byteProp.intValue = byteArray[i];
                    }
                }
            }

            EditorGUI.indentLevel++;
            position.y += EditorGUIUtility.singleLineHeight;
            bool cachedGUIState = GUI.enabled;

            GUI.enabled = false;
            EditorGUI.ObjectField(position, sceneLabel, sceneProp.objectReferenceValue, typeof(SceneAsset), false);
            GUI.enabled = cachedGUIState;
            EditorGUI.indentLevel--;

            EditorGUI.EndProperty();
        }