Example #1
0
 static public void ChangeLayer(GameObject go, LayerMaskType layer)
 {
     foreach (Transform trans in go.GetComponentsInChildren <Transform>())
     {
         trans.gameObject.layer = LayerMask.NameToLayer(layer.ToString());
     }
 }
    void MaskField(
        string label,
        Material material,
        string maskTypePropertyName,
        string maskParametersPropertyName,
        string maskAxisPropertyName,
        Vector4[] axisCache,
        Vector4[] parameterCache,
        bool normalMapEnabled)
    {
        EditorGUI.BeginChangeCheck():
        LayerMaskType maskType = (LayerMaskType)AvatarMaterialEditorGUILayout.IntField(label, material, maskTypePropertyName, layerMaskTypeLabels):
        if (EditorGUI.EndChangeCheck())
        {
            material.SetVector(maskAxisPropertyName, axisCache[(int)maskType]):
            material.SetVector(maskParametersPropertyName, parameterCache[(int)maskType]):
        }

        // Show mask-specific controls
        EditorGUI.BeginChangeCheck():
        switch (maskType)
        {
            case LayerMaskType.Positional:
                AvatarMaterialEditorGUILayout.Vector3Field("Axis", material, maskAxisPropertyName):
                AvatarMaterialEditorGUILayout.VectorComponentField("Center distance", material, maskParametersPropertyName, 0):
                AvatarMaterialEditorGUILayout.VectorComponentField("Fade above", material, maskParametersPropertyName, 1):
                AvatarMaterialEditorGUILayout.VectorComponentField("Fade below", material, maskParametersPropertyName, 2):
                break:
            case LayerMaskType.ViewReflection:
                AvatarMaterialEditorGUILayout.Vector3Field("Axis", material, maskAxisPropertyName):
                AvatarMaterialEditorGUILayout.VectorComponentField("Fade begin", material, maskParametersPropertyName, 0):
                AvatarMaterialEditorGUILayout.VectorComponentField("Fade end", material, maskParametersPropertyName, 1):
                if (normalMapEnabled)
                {
                    AvatarMaterialEditorGUILayout.VectorComponentField("Normal map strength", material, maskParametersPropertyName, 2):
                }
                break:
            case LayerMaskType.Fresnel:
                AvatarMaterialEditorGUILayout.VectorComponentField("Power", material, maskParametersPropertyName, 0):
                AvatarMaterialEditorGUILayout.VectorComponentField("Fade begin", material, maskParametersPropertyName, 1):
                AvatarMaterialEditorGUILayout.VectorComponentField("Fade end", material, maskParametersPropertyName, 2):
                if (normalMapEnabled)
                {
                    AvatarMaterialEditorGUILayout.VectorComponentField("Normal map strength", material, maskParametersPropertyName, 3):
                }
                break:
            case LayerMaskType.Pulse:
                AvatarMaterialEditorGUILayout.Vector3Field("Axis", material, maskAxisPropertyName):
                AvatarMaterialEditorGUILayout.VectorComponentField("Pulse distance", material, maskParametersPropertyName, 0):
                AvatarMaterialEditorGUILayout.VectorComponentField("Pulse speed", material, maskParametersPropertyName, 1):
                AvatarMaterialEditorGUILayout.VectorComponentField("Power", material, maskParametersPropertyName, 2):
                break:
        }
        if (EditorGUI.EndChangeCheck())
        {
            parameterCache[(int)maskType] = material.GetVector(maskParametersPropertyName):
            axisCache[(int)maskType] = material.GetVector(maskAxisPropertyName):
        }
    }
Example #3
0
        public static bool CompareLayer(int ly, LayerMaskType flag)
        {
            int layer = LayerMask.NameToLayer(flag.ToString());

            if (ly == layer)
            {
                return(true);
            }
            return(false);
        }
Example #4
0
        static public T InstantiateObject <T>(T prefab, Transform parent, LayerMaskType layer) where T : Transform
        {
            if (prefab == null)
            {
                return(null);
            }

            T clone = InstantiateObject <T>(prefab, parent);

            ChangeLayer(clone.gameObject, layer);
            return(clone);
        }
