Beispiel #1
0
        public virtual async Task UpdateAsync(Material material, string tags, bool isDescriptionEditable = false)
        {
            material.Text =
                sanitizer.Sanitize(material
                                   .Text); // TODO сделать совместную валидацию, санитайзин и превью на основе одного DOM

            var(preview, description) = MaterialExtensions.MakePreviewAndDescription(material.Text,
                                                                                     materialsOptions.DescriptionLength,
                                                                                     materialsOptions.PreviewLength);

            material.Preview = preview;

            if (isDescriptionEditable)
            {
                material.Description = SimpleHtmlToText.ClearTags(sanitizer.Sanitize(material.Description));
            }
            else
            {
                material.Description = description;
            }

            /*material.MakePreviewAndDescription(materialsOptions.DescriptionLength,
             *  materialsOptions.PreviewLength);*/

            await db.UpdateAsync(material);

            await tagsManager.MaterialCreateAndSetTagsAsync(material, tags);
        }
Beispiel #2
0
        // Token: 0x06002B9C RID: 11164 RVA: 0x001040F8 File Offset: 0x001022F8
        private static bool UpdateAllowed()
        {
            //MultiplayerBuilder.SetDefaultPlaceTransform(ref MultiplayerBuilder.placePosition, ref MultiplayerBuilder.placeRotation);
            bool flag = false;
            ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>();
            bool flag2;

            if (componentInParent != null)
            {
                Transform transform = componentInParent.transform;
                transform.position = MultiplayerBuilder.placePosition;
                transform.rotation = MultiplayerBuilder.placeRotation;
                flag2 = componentInParent.UpdateGhostModel(MultiplayerBuilder.GetAimTransform(), MultiplayerBuilder.ghostModel, default(RaycastHit), out flag);
                //MultiplayerBuilder.placePosition = transform.position;
                //MultiplayerBuilder.placeRotation = transform.rotation;
                if (flag)
                {
                    MultiplayerBuilder.renderers = MaterialExtensions.AssignMaterial(MultiplayerBuilder.ghostModel, MultiplayerBuilder.ghostStructureMaterial);
                    MultiplayerBuilder.InitBounds(MultiplayerBuilder.ghostModel);
                }
            }
            else
            {
                flag2 = MultiplayerBuilder.CheckAsSubModule();
            }
            if (flag2)
            {
                List <GameObject> list = new List <GameObject>();
                MultiplayerBuilder.GetObstacles(MultiplayerBuilder.placePosition, MultiplayerBuilder.placeRotation, MultiplayerBuilder.bounds, list);
                flag2 = (list.Count == 0);
                list.Clear();
            }
            return(flag2);
        }
        /// <summary>
        /// Clones a <see cref="ModelComponent"/>s <see cref="Material"/> if required;
        /// </summary>
        /// <param name="modelComponent"></param>
        /// <param name="materialIndex"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If <paramref name="modelComponent"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="materialIndex"/> is less than 0 or greater than <see cref="ModelComponent.GetMaterialCount"/> and not in <see cref="ModelComponent.Materials"/>.</exception>
        private static Material GetMaterialCopy(this ModelComponent modelComponent, int materialIndex)
        {
            if (modelComponent == null)
            {
                throw new ArgumentNullException(nameof(modelComponent));
            }

            if (!IsValidMaterialIndex(modelComponent, materialIndex))
            {
                throw new ArgumentOutOfRangeException(nameof(materialIndex));
            }

            var material = modelComponent.GetMaterial(materialIndex);

            if (material is ModelComponentMaterialCopy copy && copy.ModelComponent == modelComponent)
            {
                return(material);
            }

            var materialCopy = new ModelComponentMaterialCopy()
            {
                ModelComponent = modelComponent,
            };

            MaterialExtensions.CopyProperties(material, materialCopy);

            modelComponent.Materials[materialIndex] = materialCopy;

            return(materialCopy);
        }
Beispiel #4
0
        private static void UpdatePosition()
        {
            ConstructableBase componentInParent = ghostModel.GetComponentInParent <ConstructableBase>();

            if (componentInParent != null)
            {
                Transform transform = componentInParent.transform;
                transform.position = PlacePosition;
                transform.rotation = PlaceRotation;

                bool      flag;
                BaseGhost baseGhost = ghostModel.GetComponent <BaseGhost>();
                bool      flag2     = UpdatePlacement(baseGhost, GetAimTransform(), componentInParent.placeMaxDistance, out bool positionFound, out flag, componentInParent);
                componentInParent.SetGhostVisible(positionFound);

                if (flag2 && RotationMetadata.HasValue)
                {
                    ApplyRotationMetadata(baseGhost, RotationMetadata.Value);
                }
                if (flag)
                {
                    renderers = MaterialExtensions.AssignMaterial(ghostModel, ghostStructureMaterial);
                    InitBounds(ghostModel);
                }
            }
            Transform ghostModelTransform = ghostModel.transform;

            ghostModelTransform.position   = PlacePosition + PlaceRotation * ghostModelPosition;
            ghostModelTransform.rotation   = PlaceRotation * ghostModelRotation;
            ghostModelTransform.localScale = ghostModelScale;
        }
