Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MrP · Feb 12, 2013 at 11:25 AM · c#javascriptconvertdeclaration

help me converting js to c#

I already converted few things but I still don't know something please help me. I marked the place what I don't know with "??".

Thank you

//JS

 var saved : float[,,];
 private var tData : TerrainData;
 var cratertex : Texture2D;
 var craterData;
 var xRes: int;
 var yRes: int;
 var layers: int;
 
 function Start () 
 {
     tData = Terrain.activeTerrain.terrainData;
     yRes = tData.alphamapHeight;
     xRes = tData.alphamapWidth;
     layers = tData.alphamapLayers;
     craterData = cratertex.GetPixels();
     saved = tData.GetAlphamaps (0, 0, xRes, yRes);
 }
 
 function OnApplicationQuit () 
 {
     tData.SetAlphamaps (0,0,saved);
 }
 
 function Update () 
 {
     if (Input.GetMouseButtonDown(0))
     {
         var g : int = Mathf.Lerp(0, xRes, Mathf.InverseLerp(0, tData.size.x, mouse.mousepos.x));
         var b : int = Mathf.Lerp(0, yRes, Mathf.InverseLerp(0, tData.size.z, mouse.mousepos.z));
         g = Mathf.Clamp(g, cratertex.width/2, xRes-cratertex.width/2);
         b = Mathf.Clamp(b, cratertex.height/2, yRes-cratertex.height/2);
         var area = tData.GetAlphamaps(g-cratertex.width/2, b-cratertex.height/2, cratertex.width, cratertex.height);
         for (x = 0; x < cratertex.height; x++) 
         {
             for (y = 0; y < cratertex.width; y++) 
             {
                 for (z = 0; z < layers; z++)
                 {    
                     if (z == 1)
                     {
                         area [x,y,z] += craterData[x*cratertex.width + y].a;
                     }
                     else
                     {    
                         area [x,y,z] -= craterData[x*cratertex.width + y].a;    
                     }    
                 }
             }
         }
         tData.SetAlphamaps (g-cratertex.width/2,b-cratertex.height/2,area);
     }
 }
 
 



 

//C# using UnityEngine; using System.Collections;

public class texturechanger : MonoBehaviour { float[,,] saved; private TerrainData tData; Texture2D cratertex; ?? craterData; int xRes; int yRes; int layers; public static Vector3 mousepos;

 void  Start ()
 {
     tData = Terrain.activeTerrain.terrainData;
     yRes = tData.alphamapHeight;
     xRes = tData.alphamapWidth;
     layers = tData.alphamapLayers;
     craterData = cratertex.GetPixels();
     saved = tData.GetAlphamaps (0, 0, xRes, yRes);
 }
 
 void  OnApplicationQuit ()
 {
     tData.SetAlphamaps (0,0,saved);
 }
 void  Update ()
 {
     if (Input.GetMouseButtonDown(0))
     {
         int g = Mathf.Lerp(0, xRes, Mathf.InverseLerp(0, tData.size.x, mousepos.x));
         int b = Mathf.Lerp(0, yRes, Mathf.InverseLerp(0, tData.size.z, mousepos.z));
         g = Mathf.Clamp(g, cratertex.width/2, xRes-cratertex.width/2);
         b = Mathf.Clamp(b, cratertex.height/2, yRes-cratertex.height/2);
         ?? area = tData.GetAlphamaps(g-cratertex.width/2, b-cratertex.height/2, cratertex.width, cratertex.height);
         for (int x = 0; x < cratertex.height; ++x) 
         {
             for (int y = 0; y < cratertex.width; ++y) 
             {
                 for (int z = 0; z < layers; ++z)
                 {    
                     if (z == 1)
                     {
                         area [x,y,z] += craterData[x*cratertex.width + y].a;
                     }
                     
                     else
                     {    
                         area [x,y,z] -= craterData[x*cratertex.width + y].a;    
                     }    
                 }
             }
         }
         tData.SetAlphamaps (g-cratertex.width/2,b-cratertex.height/2,area);
     }
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FL · Feb 12, 2013 at 07:14 PM

First ?? = Color[]

Second ?? = float[,,]

I only checked the return values from http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.GetPixels.html and http://docs.unity3d.com/Documentation/ScriptReference/TerrainData.GetAlphamaps.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with conversion from javascript to c# 3 Answers

convert some c# to javascript please 0 Answers

Convert this string formatting from C# to JS 1 Answer

Need help converting Javascript to C# 3 Answers

small example sendmessage from javascript to C# wrong??? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges