Example #1
0
    public UIContextData GetNearestContext()
    {
        UIContextData val         = null;
        var           minDistance = 9999999;
        var           worldRadius = FindObjectOfType <World>().Radius;

        foreach (var wobj in FindObjectsOfType <WorldObject>())
        {
            if (wobj.Context == null)
            {
                continue;
            }
            if (wobj.Context.type == UIContextType.player)
            {
                continue;
            }
            var distance = WorldObject.Distance(wobj, worldObject);
            if (WorldObject.AreClose(wobj, worldObject))
            {
                if (distance < minDistance)
                {
                    distance = minDistance;
                    val      = wobj.Context;
                }
            }
        }
        return(val);
    }
Example #2
0
        public float Normalize(UIContextData context)
        {
            switch (unit)
            {
            case UILengthUnit.Auto:
                break;

            case UILengthUnit.Px:
                return(value * context.pixelScale);

            case UILengthUnit.Cm:
                return(value * context.pixelScale * context.dpi / 2.54f);

            case UILengthUnit.Mm:
                return(value * context.pixelScale * context.dpi / 25.4f);

            case UILengthUnit.In:
                return(value * context.pixelScale * context.dpi);

            case UILengthUnit.Pt:
                return(value * context.pixelScale * context.dpi * (1f / 72f));

            case UILengthUnit.Pc:
                return(value * context.pixelScale * context.dpi * (1f / 6f));

            case UILengthUnit.Em:

                break;

            case UILengthUnit.Ex:
                break;

            case UILengthUnit.Ch:
                break;

            case UILengthUnit.Rem:
                break;

            case UILengthUnit.Vw:
                return(value * context.pixelScale * (context.size.x * 0.01f));

            case UILengthUnit.Vh:
                return(value * context.pixelScale * (context.size.y * 0.01f));

            case UILengthUnit.Vmin:
                return(value * context.pixelScale * (math.min(context.size.x, context.size.y) * 0.01f));

            case UILengthUnit.Vmax:
                return(value * context.pixelScale * (math.max(context.size.x, context.size.y) * 0.01f));

            case UILengthUnit.Percent:
                return(value * context.pixelScale * context.relativeTo);

            default:
                break;
            }
            return(0f);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        String text    = String.Empty;
        String url     = TargetUrl;
        bool   enabled = true;
        String onClick = String.Empty;

        // If new element is set, load it directly, otherwise use first element with prefix 'new' in its name.
        UIElementInfo uiNew = String.IsNullOrEmpty(NewElement) ? UIContext.UIElement.GetNewElement() :
                              UIElementInfoProvider.GetUIElementInfo(UIContext.UIElement.ElementResourceID, NewElement);

        bool   openInDialog = false;
        String dialogWidth  = null;
        String dialogHeight = null;

        if (uiNew != null)
        {
            UIContextData data = new UIContextData();
            data.LoadData(uiNew.ElementProperties);
            text    = UIElementInfoProvider.GetElementCaption(uiNew);
            enabled = UIContextHelper.CheckElementVisibilityCondition(uiNew);
            url     = ContextResolver.ResolveMacros(UIContextHelper.GetElementUrl(uiNew, UIContext));

            openInDialog = data["OpenInDialog"].ToBoolean(false);
            dialogWidth  = data["DialogWidth"].ToString(null);
            dialogHeight = data["DialogHeight"].ToString(null);

            // Set on-click for JavaScript type
            if (uiNew.ElementType == UIElementTypeEnum.Javascript)
            {
                onClick = url;
                url     = String.Empty;
            }
            else
            {
                // For URL append dialog hash if needed
                url = UIContextHelper.AppendDialogHash(UIContext, url);
            }
        }

        // If url is non empty add action
        if (((url != String.Empty) || (onClick != String.Empty)) && (HeaderActions != null))
        {
            HeaderActions.AddAction(new HeaderAction()
            {
                Text          = GetString(text),
                RedirectUrl   = url,
                Enabled       = enabled,
                OnClientClick = onClick,
                OpenInDialog  = openInDialog,
                DialogWidth   = dialogWidth,
                DialogHeight  = dialogHeight
            });
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        String text = String.Empty;
        String url = TargetUrl;
        bool enabled = true;
        String onClick = String.Empty;

        // If new element is set, load it directly, otherwise use first element with prefix 'new' in its name.
        UIElementInfo uiNew = String.IsNullOrEmpty(NewElement) ? UIContext.UIElement.GetNewElement() :
            UIElementInfoProvider.GetUIElementInfo(UIContext.UIElement.ElementResourceID, NewElement);

        bool openInDialog = false;
        String dialogWidth = null;
        String dialogHeight = null;

        if (uiNew != null)
        {
            UIContextData data = new UIContextData();
            data.LoadData(uiNew.ElementProperties);
            text = UIElementInfoProvider.GetElementCaption(uiNew);
            enabled = UIContextHelper.CheckElementVisibilityCondition(uiNew);
            url = ContextResolver.ResolveMacros(UIContextHelper.GetElementUrl(uiNew, UIContext));

            openInDialog = data["OpenInDialog"].ToBoolean(false);
            dialogWidth = data["DialogWidth"].ToString(null);
            dialogHeight = data["DialogHeight"].ToString(null);

            // Set on-click for JavaScript type
            if (uiNew.ElementType == UIElementTypeEnum.Javascript)
            {
                onClick = url;
                url = String.Empty;
            }
            else
            {
                // For URL append dialog hash if needed
                url = UIContextHelper.AppendDialogHash(UIContext, url);
            }
        }

        // If url is non empty add action
        if (((url != String.Empty) || (onClick != String.Empty)) && (HeaderActions != null))
        {
            HeaderActions.AddAction(new HeaderAction()
            {
                Text = GetString(text),
                RedirectUrl = url,
                Enabled = enabled,
                OnClientClick = onClick,
                OpenInDialog = openInDialog,
                DialogWidth = dialogWidth,
                DialogHeight = dialogHeight
            });
        }
    }
Example #5
0
    void Update()
    {
        selectedContext = player.GetNearestContext();

        foreach (var uicp in UIContextViews)
        {
            if (selectedContext != null && selectedContext.ContextVisible)
            {
                if (uicp.type == selectedContext.type)
                {
                    uicp.view.gameObject.SetActive(true);
                    uicp.view.Bind(selectedContext);
                }
                else
                {
                    uicp.view.gameObject.SetActive(false);
                }
            }
            else
            {
                uicp.view.gameObject.SetActive(false);
            }
        }
    }
    protected override void OnInit(EventArgs e)
    {
        if (StopProcessing)
        {
            // No actions if processing is stopped
        }
        else
        {
            if (!String.IsNullOrEmpty(AfterDeleteScript))
            {
                gridElem.OnAction += gridElem_OnAction;
            }

            // If edit element name is set, load it directly. Otherwise load first element with prefix 'edit' in it's name.
            mUIEdit = String.IsNullOrEmpty(EditElement) ? UIContext.UIElement.GetEditElement() :
                      UIElementInfoProvider.GetUIElementInfo(UIContext.UIElement.ElementResourceID, EditElement);

            gridElem.CurrentResolver.SetNamedSourceData("UIContext", UIContext);

            if (mUIEdit != null)
            {
                UIContextData data = new UIContextData();
                data.LoadData(mUIEdit.ElementProperties);
                mEditInDialog = data["OpenInDialog"].ToBoolean(false);

                gridElem.EditInDialog = mEditInDialog;
                gridElem.DialogWidth  = data["DialogWidth"].ToString(null);
                gridElem.DialogHeight = data["DialogHeight"].ToString(null);
            }

            // Check modify permission on object type, to disable delete button
            var objectType = ObjectType;

            // Pass element's object type to unigrid. It may be overridden with unigrid definition
            if (!String.IsNullOrEmpty(objectType))
            {
                gridElem.ObjectType = objectType;
            }

            mEmptyCurrentInfo = gridElem.InfoObject;

            // Try to fake siteID (if object has siteID column)
            if ((mEmptyCurrentInfo != null) && (mEmptyCurrentInfo.TypeInfo.SiteIDColumn != ObjectTypeInfo.COLUMN_NAME_UNKNOWN))
            {
                mEmptyCurrentInfo.Generalized.ObjectSiteID = GetSiteID(mEmptyCurrentInfo);
            }

            // Apply delete check only for non global admins
            if (!MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))
            {
                gridElem.OnBeforeDataReload  += gridElem_OnBeforeDataReload;
                gridElem.OnExternalDataBound += gridElem_OnExternalDataBound;
            }

            if (AllowDataExport)
            {
                gridElem.ShowExportMenu = AllowDataExport;
            }

            // Must be called before permission check to initialize grid extenders properly
            base.OnInit(e);

            // Check view permission for object type
            if (CheckInfoViewPermissions && !CheckViewPermissions(mEmptyCurrentInfo))
            {
                gridElem.StopProcessing = true;
                gridElem.Visible        = false;
            }
        }
    }
