I have an issue using the Rust sdk in Unity (Rust as in Reddit - Dive into anything )
The script the Dev’s provided to upload your creations into the Steam workshop seem to be broken.
using UnityEngine;
using System.Collections.Generic;
[CreateAssetMenu( menuName = "Scriptable Object/Workshop Skin Meta", fileName = "meta.asset" )]
public class WorkshopSkin : WorkshopBase
{
public enum SkinType : int
{
TShirt,
Pants,
SleepingBag,
Hoodie,
LongTShirt,
Cap,
Beenie,
Boots,
Jacket,
Balaclava,
Boonie,
SnowJacket
}
public static string[] itemName =
{
"tshirt",
"pants",
"sleepingbag",
"hoodie",
"tshirt.long",
"hat.cap",
"hat.beenie",
"shoes.boots",
"jacket",
"mask.balaclava",
"hat.boonie",
"jacket.snow"
};
[Header( "Skin Setup" )]
public SkinType skinType;
public Material skinMaterial;
#if UNITY_EDITOR
public override void StartPreview()
{
var oldPreview = GameObject.Find( "PreviewPrefab" );
if ( oldPreview != null )
{
GameObject.DestroyImmediate( oldPreview, true );
}
var prefabName = "Assets/Content/Skinnable/" + skinType.ToString() + "/preview.prefab"; 
var prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>( prefabName );
if ( prefab == null )
{
Debug.LogError( "Couldn't Find: " + prefabName );
return;
}
var pf = GameObject.Instantiate<GameObject>( prefab );
foreach ( var obj in pf.GetComponentsInChildren<Renderer>())
{
if ( !obj.CompareTag( "skin0" ) ) continue;
var mats = obj.sharedMaterials;
mats[0] = skinMaterial;
obj.sharedMaterials = mats;
}
pf.name = "PreviewPrefab";
pf.transform.position = Vector3.zero;
pf.transform.rotation = Quaternion.identity;
}
public override List<string> GetTags()
{
return new List<string>() { "Skin", skinType.ToString() + " Skin" };
}
#endif
}
Doesn’t look like you are actually referencing the corresponding namespace.
using UnityEngine;
using System.Collections.Generic
Not sure which one to use, however right now your project does not know about “CreateAssetMenu”.
Edit: Seems like it should be part of UnityEngine… too early, sorry.
Edit2: Just tried it in a blank project and it works out of the box. There are some more errors in the code according to your screenshot, so it might be good to fix those first to make sure it’s not some kind of compilation chain effect.
Baste
August 24, 2015, 11:01am
3
Are you using Unity 4? The CreateAssetMenu attribute did not exist in Unity 4 - at least it’s not in the docs.
Glockenbeat:
Doesn’t look like you are actually referencing the corresponding namespace.
using UnityEngine;
using System.Collections.Generic
Not sure which one to use, however right now your project does not know about “CreateAssetMenu”.
Edit: Seems like it should be part of UnityEngine… too early, sorry.
Edit2: Just tried it in a blank project and it works out of the box. There are some more errors in the code according to your screenshot, so it might be good to fix those first to make sure it’s not some kind of compilation chain effect.
Thanks, I did try and add using UnityEditor; but then realised the same as you, it’s in Engine.
The other error exists in this .cs
FYI - none of this work is my own, it’s owned by Facepunch and is part of their SDK.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Linq;
public class DuplicateWithReferences : MonoBehaviour
{
[MenuItem( "Assets/Tools/Duplicate With References %#d" )]
private static void DoRun()
{
var path = "";
// Try to work out what folder we're clicking on. This code is from google.
foreach ( UnityEngine.Object obj in Selection.GetFiltered( typeof( UnityEngine.Object ), SelectionMode.Assets ) )
{
path = AssetDatabase.GetAssetPath( obj );
if ( System.IO.File.Exists( path ) )
{
path = System.IO.Path.GetDirectoryName( path );
break;
}
}
// Not a directory - bail
if ( !System.IO.Directory.Exists( path ) )
return;
// Create a "<name> 1" path
var targetPath = AssetDatabase.GenerateUniqueAssetPath( path );
// Do the business
Duplicate( path, targetPath );
EditorUtility.ClearProgressBar();
}
public static void Duplicate( string from, string to )
{
EditorUtility.DisplayProgressBar( "Duplicate With References", "Copying " + from, 0.1f );
AssetDatabase.CopyAsset( from, to );
EditorUtility.ClearProgressBar();
EditorUtility.DisplayProgressBar( "Duplicate With References", "Importing " + to, 0.3f );
AssetDatabase.ImportAsset( to, ImportAssetOptions.ImportRecursive );
EditorUtility.ClearProgressBar();
EditorUtility.DisplayProgressBar( "Duplicate With References", "Fixing References " + to, 0.7f );
FixReferences( from, to );
EditorUtility.ClearProgressBar();
EditorUtility.DisplayProgressBar( "Duplicate With References", "Saving " + to, 1.0f );
AssetDatabase.SaveAssets();
EditorUtility.ClearProgressBar();
EditorUtility.ClearProgressBar();
}
public static void FixReferences( string from, string to )
{
foreach ( var obj in AssetDatabase.FindAssets( "", new[] { to } ).Select( x => AssetDatabase.LoadAssetAtPath<Object>( AssetDatabase.GUIDToAssetPath( x ) ) ) )
{
JoinReferences( from, to, obj );
if ( obj is GameObject )
{
foreach ( var c in ( obj as GameObject ).GetComponentsInChildren<Component>( true ) )
{
JoinReferences( from, to, c );
}
}
}
}
static void FilesRecursive( string folder, System.Action<string> func )
{
foreach ( var file in System.IO.Directory.GetFiles( folder ) )
{
if ( System.IO.Directory.Exists( file ) )
{
FilesRecursive( file, func );
continue;
}
func( file );
}
}
//
// Replace any references to files in Source with Target (same filenames etc)
//
static void JoinReferences( string strSource, string strTarget, Object obj )
{
SerializedObject so = new SerializedObject( obj );
var sp = so.GetIterator();
while ( sp.Next( true ) )
{
if ( sp.propertyType != SerializedPropertyType.ObjectReference ) continue;
if ( sp.objectReferenceValue == null ) continue;
var oldPath = AssetDatabase.GetAssetPath( sp.objectReferenceValue );
if ( !oldPath.StartsWith( strSource, System.StringComparison.InvariantCultureIgnoreCase ) ) continue;
var newPath = oldPath.Replace( strSource, strTarget );
var newObj = AssetDatabase.LoadAssetAtPath( newPath, sp.objectReferenceValue.GetType() );
if ( newObj == null )
continue;
sp.objectReferenceValue = newObj;
}
so.ApplyModifiedProperties();
}
}
I’m using unity 5.0.0f4