Beispiel #5
0
        // Token: 0x060030FC RID: 12540 RVA: 0x0012D3C4 File Offset: 0x0012B5C4
        public static void Update()
        {
            MultiplayerBuilder.Initialize();
            MultiplayerBuilder.canPlace = false;
            if (MultiplayerBuilder.prefab == null)
            {
                return;
            }
            if (MultiplayerBuilder.CreateGhost())
            {
            }
            MultiplayerBuilder.canPlace = MultiplayerBuilder.UpdateAllowed();
            Transform transform = MultiplayerBuilder.ghostModel.transform;

            transform.position   = MultiplayerBuilder.placePosition + MultiplayerBuilder.placeRotation * MultiplayerBuilder.ghostModelPosition;
            transform.rotation   = MultiplayerBuilder.placeRotation * MultiplayerBuilder.ghostModelRotation;
            transform.localScale = MultiplayerBuilder.ghostModelScale;
            Color color = (!MultiplayerBuilder.canPlace) ? MultiplayerBuilder.placeColorDeny : MultiplayerBuilder.placeColorAllow;

            IBuilderGhostModel[] components = MultiplayerBuilder.ghostModel.GetComponents <IBuilderGhostModel>();
            for (int i = 0; i < components.Length; i++)
            {
                components[i].UpdateGhostModelColor(MultiplayerBuilder.canPlace, ref color);
            }
            MaterialExtensions.SetColor(MultiplayerBuilder.renderers, ShaderPropertyID._Tint, color);
        }
        public virtual async Task CreateAsync(
            Material material, string tags, bool isDescriptionEditable = false)
        {
            material.Text = sanitizer.Sanitize(material.Text);

            var(preview, description) = MaterialExtensions.MakePreviewAndDescription(material.Text,
                                                                                     materialsOptions.DescriptionLength,
                                                                                     materialsOptions.PreviewLength);

            material.Preview = preview;

            if (isDescriptionEditable)
            {
                material.Description = SimpleHtmlToText.ClearTags(sanitizer.Sanitize(material.Description));
            }
            else
            {
                material.Description = description;
            }

            using (db.BeginTransaction())
            {
                material.Id = await db.InsertWithInt32IdentityAsync(material);

                await db.Materials.Where(x => x.Id == material.Id).Set(x => x.SortNumber, x => material.Id)
                .UpdateAsync();

                await tagsManager.MaterialCreateAndSetTagsAsync(material, tags);

                db.CommitTransaction();
            }
        }
        static Material defaultMaterial = null; // used RuntimeURDF
        private static void CreateDefaultMaterial()
        {
            Material material = defaultMaterial;

#if UNITY_EDITOR
            if (!RuntimeUrdf.IsRuntimeMode())
            {
                material = RuntimeUrdf.AssetDatabase_LoadAssetAtPath <Material>(UrdfAssetPathHandler.GetMaterialAssetPath(DefaultMaterialName));
            }
#endif
            if (material != null)
            {
                return;
            }

            material = MaterialExtensions.CreateBasicMaterial();
            MaterialExtensions.SetMaterialColor(material, new Color(0.33f, 0.33f, 0.33f, 0.0f));

            // just keep it in memory while the app is running.
            defaultMaterial = material;
#if UNITY_EDITOR
            if (!RuntimeUrdf.IsRuntimeMode())
            {
                // create the material to be reused
                RuntimeUrdf.AssetDatabase_CreateAsset(material, UrdfAssetPathHandler.GetMaterialAssetPath(DefaultMaterialName));
            }
#endif
        }
        private static Material CreateMaterial(this Link.Visual.Material urdfMaterial)
        {
            if (urdfMaterial.name == "")
            {
                urdfMaterial.name = GenerateMaterialName(urdfMaterial);
            }

            var material = RuntimeUrdf.AssetDatabase_LoadAssetAtPath <Material>(UrdfAssetPathHandler.GetMaterialAssetPath(urdfMaterial.name));

            if (material != null)
            {   //material already exists
                return(material);
            }

            material = MaterialExtensions.CreateBasicMaterial();
            if (urdfMaterial.color != null)
            {
                MaterialExtensions.SetMaterialColor(material, CreateColor(urdfMaterial.color));
            }
            else if (urdfMaterial.texture != null)
            {
                material.mainTexture = LoadTexture(urdfMaterial.texture.filename);
            }

            RuntimeUrdf.AssetDatabase_CreateAsset(material, UrdfAssetPathHandler.GetMaterialAssetPath(urdfMaterial.name));
            return(material);
        }
Beispiel #9
0
        public virtual async Task CreateAsync(Material material, string tags, bool isDescriptionEditable = false)
        {
            material.Text = sanitizer.Sanitize(material.Text);

            var(preview, description) = MaterialExtensions.MakePreviewAndDescription(material.Text,
                                                                                     materialsOptions.DescriptionLength,
                                                                                     materialsOptions.PreviewLength);

            material.Preview = preview;

            if (isDescriptionEditable)
            {
                material.Description = SimpleHtmlToText.ClearTags(sanitizer.Sanitize(material.Description));
            }
            else
            {
                material.Description = description;
            }


            /*material.MakePreviewAndDescription(materialsOptions.DescriptionLength,
             *  materialsOptions.PreviewLength);*/

            material.Id = await db.InsertWithInt32IdentityAsync(material);

            await tagsManager.MaterialCreateAndSetTagsAsync(material, tags);
        }
