又一封神Unity插件SECTR地形优化的代码三段分享

Posted avi9111

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了又一封神Unity插件SECTR地形优化的代码三段分享相关的知识,希望对你有一定的参考价值。

国内其实用这个插件的不错,一是因为太专业,二是因为国内也很多牛人自己写“类似”的

但是一个神作,神奇的地方在于代码几乎一字不需要改,只能全文背诵

首先是,多个镜头“并发”

去掉远处雾显示,让镜头能“看的很远”

PipCamera, 首先是重叠的pip镜头只占1/3 (viewPortW==0.33)

 之后去去掉雾的代码

// Copyright (c) 2014 Make Code Now! LLC

using System;
using UnityEngine;
using System.Collections;

/// \\ingroup Demo
/// Disables fog in the associated camera (for use in the PiP camera).
[RequireComponent(typeof(Camera))]
[ExecuteInEditMode]
public class SECTR_FogDisable : MonoBehaviour

	private bool previousFogState;

	private void OnEnable()
	
		
	

	void OnPreRender()
	
		previousFogState = RenderSettings.fog;
		RenderSettings.fog = false;
	
	
	void OnPostRender()
	
		RenderSettings.fog = previousFogState;            
	

然后,镜头控制

//应该是只能是电脑平台,不支持手机的代码
// Copyright (c) 2014 Make Code Now! LLC

using UnityEngine;
using System.Collections;

/// \\ingroup Demo
/// Implements a standard spectator/fly camera.
/// 
/// Simple class adds movement to the FP Controller base. Useful for 
/// debug cameras and the like.
[AddComponentMenu("Procedural Worlds/SECTR/Demos/SECTR Ghost Controller")]
public class SECTR_GhostController : SECTR_FPController 

	#region Public Interface
	[SECTR_ToolTip("The speed at which to fly through the world.",0.1f,30f)]
	public float FlySpeed = 0.5f;
	[SECTR_ToolTip("The translation acceleration amount applied by keyboard input.")]
	public float AccelerationRatio = 1f;
	[SECTR_ToolTip("The amount by which holding down Ctrl slows you down.")]
	public float SlowDownRatio = 0.5F;
    #endregion

	#region Unity Interface	
	protected override void Update()
	
		base.Update();

	    if(Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
	    
	        FlySpeed *= AccelerationRatio * Time.deltaTime;
	    
	
	    if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
	    
			FlySpeed /= AccelerationRatio * Time.deltaTime;
	    
	
	    if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl))
	    
			FlySpeed *= SlowDownRatio * Time.deltaTime;
	    
	
	    if (Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(KeyCode.RightControl))
	    
			FlySpeed /= SlowDownRatio * Time.deltaTime;
	    

		Vector2 vJoystick;
		if(Input.multiTouchEnabled && !Application.isEditor)
		
			vJoystick = GetScreenJoystick(false);
		
		else
		
			vJoystick = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
		
	
		transform.position += (transform.forward * FlySpeed * Time.deltaTime * vJoystick.y) + (transform.right * FlySpeed * Time.deltaTime * vJoystick.x);
	
	    if (Input.GetKey(KeyCode.E))
	    
			transform.position += transform.up * FlySpeed * Time.deltaTime * 0.5F;
	    
	    else if (Input.GetKey(KeyCode.Q))
	    
			transform.position -= transform.right * FlySpeed * Time.deltaTime * 0.5F;
	    
	
	#endregion

之后,如何通过按键P切换Pip镜头和Main镜头

(真有点举重若轻的感觉)

//非NGUI,也非UGUI,而是自己写了一个状态按钮
protected delegate void DemoButtonPressedDelegate(bool active);

public DemoButtonPressedDelegate demoButtonPressed = null;

//注册方法

demoButtons.Add(new DemoButton(key, activeHint, inactiveHint, buttonPressedDelegate));

//使用代码

//回调的方法:demoButtonPressed 只回传active参数:true|false
demoButton.demoButtonPressed(demoButton.active);

设置,按钮的9级透明度

第四,编辑器扩展

(外国人真的很闲(“不卷”))

以上是关于又一封神Unity插件SECTR地形优化的代码三段分享的主要内容,如果未能解决你的问题,请参考以下文章

Unity地形野外插件_Gaia

Unity 2018 3.0地形优化与新增特性

Unity 2018 3.0地形优化与新增特性

unity软件地形画笔一直在删除

厚积薄发大世界场景优化和加载策略

Unity3D性能优化