Author Topic: Accessing Tenkoku Variables from Code  (Read 6069 times)

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1587
    • View Profile
    • Tanuki Digital
Accessing Tenkoku Variables from Code
« on: April 20, 2015, 12:04:00 PM »
NOTE:Formore in depth information on code access, please take a look at the official documentation pdf here: http://www.tanukidigital.com/tenkoku/documentation

Accessing variables via script is very easy.  All you have to do is cache a reference to the main module and then you can directly edit specific variables from anywhere in your project...

First Reference main module...
Code: [Select]
    private var tenkokuModule : TenkokuModule;
    function Start () {
        tenkokuModule = GameObject.Find("Tenkoku DynamicSky").GetComponent(TenkokuModule) as TenkokuModule;
    }

Then you can access/change any of the time variables...
Code: [Select]
    tenkokuModule.currentYear = 2015;
    tenkokuModule.currentMonth = 3;
    tenkokuModule.currentDay = 21;
    tenkokuModule.currentHour = 7;
    tenkokuModule.currentMinute = 30;
    tenkokuModule.currentSecond =0;

And you can set position variables...
Code: [Select]
    tenkokuModule.setLatitude = 40.2;
    tenkokuModule.setLongitude = 0.0;

And you can set weather variables...
Code: [Select]
    tenkokuModule.weather_cloudAltoStratusAmt = 0.1;
    tenkokuModule.weather_cloudCirrusAmt = 0.2;
    tenkokuModule.weather_cloudCumulusAmt = 0.5;
    tenkokuModule.weather_OvercastAmt = 0.0;
    tenkokuModule.weather_cloudScale = 1.0;
    tenkokuModule.weather_cloudSpeed = 0.2;
    tenkokuModule.weather_RainAmt = 0.0;
    tenkokuModule.weather_SnowAmt = 0.0;
    tenkokuModule.weather_FogAmt = 0.0;
    tenkokuModule.weather_WindAmt = 0.3;
    tenkokuModule.weather_WindDir = 180.0;

Or you can setup and trigger the automatic(random) weather generator...
the below will turn on the auto weather, set the weather pattern to play for 5 minutes, and set the between-pattern transition to about 10 seconds. However it's best to also set a boolean variable (below called randomizePattern) so that you can force a new pattern update when you want to.
Code: [Select]
    tenkokuModule.weatherTypeIndex = 1;
    tenkokuModule.weather_autoForecastTime = 5.0;
    tenkokuModule.weather_TransitionTime = 0.1;
    if (randomizePattern){
         randomizePattern = false;
         tenkokuModule.weather_forceUpdate = true;
    }

You can also set the tracking camera from code...
The below code snippet will allow you to change the currently tacked camera by setting the "useCamera" variable.  This is useful if you need to switch between multiple cameras during your game, or if you instantiate your player/camera from code.
Code: [Select]
    #pragma strict
    var useCamera : Transform;
    private var tenkokuModule : TenkokuModule;
     
    function Start () {
        tenkokuModule = GameObject.Find("Tenkoku DynamicSky").GetComponent(TenkokuModule) as TenkokuModule;
    }
     
    function LateUpdate () {
        if (tenkokuModule != null){
            if (useCamera != null){
                tenkokuModule.mainCamera = useCamera;
            }
        }
    }
« Last Edit: June 04, 2015, 10:11:31 PM by Chingwa »

jet

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Accessing Tenkoku Variables from Code
« Reply #1 on: May 23, 2015, 01:48:52 AM »
I use c#, So accessing with JS code is to difficulty. I don't won't move tenkoku JS code move to standard asset folder for access. let me know another way?

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1587
    • View Profile
    • Tanuki Digital
Re: Accessing Tenkoku Variables from Code
« Reply #2 on: May 23, 2015, 09:10:07 AM »
Hi Jet,

I'm eventually going to be doing a C# conversion, but this is still a few months away at least.  In the meantime I'm sure I can build in better access from C# scripts.... I've had a couple requests for this in the past few days already... and hopefully I'll have a better solution for you soon.  Stay Tuned!

jet

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Accessing Tenkoku Variables from Code
« Reply #3 on: May 25, 2015, 03:25:43 AM »
And I'll try TENKOKU with google cardboard. but It's not working. please check.
Thank.

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1587
    • View Profile
    • Tanuki Digital