Beispiel #10
0
        public static bool Prefix(ref uGUI_DepthCompass __instance)
        {
            Ocean.DepthClass depthClass = Player.main.GetDepthClass();

            if (__instance._cachedDepthClass != depthClass)
            {
                __instance._cachedDepthClass = depthClass;
                if (__instance._depthMode == uGUI_DepthCompass.DepthMode.Player)
                {
                    __instance.UpdateHalfMoonSprite();
                }
            }
            switch (depthClass)
            {
            case Ocean.DepthClass.Unsafe:
            case Ocean.DepthClass.Crush:
                __instance.shadow.sprite = __instance.shadowDanger;
                MaterialExtensions.SetBlending(__instance.shadow.material, Blending.AlphaBlend, false);
                __instance.depthText.color  = __instance.textColorDanger;
                __instance.suffixText.color = __instance.textColorDanger;
                return(false);
            }
            __instance.shadow.sprite = __instance.shadowNormal;
            MaterialExtensions.SetBlending(__instance.shadow.material, Blending.Multiplicative, true);
            __instance.depthText.color  = __instance.textColorNormal;
            __instance.suffixText.color = __instance.textColorNormal;
            return(false);
        }
Beispiel #11
0
        // Token: 0x06002B9B RID: 11163 RVA: 0x00103EBC File Offset: 0x001020BC
        private static bool CreateGhost()
        {
            if (MultiplayerBuilder.ghostModel != null)
            {
                return(false);
            }

            Constructable component = MultiplayerBuilder.prefab.GetComponent <Constructable>();

            MultiplayerBuilder.constructableTechType   = component.techType;
            MultiplayerBuilder.placeMinDistance        = component.placeMinDistance;
            MultiplayerBuilder.placeMaxDistance        = component.placeMaxDistance;
            MultiplayerBuilder.placeDefaultDistance    = component.placeDefaultDistance;
            MultiplayerBuilder.allowedSurfaceTypes     = component.allowedSurfaceTypes;
            MultiplayerBuilder.forceUpright            = component.forceUpright;
            MultiplayerBuilder.allowedInSub            = component.allowedInSub;
            MultiplayerBuilder.allowedInBase           = component.allowedInBase;
            MultiplayerBuilder.allowedOutside          = component.allowedOutside;
            MultiplayerBuilder.allowedOnConstructables = component.allowedOnConstructables;
            MultiplayerBuilder.rotationEnabled         = component.rotationEnabled;
            ConstructableBase component2 = MultiplayerBuilder.prefab.GetComponent <ConstructableBase>();

            if (component2 != null)
            {
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(MultiplayerBuilder.prefab);
                component2 = gameObject.GetComponent <ConstructableBase>();
                MultiplayerBuilder.ghostModel = component2.model;
                BaseGhost component3 = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>();
                component3.SetupGhost();
                MultiplayerBuilder.ghostModelPosition = Vector3.zero;
                MultiplayerBuilder.ghostModelRotation = Quaternion.identity;
                MultiplayerBuilder.ghostModelScale    = Vector3.one;
                MultiplayerBuilder.renderers          = MaterialExtensions.AssignMaterial(MultiplayerBuilder.ghostModel, MultiplayerBuilder.ghostStructureMaterial);
                MultiplayerBuilder.InitBounds(MultiplayerBuilder.ghostModel);
            }
            else
            {
                MultiplayerBuilder.ghostModel = UnityEngine.Object.Instantiate <GameObject>(component.model);
                MultiplayerBuilder.ghostModel.SetActive(true);
                Transform  component4 = component.GetComponent <Transform>();
                Transform  component5 = component.model.GetComponent <Transform>();
                Quaternion quaternion = Quaternion.Inverse(component4.rotation);
                MultiplayerBuilder.ghostModelPosition = quaternion * (component5.position - component4.position);
                MultiplayerBuilder.ghostModelRotation = quaternion * component5.rotation;
                MultiplayerBuilder.ghostModelScale    = component5.lossyScale;
                Collider[] componentsInChildren = MultiplayerBuilder.ghostModel.GetComponentsInChildren <Collider>();
                for (int i = 0; i < componentsInChildren.Length; i++)
                {
                    UnityEngine.Object.Destroy(componentsInChildren[i]);
                }

                MultiplayerBuilder.renderers = MaterialExtensions.AssignMaterial(MultiplayerBuilder.ghostModel, MultiplayerBuilder.ghostStructureMaterial);
                MultiplayerBuilder.SetupRenderers(MultiplayerBuilder.ghostModel, Player.main.IsInSub());
                MultiplayerBuilder.CreatePowerPreview(MultiplayerBuilder.constructableTechType, MultiplayerBuilder.ghostModel);
                MultiplayerBuilder.InitBounds(MultiplayerBuilder.prefab);
            }

            return(true);
        }
Beispiel #12
0
 /// <summary>
 /// Resets original color of the part being highlighted
 /// </summary>
 /// <param name="index">Index of the part in the Articulation chain</param>
 private void ResetJointColors(int index)
 {
     Renderer[] previousRendererList = articulationChain[index].transform.GetChild(0).GetComponentsInChildren <Renderer>();
     for (int counter = 0; counter < previousRendererList.Length; counter++)
     {
         MaterialExtensions.SetMaterialColor(previousRendererList[counter].material, prevColor[counter]);
     }
 }
