Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        Debug.Log(QualitySettings.GetQualityLevel().ToString());
        if (QualitySettings.GetQualityLevel() >= 4)
        {
            Debug.Log("CaptureRes: 2048");
            captureResolution = 1024;
        }
        if (QualitySettings.GetQualityLevel() == 5)
        {
            Debug.Log("CaptureAA: 2");
            captureAASetting = 2;
        }
        else if (QualitySettings.GetQualityLevel() > 5)
        {
            Debug.Log("CaptureAA: 4");
            captureAASetting = 1;
        }

        _toolMenu         = GetComponent <ToolMenu>();
        captureCamera     = transform.Find("CaptureCamera").GetComponent <Camera>();
        captureTexture    = new Texture2D(captureResolution, captureResolution, TextureFormat.ARGB32, true);
        captureRenderer   = captureTarget.GetComponent <MeshRenderer>();
        renderTexturePool = new RenderTexture[2];
        for (int i = 0; i < 2; ++i)
        {
            renderTexturePool[i] = new RenderTexture(captureResolution, captureResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
            renderTexturePool[i].antiAliasing = captureAASetting;
            renderTexturePool[i].Create();
        }


        splineTool = new SplineTool(this, _splineRenderTarget, _line, circleCursor);
        splineTool.SetSplineJaggedness(false);
        stampTool  = new StampTool(this, _stampPrefab);
        meterTool  = new MeterTool(this, _line, meterCursor);
        eraserTool = new EraserTool(this, eraserSprite, eraserCursor);


        activeTool = splineTool;
        activeTool.Activate();

        float mapWHratio  = 16.0f / 9.0f;
        int   screenWidth = Screen.width;

        screenWidth -= screenWidth / 20;
        screenWidth  = (int)Mathf.Min(captureResolution * 1.25f, screenWidth);
        int height = (int)(screenWidth / mapWHratio);

        UIImageTransform.sizeDelta = new Vector2(screenWidth, height);

        backups = new Color32[backupCount][];
        for (int i = 0; i < backupCount; ++i)
        {
            backups[i] = new Color32[captureResolution * captureResolution];
        }
    }
Beispiel #2
0
    void Copy()
    {
        //FlowMoveAnimation st = gameObject.GetComponent<FlowMoveAnimation>();
        SplineTool st = gameObject.GetComponent <SplineTool>();

        if (st == null)
        {
            Debug.LogError("this gameobject SplineTool compent is null");
        }
        points = st.points;
    }
Beispiel #3
0
 void Copy()
 {
     st = gameObject.GetComponent <SplineTool>();
     if (st == null)
     {
         Debug.LogError("this gameobject SplineTool compent is null");
     }
     this.mesh  = st.mesh;
     this.mat   = st.mat;
     points     = st.points;
     MeshWidth  = st.MeshWidth;
     Smoothness = st.Smoothness;
 }
Beispiel #4
0
    public override void OnInspectorGUI()
    {
        SplineTool rt = (SplineTool)target;

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Init"))
        {
            string scene = System.IO.Path.GetFileNameWithoutExtension(UnityEditor.EditorApplication.currentScene);
            string str   = scene + GameObject.FindObjectsOfType(typeof(SplineTool)).Length.ToString();
            rt.gameObject.name = str + "_Spline";
            rt.init();
            GameObject p1 = new GameObject("P1");
            p1.transform.parent        = rt.transform;
            p1.transform.localPosition = Vector3.zero;
            GameObject p2 = new GameObject("P2");
            p2.transform.parent        = rt.transform;
            p2.transform.localPosition = Vector3.forward;
            GameObject p3 = new GameObject("P3");
            p3.transform.parent        = rt.transform;
            p3.transform.localPosition = Vector3.forward * 2;
            p1.AddComponent <CurvePoint>();
            p2.AddComponent <CurvePoint>();
            p3.AddComponent <CurvePoint>();
            rt.points.Add(p1);
            rt.points.Add(p2);
            rt.points.Add(p3);
            //rt.gameObject.AddComponent<TextureAnimator>();
            //rt.gameObject.GetComponent<TextureAnimator>().Speed = new Vector2(0.1f, 0);
        }
        if (GUILayout.Button("Delete"))
        {
            DestroyImmediate(rt.gameObject);
            return;
        }
        GUILayout.EndHorizontal();
        if (GUILayout.Button("Add Point"))
        {
            GameObject pn = new GameObject("P" + (rt.points.Count + 1));
            int        c  = rt.points.Count;
            Vector3    p1 = rt.points[c - 1].transform.localPosition;
            Vector3    p2 = rt.points[c - 2].transform.localPosition;
            float      d  = Vector3.Distance(p1, p2);
            pn.transform.parent        = rt.transform;
            pn.transform.localPosition = Vector3.MoveTowards(p1, p2, -d);
            pn.AddComponent <CurvePoint>();
            rt.points.Add(pn);
            //UnityEditor.Selection.activeGameObject = pn;
        }
        if (GUILayout.Button("Fresh Mesh"))
        {
            Debug.Log("Fresh Mesh................");
            Mesh     mesh = new Mesh();
            Material mat  = new Material(Shader.Find("Unlit/Color"));
            mat.name  = rt.gameObject.name + "Mat";
            mesh.name = rt.gameObject.name + "Mesh";
            rt.gameObject.GetComponent <MeshFilter>().sharedMesh       = mesh;
            rt.gameObject.GetComponent <MeshRenderer>().sharedMaterial = mat;
            rt.mat  = mat;
            rt.mesh = mesh;
            rt.points.Clear();
            for (int i = 0; i < rt.transform.childCount; i++)
            {
                rt.points.Add(rt.transform.GetChild(i).gameObject);
            }
            rt.Update();
        }
        if (GUILayout.Button("Create Prefab"))
        {
            string filePath = UnityEditor.EditorUtility.SaveFilePanelInProject("Save Mesh Asset", rt.gameObject.name, "", "");
            if (filePath == "")
            {
                return;
            }
            UnityEditor.AssetDatabase.CreateAsset(rt.mat, filePath + ".mat");
            UnityEditor.AssetDatabase.CreateAsset(rt.mesh, filePath + ".asset");
            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Plane);
            go.transform.position   = rt.gameObject.transform.position;
            go.transform.rotation   = rt.gameObject.transform.rotation;
            go.transform.localScale = rt.gameObject.transform.localScale;
            go.name = rt.gameObject.name;
            go.GetComponent <MeshFilter>().sharedMesh                   = rt.mesh;
            go.GetComponent <MeshRenderer>().sharedMaterial             = rt.mat;
            go.GetComponent <MeshRenderer>().sharedMaterial.mainTexture = rt.mat.mainTexture;
            go.AddComponent <TextureAnimator>();
            //go.GetComponent<TextureAnimator>().Speed = rt.gameObject.GetComponent<TextureAnimator>().Speed;
            DestroyImmediate(go.GetComponent <MeshCollider>());
            UnityEditor.PrefabUtility.CreatePrefab(filePath + ".prefab", go);
            UnityEditor.AssetDatabase.Refresh();
            return;
        }
        DrawDefaultInspector();
    }