Re: Accessing Tenkoku Variables from Code
« Reply #4 on: May 25, 2015, 08:06:45 AM »
Tenkoku isn't developed or supported on mobile platforms.  It may work in some cases, but I would think in general mobile will have issues.

001100

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Accessing Tenkoku Variables from Code
« Reply #5 on: May 28, 2015, 04:12:43 PM »
I've had a couple requests for this in the past few days already... and hopefully I'll have a better solution for you soon.  Stay Tuned!
Cool! You were about to get another request from me too  ;D I tried moving the scripts per some tutorials but that didn't work for me. I'm eagerly waiting for your solution!

munkman

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Accessing Tenkoku Variables from Code
« Reply #6 on: June 01, 2015, 10:57:48 AM »
I also vote for a C# version. The problem is you cannot move Tenkoku into the Standard Assets folder. Tenkoku accesses C# image effects which are in that same folder! I think I have to resort to writing a Javascript that interfaces between my C# classes and Tenkoku.

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1587
    • View Profile
    • Tanuki Digital
Re: Accessing Tenkoku Variables from Code
« Reply #7 on: June 04, 2015, 12:57:45 PM »
Hi munkman,

a C# version will be a bit of a ways off, however the next update will have some functions that give easier access to changing Tenkoku system variables from C#... stay tuned!
« Last Edit: June 04, 2015, 01:04:00 PM by Chingwa »

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1587
    • View Profile
    • Tanuki Digital
Re: Accessing Tenkoku Variables from Code
« Reply #8 on: June 04, 2015, 10:10:12 PM »
OK, there's a new function in version 1.0.4(available now!) that allows you to use SendMessage with Tenkoku variables from C#.  Please take a look at the documentation pdf (page 12) for more information on this.  http://www.tanukidigital.com/tenkoku/documentation

001100

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Accessing Tenkoku Variables from Code
« Reply #9 on: August 25, 2015, 06:11:05 PM »
Hi Chingwa, how can I set the "Sync to system time" and "Sync to system date" options via script? What are the variables?

Also, how about "advance time" variable? And if advance time = 0, that has the same effect as not selecting it, right?

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1587
    • View Profile
    • Tanuki Digital
Re: Accessing Tenkoku Variables from Code
« Reply #10 on: August 27, 2015, 08:54:52 AM »
You can use the the internal boolean variables below:
.autoTimeSync
.autoDateSync

They are set to 'false' by default but you should be able to access them using the same methods described in the docs on code access.

For advancing time, you first need to set the boolean .autoTime variable to 'true', and then you need to set the time compression amount (float) with .timeCompression. a value of 1.0 is equal to realtime and a higher value is a multiplier...2 is twice as fast as realtime.  200 is 200 times as fast as realtime, etc.  You can also do decimal values to slow down to (0.5 for half speed) and can also use negative values to "rewind" time.

001100

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Accessing Tenkoku Variables from Code
« Reply #11 on: August 28, 2015, 07:00:25 PM »
Thanks, Chingwa!

By the way, does "sync time" override the time advance?

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1587
    • View Profile
    • Tanuki Digital
Re: Accessing Tenkoku Variables from Code
« Reply #12 on: August 28, 2015, 08:13:40 PM »
Yes, I believe it should.  Setting the .autoTimeSync variable to true should override the autotime and timecompression.  It essentially just reads the current time from the computer and locks it in step to that.  Same goes for the .autoDateSync.

001100

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Re: Accessing Tenkoku Variables from Code
« Reply #13 on: August 29, 2015, 07:20:46 PM »
Ok, I am using C# so how would I implement those variables into the sendmessage?

tenkokuModule.SendMessage ("Tenkoku_autoTimeSync",true, SendMessageOptions.DontRequireReceiver); ?

Chingwa

  • Administrator
  • Hero Member
  • *****
  • Posts: 1587
    • View Profile
    • Tanuki Digital
Re: Accessing Tenkoku Variables from Code
« Reply #14 on: August 29, 2015, 09:04:08 PM »
Actually you won't be able to access these variables through the SendMessage function.  These particular variables haven't been setup to work with SendMessage, unlike the time/date variables.  I can add these in for the next update.

Otherwise could move the "SCRIPTS" folder into a folder called "Assets/Standard Assets", this should allow you to access the js variables via C# for now.