Beispiel #13
0
 /// <summary>
 /// Stores original color of the part being highlighted
 /// </summary>
 /// <param name="index">Index of the part in the Articulation chain</param>
 private void StoreJointColors(int index)
 {
     Renderer[] materialLists = articulationChain[index].transform.GetChild(0).GetComponentsInChildren <Renderer>();
     prevColor = new Color[materialLists.Length];
     for (int counter = 0; counter < materialLists.Length; counter++)
     {
         prevColor[counter] = MaterialExtensions.GetMaterialColor(materialLists[counter]);
     }
 }
Beispiel #14
0
        public Material SeedMaterial(Category category, string title, int commentsCount, string firstLine,
                                     string lineElement, LinesCount linesCount)
        {
            var publishDate       = dataContainer.IterateCommentPublishDate();
            int linesCountCurrent = ran.Next(linesCount.Min, linesCount.Max);

            int id = dataContainer.NextMaterialId();

            Material material = new Material
            {
                Id           = id,
                Title        = title,
                Text         = MakeSeedText(lineElement, 8, linesCountCurrent, firstLine),
                AuthorId     = dataContainer.GetRandomUserId(),
                CategoryId   = category.Id,
                PublishDate  = publishDate,
                LastActivity = publishDate,
                SortNumber   = id
            };

            var(preview, description) = MaterialExtensions.MakePreviewAndDescription(material.Text,
                                                                                     MaterialDescriptionLength,
                                                                                     MaterialPreviewLength);

            material.Preview = preview;

            SectionType sectionType = category.GetSectionType();

            if (sectionType != null && sectionType.Name == SectionTypeNames.Articles)
            {
                material.Description = "Описание материала: " + material.Title;
            }
            else
            {
                material.Description = description;
            }


            if (commentsCount > 0)
            {
                IList <Comment> comments = MakeComments(material, commentsCount);

                //Comment last = comments.OrderByDescending(x=>x.PublishDate).First();
                //material.SetLastComment(last);

                material.LastActivity  = comments.OrderByDescending(x => x.PublishDate).First().PublishDate;
                material.CommentsCount = comments.Count;

                dataContainer.Comments.AddRange(comments);
            }

            dataContainer.Materials.Add(material);

            return(material);
        }
Beispiel #15
0
    /// <summary>
    /// Initializes Player components
    /// </summary>
    protected override void Awake()
    {
        base.Awake(); // call parent LightSource Awake() first
        if (playerInstance != null && playerInstance != this)
        {
            GameObject.Destroy(this.gameObject);
        }
        else
        {
            DontDestroyOnLoad(this.gameObject);
            playerInstance = this;
        }

        this.movement    = new PlayerMovement(massEjectionTransform, lightBallPrefab, thrustForce, changeDirectionBoost, thrustEnergyCost, brakeDrag, this.Transform, this.Rigidbody, this.LightEnergy, this.jetFuelEffect, this.rotationSpeed);
        this.lightToggle = new PlayerLightToggle(this.Transform.Find("LightsToToggle").gameObject, defaultLightStatus, this, minimalEnergyRestrictionToggleLights, propulsionLightRange);
        this.materials   = new MaterialExtensions();

        this.defaultDrag      = Rigidbody.drag;
        this.isDead           = false;
        this.isSafe           = true;
        this.controllerRumble = GetComponent <ControllerRumble>();
        playerSound           = GetComponent <PlayerSound>();

        this.currentLevel = SceneManager.GetActiveScene().buildIndex;
        ChangeColor(probeColorOff, false, 0);
        LoadGame();
        ResetPlayerState();

        gameOverCanvas = GameObject.FindWithTag("GameOverCanvas");

        UI = GameObject.FindWithTag("UI");

        if (gameOverCanvas == null)
        {
            Canvas[] canvases = UI.GetComponentsInChildren <Canvas>();
            foreach (Canvas canvas in canvases)
            {
                if (canvas.name == "GameOverCanvas")
                {
                    gameOverCanvas = canvas.gameObject;
                    break;
                }
            }
        }

        #if UNITY_EDITOR
        this.ValidateInputs();
        #endif
    }
Beispiel #16
0
        public EditorSceneElement_EditGadgetInstance_Paintable(EditGadgetInstance g) : base(g)
        {
            brush_now_mesh = new NowMesh(
                MeshExtensions.CreateCircleOutline(0.03f, 32),
                MaterialExtensions.CreateUnlitColorMaterial(Color.black)
                );

            surface_now_mesh = new NowMesh(
                MeshExtensions.CreateCenterQuad(),
                MaterialExtensions.CreateUnlitTransparentTextureMaterial(null)
                );

            last_texture_point = new Vector2();
            line_tool          = new SurfaceTool_Line_Basic_Straight <Color>(0.1f);
        }
Beispiel #17
0
        private static Material GetDefaultDiffuseMaterial()
        {
#if UNITY_EDITOR
            // also save the material in the Assets
            if (!RuntimeUrdf.IsRuntimeMode() && MaterialExtensions.GetRenderPipelineType() == MaterialExtensions.RenderPipelineType.Standard)
            {
                s_DefaultDiffuse = RuntimeUrdf.AssetDatabase_GetBuiltinExtraResource <Material>("Default-Diffuse.mat");
            }
#endif
            if (s_DefaultDiffuse)
            {   // Could't use the "Default-Diffuse.mat", either because of HDRP or runtime. so let's create one.
                s_DefaultDiffuse = MaterialExtensions.CreateBasicMaterial();
            }
            return(s_DefaultDiffuse);
        }