Example #5
0
    public static int GetLayerMask(LayerMaskType _type)
    {
        int        value = 0;
        List <int> list  = GetLayerList(_type);

        if (list != null)
        {
            foreach (var item in list)
            {
                value += (1 << item);
            }
        }
        return(value);
    }
Example #6
0
        static public Transform[] FindAllTransformByLayer(LayerMaskType layer)
        {
            List <Transform> list = new List <Transform>();

            Transform[] transList = GameObject.FindObjectsOfType(typeof(Transform)) as Transform[];
            int         layerr    = LayerMask.NameToLayer(layer.ToString());

            foreach (Transform trans in transList)
            {
                if (trans.gameObject.layer == layerr)
                {
                    list.Add(trans);
                }
            }
            return(list.ToArray());
        }
Example #7
0
        public static int GetRaycastLayer(params LayerMaskType[] flags)
        {
            if (flags == null || flags.Length == 0)
            {
                return(0);
            }
            int layer = 0;

            for (int i = 0; i < flags.Length; i++)
            {
                LayerMaskType mask = flags[i];
                int           temp = LayerMask.NameToLayer(mask.ToString());
                layer += 1 << temp;
            }
            return(layer);
        }
        /// <summary>
        /// 设置输入的层过滤信息
        /// </summary>
        /// <param name="type"></param>
        private void SetLayerMask(LayerMaskType type)
        {
            switch (type)
            {
            case LayerMaskType.AnchorMark:
                inputManager.layerMask = markLayer;
                break;

            case LayerMaskType.Spacial:
                inputManager.layerMask = SpatialMappingManager.Instance.LayerMask;
                break;

            case LayerMaskType.None:
                inputManager.layerMask = 0;
                break;
            }
        }
Example #9
0
        static public Transform[] FindChildrenByLayer(Transform parent, LayerMaskType layer)
        {
            List <Transform> list = new List <Transform>();

            if (parent != null)
            {
                int layerr = LayerMask.NameToLayer(layer.ToString());

                for (int i = 0; i < parent.childCount; i++)
                {
                    Transform trans = parent.GetChild(i);
                    if (trans.gameObject.layer == layerr)
                    {
                        list.Add(trans);
                    }
                }
            }
            return(list.ToArray());
        }
Example #10
0
        static public Transform FindChildByLayer(Transform parent, LayerMaskType layer)
        {
            if (parent == null)
            {
                return(null);
            }

            int layerr = LayerMask.NameToLayer(layer.ToString());

            for (int i = 0; i < parent.childCount; i++)
            {
                Transform trans = parent.GetChild(i);
                if (trans.gameObject.layer == layerr)
                {
                    return(trans);
                }
            }
            return(null);
        }
Example #11
0
 public LayerAttributes(
     Texture surface,
     Color color,
     LayerMaskType maskType,
     Vector3 maskParameters,
     Vector4 maskAxis,
     LayerSampleMode sampleMode,
     Vector4 sampleParameters,
     LayerBlendMode blendMode
 ) {
     this.surface = surface:
     this.color = color:
     this.maskType = maskType:
     this.maskParameters = maskParameters:
     this.maskAxis = maskAxis:
     this.sampleMode = sampleMode:
     this.sampleParameters = sampleParameters:
     this.blendMode = blendMode:
 }
