コード例 #1
0
        void SetRecursiveLayerSmart(GameObject gObject, LayerType layerType, bool isChild = false)
        {
            string layerName = LayerMask.LayerToName(gObject.layer);

            bool isSkinMesh = gObject.TryGetComponent <SkinnedMeshRenderer>(out SkinnedMeshRenderer mesh);

            //
            // SELECT
            //
            if (layerType == LayerType.Selection)
            {
                if (layerName == "Default")
                {
                    if (isChild && !Selection.IsSelected(gObject) && !isSkinMesh)
                    {
                        layerName = "SelectionChild";
                    }
                    else
                    {
                        layerName = "Selection";
                    }
                }
                else if (layerName == "Hover" || layerName == "HoverChild")
                {
                    if (isChild && !Selection.IsSelected(gObject) && !isSkinMesh)
                    {
                        layerName = "SelectionChild";
                    }
                    else
                    {
                        layerName = "Selection";
                    }
                }
                else if (layerName == "CameraHidden")
                {
                    layerName = "SelectionCameraHidden";
                }
                else if (layerName == "HoverCameraHidden")
                {
                    layerName = "SelectionCameraHidden";
                }
            }
            //
            // HOVER
            //
            else if (layerType == LayerType.Hover)
            {
                if (layerName == "Default")
                {
                    if (isChild && !Selection.IsSelected(gObject) && !isSkinMesh)
                    {
                        layerName = "HoverChild";
                    }
                    else
                    {
                        layerName = "Hover";
                    }
                }
                else if (layerName == "Selection" || layerName == "SelectionChild")
                {
                    if (isChild && !Selection.IsSelected(gObject) && !isSkinMesh)
                    {
                        layerName = "HoverChild";
                    }
                    else
                    {
                        layerName = "Hover";
                    }
                }
                else if (layerName == "CameraHidden")
                {
                    layerName = "HoverCameraHidden";
                }
                else if (layerName == "SelectionCameraHidden")
                {
                    layerName = "HoverCameraHidden";
                }
            }
            //
            // RESET layer
            //
            else if (layerType == LayerType.Default)
            {
                if (layerName == "SelectionCameraHidden")
                {
                    layerName = "CameraHidden";
                }
                else if (layerName == "Hover" || layerName == "HoverChild")
                {
                    string parentLayer = "";
                    if (HasParentOrConstraintSelected(gObject.transform, ref parentLayer))
                    {
                        layerName = parentLayer + "Child";
                    }
                    else
                    {
                        layerName = "Default";
                    }
                }
                else if (layerName == "HoverCameraHidden")
                {
                    layerName = "CameraHidden";
                }
                else if (layerName == "Selection" || layerName == "SelectionChild")
                {
                    string parentLayer = "";
                    if (HasParentOrConstraintSelected(gObject.transform, ref parentLayer))
                    {
                        layerName = parentLayer + "Child";
                    }
                    else
                    {
                        layerName = "Default";
                    }
                }
            }

            gObject.layer = LayerMask.NameToLayer(layerName);
            for (int i = 0; i < gObject.transform.childCount; i++)
            {
                SetRecursiveLayerSmart(gObject.transform.GetChild(i).gameObject, layerType, true);
            }

            ParametersController parametersConstroller = gObject.GetComponent <ParametersController>();

            if (null != parametersConstroller)
            {
                foreach (GameObject sourceConstraint in parametersConstroller.constraintHolders)
                {
                    if (!Selection.IsSelected(sourceConstraint))
                    {
                        SetRecursiveLayerSmart(sourceConstraint, layerType, true);
                    }
                }
            }
        }