Beispiel #18
0
        private static void CreateGhost()
        {
            Constructable component = prefab.GetComponent <Constructable>();

            constructableTechType = component.techType;
            allowedOutside        = component.allowedOutside;
            ConstructableBase component2 = prefab.GetComponent <ConstructableBase>();

            if (component2 != null)
            {
                GameObject gameObject = Object.Instantiate <GameObject>(prefab);
                component2 = gameObject.GetComponent <ConstructableBase>();
                ghostModel = component2.model;
                BaseGhost component3 = ghostModel.GetComponent <BaseGhost>();
                component3.SetupGhost();
                ghostModelPosition = Vector3.zero;
                ghostModelRotation = Quaternion.identity;
                ghostModelScale    = Vector3.one;
                renderers          = MaterialExtensions.AssignMaterial(ghostModel, ghostStructureMaterial);
                InitBounds(ghostModel);
            }
            else
            {
                ghostModel = Object.Instantiate <GameObject>(component.model);
                ghostModel.SetActive(true);
                Transform  component4 = component.GetComponent <Transform>();
                Transform  component5 = component.model.GetComponent <Transform>();
                Quaternion quaternion = Quaternion.Inverse(component4.rotation);
                ghostModelPosition = quaternion * (component5.position - component4.position);
                ghostModelRotation = quaternion * component5.rotation;
                ghostModelScale    = component5.lossyScale;
                Collider[] componentsInChildren = ghostModel.GetComponentsInChildren <Collider>();
                foreach (Collider collider in componentsInChildren)
                {
                    Object.Destroy(collider);
                }

                renderers = MaterialExtensions.AssignMaterial(ghostModel, ghostStructureMaterial);
                SetupRenderers(ghostModel, Player.main.IsInSub());
                CreatePowerPreview();
                InitBounds(prefab);
            }
        }
Beispiel #19
0
        public static void PlaceBasePiece(GameObject modulePrefab)
        {
            if (ghostModel != null)
            {
                ConstructableBase componentInParent = ghostModel.GetComponentInParent <ConstructableBase>();
                if (componentInParent != null)
                {
                    Object.Destroy(componentInParent.gameObject);
                }

                Object.Destroy(ghostModel);
            }

            prefab          = modulePrefab;
            placementTarget = null;

            CreateGhost();
            UpdatePosition();
            MaterialExtensions.SetColor(renderers, ShaderPropertyID._Tint, placeColorAllow);
        }
Beispiel #20
0
    public void setAlpha(float alpha)
    {
        MeshRenderer[] children = GetComponentsInChildren <MeshRenderer>();
        Color          newColor;

        foreach (MeshRenderer child in children)
        {
            newColor             = child.material.color;
            newColor.a           = alpha;
            child.material.color = newColor;

            if (alpha == 1f)
            {
                MaterialExtensions.ToOpaqueMode(child.material);
            }
            else
            {
                MaterialExtensions.ToFadeMode(child.material);
            }
        }
    }
Beispiel #21
0
        /// <summary>
        /// Highlights the color of the robot by changing the color of the part to a color set by the user in the inspector window
        /// </summary>
        /// <param name="selectedIndex">Index of the link selected in the Articulation Chain</param>
        private void Highlight(int selectedIndex)
        {
            if (selectedIndex == previousIndex || selectedIndex < 0 || selectedIndex >= articulationChain.Length)
            {
                return;
            }

            // reset colors for the previously selected joint
            ResetJointColors(previousIndex);

            // store colors for the current selected joint
            StoreJointColors(selectedIndex);

            DisplaySelectedJoint(selectedIndex);
            Renderer[] rendererList = articulationChain[selectedIndex].transform.GetChild(0).GetComponentsInChildren <Renderer>();

            // set the color of the selected join meshes to the highlight color
            foreach (var mesh in rendererList)
            {
                MaterialExtensions.SetMaterialColor(mesh.material, highLightColor);
            }
        }
Beispiel #22
0
        // Token: 0x06002B9A RID: 11162
        public static void Update()
        {
            MultiplayerBuilder.Initialize();
            MultiplayerBuilder.canPlace = false;
            if (MultiplayerBuilder.prefab == null)
            {
                return;
            }
            if (MultiplayerBuilder.CreateGhost())
            {
                Console.WriteLine("Ghost Created!");
            }
            MultiplayerBuilder.canPlace = MultiplayerBuilder.UpdateAllowed();
            Transform expr_58 = MultiplayerBuilder.ghostModel.transform;

            expr_58.position   = MultiplayerBuilder.placePosition + MultiplayerBuilder.placeRotation * MultiplayerBuilder.ghostModelPosition;
            expr_58.rotation   = MultiplayerBuilder.placeRotation * MultiplayerBuilder.ghostModelRotation;
            expr_58.localScale = MultiplayerBuilder.ghostModelScale;
            Color color = (!MultiplayerBuilder.canPlace) ? MultiplayerBuilder.placeColorDeny : MultiplayerBuilder.placeColorAllow;

            MaterialExtensions.SetColor(MultiplayerBuilder.renderers, ShaderPropertyID._Tint, color);
        }
