예제 #1
0
        public override void OnInspectorGUI()
        {
            SplineBase spline = (target as SplineBase);

            if (GUILayout.Button("Copy material parameters to layer"))
            {
                Layer      layer           = spline.Layer;
                Material[] sharedMaterials = spline.GetComponent <Renderer>().sharedMaterials;
                for (int i = 0; i < sharedMaterials.Length; ++i)
                {
                    if (!sharedMaterials[i].HasProperty("CMain"))
                    {
                        continue;
                    }
                    layer.mainColor         = sharedMaterials[i].GetColor("CMain");
                    layer.specularColor     = sharedMaterials[i].GetColor("CSpecular");
                    layer.fresnelIntensity  = sharedMaterials[i].GetFloat("CFresnelIntensity");
                    layer.diffuse.tile      = sharedMaterials[i].GetFloat("CDiffuseTile");
                    layer.detail.tile       = sharedMaterials[i].GetFloat("CDetailTile");
                    layer.normal.tile       = sharedMaterials[i].GetFloat("CNormalTile");
                    layer.detailNormal.tile = sharedMaterials[i].GetFloat("CDetailNormalTile");
                    layer.normal.bump       = sharedMaterials[i].GetFloat("CNormalBump");
                    layer.detailNormal.bump = sharedMaterials[i].GetFloat("CDetailNormalBump");
                }
            }
        }
예제 #2
0
        private bool BeginDragSplinePoint()
        {
            Vector3 position;

            if (GetPositionOnDragPlane(ScreenPointToRay(MousePosition), out position))
            {
                Vector3     offset = position - m_dragSpline.GetPointPosition(m_dragPointIndex);
                const float s      = 0.1f;
                if (offset.magnitude > HandleSize(m_beginDragPosition) * s)
                {
                    JunctionBase junction = m_dragSpline.GetJunction(m_dragPointIndex);

                    if (m_dragPointIndex == 0 && junction == null)
                    {
                        m_dragSpline.Prepend(position);

                        GameObject splinePoint = m_dragSpline.GetPoint(0);

                        RegisterCreatedObjectUndo(splinePoint, "BH.S3.Prepend");
                        SetTransformParentUndo(splinePoint.transform, splinePoint.transform.parent, "BH.S3.Prepend");
                    }
                    else if (m_dragPointIndex == m_dragSpline.PointsCount - 1 && junction == null)
                    {
                        m_dragSpline.Append(position);
                        m_dragPointIndex = m_dragSpline.PointsCount - 1;
                        RegisterCreatedObjectUndo(m_dragSpline.GetPoint(m_dragPointIndex), "BH.S3.Append");
                    }
                    else
                    {
                        Vector3 dir;
                        if (m_dragSpline.CurveCount == m_dragPointIndex)
                        {
                            dir = m_dragSpline.GetDirection(1.0f);
                        }
                        else
                        {
                            dir = m_dragSpline.GetDirection(0, m_dragPointIndex);
                        }

                        bool isOut           = Mathf.Sign(Vector3.Dot(offset.normalized, dir)) >= 0;
                        int  connectionIndex = m_dragSpline.CreateBranch(m_dragPointIndex, isOut);

                        junction = m_dragSpline.GetJunction(m_dragPointIndex);

                        m_dragSpline = junction.GetSpline(connectionIndex);
                        RegisterCreatedObjectUndo(m_dragSpline.gameObject, "BH.S3.Branch");

                        if (junction.ConnectionsCount == 2)
                        {
                            m_newJunction = junction;
                            RegisterCreatedObjectUndo(junction.gameObject, "BH.S3.Branch");
                        }

                        m_splines = m_splines.Add(m_dragSpline);

                        SplineRenderer splineRenderer = m_dragSpline.GetComponent <SplineRenderer>();
                        m_splineRenderers = m_splineRenderers.Add(splineRenderer);

                        if (splineRenderer != null)
                        {
                            splineRenderer.IsSelected = true;
                        }

                        m_dragPointIndex = isOut ? 1 : 0;
                    }

                    return(true);
                }
            }
            return(false);
        }