示例#1
0
        public override void OnInspectorGUI()
        {
            serializedObject.ApplyModifiedProperties();

            var newGroundLevelFraction = EditorGUILayout.FloatField("HeightDataGround", terrainCombiner.groundLevelFraction);

            if (newGroundLevelFraction != terrainCombiner.groundLevelFraction)
            {
                terrainCombiner.groundLevelFraction = Mathf.Clamp(newGroundLevelFraction, 0, 1);
                bTriggerUpdate = true;
            }

            if (GUILayout.Button("FORCE COMBINE"))
            {
                bTriggerUpdate = true;
            }

            if (bTriggerUpdate)
            {
                TCWorker.RequestUpdate(terrainCombiner);
                bTriggerUpdate = false;
            }
        }
        void HandleTransformChange()
        {
            // Contraint rotation to y axis
            Quaternion rot = CombinerInstance.transform.localRotation;

            rot = Quaternion.Euler(0, rot.eulerAngles.y, 0);
            CombinerInstance.transform.localRotation = rot;

            bool triggerRebuild = false;

            triggerRebuild |= CombinerInstance.transform.position != lastPosition;
            triggerRebuild |= CombinerInstance.transform.rotation.eulerAngles.y != lastRotation;
            triggerRebuild |= CombinerInstance.transform.localScale != lastScale;
            if (triggerRebuild)
            {
                ParentCombiner.CacheDirty = true;
                TCWorker.RequestUpdate(ParentCombiner);
            }

            lastPosition = CombinerInstance.transform.position;
            lastRotation = CombinerInstance.transform.rotation.eulerAngles.y;
            lastScale    = CombinerInstance.transform.localScale;

            CombinerInstance.position.x = CombinerInstance.transform.localPosition.z / ParentCombiner.WorldSize.z;
            CombinerInstance.position.y = CombinerInstance.transform.localPosition.x / ParentCombiner.WorldSize.x;
            CombinerInstance.rotation   = CombinerInstance.transform.rotation.eulerAngles.y;
            CombinerInstance.size.x     = CombinerInstance.transform.localScale.z;
            CombinerInstance.size.y     = CombinerInstance.transform.localScale.x;


            // Contraint position combiner terrain height
            float   y           = ParentCombiner.WorldSize.y * ParentCombiner.groundLevelFraction;
            Vector3 instancePos = CombinerInstance.transform.localPosition;

            instancePos.y = y;
            CombinerInstance.transform.localPosition = instancePos;
        }