Beispiel #23
0
    /// <summary>
    /// shows / hides the classes game objects
    /// </summary>
    /// <param name="show">if true objs are shown, otherwise hidden</param>
    /// <param name="alpha">optional transpaceny</param>
    public void SetVisibility(bool show, float alpha = 1)
    {
        _visible = show;
        List <GameObject> models = new List <GameObject>(WheelchairModels);

        foreach (var model in models)
        {
            if (model != null)
            {
                model.SetActive(show);
            }
        }
        models.Add(UpperBody);
        models.Add(Legs);
        // if BioIK is needed for real roboy, only the meshes might need to be disabled, but for now just disable it all
        foreach (var obj in models)
        {
            if (obj == null)
            {
                continue;
            }
            foreach (var r in obj.GetComponentsInChildren <Renderer>())
            {
                r.enabled = show;
                if (alpha < 1)
                {
                    MaterialExtensions.ToFadeMode(r.material);
                }
                else
                {
                    MaterialExtensions.ToOpaqueMode(r.material);
                }
                Color color = r.material.color;
                color.a          = alpha;
                r.material.color = color;
            }
        }
    }
    /// <summary>
    /// Initializes Player components
    /// </summary>
    protected override void Awake()
    {
        base.Awake(); // call parent LightSource Awake() first
        if (playerInstance != null && playerInstance != this)
        {
            GameObject.Destroy(this.gameObject);
        }
        else
        {
            DontDestroyOnLoad(this.gameObject);
            playerInstance =  this;
        }

        this.movement = new PlayerMovement(massEjectionTransform, lightBallPrefab, thrustForce, changeDirectionBoost, thrustEnergyCost, brakeDrag, this.Transform, this.Rigidbody, this.LightEnergy, this.jetFuelEffect, this.rotationSpeed);
        this.lightToggle = new PlayerLightToggle(this.Transform.Find("LightsToToggle").gameObject, defaultLightStatus, this, minimalEnergyRestrictionToggleLights, propulsionLightRange);
        this.materials = new MaterialExtensions();

        this.defaultDrag = Rigidbody.drag;
        this.isDead = false;
        this.isSafe = true;
        this.controllerRumble = GetComponent<ControllerRumble>();
        playerSound = GetComponent<PlayerSound>();

        this.currentLevel = SceneManager.GetActiveScene().buildIndex;
        ChangeColor(probeColorOff, false, 0);
        LoadGame();
        ResetPlayerState();

        gameOverCanvas = GameObject.FindWithTag("GameOverCanvas");

        UI = GameObject.FindWithTag("UI");

        if (gameOverCanvas == null)
        {
            Canvas[] canvases = UI.GetComponentsInChildren<Canvas>();
            foreach (Canvas canvas in canvases)
            {
                if (canvas.name == "GameOverCanvas")
                {
                    gameOverCanvas = canvas.gameObject;
                    break;
                }
            }
        }

        #if UNITY_EDITOR
            this.ValidateInputs();
        #endif
    }
 public void SetMaterialRenderingModeToTransparent()
 {
     MaterialExtensions.ToFadeMode(tree);
     matcolor.a = 0.25f;
     tree.color = matcolor;
 }
 public void SetMaterialRenderingModeToOpaque()
 {
     MaterialExtensions.ToOpaqueMode(tree);
     matcolor.a = 1f;
     tree.color = matcolor;
 }