Example #7
0
 public abstract void Bind(UIContextData bound);
    protected override void OnInit(EventArgs e)
    {
        if (StopProcessing)
        {
            // No actions if processing is stopped
        }
        else
        {
            if (!String.IsNullOrEmpty(AfterDeleteScript))
            {
                gridElem.OnAction += gridElem_OnAction;
            }

            // If edit element name is set, load it directly. Otherwise load first element with prefix 'edit' in it's name.
            uiEdit = String.IsNullOrEmpty(EditElement) ? UIContext.UIElement.GetEditElement() :
                UIElementInfoProvider.GetUIElementInfo(UIContext.UIElement.ElementResourceID, EditElement);

            gridElem.CurrentResolver.SetNamedSourceData("UIContext", UIContext);

            if (uiEdit != null)
            {
                UIContextData data = new UIContextData();
                data.LoadData(uiEdit.ElementProperties);
                editInDialog = data["OpenInDialog"].ToBoolean(false);

                gridElem.EditInDialog = editInDialog;
                gridElem.DialogWidth = data["DialogWidth"].ToString(null);
                gridElem.DialogHeight = data["DialogHeight"].ToString(null);
            }

            // Check modify permission on object type, to disable delete button
            var objectType = ObjectType;

            // Pass element's object type to unigrid. It may be overridden with unigrid definition
            if (!String.IsNullOrEmpty(objectType))
            {
                gridElem.ObjectType = objectType;
            }

            mEmptyCurrentInfo = gridElem.InfoObject;

            // Try to fake siteID (if object has siteID column)
            if ((mEmptyCurrentInfo != null) && (mEmptyCurrentInfo.TypeInfo.SiteIDColumn != ObjectTypeInfo.COLUMN_NAME_UNKNOWN))
            {
                mEmptyCurrentInfo.Generalized.ObjectSiteID = GetSiteID(mEmptyCurrentInfo);
            }

            // Apply delete check only for non global admins
            if (!MembershipContext.AuthenticatedUser.IsGlobalAdministrator)
            {
                gridElem.OnBeforeDataReload += gridElem_OnBeforeDataReload;
                gridElem.OnExternalDataBound += gridElem_OnExternalDataBound;
            }

            // Must be called before permission check to initialize grid extenders properly
            base.OnInit(e);

            if (CheckInfoViewPermissions)
            {
                // Check view permission for object type
                if (!CheckViewPermissions(mEmptyCurrentInfo))
                {
                    gridElem.StopProcessing = true;
                    gridElem.Visible = false;
                }
            }
        }
    }
        protected unsafe override void OnUpdate()
        {
            var    contexts     = new NativeList <UIContextData>(8, Allocator.TempJob);
            var    graphData    = new NativeList <UIGraphData>(8, Allocator.TempJob);
            Entity schemaEntity = Entity.Null;
            int    nodeCount    = 0;

            meshes.Clear();
            Entities.ForEach((UIObject obj) =>
            {
                //TODO: Writes every conversion frame but will crash under certain conditions otherwise. Crashes observed involving opening and closing subscenes without modifying anything after script reload.

                var guid = obj.model?.GetOutputGuid();

                if (!string.IsNullOrEmpty(guid))
                {
                    IntPtr ptr;
                    long allocatedLength;
                    using (var fs = File.OpenRead(UnityEditor.AssetDatabase.GUIDToAssetPath(guid))) {
                        allocatedLength = math.ceilpow2(fs.Length);
                        ptr             = (IntPtr)UnsafeUtility.Malloc(allocatedLength, 0, Allocator.Persistent);
                        using (var us = new UnmanagedMemoryStream((byte *)ptr.ToPointer(), 0, fs.Length, FileAccess.Write)) {
                            fs.CopyTo(us);
                        }
                    }
                    var gd = new UIGraphData {
                        value = ptr, allocatedLength = allocatedLength
                    };
                    graphData.Add(gd);
                    nodeCount += gd.GetNodeCount();
                    contexts.Add(UIContextData.CreateContext(obj.camera));
                    meshes.Add(new Mesh());
                    if (schemaEntity == Entity.Null)
                    {
                        schemaEntity = CreateAdditionalEntity(obj);
                        DstEntityManager.SetName(schemaEntity, "UI Schema");
                        DstEntityManager.AddSharedComponentData(schemaEntity, new UISchemaData {
                            value = schema
                        });
                    }
                    DeclareAssetDependency(obj.gameObject, schema);
                }
                obj.cachedGuid = guid;
            });

            if (graphData.Length > 0)
            {
                var graphDataArray = graphData.AsArray();
                var meshData       = Mesh.AllocateWritableMeshData(graphData.Length);
                var submeshes      = new NativeArray <int>(graphData.Length, Allocator.TempJob);
                var stream         = new NativeStream(nodeCount, Allocator.TempJob);
                new UILayoutJob
                {
                    schema        = compiledSchema,
                    graphs        = graphDataArray,
                    contexts      = contexts,
                    meshDataArray = meshData
                }.Schedule(graphData.Length, 1).Complete();
                new UINodeDecompositionJob
                {
                    schema       = compiledSchema,
                    graphs       = graphDataArray,
                    nodes        = stream.AsWriter(),
                    submeshCount = submeshes
                }.Schedule(graphData.Length, 1).Complete();
                Mesh.ApplyAndDisposeWritableMeshData(meshData, meshes);
                var result = stream.ToNativeArray <DedicatedNodeInfo>(Allocator.Temp);
                var nodes  = new NativeMultiHashMap <int, DedicatedNodeInfo>(graphData.Length, Allocator.Temp);
                for (int i = 0; i < result.Length; i++)
                {
                    nodes.Add(result[i].graphIndex, result[i]);
                }
                stream.Dispose();
                submeshes.Dispose();
                int index        = 0;
                var nodeEntities = new NativeList <Entity>(Allocator.Temp);
                Entities.ForEach((UIObject obj) =>
                {
                    if (!string.IsNullOrEmpty(obj.cachedGuid))
                    {
                        var entity = GetPrimaryEntity(obj);
                        var gd     = graphDataArray[index];
                        DstEntityManager.AddComponentData(entity, new UIGraph {
                            value = new BlittableAssetReference(obj.cachedGuid)
                        });
                        DstEntityManager.AddSharedComponentData <UIDirtyState>(entity, false);
                        Material material;
                        if (gd.TryGetConfigBlock(0, UIConfigLayoutTable.MaterialConfig, out IntPtr result))
                        {
                            material = UnityEditor.AssetDatabase.LoadAssetAtPath <Material>(UnityEditor.AssetDatabase.GUIDToAssetPath(((MaterialConfig *)(result.ToPointer()))->material.ToHex()));
                        }
                        else
                        {
                            material = obj.model.GetMaterial();
                        }



                        DeclareAssetDependency(obj.gameObject, obj.model);


                        DeclareAssetDependency(obj.gameObject, material);

                        DstEntityManager.AddSharedComponentData(entity, new RenderMesh
                        {
                            mesh                 = meshes[index],
                            material             = material,
                            subMesh              = 0,
                            castShadows          = ShadowCastingMode.Off,
                            receiveShadows       = false,
                            needMotionVectorPass = false,
                            layer                = obj.gameObject.layer
                        });
                        DstEntityManager.AddComponentData(entity, new UIPixelScale {
                            value = obj.pixelScale
                        });
                        var bounds = meshes[index].GetSubMesh(0).bounds.ToAABB();
                        DstEntityManager.AddComponentData(entity, new RenderBounds {
                            Value = bounds
                        });

                        DstEntityManager.AddComponent <UIContext>(entity);

                        if (obj.camera != null)
                        {
                            DstEntityManager.AddComponentData(entity, new UIContextSource {
                                value = GetPrimaryEntity(obj.camera)
                            });
                            var ltc = new LocalToCamera
                            {
                                cameraLTW = obj.camera.transform.localToWorldMatrix,
                                clipPlane = new float2(obj.camera.nearClipPlane, obj.camera.farClipPlane),
                                alignment = obj.alignment,
                                offsetX   = obj.offsetX,
                                offsetY   = obj.offsetY
                            };
                            DstEntityManager.AddComponentData(entity, ltc);
                            var rotation  = quaternion.LookRotation(ltc.cameraLTW.c2.xyz, ltc.cameraLTW.c1.xyz);
                            var translate = ltc.cameraLTW.c3.xyz + new float3(ltc.alignment.GetOffset(bounds.Size.xy, new float2(Screen.currentResolution.height * obj.camera.aspect, Screen.currentResolution.height)), 0) + math.mul(rotation, math.forward() * ltc.clipPlane.x * 2f) + (math.mul(rotation, math.right()) * ltc.offsetX.Normalize(contexts[index])) + (math.mul(rotation, math.up()) * ltc.offsetY.Normalize(contexts[index]));
                            DstEntityManager.SetComponentData(entity, new LocalToWorld {
                                Value = float4x4.TRS(translate, rotation, obj.pixelScale)
                            });
                            DeclareDependency(obj, obj.camera);
                        }

                        DstEntityManager.AddComponent <PerInstanceCullingTag>(entity);

                        nodeEntities.Clear();
                        var nodeInfoIter = nodes.GetValuesForKey(index);
                        while (nodeInfoIter.MoveNext())
                        {
                            var nodeInfo   = nodeInfoIter.Current;
                            var nodeEntity = CreateAdditionalEntity(obj);
                            var name       = graphData[index].GetNodeName(nodeInfo.nodeIndex);
                            if (string.IsNullOrEmpty(name))
                            {
                                name = $"Node#{nodeInfo.nodeIndex}";
                            }
                            DstEntityManager.SetName(nodeEntity, $"{DstEntityManager.GetName(entity)}[{name}]");
                            DstEntityManager.AddComponentData(nodeEntity, new UINodeInfo {
                                index = nodeInfo.nodeIndex, submesh = nodeInfo.submesh
                            });
                            DstEntityManager.AddComponentData(nodeEntity, new UIParent {
                                value = entity
                            });
                            DstEntityManager.AddComponentData(nodeEntity, new Parent {
                                Value = entity
                            });
                            DstEntityManager.AddComponentData(nodeEntity, new LocalToWorld {
                                Value = float4x4.identity
                            });
                            DstEntityManager.AddComponentData(nodeEntity, new Rotation {
                                Value = quaternion.identity
                            });
                            DstEntityManager.AddComponentData(nodeEntity, new Scale {
                                Value = 1f
                            });
                            DstEntityManager.AddComponentData(nodeEntity, new LocalToParent {
                                Value = float4x4.identity
                            });
                            if (gd.TryGetConfigBlock(0, UIConfigLayoutTable.MaterialConfig, out result))
                            {
                                material = UnityEditor.AssetDatabase.LoadAssetAtPath <Material>(UnityEditor.AssetDatabase.GUIDToAssetPath(((MaterialConfig *)result.ToPointer())->material.ToHex()));
                            }
                            else
                            {
                                material = obj.model.GetMaterial();
                            }
                            DstEntityManager.AddSharedComponentData(nodeEntity, new RenderMesh
                            {
                                mesh                 = meshes[index],
                                material             = material,
                                subMesh              = nodeInfo.submesh,
                                castShadows          = ShadowCastingMode.Off,
                                receiveShadows       = false,
                                needMotionVectorPass = false,
                                layer                = obj.gameObject.layer
                            });
                            DstEntityManager.AddComponentData(nodeEntity, new RenderBounds {
                                Value = meshes[index].GetSubMesh(nodeInfo.submesh).bounds.ToAABB()
                            });
                            DstEntityManager.AddComponent <PerInstanceCullingTag>(nodeEntity);
                            nodeEntities.Add(nodeEntity);
                            ConfigureEditorRenderData(nodeEntity, obj.gameObject, true);
                        }
                        var buffer = DstEntityManager.AddBuffer <UINode>(entity);
                        buffer.AddRange(nodeEntities.AsArray().Reinterpret <UINode>());
                        UnsafeUtility.Free(graphData[index].value.ToPointer(), Allocator.TempJob);
                        index++;
                        ConfigureEditorRenderData(entity, obj.gameObject, true);
                    }
                });
            }

            contexts.Dispose();
            graphData.Dispose();
        }
Example #10
0
 public override void Bind(UIContextData bound)
 {
     Bound = (PlayerDataObject)bound;
     GrowthRayButton.onClick.AddListener(FindObjectOfType <WorldEnlarger>().GrowWorld);
 }
Example #11
0
 public override void Bind(UIContextData bound)
 {
     Bound      = (StoreDataObject)bound;
     Title.text = Bound.type.ToString();
 }
Example #12
0
 public override void Bind(UIContextData bound)
 {
     Bound      = (WoodshopDataObject)bound;
     Title.text = "Lumberyard";
 }
Example #13
0
 public override void Bind(UIContextData bound)
 {
     Bound = (TreeDataObject)bound;
     Chop.onClick.RemoveAllListeners();
     Chop.onClick.AddListener(() => Bound.Damage(FindObjectOfType <PlayerDataObject>().ChopDMG));
 }