Example #12
0
    public static List <int> GetLayerList(LayerMaskType _type)
    {
        List <int> list = new List <int>();

        switch (_type)
        {
        case LayerMaskType.None:
            return(list);

        case LayerMaskType.NormalView:
            list.Add(LayerMask.NameToLayer("Default"));
            list.Add(LayerMask.NameToLayer("TransparentFX"));
            list.Add(LayerMask.NameToLayer("Ignore Raycast"));
            list.Add(LayerMask.NameToLayer("Water"));
            list.Add(LayerMask.NameToLayer("Terrain"));
            list.Add(LayerMask.NameToLayer("Player"));
            list.Add(LayerMask.NameToLayer("NPC"));
            list.Add(LayerMask.NameToLayer("Monster"));
            list.Add(LayerMask.NameToLayer("Static"));
            list.Add(LayerMask.NameToLayer("DraggView"));
            list.Add(LayerMask.NameToLayer("Map"));
            list.Add(LayerMask.NameToLayer("NGUI3D"));
            list.Add(LayerMask.NameToLayer("CastShadow"));
            list.Add(LayerMask.NameToLayer("OtherPlayer"));
            list.Add(LayerMask.NameToLayer("DropItem"));
            list.Add(LayerMask.NameToLayer("SceneItem"));
            list.Add(LayerMask.NameToLayer("Entourage"));
            list.Add(LayerMask.NameToLayer("Pet"));
            list.Add(LayerMask.NameToLayer("SceneEffect"));
            return(list);

        case LayerMaskType.SceneAnimView:
            list.Add(LayerMask.NameToLayer("Default"));
            list.Add(LayerMask.NameToLayer("TransparentFX"));
            list.Add(LayerMask.NameToLayer("Ignore Raycast"));
            list.Add(LayerMask.NameToLayer("Water"));
            list.Add(LayerMask.NameToLayer("Terrain"));
            list.Add(LayerMask.NameToLayer("NPC"));
            list.Add(LayerMask.NameToLayer("Monster"));
            list.Add(LayerMask.NameToLayer("Static"));
            list.Add(LayerMask.NameToLayer("DraggView"));
            list.Add(LayerMask.NameToLayer("Map"));
            list.Add(LayerMask.NameToLayer("NGUI3D"));
            list.Add(LayerMask.NameToLayer("CastShadow"));
            list.Add(LayerMask.NameToLayer("CGPlayer"));
            return(list);

        case LayerMaskType.MouseInput:
            list.Add(LayerMask.NameToLayer("Terrain"));
            list.Add(LayerMask.NameToLayer("NPC"));
            list.Add(LayerMask.NameToLayer("Monster"));
            list.Add(LayerMask.NameToLayer("Static"));
            list.Add(LayerMask.NameToLayer("DraggView"));
            list.Add(LayerMask.NameToLayer("NGUI3D"));
            list.Add(LayerMask.NameToLayer("OtherPlayer"));
            list.Add(LayerMask.NameToLayer("DropItem"));
            list.Add(LayerMask.NameToLayer("SceneItem"));
            list.Add(LayerMask.NameToLayer("Entourage"));
            list.Add(LayerMask.NameToLayer("Block"));
            return(list);

        case LayerMaskType.LightCast:
            list.Add(LayerMask.NameToLayer("Terrain"));
            list.Add(LayerMask.NameToLayer("NPC"));
            list.Add(LayerMask.NameToLayer("Monster"));
            list.Add(LayerMask.NameToLayer("OtherPlayer"));
            list.Add(LayerMask.NameToLayer("Entourage"));
            list.Add(LayerMask.NameToLayer("Player"));
            list.Add(LayerMask.NameToLayer("CastShadow"));
            return(list);

        case LayerMaskType.LogicMap:
            list.Add(LayerMask.NameToLayer("Map"));
            return(list);

        case LayerMaskType.ColorMap:
            list.Add(LayerMask.NameToLayer("CastShadow"));
            list.Add(LayerMask.NameToLayer("Grass"));
            list.Add(LayerMask.NameToLayer("Terrain"));
            list.Add(LayerMask.NameToLayer("Default"));
            return(list);

        case LayerMaskType.NGUI:
            list.Add(LayerMask.NameToLayer("NGUI"));
            list.Add(LayerMask.NameToLayer("NGUI3D"));
            list.Add(LayerMask.NameToLayer("UI"));
            return(list);

        case LayerMaskType.SCENE_ITEM:
            list.Add(LayerMask.NameToLayer("SceneItem"));
            return(list);

        case LayerMaskType.BLOCK:
            list.Add(LayerMask.NameToLayer("Block"));
            return(list);

        default:
            return(list);
        }
    }
Example #13
0
        public static int GetRaycastLayer(LayerMaskType flag)
        {
            int layer = LayerMask.NameToLayer(flag.ToString());

            return(1 << layer);
        }