Beispiel #27
0
        public static bool LateUpdatePrefix(PlaceTool __instance)
        {
            if (__instance.usingPlayer == null || !SnapBuilder.Config.Snapping.Enabled)
            {
                Inventory.main.quickSlots.SetIgnoreHotkeyInput(false);
                return(true);
            }

            Inventory.main.quickSlots.SetIgnoreHotkeyInput(__instance.rotationEnabled && SnapBuilder.Config.ToggleRotation.Enabled);

            Transform  aimTransform = Builder.GetAimTransform();
            RaycastHit hit;
            bool       bHit     = Physics.Raycast(aimTransform.position, aimTransform.forward, out hit, 5f, PlaceTool.placeLayerMask, QueryTriggerInteraction.Ignore);
            Vector3    position = __instance.ghostModel.transform.position;
            Quaternion rotation = __instance.ghostModel.transform.rotation;

            SnapBuilder.ApplyAdditiveRotation(ref __instance.additiveRotation, out var _);

            if (bHit)
            {
                bHit = SnapBuilder.TryGetSnappedHitPoint(PlaceTool.placeLayerMask, out hit, out Vector3 snappedHitPoint, out Vector3 snappedHitNormal);

                if (bHit)
                {
                    position = snappedHitPoint;

                    PlaceTool.SurfaceType surfaceType = PlaceTool.SurfaceType.Floor;
                    if (Mathf.Abs(hit.normal.y) < 0.3f)
                    {
                        surfaceType = PlaceTool.SurfaceType.Wall;
                    }
                    else if (hit.normal.y < 0f)
                    {
                        surfaceType = PlaceTool.SurfaceType.Ceiling;
                    }

                    if (__instance.rotationEnabled)
                    {   // New calculation of the rotation
                        rotation = SnapBuilder.CalculateRotation(ref __instance.additiveRotation, hit, snappedHitPoint, snappedHitNormal, true);
                    }
                    else
                    {   // Calculate rotation in the same manner as the original method
                        Vector3 forward;

                        if (__instance.alignWithSurface || surfaceType == PlaceTool.SurfaceType.Wall)
                        {
                            forward = hit.normal;
                        }
                        else
                        {
                            forward = new Vector3(-aimTransform.forward.x, 0f, -aimTransform.forward.z).normalized;
                        }

                        rotation = Quaternion.LookRotation(forward, Vector3.up);
                        if (__instance.rotationEnabled)
                        {
                            rotation *= Quaternion.AngleAxis(__instance.additiveRotation, Vector3.up);
                        }
                    }

                    switch (surfaceType)
                    {
                    case PlaceTool.SurfaceType.Floor:
                        __instance.validPosition = __instance.allowedOnGround;
                        break;

                    case PlaceTool.SurfaceType.Wall:
                        __instance.validPosition = __instance.allowedOnWalls;
                        break;

                    case PlaceTool.SurfaceType.Ceiling:
                        __instance.validPosition = __instance.allowedOnCeiling;
                        break;
                    }
                }
            }

            if (!bHit)
            {   // If there is no new hit, then the position we're snapping to isn't valid
                position = aimTransform.position + aimTransform.forward * 1.5f;
                rotation = Quaternion.LookRotation(-aimTransform.forward, Vector3.up);
                if (__instance.rotationEnabled)
                {
                    rotation *= Quaternion.AngleAxis(__instance.additiveRotation, Vector3.up);
                }
            }

            __instance.ghostModel.transform.position = position;
            __instance.ghostModel.transform.rotation = rotation;

            if (bHit)
            {
                Rigidbody componentInParent = hit.collider.gameObject.GetComponentInParent <Rigidbody>();
                __instance.validPosition = (__instance.validPosition &&
                                            (componentInParent == null || componentInParent.isKinematic || __instance.allowedOnRigidBody));
            }

            SubRoot currentSub = Player.main.GetCurrentSub();

            bool isInside = Player.main.IsInsideWalkable();

            if (bHit && hit.collider.gameObject.CompareTag("DenyBuilding"))
            {
                __instance.validPosition = false;
            }

#if BELOWZERO
            if (!__instance.allowedUnderwater && hit.point.y < 0)
            {
                __instance.validPosition = false;
            }
#endif

            if (bHit && ((__instance.allowedInBase && isInside) || (__instance.allowedOutside && !isInside)))
            {
                GameObject root = UWE.Utils.GetEntityRoot(hit.collider.gameObject);
                if (!root)
                {
                    SceneObjectIdentifier identifier = hit.collider.GetComponentInParent <SceneObjectIdentifier>();
                    if (identifier)
                    {
                        root = identifier.gameObject;
                    }
                    else
                    {
                        root = hit.collider.gameObject;
                    }
                }

                if (currentSub == null)
                {
                    __instance.validPosition &= Builder.ValidateOutdoor(root);
                }

                if (!__instance.allowedOnConstructable)
                {
                    __instance.validPosition &= root.GetComponentInParent <Constructable>() == null;
                }

                __instance.validPosition &= Builder.CheckSpace(position, rotation, PlaceTool.localBounds, PlaceTool.placeLayerMask, hit.collider);
            }
            else
            {
                __instance.validPosition = false;
            }

            MaterialExtensions.SetColor(__instance.renderers, ShaderPropertyID._Tint,
                                        __instance.validPosition ? PlaceTool.placeColorAllow : PlaceTool.placeColorDeny);
            if (__instance.hideInvalidGhostModel)
            {
                __instance.ghostModel.SetActive(__instance.validPosition);
            }

            return(false);
        }
Beispiel #28
0
        public static GameObject Load(string meshPath, float scaleX = 1, float scaleY = 1, float scaleZ = 1)
        {
#if ASSIMP_SUPPORTED
            if (!File.Exists(meshPath))
            {
                return(null);
            }

            AssimpContext importer = new AssimpContext();
            Scene         scene    = importer.ImportFile(meshPath);
            if (scene == null)
            {
                return(null);
            }

            string parentDir = Directory.GetParent(meshPath).FullName;

            // Materials
            List <UnityEngine.Material> uMaterials = new List <Material>();
            if (scene.HasMaterials)
            {
                foreach (var m in scene.Materials)
                {
                    UnityEngine.Material uMaterial = MaterialExtensions.CreateBasicMaterial();

                    // Albedo
                    if (m.HasColorDiffuse)
                    {
                        Color color = new Color(
                            m.ColorDiffuse.R,
                            m.ColorDiffuse.G,
                            m.ColorDiffuse.B,
                            m.ColorDiffuse.A
                            );
                        MaterialExtensions.SetMaterialColor(uMaterial, color);
                    }

                    // Emission
                    if (m.HasColorEmissive)
                    {
                        Color color = new Color(
                            m.ColorEmissive.R,
                            m.ColorEmissive.G,
                            m.ColorEmissive.B,
                            m.ColorEmissive.A
                            );
                        MaterialExtensions.SetMaterialEmissionColor(uMaterial, color);
                    }

                    // Reflectivity
                    if (m.HasReflectivity)
                    {
                        uMaterial.SetFloat("_Glossiness", m.Reflectivity);
                    }

                    // Texture
                    if (m.HasTextureDiffuse)
                    {
                        Texture2D uTexture    = new Texture2D(2, 2);
                        string    texturePath = Path.Combine(parentDir, m.TextureDiffuse.FilePath);

                        byte[] byteArray = File.ReadAllBytes(texturePath);
                        bool   isLoaded  = uTexture.LoadImage(byteArray);
                        if (!isLoaded)
                        {
                            throw new Exception("Cannot find texture file: " + texturePath);
                        }

                        uMaterial.SetTexture("_MainTex", uTexture);
                    }

                    uMaterials.Add(uMaterial);
                }
            }

            // Mesh
            List <MeshMaterialBinding> uMeshAndMats = new List <MeshMaterialBinding>();
            if (scene.HasMeshes)
            {
                foreach (var m in scene.Meshes)
                {
                    List <Vector3> uVertices = new List <Vector3>();
                    List <Vector3> uNormals  = new List <Vector3>();
                    List <Vector2> uUv       = new List <Vector2>();
                    List <int>     uIndices  = new List <int>();

                    // Vertices
                    if (m.HasVertices)
                    {
                        foreach (var v in m.Vertices)
                        {
                            uVertices.Add(new Vector3(-v.X, v.Y, v.Z));
                        }
                    }

                    // Normals
                    if (m.HasNormals)
                    {
                        foreach (var n in m.Normals)
                        {
                            uNormals.Add(new Vector3(-n.X, n.Y, n.Z));
                        }
                    }

                    // Triangles
                    if (m.HasFaces)
                    {
                        foreach (var f in m.Faces)
                        {
                            // Ignore degenerate faces
                            if (f.IndexCount == 1 || f.IndexCount == 2)
                            {
                                continue;
                            }

                            for (int i = 0; i < (f.IndexCount - 2); i++)
                            {
                                uIndices.Add(f.Indices[i + 2]);
                                uIndices.Add(f.Indices[i + 1]);
                                uIndices.Add(f.Indices[0]);
                            }
                        }
                    }

                    // Uv (texture coordinate)
                    if (m.HasTextureCoords(0))
                    {
                        foreach (var uv in m.TextureCoordinateChannels[0])
                        {
                            uUv.Add(new Vector2(uv.X, uv.Y));
                        }
                    }

                    UnityEngine.Mesh uMesh = new UnityEngine.Mesh();
                    uMesh.vertices  = uVertices.ToArray();
                    uMesh.normals   = uNormals.ToArray();
                    uMesh.triangles = uIndices.ToArray();
                    uMesh.uv        = uUv.ToArray();

                    uMeshAndMats.Add(new MeshMaterialBinding(m.Name, uMesh, uMaterials[m.MaterialIndex]));
                }
            }

            // Create GameObjects from nodes
            GameObject NodeToGameObject(Node node)
            {
                GameObject uOb = new GameObject(node.Name);

                // Set Mesh
                if (node.HasMeshes)
                {
                    foreach (var mIdx in node.MeshIndices)
                    {
                        var uMeshAndMat = uMeshAndMats[mIdx];

                        GameObject uSubOb = new GameObject(uMeshAndMat.MeshName);
                        uSubOb.AddComponent <MeshFilter>();
                        uSubOb.AddComponent <MeshRenderer>();
                        uSubOb.AddComponent <MeshCollider>();

                        uSubOb.GetComponent <MeshFilter>().mesh       = uMeshAndMat.Mesh;
                        uSubOb.GetComponent <MeshRenderer>().material = uMeshAndMat.Material;
                        uSubOb.transform.SetParent(uOb.transform, true);
                        uSubOb.transform.localScale = new Vector3(scaleX, scaleY, scaleZ);
                    }
                }

                // Transform
                // Decompose Assimp transform into scale, rot and translaction
                Assimp.Vector3D   aScale       = new Assimp.Vector3D();
                Assimp.Quaternion aQuat        = new Assimp.Quaternion();
                Assimp.Vector3D   aTranslation = new Assimp.Vector3D();
                node.Transform.Decompose(out aScale, out aQuat, out aTranslation);

                // Convert Assimp transfrom into Unity transform and set transformation of game object
                UnityEngine.Quaternion uQuat = new UnityEngine.Quaternion(aQuat.X, aQuat.Y, aQuat.Z, aQuat.W);
                var euler = uQuat.eulerAngles;

                uOb.transform.localScale    = new UnityEngine.Vector3(aScale.X, aScale.Y, aScale.Z);
                uOb.transform.localPosition = new UnityEngine.Vector3(aTranslation.X, aTranslation.Y, aTranslation.Z);
                uOb.transform.localRotation = UnityEngine.Quaternion.Euler(euler.x, -euler.y, euler.z);

                if (node.HasChildren)
                {
                    foreach (var cn in node.Children)
                    {
                        var uObChild = NodeToGameObject(cn);
                        uObChild.transform.SetParent(uOb.transform, false);
                    }
                }
                return(uOb);
            }

            return(NodeToGameObject(scene.RootNode));;
#else
            Debug.LogError("Runtime import of collada files is not currently supported in builds created with 'IL2CPP' scripting backend." +
                           "\nEither create a build with the scripting backend set as 'Mono' in 'Player Settings' or use STL meshes instead of Collada (dae) meshes.");
            return(null);
#endif
        }